- Button: Sizes | Variants side by side, States as Brand / Standard Solid / Standard Outline matrices (3 / 2 / 1 columns), 8px button gap; the Interact row stays only in the verification "Brand States" Story - Input / Textarea / Select: state name in the field Label slot, repeated field Label and group titles removed, aria-label keeps field meaning with the visible state name; Select uses the Input field grid - Combobox / Date Picker: Sizes / States use the same state-name Label and Input grid; Usage unchanged - Toggle: top Variants / States in 2 columns, 8px toggle gap, 단독 toggle keeps its own width - Component code, props, tokens and verification Stories unchanged; component docs updated to match
189 lines
8.6 KiB
TypeScript
189 lines
8.6 KiB
TypeScript
import { useState, type ReactNode } from "react"
|
|
import type { Meta, StoryObj } from "@storybook/react-vite"
|
|
import { Combobox, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, type ComboboxOption } from "@hm-design/ui"
|
|
import { StateBoard } from "@/components/story-board"
|
|
import { StoryPage, StoryPageHeader, StorySection } from "@/components/story-page"
|
|
|
|
// Combobox is a Popover + Command composition (search + single choice); Select stays for short lists without search.
|
|
// The representative Story shows real comboboxes; the same specimens also exist as Stories tagged `verification` (hidden from the
|
|
// sidebar). The Label is Story composition.
|
|
|
|
const frameworks: ComboboxOption[] = [
|
|
{ value: "next", label: "Next.js" },
|
|
{ value: "sveltekit", label: "SvelteKit" },
|
|
{ value: "nuxt", label: "Nuxt" },
|
|
{ value: "remix", label: "Remix", disabled: true },
|
|
{ value: "astro", label: "Astro" },
|
|
]
|
|
|
|
const longOptions: ComboboxOption[] = [
|
|
{ value: "a", label: "긴 옵션 이름은 한 줄에서 말줄임으로 잘리고 trigger 폭을 넘지 않습니다. 끝까지 읽을 수 있어야 하면 폭을 넓히세요" },
|
|
{ value: "b", label: "짧은 옵션" },
|
|
]
|
|
|
|
// Label 14/20/500 in the default text color; a Disabled field keeps the secondary color at 0.6 (same as the Form pages).
|
|
// `fill` lets the field take its grid column (representative page); the verification Stories keep the 320px field.
|
|
function Field({ label, id, disabled, fill, children }: { label: string; id: string; disabled?: boolean; fill?: boolean; children: ReactNode }) {
|
|
return (
|
|
<div className={fill ? "grid gap-2" : "grid max-w-xs gap-2"}>
|
|
<label htmlFor={id} className={`justify-self-start text-sm font-medium ${disabled ? "text-muted-foreground opacity-60" : "text-foreground"}`}>
|
|
{label}
|
|
</label>
|
|
{children}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// Representative page (2026-11-12, same rule as Input / Select): with `state`, the state name takes the field Label slot (no
|
|
// repeated field Label under a separate group title) and the trigger keeps the field meaning in its accessible name, which also
|
|
// contains the visible state name (Label in Name), e.g. "프레임워크 (Selected)". Without `state` the verification Stories are unchanged.
|
|
const stateName = (state: string | undefined, field: string) => (state ? `${field} (${state})` : undefined)
|
|
|
|
function Empty({ state }: { state?: string }) {
|
|
return (
|
|
<Field label={state ?? "프레임워크"} id="cb-empty" fill={state !== undefined}>
|
|
<Combobox id="cb-empty" aria-label={stateName(state, "프레임워크")} options={frameworks} placeholder="프레임워크 선택" searchPlaceholder="프레임워크 검색..." />
|
|
</Field>
|
|
)
|
|
}
|
|
|
|
// `showValue={false}` hides the value readout on the representative page; the verification Stories keep it.
|
|
function Controlled({ showValue = true, state }: { showValue?: boolean; state?: string }) {
|
|
const [value, setValue] = useState("nuxt")
|
|
return (
|
|
<div className="grid gap-2">
|
|
<Field label={state ?? "선택됨 (controlled)"} id="cb-controlled" fill={state !== undefined}>
|
|
<Combobox id="cb-controlled" aria-label={stateName(state, "프레임워크")} controlled options={frameworks} value={value} onValueChange={setValue} />
|
|
</Field>
|
|
{showValue ? <span className="text-sm text-muted-foreground" data-testid="controlled">{`value = ${value}`}</span> : null}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function Medium({ state }: { state?: string }) {
|
|
return (
|
|
<Field label={state ?? "Medium"} id="cb-medium" fill={state !== undefined}>
|
|
<Combobox id="cb-medium" aria-label={stateName(state, "프레임워크")} size="medium" options={frameworks} defaultValue="astro" />
|
|
</Field>
|
|
)
|
|
}
|
|
|
|
function LongLabel() {
|
|
return (
|
|
<Field label="긴 옵션" id="cb-long">
|
|
<Combobox id="cb-long" options={longOptions} defaultValue="a" />
|
|
</Field>
|
|
)
|
|
}
|
|
|
|
function Disabled({ state }: { state?: string }) {
|
|
return (
|
|
<Field label={state ?? "비활성"} id="cb-disabled" disabled fill={state !== undefined}>
|
|
<Combobox id="cb-disabled" aria-label={stateName(state, "프레임워크")} options={frameworks} defaultValue="next" disabled />
|
|
</Field>
|
|
)
|
|
}
|
|
|
|
function SelectComparison() {
|
|
return (
|
|
<div className="grid gap-6 sm:grid-cols-2">
|
|
{(["medium", "large"] as const).map((size) => (
|
|
<div key={size} className="grid content-start gap-3" data-comparison-size={size}>
|
|
<Field label={`Select · ${size}`} id={`compare-select-${size}`}>
|
|
<Select defaultValue="nuxt">
|
|
<SelectTrigger id={`compare-select-${size}`} size={size} className="w-full"><SelectValue /></SelectTrigger>
|
|
<SelectContent>
|
|
{frameworks.map((option) => <SelectItem key={option.value} value={option.value} disabled={option.disabled}>{option.label}</SelectItem>)}
|
|
</SelectContent>
|
|
</Select>
|
|
</Field>
|
|
<Field label={`Combobox · ${size}`} id={`compare-combobox-${size}`}>
|
|
<Combobox id={`compare-combobox-${size}`} size={size} options={frameworks} defaultValue="nuxt" />
|
|
</Field>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// Same 3-column track as the Form pages (1 column on narrow screens). Each cell is a one-specimen StateBoard so subtitles, dividers and
|
|
// fields line up; sections with fewer specimens leave the remaining tracks empty. A wide cell takes two tracks (the full row on narrow screens).
|
|
const Grid = ({ children }: { children: ReactNode }) => (
|
|
<div className="grid items-start gap-6 [grid-template-columns:repeat(auto-fill,minmax(min(100%,300px),1fr))] min-[1000px]:grid-cols-3">{children}</div>
|
|
)
|
|
const Cell = ({ id, label, wide, children }: { id: string; label: string; wide?: boolean; children: ReactNode }) => (
|
|
<div className={wide ? "col-span-full min-w-0 min-[1000px]:col-span-2" : "min-w-0"}>
|
|
<StateBoard min={10000} states={[{ id, label, children }]} />
|
|
</div>
|
|
)
|
|
|
|
// Sizes / States (2026-11-12): the Input / Select field grid with the common section indent — up to 3 tracks of at least 240px
|
|
// within 1120px, narrower widths drop to 2 / 1 columns. Each cell is one field whose Label is the state name.
|
|
const fieldColumns =
|
|
"grid max-w-[1120px] items-start gap-6 [grid-template-columns:repeat(auto-fill,minmax(max(240px,calc((100%_-_48px)/3)),1fr))]"
|
|
|
|
function FieldRow({ fields }: { fields: { id: string; render: ReactNode }[] }) {
|
|
return (
|
|
<div className="sb-page-indent">
|
|
<div className={fieldColumns}>
|
|
{fields.map(({ id, render }) => (
|
|
<div key={id} className="min-w-0" data-overview-state={id}>
|
|
{render}
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
// No `component`: Combobox has a required `options` prop, so Stories without args would not type-check.
|
|
const meta = { title: "Components/Search & Date/Combobox", parameters: { layout: "padded" } } satisfies Meta
|
|
export default meta
|
|
type Story = StoryObj<typeof meta>
|
|
|
|
// Representative Story: the common Story page; the sections group the same specimens.
|
|
export const All: Story = {
|
|
name: "Combobox",
|
|
parameters: { layout: "fullscreen", controls: { disable: true } },
|
|
render: () => (
|
|
<StoryPage>
|
|
<StoryPageHeader title="Combobox" />
|
|
<StorySection title="Sizes">
|
|
<FieldRow
|
|
fields={[
|
|
{ id: "empty", render: <Empty state="Default" /> },
|
|
{ id: "medium", render: <Medium state="Medium" /> },
|
|
]}
|
|
/>
|
|
</StorySection>
|
|
<StorySection title="States">
|
|
<FieldRow
|
|
fields={[
|
|
{ id: "controlled", render: <Controlled showValue={false} state="Selected" /> },
|
|
{ id: "disabled", render: <Disabled state="Disabled" /> },
|
|
]}
|
|
/>
|
|
</StorySection>
|
|
<StorySection title="Usage">
|
|
<Grid>
|
|
<Cell id="long" label="Long option"><LongLabel /></Cell>
|
|
<Cell id="select-comparison" label="Select / Combobox" wide><SelectComparison /></Cell>
|
|
</Grid>
|
|
</StorySection>
|
|
</StoryPage>
|
|
),
|
|
}
|
|
|
|
export const EmptyCombobox: Story = { tags: ["verification"], name: "Empty", render: () => <Empty /> }
|
|
export const ControlledCombobox: Story = { tags: ["verification"], name: "Controlled", render: () => <Controlled /> }
|
|
export const LongOption: Story = { tags: ["verification"], name: "Long Option", render: () => <LongLabel /> }
|
|
|
|
export const OpenBottom: Story = {
|
|
tags: ["verification"],
|
|
render: () => <div style={{ width: 280, maxWidth: "100%", minHeight: "calc(100dvh - 32px)" }}><Controlled /></div>,
|
|
}
|
|
export const OpenTop: Story = {
|
|
tags: ["verification"],
|
|
render: () => <div style={{ width: 280, maxWidth: "100%", minHeight: "calc(100dvh - 32px)", display: "grid", alignItems: "end" }}><Controlled /></div>,
|
|
}
|