import type { ReactNode, SelectHTMLAttributes } from 'react' /** * Display Case — Select * Native styled to match the chrome, with a mono caret. Accepts plain * options or grouped options (Responsive / Devices), or arbitrary * children. */ export type SelectSize = 'sm' | 'md' export type SelectOption = string | { value: string; label?: ReactNode } export interface SelectOptionGroup { label: string options: SelectOption[] } export type SelectItem = SelectOption | SelectOptionGroup export interface SelectProps extends Omit, 'size'> { options?: SelectItem[] size?: SelectSize } function renderOption(o: SelectItem) { if (o && typeof o === 'object' && 'options' in o) { return ( {o.options.map(renderOption)} ) } const value = typeof o === 'string' ? o : o.value const label = typeof o === 'string' ? o : (o.label ?? o.value) return ( {label} ) } export function Select({ options = [], size = 'md', disabled = false, children, ...rest }: SelectProps) { return ( {children ?? options.map(renderOption)} ▾ ) }