import type { Meta, StoryObj } from '@storybook/nextjs' import { useState } from 'react' import Select, { PortalSelect, SimpleSelect } from '.' import type { Item } from '.' const meta = { title: 'Base/Data Entry/Select', component: SimpleSelect, parameters: { layout: 'centered', docs: { description: { component: 'Select component with three variants: Select (with search), SimpleSelect (basic dropdown), and PortalSelect (portal-based positioning). Built on Headless UI.', }, }, }, tags: ['autodocs'], argTypes: { placeholder: { control: 'text', description: 'Placeholder text', }, disabled: { control: 'boolean', description: 'Disabled state', }, notClearable: { control: 'boolean', description: 'Hide clear button', }, hideChecked: { control: 'boolean', description: 'Hide check icon on selected item', }, }, args: { onSelect: (item) => { console.log('Selected:', item) }, }, } satisfies Meta export default meta type Story = StoryObj const fruits: Item[] = [ { value: 'apple', name: 'Apple' }, { value: 'banana', name: 'Banana' }, { value: 'cherry', name: 'Cherry' }, { value: 'date', name: 'Date' }, { value: 'elderberry', name: 'Elderberry' }, ] const countries: Item[] = [ { value: 'us', name: 'United States' }, { value: 'uk', name: 'United Kingdom' }, { value: 'ca', name: 'Canada' }, { value: 'au', name: 'Australia' }, { value: 'de', name: 'Germany' }, { value: 'fr', name: 'France' }, { value: 'jp', name: 'Japan' }, { value: 'cn', name: 'China' }, ] // SimpleSelect Demo const SimpleSelectDemo = (args: any) => { const [selected, setSelected] = useState(args.defaultValue || '') return (
{ setSelected(item.value) console.log('Selected:', item) }} /> {selected && (
Selected: {selected}
)}
) } // Default SimpleSelect export const Default: Story = { render: args => , args: { placeholder: 'Select a fruit...', defaultValue: 'apple', items: [], }, } // With placeholder (no selection) export const WithPlaceholder: Story = { render: args => , args: { placeholder: 'Choose an option...', defaultValue: '', items: [], }, } // Disabled state export const Disabled: Story = { render: args => , args: { placeholder: 'Select a fruit...', defaultValue: 'banana', disabled: true, items: [], }, } // Not clearable export const NotClearable: Story = { render: args => , args: { placeholder: 'Select a fruit...', defaultValue: 'cherry', notClearable: true, items: [], }, } // Hide checked icon export const HideChecked: Story = { render: args => , args: { placeholder: 'Select a fruit...', defaultValue: 'apple', hideChecked: true, items: [], }, } // Select with search const WithSearchDemo = () => { const [selected, setSelected] = useState('us') return (
setWithSearch(item.value as string)} allowSearch={true} />

Dropdown with search/filter capability

PortalSelect (Portal-based)

setPortal(item.value as string)} placeholder="Choose a fruit..." />

Portal-based positioning for better overflow handling

) } export const VariantComparison: Story = { render: () => , parameters: { controls: { disable: true } }, } as unknown as Story // Interactive playground const PlaygroundDemo = () => { const [selected, setSelected] = useState('apple') return (
setSelected(item.value as string)} placeholder="Select an option..." />
) } export const Playground: Story = { render: () => , parameters: { controls: { disable: true } }, } as unknown as Story