Modal dialog that demands an explicit answer
import {AlertDialog} from "@peakui/react";
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>
);
<AlertDialog.Dialog className="rounded-2xl sm:max-w-[420px]">{/* … */}</AlertDialog.Dialog>
@layer components {
.alert-dialog__backdrop {
@apply bg-linear-to-br from-black/50 to-black/70;
}
.alert-dialog__heading {
@apply text-lg;
}
}
PeakUI follows the BEM methodology, so variants and states are plain class names you can target.
The AlertDialog component uses these CSS classes (view source styles):
.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
.alert-dialog__backdrop--opaque - Dimmed backdrop (default)
.alert-dialog__backdrop--blur - Blurred backdrop
.alert-dialog__backdrop--transparent - Transparent backdrop
.alert-dialog__dialog--xs
.alert-dialog__dialog--sm
.alert-dialog__dialog--md
.alert-dialog__dialog--lg
.alert-dialog__dialog--cover - Full height and width
.alert-dialog__icon--default
.alert-dialog__icon--accent
.alert-dialog__icon--success
.alert-dialog__icon--warning
.alert-dialog__icon--danger
[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
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"]
| Prop | Type | Default | Description |
|---|
children | React.ReactNode | - | The trigger element followed by the overlay |
state | UseOverlayStateReturn | - | Overlay state from useOverlayState() |
...rest | DialogTriggerProps | - | React Aria DialogTrigger attributes |
| Prop | Type | Default | Description |
|---|
children | React.ReactNode | - | Non-interactive element to make pressable |
className | string | - | Additional classes |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered <div>; E defaults to 'div' |
...rest | HTMLAttributes | - | The attributes of the rendered element |
| Prop | Type | Default | Description |
|---|
variant | "opaque" | "blur" | "transparent" | "opaque" | Backdrop overlay style |
isDismissable | boolean | false | Close on backdrop interaction |
isKeyboardDismissDisabled | boolean | true | Disable the Escape key |
isOpen | boolean | - | Controlled open state |
defaultOpen | boolean | false | Initially open, without controlling |
onOpenChange | (isOpen: boolean) => void | - | Open state change handler |
UNSTABLE_portalContainer | HTMLElement | - | Custom portal container |
className | string | ((renderProps) => string) | - | Additional classes, or a function of the state |
...rest | ModalOverlayProps | - | React Aria ModalOverlay attributes |
| Prop | Type | Default | Description |
|---|
placement | "auto" | "top" | "center" | "bottom" | "auto" | Position on screen |
size | "xs" | "sm" | "md" | "lg" | "cover" | "md" | Size variant |
className | string | ((renderProps) => string) | - | Additional classes, or a function of the state |
...rest | ModalProps | - | React Aria Modal attributes |
| Prop | Type | Default | Description |
|---|
children | React.ReactNode | (({close}) => React.ReactNode) | - | Content, or a function receiving close |
role | "dialog" | "alertdialog" | "alertdialog" | ARIA role |
aria-label | string | - | Accessible name when no AlertDialog.Heading is present |
aria-labelledby | string | - | ID of the labelling element; set from AlertDialog.Heading |
aria-describedby | string | - | ID of the describing element |
className | string | - | Additional classes |
...rest | DialogProps | - | React Aria Dialog attributes |
| Prop | Type | Default | Description |
|---|
children | React.ReactNode | - | Header content |
className | string | - | Additional classes |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered <div>; E defaults to 'div' |
...rest | HTMLAttributes | - | The attributes of the rendered element |
| Prop | Type | Default | Description |
|---|
status | "default" | "accent" | "success" | "warning" | "danger" | "danger" | Tint, and the default icon when children is empty |
children | React.ReactNode | - | Custom icon |
className | string | - | Additional classes |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered <div>; E defaults to 'div' |
...rest | HTMLAttributes | - | The attributes of the rendered element |
| Prop | Type | Default | Description |
|---|
children | React.ReactNode | - | Heading text; labels the dialog via aria-labelledby |
className | string | - | Additional classes |
...rest | HeadingProps | - | React Aria Heading attributes |
| Prop | Type | Default | Description |
|---|
children | React.ReactNode | - | Body content |
className | string | - | Additional classes |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered <div>; E defaults to 'div' |
...rest | HTMLAttributes | - | The attributes of the rendered element |
| Prop | Type | Default | Description |
|---|
children | React.ReactNode | - | Footer content, usually buttons |
className | string | - | Additional classes |
render | DOMRenderFunction<E, undefined> | - | Replaces the rendered <div>; E defaults to 'div' |
...rest | HTMLAttributes | - | The attributes of the rendered element |
| Prop | Type | Default | Description |
|---|
children | React.ReactNode | - | Custom close button content; defaults to the cross glyph |
className | string | ((renderProps) => string) | - | Additional classes, or a function of the state |
...rest | ButtonProps | - | React Aria Button attributes; slot defaults to "close" |
| Prop | Type | Description |
|---|
AlertDialog.Backdrop className | (renderProps: ModalOverlayRenderProps) => string | Computes classes from isEntering, isExiting and state |
AlertDialog.Container className | (renderProps: ModalRenderProps) => string | Computes classes from isEntering, isExiting and state |
AlertDialog.Dialog children | (opts: {close: () => void}) => React.ReactNode | Renders content with a callback that closes the dialog |