import type { Meta, StoryObj } from '@storybook/react'; import { expect, userEvent, within } from 'storybook/test'; import { Switch } from './switch'; import { Label } from '../label'; import React from 'react'; const meta: Meta = { title: 'UI/Switch', component: Switch, render: args => , argTypes: { checked: { control: 'boolean', description: 'The controlled checked state of the switch.', }, disabled: { control: 'boolean', description: 'Whether the switch is disabled.', }, size: { control: 'select', options: ['sm', 'md', 'lg'], description: 'Size variant — matches the form sizing scale.', }, }, }; export default meta; type Story = StoryObj; export const Default: Story = { render: args => (
), }; export const Disabled: Story = { render: () => (
), }; /** * Size comparison: sm, md (default), lg side-by-side. */ export const Sizes: Story = { render: () => (
), }; export const Toggle: Story = { render: () => (
), play: async ({ canvasElement }) => { const canvas = within(canvasElement); const switchEl = canvas.getByRole('switch'); await expect(switchEl).toHaveAttribute('aria-checked', 'false'); await userEvent.click(switchEl); await expect(switchEl).toHaveAttribute('aria-checked', 'true'); await userEvent.click(switchEl); await expect(switchEl).toHaveAttribute('aria-checked', 'false'); }, };