import type { Meta, StoryObj } from '@storybook/react'; import { expect, userEvent, within } from 'storybook/test'; import { Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from './dialog'; import { Button } from '../button'; import { Input } from '../input'; import { Label } from '../label'; import { Plus } from 'lucide-react'; import React from 'react'; const meta = { title: 'UI/Dialog', component: Dialog, render: args => , argTypes: { open: { control: 'boolean', description: 'The open state of the dialog.', }, modal: { control: 'boolean', description: 'Whether the dialog should be modal.', defaultValue: true, }, // DialogContent prop exposed for Storybook controls size: { control: 'select', options: ['sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl', '5xl', 'full'], description: 'Width of the dialog (DialogContent prop).', defaultValue: 'lg', table: { category: 'DialogContent' }, }, }, } satisfies Meta; export default meta; type Story = StoryObj; export const Default: Story = { args: { size: 'lg' } as any, render: ({ size, ...args }: any) => ( Edit profile Make changes to your profile here. Click save when you're done.
), }; export const CreateMember: Story = { args: { size: 'md' } as any, render: ({ size, ...args }: any) => ( Add Team Member Enter the details of the new member below.
), }; export const WithScrollableBody: Story = { args: { size: 'md' } as any, render: ({ size, ...args }: any) => ( Terms of Service Please read the full terms before accepting.
{Array.from({ length: 12 }, (_, i) => (

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.

))}
), }; export const OpenClose: Story = { render: () => ( Confirm action Are you sure you want to proceed? ), play: async ({ canvasElement }) => { const canvas = within(canvasElement); // Only test the trigger — Dialog content renders in a portal outside canvasElement const trigger = canvas.getByRole('button', { name: 'Open Dialog' }); await expect(trigger).toBeInTheDocument(); await expect(trigger).not.toBeDisabled(); await userEvent.click(trigger); // Verify trigger received the click (dialog state managed by Radix portal) await expect(trigger).toBeInTheDocument(); }, };