/** * Combobox Component Type Definitions * Shared types used across all combobox components */ /** * Item data structure for combobox options */ export interface ComboboxItem { /** Unique identifier for the item */ value: string; /** Display text for the item */ label: string; /** Whether the item is disabled */ disabled?: boolean; } /** * Value type for combobox component * - Single-select: string * - Multi-select: string[] */ export type ComboboxValue = string | string[]; /** * Event detail for selection change */ export interface ComboboxChangeEventDetail { /** Current value (single string or array for multi-select) */ value: ComboboxValue; /** Selected item (single-select only) */ item?: ComboboxItem; /** Selected items (multi-select only) */ items?: ComboboxItem[]; } /** * Event detail for search input change */ export interface ComboboxSearchEventDetail { /** Current search query */ query: string; /** Timestamp of the search event */ timestamp: number; } /** * Event detail for custom value creation * Emitted when user enters a value not in the options list */ export interface ComboboxCustomValueEventDetail { /** The custom value entered by the user */ value: string; /** Whether the value was accepted and added */ accepted: boolean; } /** * Event detail for open state change */ export interface ComboboxOpenChangeEventDetail { /** Whether dropdown is open */ open: boolean; } /** * Reason why the combobox shows an empty state */ export type ComboboxEmptyReason = /** No items match the search query */ 'no-results' /** No search input provided yet */ | 'no-input' /** Items are being loaded */ | 'loading' /** An error occurred while loading items */ | 'error'; /** * Display mode for multi-select values in the trigger */ export type ComboboxMultiSelectDisplay = /** Show individual chips/tags for each selected item */ 'chips' /** Show a count (e.g., "3 selected") */ | 'count' /** Show comma-separated text */ | 'text'; /** * Dropdown placement options */ export type ComboboxPlacement = 'top' | 'bottom' | 'left' | 'right'; /** * Filter mode for combobox search */ export type ComboboxFilterMode = /** Filter items starting with the query */ 'startsWith' /** Filter items containing the query anywhere */ | 'contains' /** Custom filter function provided by consumer */ | 'custom'; /** * Context shared between combobox components * Provided by seki-combobox, consumed by child components */ export interface ComboboxContext { /** Current selected value(s) */ value: ComboboxValue; /** Whether multi-select mode is enabled */ multiple: boolean; /** Whether dropdown is open */ open: boolean; /** Whether combobox is disabled */ disabled: boolean; /** Whether combobox is required */ required: boolean; /** Whether combobox is in loading state */ loading: boolean; /** Current search query */ searchQuery: string; /** Currently focused item value */ focusedItemValue: string | null; /** Whether custom values are allowed */ allowCustomValue: boolean; /** Display mode for multi-select values */ multiSelectDisplay: ComboboxMultiSelectDisplay; /** Unique ID for the input element */ inputId: string; /** Unique ID for the listbox element (for aria-controls) */ listboxId: string; /** Unique ID for the trigger element */ triggerId: string; /** Accessible label for screen readers */ ariaLabel?: string; /** ID of element that labels this combobox */ ariaLabelledby?: string; /** ID of element that describes this combobox */ ariaDescribedby?: string; /** Handler for value changes */ onValueChange: (value: ComboboxValue) => void; /** Handler for open state changes */ onOpenChange: (open: boolean) => void; /** Handler for search query changes */ onSearchChange: (query: string) => void; /** Handler for item focus changes */ onItemFocus: (value: string) => void; /** Handler for item selection */ onItemSelect: (value: string) => void; /** Handler for custom value creation */ onCustomValueCreate: (value: string) => void; /** Check if a value is selected */ isValueSelected: (value: string) => boolean; /** Get all selected items */ getSelectedItems: () => ComboboxItem[]; /** Register an item with the context */ registerItem: (item: ComboboxItem) => void; /** Unregister an item from the context */ unregisterItem: (value: string) => void; /** Get filtered items based on search query */ getFilteredItems: () => ComboboxItem[]; /** Clear the current selection */ clearSelection: () => void; /** Remove a specific value from selection (multi-select) */ removeValue: (value: string) => void; } /** * Type-ahead/search state for managing search buffer */ export interface ComboboxSearchState { /** Current search buffer */ buffer: string; /** Timeout ID for debounce */ timeoutId: number | null; /** Debounce duration in milliseconds */ debounce: number; } /** * Event detail for validation state */ export interface ComboboxValidateEventDetail { /** Whether the value is valid */ valid: boolean; /** Error message if invalid */ errorMessage?: string; }