import type { Meta, StoryObj } from "@storybook/react"; import { useState } from "react"; import { DropdownField } from "./DropdownField"; const meta: Meta = { title: "Widgets/Onboarding/Fields/DropdownField", component: DropdownField, parameters: { layout: "centered", docs: { description: { component: ` Dropdown select field for choosing from a list of options in onboarding flows. Supports both flat and grouped option lists: - **Flat options** - Simple list of choices - **Grouped options** - Categorized options with group labels \`\`\`tsx import { DropdownField } from '@mdxui/widgets' \`\`\` `, }, }, }, tags: ["autodocs"], argTypes: { required: { control: "boolean" }, disabled: { control: "boolean" }, }, decorators: [ (Story) => (
), ], }; export default meta; type Story = StoryObj; // Sample options const countryOptions = [ { value: "us", label: "United States" }, { value: "uk", label: "United Kingdom" }, { value: "ca", label: "Canada" }, { value: "au", label: "Australia" }, { value: "de", label: "Germany" }, { value: "fr", label: "France" }, ]; const groupedOptions = [ { label: "North America", options: [ { value: "us", label: "United States" }, { value: "ca", label: "Canada" }, { value: "mx", label: "Mexico" }, ], }, { label: "Europe", options: [ { value: "uk", label: "United Kingdom" }, { value: "de", label: "Germany" }, { value: "fr", label: "France" }, ], }, { label: "Asia Pacific", options: [ { value: "jp", label: "Japan" }, { value: "au", label: "Australia" }, { value: "sg", label: "Singapore" }, ], }, ]; // Wrapper to handle controlled state function DropdownFieldWithState( props: React.ComponentProps, ) { const [value, setValue] = useState(props.value || ""); return ; } /** * Default dropdown with flat options list. * Use Controls to toggle: required, disabled, value */ export const Default: Story = { render: (args) => , args: { id: "country", label: "Country", placeholder: "Select a country", description: "Where is your company headquartered?", options: countryOptions, value: "", }, }; /** * Grouped options with category headers. * Best for large option sets that benefit from organization. */ export const Grouped: Story = { name: "Grouped Options", render: (args) => , args: { id: "region", label: "Deployment Region", description: "Select your preferred deployment region", placeholder: "Select a region", options: groupedOptions, value: "", }, };