import { useId, useState, type ReactNode } from "react" import type { Meta, StoryObj } from "@storybook/react-vite" import { Label, Switch } from "@hm-design/ui" import { StateBoard } from "@/components/story-board" import { STORY_KICKER, StoryPage, StoryPageHeader, StorySection } from "@/components/story-page" function Option({ label, children }: { label: string; children: (id: string) => ReactNode }) { const id = useId() return (
{children(id)}
) } function Controlled() { const [on, setOn] = useState(false) return } const meta = { title: "Components/Form/Switch", component: Switch, parameters: { layout: "padded", docs: { description: { component: "현재 HM 규격: 트랙 36×20, 썸 16, On은 state-active, Off는 stroke 색. ui-viz에는 Switch 규격이 없어 참고만 했습니다. Radix Switch의 role=switch, 키보드, 접근성과 shadcn 기본 transition을 유지합니다.", }, }, }, } satisfies Meta export default meta type Story = StoryObj export const All: Story = { name: "Switch", parameters: { layout: "fullscreen", controls: { disable: true } }, render: () => ( {(id) => } }, { id: "on", label: "On", children: }, { id: "interactive", label: "Controlled · click toggles", children: }, ]} /> {(id) => } }, { id: "focus", label: "Focus", children: }, { id: "disabled", label: "Disabled", children: (
), }, ]} />
), play: async ({ canvasElement }) => { // preventScroll: the page opens at its header, not at the States section. canvasElement.querySelector('[data-overview-state="focus"] [role="switch"]')?.focus({ preventScroll: true }) }, } export const Off: Story = { tags: ["verification"], render: () => } export const On: Story = { tags: ["verification"], render: () => } export const Disabled: Story = { tags: ["verification"], render: () => }