import { useState } from "react"; import type { Meta, StoryObj } from "@storybook/react-vite"; import { Check, ChevronsUpDown } from "lucide-react"; import { useArgs } from "storybook/preview-api"; import { Combobox } from "./combobox"; const frameworks = [ { value: "react", label: "React" }, { value: "vue", label: "Vue" }, { value: "angular", label: "Angular" }, { value: "svelte", label: "Svelte" }, { value: "solid", label: "Solid" }, { value: "next", label: "Next.js" }, { value: "nuxt", label: "Nuxt" }, { value: "remix", label: "Remix" }, ]; const meta = { title: "Components/Combobox", component: Combobox, subcomponents: { ComboboxButton: Combobox.Button, ComboboxOptions: Combobox.Options, ComboboxOption: Combobox.Option, }, parameters: { layout: "centered", }, tags: ["autodocs"], args: { children: null, value: "", onValueChange: () => {}, }, render(args) { const [{ value }, updateArgs] = useArgs(); const setValue = (newValue: string | string[]) => updateArgs({ value: newValue }); return ( setValue(v as string)}> {value ? frameworks.find((f) => f.value === value)?.label : "Select framework..."} {frameworks.map((framework) => ( {value === framework.value && } {framework.label} ))} ); }, } satisfies Meta; export default meta; type Story = StoryObj; export const Default: Story = {}; export const WithoutSearch: Story = { render() { const [value, setValue] = useState(""); return ( setValue(v as string)}> {value ? frameworks.find((f) => f.value === value)?.label : "Select framework..."} {frameworks.map((framework) => ( {value === framework.value && } {framework.label} ))} ); }, }; export const MultiSelect: Story = { render() { const [value, setValue] = useState([]); return ( setValue(v as string[])}> {value.length > 0 ? `${value.length} selected` : "Select frameworks..."} {frameworks.map((framework) => ( {value.includes(framework.value) && } {framework.label} ))} ); }, }; export const MultiSelectWithLimit: Story = { render() { const [value, setValue] = useState([]); return (
setValue(v as string[])}> {value.length > 0 ? `${value.length}/3 selected` : "Select up to 3 frameworks..."} {frameworks.map((framework) => ( {value.includes(framework.value) && } {framework.label} ))}

Maximum 3 selections allowed

); }, }; export const Disabled: Story = { args: { disabled: true }, render() { const [value, setValue] = useState(""); return ( setValue(v as string)}> {value ? frameworks.find((f) => f.value === value)?.label : "Select framework..."} {frameworks.map((framework) => ( {value === framework.value && } {framework.label} ))} ); }, }; export const DisabledOptions: Story = { render() { const [value, setValue] = useState(""); return ( setValue(v as string)}> {value ? frameworks.find((f) => f.value === value)?.label : "Select framework..."} {frameworks.map((framework) => ( {value === framework.value && } {framework.label} ))} ); }, }; export const CustomMaxHeight: Story = { render() { const [value, setValue] = useState(""); return ( setValue(v as string)}> {value ? frameworks.find((f) => f.value === value)?.label : "Select framework..."} {frameworks.map((framework) => ( {value === framework.value && } {framework.label} ))} ); }, }; export const CustomEmptyMessage: Story = { render() { const [value, setValue] = useState(""); return ( setValue(v as string)}> {value ? frameworks.find((f) => f.value === value)?.label : "Select framework..."} {frameworks.map((framework) => ( {value === framework.value && } {framework.label} ))} ); }, };