Alert Dialog
Web/MobileA modal dialog that interrupts the user with important content and expects a response.
Installation
pnpm dlx cubix-ui@latest add alert-dialog --base radixUsage
import { Button } from "@/components/cubix/button"
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/cubix/alert-dialog"
<AlertDialog>
<AlertDialogTrigger render={<Button variant="outline" size="sm" />}>
نمایش دیالوگ
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>آیا کاملاً مطمئن هستید؟</AlertDialogTitle>
<AlertDialogDescription>
این کار قابل بازگشت نیست. حساب شما برای همیشه از سرورها حذف میشود.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>انصراف</AlertDialogCancel>
<AlertDialogAction>ادامه</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
Composition
Use the following composition to build an Alert Dialog:
AlertDialog
├── AlertDialogTrigger
└── AlertDialogContent
├── AlertDialogHeader
│ ├── AlertDialogMedia
│ ├── AlertDialogTitle
│ └── AlertDialogDescription
└── AlertDialogFooter
├── AlertDialogCancel
└── AlertDialogActionExamples
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.
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.
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | - | Controlled open state. Omit to use uncontrolled mode. |
| defaultOpen | boolean | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| children | React.ReactNode | - | The trigger and content elements. |
AlertDialogTrigger
The element that opens the dialog. Compose with Cubix Button via render.
| Prop | Type | Default | Description |
|---|---|---|---|
| render | React.ReactElement | - | Render the trigger as another Cubix element (e.g. a Button). |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogContent
The modal panel rendered with a backdrop.
| Prop | Type | Default | Description |
|---|---|---|---|
| size | "default" | "sm" | "default" | Width of the alert dialog panel. |
| dir | "ltr" | "rtl" | "rtl" | Text direction of the portaled panel. Defaults to RTL for Persian-first layouts. |
| lang | string | "fa" | Language attribute applied when dir is "rtl". Pass dir="ltr" to omit it. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogHeader / AlertDialogMedia / AlertDialogFooter
Layout regions of the dialog content.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogTitle / AlertDialogDescription
The title and supporting text of the dialog.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogAction
The confirm button. Use a destructive variant for irreversible actions.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "foreground" | "secondary" | "gray" | "destructive" | "destructive-secondary" | "outline" | "ghost" | "link" | "default" | Visual style of the confirm button. |
| size | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "sm" | Size of the confirm button. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
AlertDialogCancel
The dismiss button. Closes the dialog without confirming.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "default" | "foreground" | "secondary" | "gray" | "destructive" | "destructive-secondary" | "outline" | "ghost" | "link" | "outline" | Visual style of the cancel button. |
| size | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "sm" | Size of the cancel button. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |