본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

AlertDialog

원문 보기 위키 갱신

사용자의 주의와 명시적인 액션이 필요한 중요한 확인을 위한 모달 다이얼로그예요.

출처: HeroUI AlertDialog

본문

사용법 (Usage)

import { AlertDialog } from "@heroui/react";
{"component": "alert-dialog-default"}

구조 (Anatomy)

import {AlertDialog, Button} from "@heroui/react";

export default () => (
  <AlertDialog>
    <Button>Open Alert Dialog</Button>
    <AlertDialog.Backdrop>
      <AlertDialog.Container>
        <AlertDialog.Dialog>
          <AlertDialog.CloseTrigger /> {/* Optional: Close button */}
          <AlertDialog.Header>
            <AlertDialog.Icon /> {/* Optional: Status icon */}
            <AlertDialog.Heading />
          </AlertDialog.Header>
          <AlertDialog.Body />
          <AlertDialog.Footer />
        </AlertDialog.Dialog>
      </AlertDialog.Container>
    </AlertDialog.Backdrop>
  </AlertDialog>
);

예시 (Examples)

상태 (Statuses)

{"component": "alert-dialog-statuses"}

배치 (Placements)

{"component": "alert-dialog-placements"}

크기 (Sizes)

{"component": "alert-dialog-sizes"}

제어 상태 (Controlled State)

{"component": "alert-dialog-controlled"}

커스텀 아이콘 (Custom Icon)

{"component": "alert-dialog-custom-icon"}

커스텀 트리거 (Custom Trigger)

{"component": "alert-dialog-custom-trigger"}

백드롭 변형 (Backdrop Variants)

{"component": "alert-dialog-backdrop-variants"}

커스텀 백드롭 (Custom Backdrop)

{"component": "alert-dialog-custom-backdrop"}

닫기 동작 (Dismiss Behavior)

{"component": "alert-dialog-dismiss-behavior"}

닫기 방법 (Close Methods)

{"component": "alert-dialog-close-methods"}

커스텀 애니메이션 (Custom Animations)

{"component": "alert-dialog-custom-animations"}

커스텀 포털 (Custom Portal)

{"component": "alert-dialog-custom-portal"}

커스터마이징 (Customization)

Tailwind CSS

{"component": "alert-dialog-custom-styles"}

전역 CSS (Global CSS)

AlertDialog 컴포넌트 클래스를 커스터마이징하려면 @layer components 디렉티브를 사용하세요.

자세히 알아보기.

@layer components {
  .alert-dialog__backdrop {
    @apply bg-gradient-to-br from-black/60 to-black/80;
  }

  .alert-dialog__dialog {
    @apply rounded-2xl border border-red-500/20 shadow-2xl;
  }

  .alert-dialog__header {
    @apply gap-4;
  }

  .alert-dialog__icon {
    @apply size-16;
  }

  .alert-dialog__close-trigger {
    @apply rounded-full bg-white/10 hover:bg-white/20;
  }
}

스타일링 참고 (Styling Reference)

HeroUI는 BEM 방법론을 따라 컴포넌트 변형과 상태를 재사용하고 커스터마이징하기 쉽게 만들어요.

CSS 클래스 (CSS Classes)

AlertDialog 컴포넌트는 다음 CSS 클래스를 사용해요 (소스 스타일 보기):

기본 클래스 [!toc]

  • .alert-dialog__trigger - 알림 다이얼로그를 여는 트리거 요소
  • .alert-dialog__backdrop - 다이얼로그 뒤의 오버레이 백드롭
  • .alert-dialog__container - 배치 지원이 있는 포지셔닝 래퍼
  • .alert-dialog__dialog - 다이얼로그 콘텐츠 컨테이너
  • .alert-dialog__header - 아이콘과 제목을 위한 헤더 섹션
  • .alert-dialog__heading - 제목 텍스트 스타일
  • .alert-dialog__body - 주요 콘텐츠 영역
  • .alert-dialog__footer - 액션을 위한 푸터 섹션
  • .alert-dialog__icon - 상태 색상이 있는 아이콘 컨테이너
  • .alert-dialog__close-trigger - 닫기 버튼 요소

백드롭 변형 [!toc]

  • .alert-dialog__backdrop--opaque - 불투명한 색상의 백드롭 (기본값)
  • .alert-dialog__backdrop--blur - 유리 효과가 있는 흐림(blur) 백드롭
  • .alert-dialog__backdrop--transparent - 투명한 백드롭 (오버레이 없음)

상태 변형 (아이콘) [!toc]

  • .alert-dialog__icon--default - 기본 회색 상태
  • .alert-dialog__icon--accent - 강조 파란색 상태
  • .alert-dialog__icon--success - 성공 녹색 상태
  • .alert-dialog__icon--warning - 경고 주황색 상태
  • .alert-dialog__icon--danger - 위험 빨간색 상태

인터랙티브 상태 (Interactive States)

컴포넌트는 다음 인터랙티브 상태를 지원해요:

  • 포커스: :focus-visible 또는 [data-focus-visible="true"] - 트리거, 다이얼로그, 닫기 버튼에 적용
  • 호버: :hover 또는 [data-hovered="true"] - 닫기 버튼 호버 시 적용
  • 활성: :active 또는 [data-pressed="true"] - 닫기 버튼을 누를 때 적용
  • 진입 중: [data-entering] - 다이얼로그 열기 애니메이션 중 적용
  • 종료 중: [data-exiting] - 다이얼로그 닫기 애니메이션 중 적용
  • 배치: [data-placement="*"] - 다이얼로그 위치(auto, top, center, bottom)에 따라 적용

API 참고 (API Reference)

AlertDialog

Prop Type Default Description
children ReactNode - Trigger and container elements

AlertDialog.Trigger

Prop Type Default Description
children ReactNode - Custom trigger content
className string - CSS classes

AlertDialog.Backdrop

Prop Type Default Description
variant "opaque" | "blur" | "transparent" "opaque" Backdrop overlay style
isDismissable boolean false Close on backdrop click
isKeyboardDismissDisabled boolean true Disable ESC key to close
isOpen boolean - Controlled open state
onOpenChange (isOpen: boolean) => void - Open state change handler
className string | (values) => string - Backdrop CSS classes
UNSTABLE_portalContainer HTMLElement - Custom portal container

AlertDialog.Container

Prop Type Default Description
placement "auto" | "center" | "top" | "bottom" "auto" Dialog position on screen
size "xs" | "sm" | "md" | "lg" | "cover" "md" Alert Dialog size variant
className string | (values) => string - Container CSS classes

AlertDialog.Dialog

Prop Type Default Description
children ReactNode | ({close}) => ReactNode - Content or render function
className string - CSS classes
role string "alertdialog" ARIA role
aria-label string - Accessibility label
aria-labelledby string - ID of label element
aria-describedby string - ID of description element

AlertDialog.Header

Prop Type Default Description
children ReactNode - Header content (typically Icon and Heading)
className string - CSS classes

AlertDialog.Heading

Prop Type Default Description
children ReactNode - Heading text
className string - CSS classes

AlertDialog.Body

Prop Type Default Description
children ReactNode - Body content
className string - CSS classes

AlertDialog.Footer

Prop Type Default Description
children ReactNode - Footer content (typically action buttons)
className string - CSS classes

AlertDialog.Icon

Prop Type Default Description
children ReactNode - Custom icon element
status "default" | "accent" | "success" | "warning" | "danger" "danger" Status color variant
className string - CSS classes

AlertDialog.CloseTrigger

Prop Type Default Description
children ReactNode - Custom close button
className string | (values) => string - CSS classes

useOverlayState 훅 (Hook)

import {useOverlayState} from "@heroui/react";

const state = useOverlayState({
  defaultOpen: false,
  onOpenChange: (isOpen) => console.log(isOpen),
});

state.isOpen; // Current state
state.open(); // Open dialog
state.close(); // Close dialog
state.toggle(); // Toggle state
state.setOpen(); // Set state directly

접근성 (Accessibility)

WAI-ARIA AlertDialog 패턴을 구현해요:

  • 포커스 트랩: 포커스가 알림 다이얼로그 안에 고정돼요
  • 키보드: ESC 닫기 (활성화 시), Tab 으로 요소 순환
  • 스크린 리더: role="alertdialog" 와 함께 올바른 ARIA 속성
  • 스크롤 잠금: 열려 있을 때 본문 스크롤이 비활성화돼요
  • 필수 액션: 기본적으로 명시적인 사용자 액션을 요구해요 (백드롭/ESC 닫기 없음)

더 알아보기 (Learn more)