import type { Meta, StoryObj } from '@storybook/react-vite' import { AlertTriangle, LogOut, Send, Trash2 } from 'lucide-react' import { fn } from 'storybook/test' import { AlertDialog } from './AlertDialog' import { Button } from './Button' import { ALERT_DIALOG_COLORS } from './dialog.tokens' const ownFrame = (height = 520) => ({ docs: { story: { inline: false, iframeHeight: height } } }) const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) const meta = { title: 'Overlays/AlertDialog', component: AlertDialog, tags: ['autodocs'], parameters: { docs: { description: { component: 'Asks the user to confirm an action, on Base UI AlertDialog (`role="alertdialog"`). It doesn’t close on outside clicks and focus starts on Cancel. Use `color="danger"` for destructive actions. When `onConfirm` returns a Promise the confirm button shows a spinner, Cancel and Escape are blocked, and the dialog closes when it resolves (or stays open if it rejects).', }, }, }, argTypes: { title: { control: 'text' }, description: { control: 'text' }, confirmLabel: { control: 'text', table: { defaultValue: { summary: 'Confirm' } } }, cancelLabel: { control: 'text', table: { defaultValue: { summary: 'Cancel' } } }, loadingLabel: { control: 'text' }, color: { control: 'inline-radio', options: ALERT_DIALOG_COLORS, table: { defaultValue: { summary: 'primary' } } }, open: { control: 'boolean' }, defaultOpen: { control: 'boolean' }, className: { control: 'text' }, icon: { control: false }, trigger: { control: false }, children: { control: false }, onConfirm: { control: false }, onCancel: { control: false }, onOpenChange: { control: false }, }, args: { title: 'Delete this project?', description: 'Acme Website and its 48 files will be deleted for everyone. This can’t be undone.', confirmLabel: 'Delete project', cancelLabel: 'Cancel', color: 'danger', icon: , trigger: ( ), onConfirm: fn(), onCancel: fn(), onOpenChange: fn(), }, } satisfies Meta export default meta type Story = StoryObj export const Playground: Story = {} export const Open: Story = { args: { defaultOpen: true }, parameters: ownFrame(), } export const AsyncConfirm: Story = { args: { defaultOpen: true, loadingLabel: 'Deleting…', onConfirm: fn(() => wait(2000)), }, parameters: { ...ownFrame(), docs: { ...ownFrame().docs, description: { story: 'Press **Delete project**: the button loads for two seconds, then the dialog closes.' }, }, }, } export const WithoutIcon: Story = { args: { defaultOpen: true, icon: undefined, color: 'primary', title: 'Publish changes?', description: 'Your edits to the pricing page will go live for all visitors.', confirmLabel: 'Publish', cancelLabel: 'Keep editing', trigger: , }, parameters: ownFrame(), } export const Warning: Story = { args: { defaultOpen: true, color: 'warning', icon: , title: 'Sign out of all devices?', description: 'You will need to sign in again on your phone, tablet and other computers.', confirmLabel: 'Sign out everywhere', trigger: ( ), }, parameters: ownFrame(), } export const WithDetails: Story = { args: { defaultOpen: true, title: 'Remove 3 members?', description: 'They lose access to Acme Corporation immediately.', confirmLabel: 'Remove members', children: (
  • Jane Doe (name@example.com)
  • John Smith (john@example.com)
  • Alex Kim (alex@example.com)
), }, parameters: ownFrame(560), } export const Colors: Story = { render: (args) => (
{ALERT_DIALOG_COLORS.map((color) => ( {color[0].toUpperCase() + color.slice(1)} } /> ))}
), }