import type { ReactElement, Ref } from "react"; import type { TextFieldElementType, TextFieldProps } from "../TextField"; export type ComboboxOption = string | { id?: string; label: string; value: string; }; export type ComboboxBaseProps = TextFieldProps & { /** An icon to display in TextField (left side) */ icon?: ReactElement; /** The default value of the selected option */ defaultValue?: string | undefined; /** Callback when the selected option changes */ onSelected?: ((value: T) => void) | undefined; optionComponent?: (props: Pick, "option" | "isHighlighted">) => ReactElement; /** Prefix for option data-testid attributes (default: "combobox-option") */ optionTestIdPrefix?: string; }; export type ComboboxSyncProps = ComboboxBaseProps & { /** The list of options to display in the dropdown */ options: ComboboxOptions; asyncOptions?: never; delay?: never; minSearchLength?: never; onSearched?: never; }; export type ComboboxAsyncProps = ComboboxBaseProps & { options?: never; delay?: number; minSearchLength?: number | undefined; /** A function that returns a list of options to display in the dropdown */ asyncOptions: ((inputValue: string) => ComboboxOptions) | ((inputValue: string, options?: { signal?: AbortSignal; }) => Promise>); onSearched?: (searchTerm: string) => void; }; export type ComboboxProps = ComboboxAsyncProps | ComboboxSyncProps; export type ComboboxOptionGroup = { heading: string; options: readonly T[]; }; export type ComboboxOptions = T[] | ComboboxOptionGroup[]; export type ComboboxElementType = TextFieldElementType; export type ComboboxRef = Ref; export type ComboboxOptionProps = { option: T; optionComponent?: ComboboxBaseProps["optionComponent"]; isHighlighted: boolean; onOptionSelect: (option: T) => void; id: string; optionTestIdPrefix?: string; };