PeakUI

AlertDialog

Modal dialog that demands an explicit answer

Usage

import {AlertDialog} from "@peakui/react";

Anatomy

import {AlertDialog, Button} from "@peakui/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

Placements

Sizes

Backdrop Variants

Custom Icon

Dismiss Behavior

Controlled State

Custom Trigger

Customization

Tailwind CSS

<AlertDialog.Dialog className="rounded-2xl sm:max-w-[420px]">{/* … */}</AlertDialog.Dialog>

Global CSS

@layer components {
  .alert-dialog__backdrop {
    @apply bg-linear-to-br from-black/50 to-black/70;
  }

  .alert-dialog__heading {
    @apply text-lg;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The AlertDialog component uses these CSS classes (view source styles):

Element Classes

  • .alert-dialog__trigger - Trigger element that opens the dialog
  • .alert-dialog__backdrop - Overlay behind the dialog
  • .alert-dialog__container - Positioning wrapper with placement support
  • .alert-dialog__dialog - Dialog content container
  • .alert-dialog__header - Header section for the icon and heading
  • .alert-dialog__heading - Heading element
  • .alert-dialog__icon - Status icon indicator
  • .alert-dialog__body - Main content area
  • .alert-dialog__footer - Footer section for actions
  • .alert-dialog__close-trigger - Close button position

Backdrop Variant Classes

  • .alert-dialog__backdrop--opaque - Dimmed backdrop (default)
  • .alert-dialog__backdrop--blur - Blurred backdrop
  • .alert-dialog__backdrop--transparent - Transparent backdrop

Size Classes

  • .alert-dialog__dialog--xs
  • .alert-dialog__dialog--sm
  • .alert-dialog__dialog--md
  • .alert-dialog__dialog--lg
  • .alert-dialog__dialog--cover - Full height and width

Status Classes

  • .alert-dialog__icon--default
  • .alert-dialog__icon--accent
  • .alert-dialog__icon--success
  • .alert-dialog__icon--warning
  • .alert-dialog__icon--danger

Slots

  • [data-slot="alert-dialog-trigger"] - The AlertDialog.Trigger element
  • [data-slot="alert-dialog-backdrop"] - The AlertDialog.Backdrop overlay
  • [data-slot="alert-dialog-container"] - The AlertDialog.Container wrapper
  • [data-slot="alert-dialog-dialog"] - The AlertDialog.Dialog element
  • [data-slot="alert-dialog-header"] - The AlertDialog.Header element
  • [data-slot="alert-dialog-icon"] - The AlertDialog.Icon element
  • [data-slot="alert-dialog-default-icon"] - The icon rendered when AlertDialog.Icon has no children
  • [data-slot="alert-dialog-heading"] - The AlertDialog.Heading element
  • [data-slot="alert-dialog-body"] - The AlertDialog.Body element
  • [data-slot="alert-dialog-footer"] - The AlertDialog.Footer element
  • [data-slot="alert-dialog-close-trigger"] - The AlertDialog.CloseTrigger element

Interactive States

The overlay parts carry React Aria animation states:

  • Entering: [data-entering="true"]
  • Exiting: [data-exiting="true"]
  • Placement: [data-placement="auto | top | center | bottom"] on container and dialog

The trigger supports both pseudo-classes and data attributes:

  • Focus: :focus-visible or [data-focus-visible="true"]
  • Disabled: :disabled or [aria-disabled="true"]
  • Pressed: :active or [data-pressed="true"]

API Reference

AlertDialog

PropTypeDefaultDescription
childrenReact.ReactNode-The trigger element followed by the overlay
stateUseOverlayStateReturn-Overlay state from useOverlayState()
...restDialogTriggerProps-React Aria DialogTrigger attributes

AlertDialog.Trigger

PropTypeDefaultDescription
childrenReact.ReactNode-Non-interactive element to make pressable
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

AlertDialog.Backdrop

PropTypeDefaultDescription
variant"opaque" | "blur" | "transparent""opaque"Backdrop overlay style
isDismissablebooleanfalseClose on backdrop interaction
isKeyboardDismissDisabledbooleantrueDisable the Escape key
isOpenboolean-Controlled open state
defaultOpenbooleanfalseInitially open, without controlling
onOpenChange(isOpen: boolean) => void-Open state change handler
UNSTABLE_portalContainerHTMLElement-Custom portal container
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restModalOverlayProps-React Aria ModalOverlay attributes

AlertDialog.Container

PropTypeDefaultDescription
placement"auto" | "top" | "center" | "bottom""auto"Position on screen
size"xs" | "sm" | "md" | "lg" | "cover""md"Size variant
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restModalProps-React Aria Modal attributes

AlertDialog.Dialog

PropTypeDefaultDescription
childrenReact.ReactNode | (({close}) => React.ReactNode)-Content, or a function receiving close
role"dialog" | "alertdialog""alertdialog"ARIA role
aria-labelstring-Accessible name when no AlertDialog.Heading is present
aria-labelledbystring-ID of the labelling element; set from AlertDialog.Heading
aria-describedbystring-ID of the describing element
classNamestring-Additional classes
...restDialogProps-React Aria Dialog attributes

AlertDialog.Header

PropTypeDefaultDescription
childrenReact.ReactNode-Header content
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

AlertDialog.Icon

PropTypeDefaultDescription
status"default" | "accent" | "success" | "warning" | "danger""danger"Tint, and the default icon when children is empty
childrenReact.ReactNode-Custom icon
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

AlertDialog.Heading

PropTypeDefaultDescription
childrenReact.ReactNode-Heading text; labels the dialog via aria-labelledby
classNamestring-Additional classes
...restHeadingProps-React Aria Heading attributes

AlertDialog.Body

PropTypeDefaultDescription
childrenReact.ReactNode-Body content
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

AlertDialog.Footer

PropTypeDefaultDescription
childrenReact.ReactNode-Footer content, usually buttons
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered <div>; E defaults to 'div'
...restHTMLAttributes-The attributes of the rendered element

AlertDialog.CloseTrigger

PropTypeDefaultDescription
childrenReact.ReactNode-Custom close button content; defaults to the cross glyph
classNamestring | ((renderProps) => string)-Additional classes, or a function of the state
...restButtonProps-React Aria Button attributes; slot defaults to "close"

Render Props

PropTypeDescription
AlertDialog.Backdrop className(renderProps: ModalOverlayRenderProps) => stringComputes classes from isEntering, isExiting and state
AlertDialog.Container className(renderProps: ModalRenderProps) => stringComputes classes from isEntering, isExiting and state
AlertDialog.Dialog children(opts: {close: () => void}) => React.ReactNodeRenders content with a callback that closes the dialog

On this page