Alert Dialog

Web/Mobile

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

Installation

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

Usage

Import
import { Button } from "@/components/cubix/button"
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/cubix/alert-dialog"
Example
<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
        └── AlertDialogAction

Examples

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.

PropTypeDefaultDescription
openboolean-Controlled open state. Omit to use uncontrolled mode.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => void-Called when the open state changes.
childrenReact.ReactNode-The trigger and content elements.

AlertDialogTrigger

The element that opens the dialog. Compose with Cubix Button via render.

PropTypeDefaultDescription
renderReact.ReactElement-Render the trigger as another Cubix 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.
dir"ltr" | "rtl""rtl"Text direction of the portaled panel. Defaults to RTL for Persian-first layouts.
langstring"fa"Language attribute applied when dir is "rtl". Pass dir="ltr" to omit it.
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" | "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.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

AlertDialogCancel

The dismiss button. Closes the dialog without confirming.

PropTypeDefaultDescription
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.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).