Alert Dialog
A confirmation that rises out of a blur, with the warning icon popping in before the rest.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/alert-dialogThis adds components/keyframery/alert-dialog.tsx and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.
Usage
import {
AlertDialog,
AlertDialogBackdrop,
AlertDialogClose,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/keyframery/alert-dialog"
export default function Usage() {
return (
<AlertDialog>
<AlertDialogTrigger variant="destructive">Delete</AlertDialogTrigger>
<AlertDialogBackdrop />
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete this project?</AlertDialogTitle>
<AlertDialogDescription>This can't be undone.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogClose>Cancel</AlertDialogClose>
<AlertDialogClose variant="destructive">Delete</AlertDialogClose>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}Anatomy
How the parts fit together:
AlertDialog
├── AlertDialogTrigger
├── AlertDialogBackdrop
└── AlertDialogContent
├── AlertDialogHeader
│ ├── AlertDialogTitle
│ └── AlertDialogDescription
└── AlertDialogFooter
└── AlertDialogCloseExamples
Basic
For a decision that needs an answer. Escape and clicks outside don't close it; one of the buttons must.
Destructive, with an icon
AlertDialogMedia holds an icon above the title. Use the destructive variant for what can't be undone.
Waiting for the action
Give a close button an action that returns a promise. The dialog stays open, with a spinner, until it settles.
Motion
| Move | What you see |
|---|---|
| Unfold | The sheet rises from below out of a blur while the backdrop blurs in behind it. |
| Pop | The warning icon lands first, with a pop. |
| Cascade | Title, message and buttons follow one after another. |
| Press | Buttons sink and spring back. |
Timing and springiness follow the motion style you set. To change how fast this alert dialog moves, pass speed:
<AlertDialog speed="fast">
…
</AlertDialog>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--alert-dialog-face | Sheet surface | --popover |
--alert-dialog-ink | Sheet text | --popover-foreground |
--alert-dialog-action | Primary or destructive action and icon | --primary / --destructive; destructive dark mixes with --background at 24% |
--alert-dialog-radius | Sheet corners | 18px |
--alert-dialog-width | Sheet maximum width | 400px |
--alert-dialog-height | Key height | 2rem |
--alert-dialog-gap | Footer button gap | 0.5rem |
API reference
Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK alert dialog reference.
AlertDialog
Prop
Type
AlertDialogTrigger
Renders a <button>, and takes its props too.
Prop
Type
AlertDialogContent
Renders a <div>, and takes its props too.
Prop
Type
AlertDialogClose
Renders a <button>, and takes its props too.
Prop
Type
AlertDialogShortcut
Renders a <span>, and takes its props too.
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
AlertDialogBackdrop: a<div>AlertDialogHeader: a<div>AlertDialogTitle: a<h2>AlertDialogDescription: a<p>AlertDialogFooter: a<div>AlertDialogMedia: a<div>
Keyboard
| Key | What it does |
|---|---|
| Enter | Presses the focused button. |
| Tab | Moves between the dialog's buttons. Focus stays inside. |
| Escape | Does nothing: an alert dialog needs an answer. |
Accessibility
Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.
Swap the import
Already using UI SDK's alert dialog with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.
// Before
import { … } from "@ui-sdk/react/alert-dialog"
// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/alert-dialog"Questions
How does the animated Alert Dialog for UI SDK move?
Unfold: The sheet rises from below out of a blur while the backdrop blurs in behind it. Pop: The warning icon lands first, with a pop. Cascade: Title, message and buttons follow one after another. Press: Buttons sink and spring back.
Do I need Motion or Framer Motion for the animated Alert Dialog?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
Can I keep my own styling and only take the motion?
Yes. Import from @/components/keyframery/primitives/alert-dialog instead. It has the same parts and props as @ui-sdk/react/alert-dialog and adds motion only.
What happens to the Alert Dialog when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.