Components

Alert Dialog

A modal dialog that interrupts the user with important content and expects a response.

Installation

Cortexcn
pnpm dlx shadcn@latest add @cortexcn/alert-dialog

Usage

import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogOverlay, AlertDialogPortal, AlertDialogTitle, AlertDialogTrigger } from "@/components/alert-dialog";

Examples

Basic

import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/alert-dialog"import { Button } from "@/components/button"export function AlertDialogBasic() {  return (    <div className="flex flex-col gap-6 items-center">      <AlertDialog>        <AlertDialogTrigger asChild>          <Button variant="outline">Default</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>Continue</AlertDialogAction>          </AlertDialogFooter>        </AlertDialogContent>      </AlertDialog>    </div>  )}

Small

import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/alert-dialog"import { Button } from "@/components/button"export function AlertDialogSmall() {  return (    <div className="flex flex-col gap-6 items-center">      <AlertDialog>        <AlertDialogTrigger asChild>          <Button variant="outline">Small</Button>        </AlertDialogTrigger>        <AlertDialogContent size="sm">          <AlertDialogHeader>            <AlertDialogTitle>Allow accessory to connect?</AlertDialogTitle>            <AlertDialogDescription>              Do you want to allow the USB accessory to connect to this device?            </AlertDialogDescription>          </AlertDialogHeader>          <AlertDialogFooter>            <AlertDialogCancel>Don&apos;t allow</AlertDialogCancel>            <AlertDialogAction>Allow</AlertDialogAction>          </AlertDialogFooter>        </AlertDialogContent>      </AlertDialog>    </div>  )}

With media

import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogTitle, AlertDialogTrigger } from "@/components/alert-dialog"import { Button } from "@/components/button"import { BluetoothIcon } from "lucide-react"export function AlertDialogWithMedia() {  return (    <div className="flex flex-col gap-6 items-center">      <AlertDialog>        <AlertDialogTrigger asChild>          <Button variant="outline">Default (Media)</Button>        </AlertDialogTrigger>        <AlertDialogContent>          <AlertDialogHeader>            <AlertDialogMedia>              <BluetoothIcon />            </AlertDialogMedia>            <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>            <AlertDialogDescription>              This will permanently delete your account and remove your data              from our servers.            </AlertDialogDescription>          </AlertDialogHeader>          <AlertDialogFooter>            <AlertDialogCancel>Cancel</AlertDialogCancel>            <AlertDialogAction>Continue</AlertDialogAction>          </AlertDialogFooter>        </AlertDialogContent>      </AlertDialog>    </div>  )}

Small with media

import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogTitle, AlertDialogTrigger } from "@/components/alert-dialog"import { Button } from "@/components/button"import { BluetoothIcon } from "lucide-react"export function AlertDialogSmallWithMedia() {  return (    <div className="flex flex-col gap-6 items-center">      <AlertDialog>        <AlertDialogTrigger asChild>          <Button variant="outline">Small (Media)</Button>        </AlertDialogTrigger>        <AlertDialogContent size="sm">          <AlertDialogHeader>            <AlertDialogMedia>              <BluetoothIcon />            </AlertDialogMedia>            <AlertDialogTitle>Allow accessory to connect?</AlertDialogTitle>            <AlertDialogDescription>              Do you want to allow the USB accessory to connect to this device?            </AlertDialogDescription>          </AlertDialogHeader>          <AlertDialogFooter>            <AlertDialogCancel>Don&apos;t allow</AlertDialogCancel>            <AlertDialogAction>Allow</AlertDialogAction>          </AlertDialogFooter>        </AlertDialogContent>      </AlertDialog>    </div>  )}

Destructive

import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogMedia, AlertDialogTitle, AlertDialogTrigger } from "@/components/alert-dialog"import { Button } from "@/components/button"import { Trash2Icon } from "lucide-react"export function AlertDialogDestructive() {  return (    <div className="flex flex-col gap-6 items-center">      <AlertDialog>        <AlertDialogTrigger asChild>          <Button variant="destructive">Delete Chat</Button>        </AlertDialogTrigger>        <AlertDialogContent size="sm">          <AlertDialogHeader>            <AlertDialogMedia className="bg-destructive/10 text-destructive dark:bg-destructive/20 dark:text-destructive">              <Trash2Icon />            </AlertDialogMedia>            <AlertDialogTitle>Delete chat?</AlertDialogTitle>            <AlertDialogDescription>              This will permanently delete this chat conversation. View{" "}              <a href="#">Settings</a> delete any memories saved during this              chat.            </AlertDialogDescription>          </AlertDialogHeader>          <AlertDialogFooter>            <AlertDialogCancel variant="ghost">Cancel</AlertDialogCancel>            <AlertDialogAction variant="destructive">Delete</AlertDialogAction>          </AlertDialogFooter>        </AlertDialogContent>      </AlertDialog>    </div>  )}

In dialog

import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "@/components/alert-dialog"import { Button } from "@/components/button"import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/dialog"export function AlertDialogInDialog() {  return (    <div className="flex flex-col gap-6 items-center">      <Dialog>        <DialogTrigger asChild>          <Button variant="outline">Open Dialog</Button>        </DialogTrigger>        <DialogContent>          <DialogHeader>            <DialogTitle>Alert Dialog Example</DialogTitle>            <DialogDescription>              Click the button below to open an alert dialog.            </DialogDescription>          </DialogHeader>          <DialogFooter>            <AlertDialog>              <AlertDialogTrigger asChild>                <Button>Open Alert Dialog</Button>              </AlertDialogTrigger>              <AlertDialogContent size="sm">                <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>Continue</AlertDialogAction>                </AlertDialogFooter>              </AlertDialogContent>            </AlertDialog>          </DialogFooter>        </DialogContent>      </Dialog>    </div>  )}

Adapted from the shadcn/ui Alert Dialog (MIT).