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 { STORY_KICKER, 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: "짧은 옵션" }, ] function Field({ label, id, children }: { label: string; id: string; children: ReactNode }) { return (
{children}
) } function Empty() { return ( ) } function Controlled() { const [value, setValue] = useState("nuxt") return (
{`value = ${value}`}
) } function Medium() { return ( ) } function LongLabel() { return ( ) } function Disabled() { return ( ) } function SelectComparison() { return (
{(["medium", "large"] as const).map((size) => (
))}
) } const sections = [ { id: "empty", label: "Empty placeholder + search (Remix is a disabled option)", node: }, { id: "controlled", label: "Selected, controlled", node: }, { id: "medium", label: "Medium size", node: }, { id: "long", label: "Long option", node: }, { id: "disabled", label: "Disabled", node: }, ] // 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 const board = (...ids: string[]) => ( ids.includes(s.id)).map((s) => ({ id: s.id, label: s.label, children: s.node }))} /> ) // 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: () => ( {board("empty")} s.id === "medium").map((s) => ({ id: s.id, label: s.label, children: s.node })), { id: "select-comparison", label: "Select / Combobox visual comparison", wide: true, children: }, ]} /> {board("controlled", "disabled")} {board("long")} ), } export const EmptyCombobox: Story = { tags: ["verification"], name: "Empty", render: () => } export const ControlledCombobox: Story = { tags: ["verification"], name: "Controlled", render: () => } export const LongOption: Story = { tags: ["verification"], name: "Long Option", render: () => } export const OpenBottom: Story = { tags: ["verification"], render: () =>
, } export const OpenTop: Story = { tags: ["verification"], render: () =>
, }