Alert Dialog

A modal dialog that interrupts the user with important content and expects a response. Built on Radix Alert Dialog.

Default

Confirm a sensitive action before it runs.

Installation

CLI
npx @sonojs/ui@latest add alert-dialog
Also needsnpx @sonojs/ui@latest add button

Usage

alert-dialog.tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import { Button } from "@/components/ui/button"

export function Example() {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button variant="outline">Show Dialog</Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
          <AlertDialogDescription>
            This action cannot be undone. This will permanently delete your
            account and remove your data from our servers.
          </AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Cancel</AlertDialogCancel>
          <AlertDialogAction>Continue</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}

Props

PropTypeDefaultDescription
size"default" · "sm""default"On AlertDialogContent: default is wider on sm+; sm is compact with a 2-column footer.
variantButton variantAction: "default" · Cancel: "outline"On AlertDialogAction / AlertDialogCancel: forwarded to Button.
asChildbooleanfalseOn AlertDialogTrigger: merge props into the child (e.g. Button).