import type { UseMultipleSelectionStateChangeTypes } from "downshift"; import type { ComponentType, FocusEventHandler, ForwardedRef, PropsWithChildren, ReactNode, RefObject } from "react"; import type { IconComponentType } from "../../Icons"; export type AutoCompleteVariant = "medium" | "large"; export type AutoCompleteLocale = { emptyStateTitle?: string; clearInputButton?: string; selectionMessage?: (optionName: string, option: Option | null) => string; itemsAvailable?: (resultCount: number) => string; showMoreButton?: (extraResults: number) => string; optionItemPrefix?: (multiple: boolean) => string; }; export interface AutoCompleteBaseProps { /** * The id of the `AutoComplete`. */ id?: string; /** * The aria-label of the `AutoComplete`. */ "aria-label"?: string; /** * The label id of the `AutoComplete`. */ labelId?: string; /** * The icon of the `AutoComplete`. */ icon?: IconComponentType; /** * The name of the `AutoComplete`. */ name?: string; /** * Whether the `AutoComplete` is required. * @default false */ required?: boolean; /** * The class name of the `AutoComplete`. */ className?: string; /** * The class name of the `AutoComplete` values. */ valuesClassName?: string; /** * The class name of the `AutoComplete` menu. */ menuClassName?: string; /** * The variant of the `AutoComplete`. * @default "medium" */ variant?: AutoCompleteVariant; /** * The placeholder of the `AutoComplete`. */ placeholder?: string; /** * Whether the `AutoComplete` is disabled. * @default false */ disabled?: boolean; /** * Whether the `AutoComplete` should be focused. */ autoFocus?: boolean; /** * The options of the `AutoComplete`. */ options?: T[]; /** * The current value of the `AutoComplete`. */ inputValue?: string; /** * The callback function that is called when the text of the `AutoComplete` changes. */ onTextChange?: (text: string) => any; /** * The callback function that is called when the `AutoComplete` gains focus. */ onFocus?: FocusEventHandler; /** * The callback function that is called when the `AutoComplete` loses focus. */ onBlur?: FocusEventHandler; /** * Whether the `AutoComplete` is creatable. */ creatable?: boolean; /** * Whether the `AutoComplete` should clear the input value. */ clearable?: boolean; /** * Whether the `AutoComplete` should select the option on blur. */ selectOnBlur?: boolean; /** * The maximum number of results to display in the `AutoComplete` menu. * @default 7 */ maxResults?: number; /** * The function used to create options from the input value. */ createFromInputValue?: CreateFromInputValue; /** * The keys used to split the input value into multiple options. */ separatorKeys?: string[]; /** * The template used to render the value of the `AutoComplete`. */ renderValueTemplate?: (args: RenderValueTemplateArgs) => JSX.Element; /** * The empty state of the `AutoComplete`. */ emptyState?: ReactNode; /** * The footer of the `AutoComplete` menu. */ menuFooter?: ReactNode; /** * The component used to render the option items. */ optionItemComponent?: OptionItemComponentType; /** * Whether the input should be kept on a single line. */ noWrap?: boolean; /** * The end item of the `AutoComplete`. */ endItem?: ReactNode; /** * The size of the `AutoComplete` menu. * `medium` will display about 5 results in the dropdown; use `large` variant to display more. * @default "medium" */ menuSize?: "medium" | "large"; /** * The locale of the `AutoComplete`. */ locale?: AutoCompleteLocale; /** * @deprecated Use of this props is discouraged and is only there for backwards compatibility. */ internalsRef?: ForwardedRef; } export interface AutoCompleteInternals { /** * Current internal inputValue */ inputValue: string; /** * RefObject containing the underlying combobox input element */ inputRef: RefObject; } export interface AutoCompleteSingleProps extends AutoCompleteBaseProps { /** * Whether the `AutoComplete` is a multiple selection. */ multiple?: false; /** * The value of the `AutoComplete`. */ value?: T; /** * The callback function that is called when the value of the `AutoComplete` changes. */ onChange: (option: T | null, changeType?: AutoCompleteChangeTypesValue) => void; } type UseMultipleSelectionStateChangeTypesKey = keyof typeof UseMultipleSelectionStateChangeTypes; export type AutoCompleteChangeTypesValue = (typeof UseMultipleSelectionStateChangeTypes)[UseMultipleSelectionStateChangeTypesKey]; export interface AutoCompleteMultiProps extends AutoCompleteBaseProps { /** * Whether the `AutoComplete` is a multiple selection. */ multiple: true; /** * The value of the `AutoComplete`. */ value?: T[]; /** * The callback function that is called when the value of the `AutoComplete` changes. */ onChange: (option: T[] | null, changeType?: AutoCompleteChangeTypesValue) => void; } export type AutoCompleteProps = AutoCompleteMultiProps | AutoCompleteSingleProps; type OptionsValue = string | number | boolean; export interface Option { /** * The value of the `Option`. */ value: OptionsValue; /** * The label of the `Option`. */ label: string; /** * The metadata of the `Option`. */ metadata?: string[]; /** * Whether the `Option` is new. */ new?: boolean; /** * Whether the `Option` is disabled. */ disabled?: boolean; /** * Whether the `Option` should bypass the needle match. */ bypassNeedleMatch?: boolean; } export interface OptionItemProps { option: T; multiple: boolean; inputValue: string; highlighted: boolean; } export type OptionItemComponentType = ComponentType>>; export interface OptionRendererParams { multiple: boolean; inputValue: string; highlighted: boolean; } export interface RenderValueTemplateArgs { option: T; editable: boolean; } export type CreateFromInputValue = (options: T[] | undefined, inputValue: string) => Option[]; export {};