Components

Alert Dialog

The shadcn/ui Alert Dialog with the DuskUI open and close animation, an icon slot and a compact size — plus two accessible React alert dialog blocks built with Motion and Radix: a destructive confirmation with type-to-confirm and async loading, and a session-timeout warning with a live countdown ring.

  • Drop-in shadcn API
  • role=alertdialog
  • Motion blocks
  • prefers-reduced-motion

Installation

$ npx shadcn@latest add https://duskui.com/r/alert-dialog.json

Full shadcn/ui API plus AlertDialogMedia, size="sm" on the content and variant / size on the action and cancel buttons. It styles those buttons with the DuskUI Button's buttonVariants. Animations are CSS (tw-animate-css), so the base needs no Motion.

Usage

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

export function DiscardDraft() {
  return (
    <AlertDialog>
      <AlertDialogTrigger asChild>
        <Button variant="outline">Discard draft</Button>
      </AlertDialogTrigger>
      <AlertDialogContent>
        <AlertDialogHeader>
          <AlertDialogTitle>Discard this draft?</AlertDialogTitle>
          <AlertDialogDescription>You can't get it back.</AlertDialogDescription>
        </AlertDialogHeader>
        <AlertDialogFooter>
          <AlertDialogCancel>Keep editing</AlertDialogCancel>
          <AlertDialogAction variant="destructive">Discard</AlertDialogAction>
        </AlertDialogFooter>
      </AlertDialogContent>
    </AlertDialog>
  )
}

Examples

Default

Fades and scales in slightly, then exits faster than it entered. Unlike Dialog, clicking the backdrop does nothing and focus starts on Cancel: the user has to answer. Give AlertDialogAction a variant to make it destructive.

Compact with icon

size="sm" narrows the dialog, centers the header and splits the footer into two equal buttons. AlertDialogMedia adds a tinted icon badge above the title.

Blocks

Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.

Destructive Alert Dialog

For deleting things that can't come back. A red icon marks the danger, consequences lists what will be lost, and with confirmText each character turns red as it matches. Return a promise from onConfirm and the button shows the DuskUI Button loading state; Escape and Cancel are blocked mid-request, and a failure shakes the dialog and shows the error inline. Unlike the Dialog's Confirm Dialog, it uses Alert Dialog semantics, so clicking outside never closes it. Try both buttons.

$ npx shadcn@latest add https://duskui.com/r/destructive-alert-dialog.json
PropTypeDefaultDescription
triggerReactElement—Element that opens the dialog. Omit when controlling open.
open / onOpenChangeboolean / (open: boolean) => void—Controlled state.
titleReactNode—Dialog title. Required.
descriptionReactNode—Supporting text. A screen-reader-only fallback is used when omitted.
consequencesReactNode[]—What will be lost, shown as a list that staggers in.
onConfirm() => unknown | Promise<unknown>—Runs on confirm. Throw to keep the dialog open with an error.
confirmTextstring—Text the user must type before confirming. Focus starts in that field.
confirmLabel / cancelLabelReactNode"Delete" / "Cancel"Button labels.
pendingLabelReactNode—Shown next to the spinner while confirming.
iconReactNode<Trash2 />Icon inside the red badge.
errorMessageReactNode—Replaces the thrown error's message.

Session Timeout Dialog

“Are you still there?” Open it from your idle timer: a ring drains around the seconds left and turns red for the last ten, then onSignOut("timeout") runs. Focus lands on Stay signed in, and Escape also counts as staying. The countdown uses wall-clock time, so it stays correct after the tab has been in the background.

$ npx shadcn@latest add https://duskui.com/r/session-timeout-dialog.json
PropTypeDefaultDescription
open / onOpenChangeboolean / (open: boolean) => void—Controlled state. Required.
secondsnumber60Seconds the user has to respond.
onStay() => void—The user stayed (button or Escape). Refresh the session.
onSignOut(reason: "manual" | "timeout") => void—The user left or time ran out.
titleReactNode"Are you still there?"Dialog title.
descriptionReactNode | (secondsLeft: number) => ReactNode—Text under the title; a function receives the seconds left.
stayLabel / signOutLabelReactNode"Stay signed in" / "Sign out"Button labels.

API Reference

Same parts as shadcn/ui: AlertDialog, AlertDialogTrigger, AlertDialogContent, AlertDialogHeader, AlertDialogFooter, AlertDialogTitle, AlertDialogDescription, AlertDialogAction, AlertDialogCancel, AlertDialogOverlay and AlertDialogPortal, plus AlertDialogMedia. Each forwards the Radix Alert Dialog props.

PropTypeDefaultDescription
open / onOpenChangeboolean / (open: boolean) => void—Controlled state (on AlertDialog).
size"default" | "sm""default"sm is narrower, centered, with equal-width footer buttons (on AlertDialogContent).
variant / sizeButton variant / size"default" / "outline"Button style of AlertDialogAction / AlertDialogCancel.
onOpenAutoFocus / onEscapeKeyDown(event) => void—Radix hooks on AlertDialogContent; call preventDefault() to override.

Accessibility

  • Built on Radix Alert Dialog: role="alertdialog", focus is trapped, the page behind is hidden from screen readers and focus returns to the trigger.
  • Clicking outside never closes it, and focus starts on Cancel, the safe choice. Escape still closes it, except while a block's async action is running.
  • Always render an AlertDialogTitle and an AlertDialogDescription; they become the dialog's accessible name and description.
  • The Destructive Alert Dialog keeps both buttons focusable while pending (aria-disabled + aria-busy) and reads the confirm text once instead of letter by letter.
  • The Session Timeout Dialog announces the time left when it opens and once more at ten seconds, not on every tick.
  • Under prefers-reduced-motion the dialog only fades, the shake is skipped, and the countdown digits swap without sliding.