Components
Alert dialog
The Dialog surface for a decision that cannot be undone: no close button, no outside dismiss, focus starting on the safe choice.
pnpm dlx shadcn@latest add @caliper/alert-dialogWhen to use
Use it for
- Deleting a workspace, revoking a key, discarding unsaved work.
- Anything where the next click is permanent.
Skip it when
- Information or forms; use a dialog.
- Anything you can undo; do it and offer Undo in a toast.
Decisions
Why it is built this way, so you know what to keep when you change your copy.
Behaviour
- Focus starts on Cancel
- The least destructive choice is the one an accidental Enter lands on. Escape also cancels.
- An outside click does nothing
- A decision this large should not be dismissed by missing a button. Only Cancel and Escape close it.
Usage
- The action names what it does
- “Delete workspace” instead of “OK”, so the last thing read before the click is the consequence.
Installation
pnpm dlx shadcn@latest add @caliper/alert-dialog
Adds its 5 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage
This is the code behind the preview above. It is built from AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle and AlertDialogTrigger.
import { useState, type ReactNode } from "react" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/ui/alert-dialog" import { cn } from "@/components/ui/lib/cn" import { Button } from "@/components/ui/button" function Panel({ title, context, children, className }: { title: ReactNode; context: ReactNode; children: ReactNode; className?: string }) { return ( <section className={cn("grid w-full max-w-md gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting", className)}> <div className="grid gap-1"> {/* div, not p: titles here can hold a badge or a direction-aware block. */} <div className="font-medium">{title}</div> <p className="text-sm text-muted-foreground">{context}</p> </div> {children} </section> ); } export function AlertDialogDemo() { const [result, setResult] = useState("Owned by Sofia Ortega since March 2024."); return ( <Panel title="Danger zone" context="Forma Studio · 14 projects and 212 files"> <div className="flex flex-wrap items-center justify-between gap-3 rounded-control border border-border px-4 py-3"> <span className="grid text-sm"> <span className="font-medium">Delete this workspace</span> <span className="text-muted-foreground">Removes everything for every member.</span> </span> <AlertDialog> <AlertDialogTrigger asChild> <Button variant="destructive" size="sm">Delete workspace…</Button> </AlertDialogTrigger> <AlertDialogContent> <AlertDialogHeader> <AlertDialogTitle>Delete Forma Studio?</AlertDialogTitle> <AlertDialogDescription>This removes 14 projects and 212 files for everyone in the workspace. You cannot undo it.</AlertDialogDescription> </AlertDialogHeader> <AlertDialogFooter> <AlertDialogCancel onClick={() => setResult("Kept. Nothing was deleted.")}>Keep workspace</AlertDialogCancel> <AlertDialogAction onClick={() => setResult("Workspace deleted (example only).")}>Delete workspace</AlertDialogAction> </AlertDialogFooter> </AlertDialogContent> </AlertDialog> </div> <p role="status" className="text-sm text-muted-foreground">{result}</p> </Panel> ); }
API reference
AlertDialog
component
No props of its own; it accepts the native props of its root element.
AlertDialogAction
component
Also accepts the native props of its root element and a ref.
AlertDialogCancel
component
Also accepts the native props of its root element and a ref.
AlertDialogContent
component
No props of its own; it accepts the native props of its root element.
AlertDialogDescription
component
No props of its own; it accepts the native props of its root element.
AlertDialogHeader
component
No props of its own; it accepts the native props of its root element.
AlertDialogTitle
component
No props of its own; it accepts the native props of its root element.
AlertDialogTrigger
component
No props of its own; it accepts the native props of its root element.
Accessibility
It exposes alertdialog semantics.
Keyboard and focus handling comes from Radix dialog: arrow keys move through items, Enter and Space select, and Escape closes and returns focus.
Motion
It declares no animation in its component source. Any transition comes from its stylesheet, which uses the duration tokens that collapse to instant under prefers-reduced-motion.