Alert Dialog

A modal dialog that interrupts the user with important content and expects a response.

Installation

pnpm dlx cubix@latest add alert-dialog --base radix

Usage

Import
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/cubix/alert-dialog"
Example
<AlertDialog>
  <AlertDialogTrigger render={<Button variant="outline" />}>
    Show Dialog
  </AlertDialogTrigger>
  <AlertDialogContent>
    <AlertDialogHeader>
      <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
      <AlertDialogDescription>
        This action cannot be undone. This will permanently delete your
        account from our servers.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel>Cancel</AlertDialogCancel>
      <AlertDialogAction>Continue</AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

Composition

Use the following composition to build an Alert Dialog:

 
AlertDialog
├── AlertDialogTrigger
└── AlertDialogContent
    ├── AlertDialogHeader
       ├── AlertDialogMedia
       ├── AlertDialogTitle
       └── AlertDialogDescription
    └── AlertDialogFooter
        ├── AlertDialogCancel
        └── AlertDialogAction

Examples

Basic

A basic alert dialog with a title, description, and cancel and continue buttons.

Small

Use the size="sm" prop to make the alert dialog smaller.

Media

Use AlertDialogMedia to add an icon or image above the title.

Small with Media

Combine size="sm" with AlertDialogMedia for a compact dialog with an icon.

Destructive

Use variant="destructive" on the action when the confirm step cannot be undone.

RTL

Set dir="rtl" and lang="fa" on the trigger wrapper and on AlertDialogContent so layout, actions, and IRANSans XV follow Persian. The panel is portaled, so it needs those attributes too.

API Reference

Note: Alert dialogs trap focus and require an explicit choice. Prefer this over a regular Dialog when the user must confirm or cancel.

AlertDialog

The container that wraps the trigger and content and manages open state.

PropTypeDefaultDescription
childrenReact.ReactNode-The trigger and content elements. State is managed internally (uncontrolled).

AlertDialogTrigger

The element that opens the dialog. Use render to merge onto a Button.

PropTypeDefaultDescription
renderReact.ReactElement-Render the trigger as another element (e.g. a Button).
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AlertDialogContent

The modal panel rendered with a backdrop.

PropTypeDefaultDescription
size"default" | "sm""default"Width of the alert dialog panel.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AlertDialogHeader / AlertDialogMedia / AlertDialogFooter

Layout regions of the dialog content.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AlertDialogTitle / AlertDialogDescription

The title and supporting text of the dialog.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AlertDialogAction

The confirm button. Use a destructive variant for irreversible actions.

PropTypeDefaultDescription
variant"default" | "secondary" | "destructive" | "outline" | "ghost" | "link""default"Visual style of the confirm button.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AlertDialogCancel

The dismiss button. Closes the dialog without confirming.

PropTypeDefaultDescription
variant"default" | "secondary" | "destructive" | "outline" | "ghost" | "link""outline"Visual style of the cancel button.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).