Components
Alert Dialog
Interruptive confirmation dialog that requires an explicit user decision before continuing.
import {
AlertDialog,
AlertDialogClose,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
export default function Particle() {
return (
<AlertDialog>
<AlertDialogTrigger render={<Button variant="outline" />}>
Archive Project
</AlertDialogTrigger>
<AlertDialogPopup className="sm:max-w-md">
<AlertDialogHeader>
<AlertDialogTitle>Archive this project?</AlertDialogTitle>
<AlertDialogDescription>
The repository will become read-only for all team members. You can
restore it anytime from workspace settings.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogClose render={<Button variant="ghost" />}>
Cancel
</AlertDialogClose>
<AlertDialogClose render={<Button />}>Archive</AlertDialogClose>
</AlertDialogFooter>
</AlertDialogPopup>
</AlertDialog>
);
}
Installation
pnpm dlx shadcn@latest add @taut-ui/alert-dialog
Usage
import {
AlertDialog,
AlertDialogClose,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"<AlertDialog>
<AlertDialogTrigger>Delete</AlertDialogTrigger>
<AlertDialogPopup>
<AlertDialogHeader>
<AlertDialogTitle>Are you sure?</AlertDialogTitle>
<AlertDialogDescription>This action cannot be undone.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogClose>Cancel</AlertDialogClose>
<AlertDialogClose>Continue</AlertDialogClose>
</AlertDialogFooter>
</AlertDialogPopup>
</AlertDialog>Examples
Destructive with Icon
import { Trash2Icon } from "lucide-react";
import {
AlertDialog,
AlertDialogClose,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogIcon,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
export default function Particle() {
return (
<AlertDialog>
<AlertDialogTrigger render={<Button variant="destructive" />}>
Delete Workspace
</AlertDialogTrigger>
<AlertDialogPopup className="sm:max-w-md">
<AlertDialogHeader>
<AlertDialogIcon className="bg-[color-mix(in_oklab,var(--color-popover),var(--color-destructive)_16%)] text-destructive">
<Trash2Icon />
</AlertDialogIcon>
<AlertDialogTitle>Delete workspace permanently?</AlertDialogTitle>
<AlertDialogDescription>
This action cannot be undone. All projects, deployments, and API
keys inside this workspace will be permanently erased.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogClose render={<Button variant="ghost" />}>
Cancel
</AlertDialogClose>
<AlertDialogClose render={<Button variant="destructive" />}>
Delete forever
</AlertDialogClose>
</AlertDialogFooter>
</AlertDialogPopup>
</AlertDialog>
);
}
Async Action
"use client";
import { useState } from "react";
import {
AlertDialog,
AlertDialogClose,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
export default function Particle() {
const [open, setOpen] = useState(false);
const [isPending, setIsPending] = useState(false);
function handleRevoke() {
setIsPending(true);
setTimeout(() => {
setIsPending(false);
setOpen(false);
}, 1200);
}
return (
<AlertDialog onOpenChange={setOpen} open={open}>
<AlertDialogTrigger render={<Button variant="outline" />}>
Revoke Sessions
</AlertDialogTrigger>
<AlertDialogPopup className="sm:max-w-md">
<AlertDialogHeader>
<AlertDialogTitle>Sign out all devices?</AlertDialogTitle>
<AlertDialogDescription>
Every active session except this browser will be signed out
immediately.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogClose
disabled={isPending}
render={<Button variant="ghost" />}
>
Cancel
</AlertDialogClose>
<Button
loading={isPending}
onClick={handleRevoke}
variant="destructive"
>
Revoke all
</Button>
</AlertDialogFooter>
</AlertDialogPopup>
</AlertDialog>
);
}
API Reference
AlertDialog
Re-exports AlertDialog.Root from @base-ui/react/alert-dialog. Unlike Dialog, clicking the backdrop does not dismiss the dialog.
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | - | Controlled open state |
defaultOpen | boolean | false | Initial uncontrolled open state |
onOpenChange | (open: boolean) => void | - | Called when the open state changes |
AlertDialogPopup / AlertDialogContent
Composes AlertDialogPortal, AlertDialogBackdrop, AlertDialogViewport, and AlertDialog.Popup.
| Prop | Type | Default | Description |
|---|---|---|---|
portalProps | AlertDialog.Portal.Props | - | Props forwarded to AlertDialogPortal |
className | string | - | Additional CSS classes |
AlertDialogHeader / AlertDialogIcon / AlertDialogTitle / AlertDialogDescription / AlertDialogFooter / AlertDialogTrigger / AlertDialogClose
Composable layout and action primitives built on Dialog header/footer slots and Base UI AlertDialog.