import type { ReactElement, ReactNode } from 'react'; import type { PlainObject, ComponentType, ComponentStyleType, Option } from './common'; import React from 'react'; import { UseComboboxGetMenuPropsReturnValue, UseComboboxGetToggleButtonPropsReturnValue } from 'downshift'; export type SelectState = { isOpen: boolean; highlightedIndex: number; searchText: string; selectedOption: Option | null; options: Option[]; }; export type SelectActions = { closeMenu: () => void; openMenu: () => void; selectOption: (option: Option) => void; setHighlightedIndex: (index: number) => void; setInputValue: (value: string) => void; toggleMenu: () => void; reset: () => void; }; export type SelectContext = { state: SelectState; actions: SelectActions; }; export type SelectComponentType = ComponentType & { className: string; } & PropsType>; export type LabelType = SelectComponentType<{ children: ReactNode; labelProps: PlainObject; }, ValueType>; export type ComboboxType = SelectComponentType<{ children: ReactNode; comboboxProps: PlainObject; }, ValueType>; export type TextInputType = SelectComponentType<{ inputProps: PlainObject; }, ValueType>; export type ToggleMenuButtonType = SelectComponentType<{ downshiftToggleButtonProps: UseComboboxGetToggleButtonPropsReturnValue; children: ReactNode; }, ValueType>; export type MenuType = SelectComponentType<{ style?: React.CSSProperties; downshiftMenuProps: UseComboboxGetMenuPropsReturnValue; getOptionDomProps: (opts: { option: Option; index: number; }) => PlainObject; renderOption: (props: { option: Option; index: number; }) => ReactElement; }, ValueType>; type MenuOptionContext = { isHighlighted: boolean; option: Option; index: number; }; export type MenuOptionType = SelectComponentType, ValueType>; export type InfoBoxType = SelectComponentType<{ children: ReactNode; }, ValueType>; export type ClearButtonType = SelectComponentType; export type SelectComponents = { Label: LabelType; Combobox: ComboboxType; TextInput: TextInputType; ToggleMenuButton: ToggleMenuButtonType; Menu: MenuType; MenuOption: MenuOptionType; InfoBox: InfoBoxType; ClearButton: ClearButtonType; }; export type SelectComponentStyleType = ComponentStyleType & PropsType>; export type Component = (props: PropsType) => ReactElement; export type MenuOptionStyleType = SelectComponentStyleType; export type SelectComponentStyles = { Select: SelectComponentStyleType; Label: SelectComponentStyleType; Combobox: SelectComponentStyleType; TextInput: SelectComponentStyleType; ToggleMenuButton: SelectComponentStyleType; Menu: SelectComponentStyleType; MenuOption: MenuOptionStyleType; InfoBox: SelectComponentStyleType; }; export type FnOnSearchTextChange = (newSearchText: string) => void; export type SelectProps = { options: Option[]; label: ReactNode; placeholder?: string; info: ReactNode; selectedOption: Option | null; onSelectOption: (option: Option | null) => void; onSearchTextChange: FnOnSearchTextChange; textInputProps?: PlainObject; clearable?: boolean; enterSelect?: boolean; components?: Partial>; classNames?: Partial>; }; export type SelectType = (props: SelectProps) => React.ReactElement; export {};