1
3
Block

Alert Dialog

PreviousNext

The Dialog component is a customizable modal dialog that supports flexible content, triggers, and closing mechanisms with smooth animations.

import { AlertTriangle } from "lucide-react"

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

export function AlertDialogDemo() {
  return (
    <div className="space-y-6">
      {/* Example 1: Delete Confirmation */}
      <div>
        <AlertDialog>
          <AlertDialogTrigger asChild>
            <Button variant="destructive">Delete Account</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 className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
                Delete Account
              </AlertDialogAction>
            </AlertDialogFooter>
          </AlertDialogContent>
        </AlertDialog>
      </div>

      {/* Example 2: Logout Confirmation */}
      <div>
        <AlertDialog>
          <AlertDialogTrigger asChild>
            <Button variant="outline">Log out</Button>
          </AlertDialogTrigger>
          <AlertDialogContent>
            <AlertDialogHeader>
              <AlertDialogTitle>Log out?</AlertDialogTitle>
              <AlertDialogDescription>
                Are you sure you want to log out? You will need to log in again
                to access your account.
              </AlertDialogDescription>
            </AlertDialogHeader>
            <AlertDialogFooter>
              <AlertDialogCancel>Stay signed in</AlertDialogCancel>
              <AlertDialogAction>Log out</AlertDialogAction>
            </AlertDialogFooter>
          </AlertDialogContent>
        </AlertDialog>
      </div>

      {/* Example 3: Warning with Icon */}
      <div>
        <AlertDialog>
          <AlertDialogTrigger asChild>
            <Button>Share Project</Button>
          </AlertDialogTrigger>
          <AlertDialogContent>
            <AlertDialogHeader className="space-y-2">
              <div className="flex items-center space-x-2">
                <AlertTriangle className="text-destructive h-5 w-5" />
                <AlertDialogTitle>Share with team?</AlertDialogTitle>
              </div>
              <AlertDialogDescription>
                This will give all team members access to edit this project.
                Only share if you are sure they are the right people.
              </AlertDialogDescription>
            </AlertDialogHeader>
            <AlertDialogFooter>
              <AlertDialogCancel>Cancel</AlertDialogCancel>
              <AlertDialogAction>Share Project</AlertDialogAction>
            </AlertDialogFooter>
          </AlertDialogContent>
        </AlertDialog>
      </div>
    </div>
  )
}

Installation

pnpm dlx shadcn@latest add https://ebonui.com/r/alert-dialog.json

Usage

import { AlertDialogDemo } from "@/registry/example/alert-dialog-demo"
<div className="relative h-[500px] w-full overflow-hidden">
  <AlertDialogDemo />
</div>

Props

Dialog

PropTypeDefaultDescription
classNamestring-Additional CSS classes for styling.
openboolean-Controls open state manually.
onOpenChange(open: boolean) => void-Callback to handle open state changes.

AlertDialogTrigger

PropTypeDefaultDescription
asChildbooleanfalseWhether to render the trigger as a child element.
classNamestring-Additional CSS classes.

AlertDialogContent

PropTypeDefaultDescription
classNamestring-Additional CSS classes for styling.
overlayClassNamestring-CSS classes for the overlay.
closeOnClickOutsidebooleantrueWhether clicking outside closes the dialog.

AlertDialogCloseTrigger

PropTypeDefaultDescription
asChildbooleanfalseWhether to render the close trigger as a child element.
classNamestring-Additional CSS classes.

AlertDialogHeader

This is a container for the dialog header.

AlertDialogTitle

This is the title of the dialog.

AlertDialogDescription

This is a brief description of the dialog’s purpose.

AlertDialogFooter

This is a container for footer actions (e.g., buttons).