Skip to content
Docs
컴포넌트로 돌아가기

ConfirmModal

@hua-labs/ui
v1.1.0

다양한 타입, 선택적 입력 검증, 로딩 상태를 지원하는 확인 모달 컴포넌트입니다.

설치

bash
npm install @hua-labs/hua
Import
tsx
import { ConfirmModal } from "@hua-labs/hua";

@hua-labs/ui의 UI 컴포넌트를 @hua-labs/hua에서 통합 제공합니다.

UI 컴포넌트, 모션 훅, i18n을 하나의 패키지로 사용할 수 있습니다.

라이브 데모

타입별 모달

입력 확인 필요

로딩 상태

Props

이름타입기본값설명
isOpen*boolean-모달 열림 상태
onClose*() => void-닫기 콜백
onConfirm*() => void-확인 콜백
title*string-모달 제목
message*string-모달 메시지
type"danger" | "warning" | "info" | "success" | "error""danger"모달 타입 (아이콘 및 버튼 색상에 영향)
warningstring-추가 경고 메시지
confirmTextstring"확인"확인 버튼 텍스트
cancelTextstring"취소"취소 버튼 텍스트
loadingbooleanfalse로딩 상태 표시
showInputbooleanfalse확인용 입력 필드 표시
size"sm" | "md" | "lg" | "xl" | "2xl""md"Modal size
confirmButtonTextstring-Confirm button text (alias for confirmText)
disabledbooleanfalseDisable confirm button
showCancelbooleantrueShow cancel button
inputValuestring-Input value when showInput is true
onInputChange(value: string) => void-Input change handler
inputPlaceholderstring-Input placeholder text
inputLabelstring-Input label text
requiredInputValuestring-확인 버튼 활성화를 위한 필수 입력 값

코드 예시

기본 사용법tsx
1// Via framework (recommended)
2import { ConfirmModal } from '@hua-labs/ui';
3import { Button } from '@hua-labs/ui';
4// Or direct import
5// import { ConfirmModal } from '@hua-labs/ui/overlay';
6import { useState } from 'react';
7 
8const [isOpen, setIsOpen] = useState(false);
9 
10<Button onClick={() => setIsOpen(true)}>Delete</Button>
11 
12<ConfirmModal
13 isOpen={isOpen}
14 onClose={() => setIsOpen(false)}
15 onConfirm={() => {
16 console.log('Confirmed!');
17 setIsOpen(false);
18 }}
19 title="Delete Item"
20 message="Are you sure you want to delete this item?"
21/>
경고tsx
1<ConfirmModal
2 isOpen={isOpen}
3 onClose={() => setIsOpen(false)}
4 onConfirm={handleConfirm}
5 type="warning"
6 title="Warning"
7 message="This action may affect other items."
8 warning="Proceed with caution."
9/>
입력 확인 필요tsx
1const [inputValue, setInputValue] = useState('');
2 
3<ConfirmModal
4 isOpen={isOpen}
5 onClose={() => setIsOpen(false)}
6 onConfirm={handleDelete}
7 title="Delete Account"
8 message="Type 'DELETE' to confirm."
9 showInput
10 inputLabel="Confirmation"
11 inputPlaceholder="Type DELETE"
12 requiredInputValue="DELETE"
13 inputValue={inputValue}
14 onInputChange={setInputValue}
15/>
로딩 상태tsx
1const [isLoading, setIsLoading] = useState(false);
2 
3<ConfirmModal
4 isOpen={isOpen}
5 onClose={() => setIsOpen(false)}
6 onConfirm={async () => {
7 setIsLoading(true);
8 await performAction();
9 setIsLoading(false);
10 setIsOpen(false);
11 }}
12 title="Processing"
13 message="Please wait..."
14 loading={isLoading}
15/>

타입별 용도

  • danger - 삭제, 되돌릴 수 없는 작업
  • warning - 주의가 필요한 작업
  • info - 정보 확인, 일반 확인
  • success - 성공 확인, 완료 확인
  • error - 에러 확인

접근성

  • 포커스 트랩: 모달 내부에 포커스가 유지됩니다
  • ESC 키: ESC 키로 모달 닫기
  • 입력 검증: 올바른 입력 전까지 확인 버튼 비활성화