import { Variants } from "../../atoms/types/variants.js"; import { TooltipProps } from "../Tooltip/Tooltip.js"; import { FC, KeyboardEvent, ReactNode, RefObject } from "react"; //#region src/molecules/Select/Select.types.d.ts interface SelectOptionRequired { value: string; label: string; disabled?: boolean; } type SelectOption = T & { children?: T[]; }; interface SingleSelectCommon { value: SelectOption | undefined; onSelect: (value: SelectOption | undefined) => void; customValueComponent?: FC<{ item: SelectOption; /** True when the select is locked, so the value can't be changed */ locked?: boolean; }>; } interface MultiSelectBase { values: SelectOption[]; onSelect: (values: SelectOption[], selectedValue?: SelectOption) => void; syncParentChildSelection?: boolean; } type MultiSelectWithSelectedAsText = { showSelectedAsText: boolean | (({ selectedAmount, totalAmount }: { selectedAmount: number; totalAmount: number; }) => string); } & MultiSelectBase; type MultiSelectWithCustomValueComponent = { showSelectedAsText?: undefined; customValueComponent?: FC<{ item: SelectOption; onDelete: () => void; tryingToRemove: boolean; /** True when the select is locked. `onDelete` does nothing, so hide any delete control */ locked?: boolean; }>; } & MultiSelectBase; type MultiSelectCommon = MultiSelectWithSelectedAsText | MultiSelectWithCustomValueComponent; interface MenuModeSelectProps { mode?: 'menu'; } interface PersistentSelectProps { maxHeight?: string; } interface PersistentModeSelectProps extends PersistentSelectProps { mode: 'persistent'; } interface SelectGroup { title?: string; items: SelectOption[]; } interface GroupedSelectProps { groups: SelectGroup[]; items?: undefined; } type CommonListSelectProps = { items: SelectOption[]; groups?: undefined; }; interface ListSelectWithAddItemProps extends CommonListSelectProps { onAddItem: (item: string) => void; itemSingularWord?: string; } interface ListSelectWithoutAddItemProps extends CommonListSelectProps { onAddItem?: undefined; itemSingularWord?: undefined; } type ListSelectProps = ListSelectWithAddItemProps | ListSelectWithoutAddItemProps; type SelectedState = 'selected' | 'indeterminate' | 'none'; interface CustomMenuItemComponentProps { CustomMenuItemComponent?: FC<{ item: SelectOption; selectedState: SelectedState; }>; } type CommonSelectProps = { id?: string; variant?: Variants; label?: string; helperText?: string; showHelperIcon?: boolean; placeholder?: string; sortValues?: boolean; disabled?: boolean; loading?: boolean; lightBackground?: boolean; underlineHighlight?: boolean; clearable?: boolean; meta?: ReactNode; onSearchChange?: (inputValue: string) => void; inDialog?: boolean; onOpenCallback?: (value: boolean) => void; onSearchFilter?: (searchValue: string, item: T) => void; /** Text shown when there are no items to display, defaults to "No items found" */ noItemsText?: string; explanation?: string; explanationPosition?: TooltipProps['placement']; 'data-testid'?: string; 'aria-label'?: string; 'aria-labelledby'?: string; 'aria-describedby'?: string; leadingContent?: ReactNode; /** Value is validated/accepted and can't be changed. Shows a lock icon. */ locked?: boolean; /** Value was filled in automatically. Consumer is responsible for resetting this when the user changes the value. */ autofilled?: boolean; } & CustomMenuItemComponentProps; //#endregion export { CommonSelectProps, GroupedSelectProps, ListSelectProps, MenuModeSelectProps, MultiSelectCommon, PersistentModeSelectProps, PersistentSelectProps, SelectOption, SelectOptionRequired, SingleSelectCommon };