Alert Dialog

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

Installation

pnpm dlx shadcn@latest add @lumi-ui/alert-dialog

Basic Usage

Import the AlertDialog, AlertDialogTrigger, AlertDialogPopup, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogBody, and AlertDialogFooter components. Compose them to create a simple alert dialog.

Recipes

Customizing the Dialog

You can customize the dialog by passing props to the AlertDialogPopup component. For example, you can change the variant to destructive to indicate a destructive action.

Anatomy

<AlertDialog>
  <AlertDialogTrigger />
  <AlertDialogPopup>
    <AlertDialogHeader>
      <AlertDialogTitle />
      <AlertDialogDescription />
    </AlertDialogHeader>
    <AlertDialogBody />
    <AlertDialogFooter />
  </AlertDialogPopup>
</AlertDialog>
ComponentRole
AlertDialogThe root component and context provider.
AlertDialogTriggerThe button or element that opens the dialog.
AlertDialogPopupComponent that wraps the floating panel containing the dialog content.
AlertDialogHeaderA wrapper for the dialog's title and description.
AlertDialogTitleThe title of the dialog.
AlertDialogDescriptionA short description of the dialog's content.
AlertDialogBodyThe main content of the dialog.
AlertDialogFooterA wrapper for the dialog's action buttons.

Migration from shadcn/ui

The component has been renamed from AlertDialog to AlertDialog for consistency. The names for content panels and labels have also been updated.

shadcn/uilumi/uiChange
AlertDialogAlertDialogNo Change
AlertDialogContentAlertDialogPopupRenamed
AlertDialogTitleAlertDialogTitleNo Change
AlertDialogDescriptionAlertDialogDescriptionNo Change
AlertDialogHeaderAlertDialogHeaderNo Change
AlertDialogFooterAlertDialogFooterNo Change
AlertDialogActionButtonReplaced with Button component
AlertDialogCancelButtonReplaced with Button component

Key Differences & New Features

AlertDialog component introduces several enhancements for better positioning and styling, which are exposed as props on the AlertDialogPopup component.

Featurelumi/uishadcn/ui
Popup ArrowshowArrow prop on AlertDialogPopupNot available
Width MatchingmatchAnchorWidth prop on AlertDialogPopupNot available
PositioningExplicit side, align, sideOffset propsImplicitly controlled via props on AlertDialogContent

Migration Example

alert-dialog-demo.tsx
import {
  AlertDialog,
  AlertDialogAction,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
 
function Demo() {
  return (
    <AlertDialog>
      <AlertDialogTrigger>Show Dialog</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>
  );
}