import { useId, useState, type ReactNode } from "react" import type { Meta, StoryObj } from "@storybook/react-vite" import { Checkbox, Label } from "@hm-design/ui" import { StateBoard } from "@/components/story-board" import { STORY_KICKER, StoryPage, StoryPageHeader, StorySection } from "@/components/story-page" // Current HM Checkbox. ui-viz has no Checkbox spec, so it was reference only. // The option label is the HM Label; its foreground role for Checkbox options is still TBD in ui_viz. function Option({ label, children }: { label: string; children: (id: string) => ReactNode }) { const id = useId() return (
{children(id)}
) } function Controlled() { const [checked, setChecked] = useState("indeterminate") return ( ) } const meta = { title: "Components/Form/Checkbox", component: Checkbox, parameters: { layout: "padded", docs: { description: { component: "현재 HM 규격: 18px 박스, radius 4, border 1px(stroke), Checked/Indeterminate는 state-active 테두리·면 + on-state-active 아이콘. Radix Checkbox의 data-state, indeterminate, 키보드(Space)와 접근성을 유지합니다. ui-viz에는 Checkbox 규격이 없어 참고만 했습니다.", }, }, }, } satisfies Meta export default meta type Story = StoryObj export const All: Story = { name: "Checkbox", parameters: { layout: "fullscreen", controls: { disable: true } }, render: () => ( {(id) => } }, { id: "checked", label: "Checked", children: }, { id: "indeterminate", label: "Indeterminate", children: }, { id: "interactive", label: "Controlled · click toggles", noteAfter: true, note: "Indeterminate에서 클릭하면 checked가 됩니다(Radix).", children: }, ]} /> {(id) => } }, { id: "focus", label: "Focus", children: }, { id: "disabled", label: "Disabled", children: (
), }, ]} />
{(id) => } }]} />
), }, ]} />
), play: async ({ canvasElement }) => { // preventScroll: the page opens at its header, not at the States section. canvasElement.querySelector('[data-overview-state="focus"] [role="checkbox"]')?.focus({ preventScroll: true }) }, } export const Unchecked: Story = { tags: ["verification"], render: () => } export const Checked: Story = { tags: ["verification"], render: () => } export const Indeterminate: Story = { tags: ["verification"], render: () => } export const Disabled: Story = { tags: ["verification"], render: () => } export const Error: Story = { tags: ["verification"], render: () => } export const Playground: Story = { tags: ["verification"], args: { disabled: false, defaultChecked: false }, render: (args) => , }