import { default as React } from 'react'; import { ComboBoxGroup, ComboBoxMode } from './types'; import { CommandItem } from '../command/types'; /** * Props interface for the ComboBox component. */ export default interface IComboBoxProps { /** * =========================== * Core Props * =========================== */ /** * Placeholder text shown in the ComboBox input when empty * @default Search... */ placeholder?: string; /** * Text displayed when no results match the current search * @default No results found for */ noResultText?: string; /** * Mode of the ComboBox. * @default 'single' */ mode?: T; /** * Array of ComboBox result groups to display. * Each group can have a label and contains multiple ComboBox items. */ menuItems: ComboBoxGroup[]; /** * Current search text value for the input field. * Use this for controlled component behavior together with onType. */ value?: T extends 'single' ? string : string[]; /** * Callback fired when the user selects an item * @param value The selected item values */ onSelect?: (value: T extends 'single' ? string : string[]) => void; /** * Callback fired when the ComboBox menu is opened or closed * @param open Boolean indicating if the ComboBox menu is now open */ onOpenChange?: (open: boolean) => void; /** * =========================== * State Props * =========================== */ /** * If true, shows a loading spinner and indicates that content is loading * @default false */ isContentLoading?: boolean; /** * Controls whether the ComboBox menu is open (for controlled components) */ isOpen?: boolean; /** * If true, disables the ComboBox input and trigger * @default false */ isDisabled?: boolean; /** * If true, shows a loading skeleton and indicates that trigger is loading * @default false */ isLoading?: boolean; /** * =========================== * Accessibility Props * =========================== */ /** * Custom ID for the trigger element, useful for accessibility and testing */ triggerId?: string; /** * Custom ID for the content element, useful for accessibility and testing */ contentId?: string; /** * Ref to access the ComboBox trigger button element */ ref?: React.RefObject; /** * =========================== * Customization Props * =========================== */ /** * Optional custom render function for item content. * When provided, replaces the default label text in each dropdown item. * In multi mode, the checkbox prefix is preserved automatically. * * @example * ```tsx * renderItem={(item) => ( *
* * {item.label} *
* )} * ``` */ renderItem?: (item: CommandItem) => React.ReactNode; /** * Custom filter function to override the default exact substring matching. * Receives the full item object and the search string, and returns whether the item should be shown. * Defaults to case-insensitive exact substring match against both label and value. * * @param item - The item object with `label` and `value` * @param search - The current search query * @returns `true` to show the item, `false` to hide it * * @example * ```tsx * // Only show items whose label starts with the search string * filter={(item, search) => * item.label.toLowerCase().startsWith(search.toLowerCase()) * } * ``` */ filter?: (item: { label: string; value: string; }, search: string) => boolean; /** * Controlled search text of the search input. * Use together with `onSearchValueChange`. Omit to let the ComboBox manage the search text. * * @example * ```tsx * const [search, setSearch] = useState(''); * * ``` */ searchValue?: string; /** * Called on every change of the search input, including clearing it. * * @param search - The new search text */ onSearchValueChange?: (search: string) => void; /** * Multi mode only. Called when "Alle wählen" of a group is clicked, * with the values of all selectable items in that group (the search is not applied). * When provided, the default select-all is not applied, so the consumer decides what to select. * * @param allValues - Values of all selectable items in the clicked group * * @example * ```tsx * // Select only the items matching the current search * onSelectAll={allValues => * setValue(prev => [...new Set([...prev, ...allValues.filter(v => matches(v, search))])]) * } * ``` */ onSelectAll?: (allValues: string[]) => void; }