Alert Dialog
A modal dialog that interrupts the user with important content and expects a response.
Playground
Installation
Install in any React + Tailwind project:
$npx shadcn@latest add https://twigs.globirdenergy.com.au/r/alert-dialog.json
Source
The exact file the registry serves to consumers.
'use client';
import * as React from 'react';
import { AlertDialog as BaseAlertDialog } from '@base-ui/react/alert-dialog';
import { cn } from '@/lib/utils';
import { buttonVariants } from '@/registry/new-york/ui/button';
// Spec source: Figma "APP Re-design Phase 1" → page "Alert Dialog ✅"
// 512x172, padding 24, radius 16, bg #ffffff, border #e5e5e5, gap 16
const AlertDialog = BaseAlertDialog.Root;
const AlertDialogTrigger = BaseAlertDialog.Trigger;
const AlertDialogPortal = BaseAlertDialog.Portal;
function AlertDialogOverlay({
className,
...props
}: React.ComponentProps<typeof BaseAlertDialog.Backdrop>) {
return (
<BaseAlertDialog.Backdrop
data-slot="alert-dialog-overlay"
className={cn(
'fixed inset-0 z-50 bg-black/50 data-[ending-style]:opacity-0 data-[starting-style]:opacity-0 transition-opacity duration-200',
className,
)}
{...props}
/>
);
}
function AlertDialogContent({
className,
...props
}: React.ComponentProps<typeof BaseAlertDialog.Popup>) {
return (
<AlertDialogPortal>
<AlertDialogOverlay />
<BaseAlertDialog.Popup
data-slot="alert-dialog-content"
className={cn(
'fixed left-1/2 top-1/2 z-50 grid w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-2xl border bg-background p-6 shadow-lg duration-200',
'data-[ending-style]:opacity-0 data-[ending-style]:scale-95 data-[starting-style]:opacity-0 data-[starting-style]:scale-95 transition-[opacity,transform]',
className,
)}
{...props}
/>
</AlertDialogPortal>
);
}
function AlertDialogHeader({ className, ...props }: React.ComponentProps<'div'>) {
return (
<div
data-slot="alert-dialog-header"
className={cn('flex flex-col gap-2 text-center sm:text-left', className)}
{...props}
/>
);
}
function AlertDialogFooter({ className, ...props }: React.ComponentProps<'div'>) {
return (
<div
data-slot="alert-dialog-footer"
className={cn('flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)}
{...props}
/>
);
}
function AlertDialogTitle({
className,
...props
}: React.ComponentProps<typeof BaseAlertDialog.Title>) {
return (
<BaseAlertDialog.Title
data-slot="alert-dialog-title"
className={cn('font-headline text-lg font-semibold', className)}
{...props}
/>
);
}
function AlertDialogDescription({
className,
...props
}: React.ComponentProps<typeof BaseAlertDialog.Description>) {
return (
<BaseAlertDialog.Description
data-slot="alert-dialog-description"
className={cn('text-muted-foreground text-sm', className)}
{...props}
/>
);
}
function AlertDialogAction({
className,
...props
}: React.ComponentProps<typeof BaseAlertDialog.Close>) {
return (
<BaseAlertDialog.Close
data-slot="alert-dialog-action"
className={cn(buttonVariants(), className)}
{...props}
/>
);
}
function AlertDialogCancel({
className,
...props
}: React.ComponentProps<typeof BaseAlertDialog.Close>) {
return (
<BaseAlertDialog.Close
data-slot="alert-dialog-cancel"
className={cn(buttonVariants({ variant: 'outline' }), className)}
{...props}
/>
);
}
export {
AlertDialog,
AlertDialogTrigger,
AlertDialogPortal,
AlertDialogOverlay,
AlertDialogContent,
AlertDialogHeader,
AlertDialogFooter,
AlertDialogTitle,
AlertDialogDescription,
AlertDialogAction,
AlertDialogCancel,
};