93 lines
4.1 KiB
TypeScript
93 lines
4.1 KiB
TypeScript
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
import { Label, RadioGroup, RadioGroupItem } from "@hm-design/ui"
|
|
import { StateBoard } from "@/components/story-board"
|
|
import { STORY_KICKER, StoryPage, StoryPageHeader, StorySection } from "@/components/story-page"
|
|
|
|
// Current HM Radio Group. ui-viz has no Radio spec, so it was reference only.
|
|
|
|
function Group({
|
|
prefix,
|
|
defaultValue = "a",
|
|
disabled,
|
|
disabledItem,
|
|
invalid,
|
|
orientation,
|
|
}: {
|
|
prefix: string
|
|
defaultValue?: string
|
|
disabled?: boolean
|
|
disabledItem?: string
|
|
invalid?: boolean
|
|
orientation?: "horizontal" | "vertical"
|
|
}) {
|
|
return (
|
|
<RadioGroup defaultValue={defaultValue} disabled={disabled} orientation={orientation} aria-label={prefix}>
|
|
{["a", "b", "c"].map((v) => (
|
|
<div key={v} className="flex items-center gap-2">
|
|
<RadioGroupItem value={v} id={`${prefix}-${v}`} disabled={disabledItem === v} aria-invalid={invalid ? true : undefined} />
|
|
<Label htmlFor={`${prefix}-${v}`}>Option {v.toUpperCase()}</Label>
|
|
</div>
|
|
))}
|
|
</RadioGroup>
|
|
)
|
|
}
|
|
|
|
const meta = {
|
|
title: "Components/Form/Radio Group",
|
|
component: RadioGroup,
|
|
parameters: {
|
|
layout: "padded",
|
|
docs: {
|
|
description: {
|
|
component:
|
|
"현재 HM 규격: 18px 원, border 1px(stroke), Checked/Selected는 state-active 테두리 + 8px state-active dot, group gap 12(horizontal 16). Radix RadioGroup의 roving focus, 방향키 선택, ARIA를 유지합니다. ui-viz에는 Radio 규격이 없어 참고만 했습니다.",
|
|
},
|
|
},
|
|
},
|
|
} satisfies Meta<typeof RadioGroup>
|
|
export default meta
|
|
type Story = StoryObj<typeof meta>
|
|
|
|
export const All: Story = {
|
|
name: "Radio Group",
|
|
parameters: { layout: "fullscreen", controls: { disable: true } },
|
|
render: () => (
|
|
<StoryPage>
|
|
<StoryPageHeader
|
|
kicker={STORY_KICKER.components}
|
|
title="Radio Group"
|
|
description="여러 선택지 중 하나를 고르는 컨트롤입니다. 그룹 안에서는 방향키로 이동·선택합니다(Radix roving focus)."
|
|
/>
|
|
<StorySection title="Overview">
|
|
<StateBoard min={240} states={[{ id: "vertical", label: "Vertical (default) · Checked / Unchecked", children: <Group prefix="v" defaultValue="b" /> }]} />
|
|
</StorySection>
|
|
<StorySection title="Variants">
|
|
<StateBoard min={240} states={[{ id: "horizontal", label: "Horizontal", children: <Group prefix="h" orientation="horizontal" /> }]} />
|
|
</StorySection>
|
|
<StorySection title="States">
|
|
<StateBoard
|
|
min={240}
|
|
states={[
|
|
{ id: "hover", label: "Hover", noteAfter: true, note: "Hover한 항목의 테두리가 primary 색이 됩니다.", children: <Group prefix="hv" defaultValue="" /> },
|
|
{ id: "focus", label: "Focus", noteAfter: true, note: "그룹에 Tab으로 들어가면 선택된 항목에 focus ring이 표시됩니다.", children: <Group prefix="f" /> },
|
|
{ id: "disabled-item", label: "Disabled · 항목", children: <Group prefix="di" disabledItem="b" /> },
|
|
{ id: "disabled-group", label: "Disabled · 그룹", children: <Group prefix="dg" disabled /> },
|
|
]}
|
|
/>
|
|
</StorySection>
|
|
<StorySection title="Validation" description="aria-invalid로 Error 테두리를 표시합니다.">
|
|
<StateBoard min={240} states={[{ id: "error", label: "Error", children: <Group prefix="e" invalid /> }]} />
|
|
</StorySection>
|
|
</StoryPage>
|
|
),
|
|
play: async ({ canvasElement }) => {
|
|
// preventScroll: the page opens at its header, not at the States section.
|
|
canvasElement.querySelector<HTMLButtonElement>('[data-overview-state="focus"] [role="radio"][data-state="checked"]')?.focus({ preventScroll: true })
|
|
},
|
|
}
|
|
|
|
export const Vertical: Story = { tags: ["verification"], render: () => <Group prefix="sv" /> }
|
|
export const Horizontal: Story = { tags: ["verification"], render: () => <Group prefix="sh" orientation="horizontal" /> }
|
|
export const Disabled: Story = { tags: ["verification"], render: () => <Group prefix="sd" disabled /> }
|
|
export const Error: Story = { tags: ["verification"], render: () => <Group prefix="se" invalid /> }
|