Modal dialog for critical confirmations requiring user attention and explicit action
import { AlertDialog } from "@darkcode-ui/react" ;
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
export function Default () { Expand code
Import the AlertDialog component and access all parts using dot notation.
import {AlertDialog, Button} from "@darkcode-ui/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 >
);
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
export function Statuses () { Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
export function Placements () { Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
export function BackdropVariants () { Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
import {Rocket} from "@gravity-ui/icons" ;
Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
import {LockOpen} from "@gravity-ui/icons" ;
Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
import {TriangleExclamation} from "@gravity-ui/icons" ;
Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
import {CircleInfo} from "@gravity-ui/icons" ;
Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
export function CloseMethods () { Expand code
"use client" ;
import {AlertDialog, Button, useOverlayState} from "@darkcode-ui/react" ;
import React from "react" ;
Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
import {TrashBin} from "@gravity-ui/icons" ;
Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
import {ArrowUpFromLine, Sparkles} from "@gravity-ui/icons" ;
import React from "react" ; Expand code
"use client" ;
import {AlertDialog, Button} from "@darkcode-ui/react" ;
import {useCallback, useRef, useState} from "react" ;
Expand code
import {AlertDialog, Button} from "@darkcode-ui/react" ;
function CustomAlertDialog () {
return (
< AlertDialog >
< Button variant = "danger" >Delete</ Button >
< AlertDialog.Backdrop className = "bg-red-950/90" >
< AlertDialog.Container className = "items-start pt-20" >
< AlertDialog.Dialog className = "border-2 border-red-500 sm:max-w-[400px]" >
< AlertDialog.CloseTrigger />
< AlertDialog.Header >
< AlertDialog.Icon status = "danger" />
< AlertDialog.Heading >Custom Styled Alert</ AlertDialog.Heading >
</ AlertDialog.Header >
< AlertDialog.Body >
< p >This alert dialog has custom styling applied via Tailwind classes</ p >
</ AlertDialog.Body >
< AlertDialog.Footer >
< Button slot = "close" variant = "tertiary" >
Cancel
</ Button >
< Button slot = "close" variant = "danger" >
Delete
</ Button >
</ AlertDialog.Footer >
</ AlertDialog.Dialog >
</ AlertDialog.Container >
</ AlertDialog.Backdrop >
</ AlertDialog >
);
}
To customize the AlertDialog component classes, you can use the @layer components directive.
Learn more .
@layer components {
.alert-dialog__backdrop {
@ apply bg-gradient-to-br from-black /60 to-black /80;
}
.alert-dialog__dialog {
@ apply rounded- 2 xl border border-red- 500/20 shadow- 2 xl ;
}
.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 ;
}
}
DarkCode UI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
The AlertDialog component uses these CSS classes (View source styles ):
.alert-dialog__trigger - Trigger element that opens the alert dialog
.alert-dialog__backdrop - Overlay backdrop behind the dialog
.alert-dialog__container - Positioning wrapper with placement support
.alert-dialog__dialog - Dialog content container
.alert-dialog__header - Header section for icon and title
.alert-dialog__heading - Heading text styles
.alert-dialog__body - Main content area
.alert-dialog__footer - Footer section for actions
.alert-dialog__icon - Icon container with status colors
.alert-dialog__close-trigger - Close button element
.alert-dialog__backdrop--opaque - Opaque colored backdrop (default)
.alert-dialog__backdrop--blur - Blurred backdrop with glass effect
.alert-dialog__backdrop--transparent - Transparent backdrop (no overlay)
.alert-dialog__icon--default - Default gray status
.alert-dialog__icon--accent - Accent blue status
.alert-dialog__icon--success - Success green status
.alert-dialog__icon--warning - Warning orange status
.alert-dialog__icon--danger - Danger red status
The component supports these interactive states:
Focus : :focus-visible or [data-focus-visible="true"] - Applied to trigger, dialog, and close button
Hover : :hover or [data-hovered="true"] - Applied to close button on hover
Active : :active or [data-pressed="true"] - Applied to close button when pressed
Entering : [data-entering] - Applied during dialog opening animation
Exiting : [data-exiting] - Applied during dialog closing animation
Placement : [data-placement="*"] - Applied based on dialog position (auto, top, center, bottom)
Prop Type Default Description childrenReactNode- Trigger and container elements
Prop Type Default Description childrenReactNode- Custom trigger content classNamestring- CSS classes
Prop Type Default Description variant"opaque" | "blur" | "transparent""opaque"Backdrop overlay style isDismissablebooleanfalseClose on backdrop click isKeyboardDismissDisabledbooleantrueDisable ESC key to close isOpenboolean- Controlled open state onOpenChange(isOpen: boolean) => void- Open state change handler classNamestring | (values) => string- Backdrop CSS classes UNSTABLE_portalContainerHTMLElement- Custom portal 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 classNamestring | (values) => string- Container CSS classes
Prop Type Default Description childrenReactNode | ({close}) => ReactNode- Content or render function classNamestring- CSS classes rolestring"alertdialog"ARIA role aria-labelstring- Accessibility label aria-labelledbystring- ID of label element aria-describedbystring- ID of description element
Prop Type Default Description childrenReactNode- Header content (typically Icon and Heading) classNamestring- CSS classes
Prop Type Default Description childrenReactNode- Heading text classNamestring- CSS classes
Prop Type Default Description childrenReactNode- Body content classNamestring- CSS classes
Prop Type Default Description childrenReactNode- Footer content (typically action buttons) classNamestring- CSS classes
Prop Type Default Description childrenReactNode- Custom icon element status"default" | "accent" | "success" | "warning" | "danger""danger"Status color variant classNamestring- CSS classes
Prop Type Default Description childrenReactNode- Custom close button classNamestring | (values) => string- CSS classes
import {useOverlayState} from "@darkcode-ui/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
Implements WAI-ARIA AlertDialog pattern :
Focus trap : Focus locked within alert dialog
Keyboard : ESC closes (when enabled), Tab cycles elements
Screen readers : Proper ARIA attributes with role="alertdialog"
Scroll lock : Body scroll disabled when open
Required action : Defaults to requiring explicit user action (no backdrop/ESC dismiss)