import React from 'react'; import { TextFieldProps } from '../TextField'; import { PositionStrategy } from '../Popper'; import { AnchorPos, GetOptionSelected, MenuItemProps, OnRequestClose, Value } from '../Menu'; export type AutocompleteTextFieldProps = Omit; export interface AutocompleteProps extends AutocompleteTextFieldProps { readonly items: readonly T[]; readonly value: Value; /** * Array of items. If will be array of objects or array of strings */ readonly multiple?: Multiple; /** * Menu open state\ * If `true` then menu is open, otherwise - closed */ readonly isOpen?: boolean; /** * Loading indicator visibility\ * If `true` then visible, otherwise - hidden */ /** * Anchor position\ * \ * Default: `bottom` */ readonly anchorPos?: AnchorPos; /** * When enabled, the popper will automatically try to find the best placement * if the preferred placement doesn't fit in the viewport. * The component will iterate through possible placements until it finds one that fits. * * **Default**: `true` * ``` */ readonly autoFlip?: boolean; /** * The positioning strategy to use. * - `'fixed'`: Positions relative to the viewport. Works reliably in all cases. * - `'absolute'`: Positions relative to the nearest positioned ancestor. * When using 'absolute', make sure a parent element has `position: relative`. * * **Default**: `fixed` * ``` */ readonly positionStrategy?: PositionStrategy; readonly alternativePlacements?: readonly AnchorPos[]; /** * Minimum distance (in pixels) that the popper must maintain from the viewport edges. * Used to prevent the popper from being positioned too close to the screen boundaries. * The popper will try to flip to another placement if it cannot maintain this margin. * * **Default**: `8` * ``` */ readonly viewportMargin?: number; /** * Text field loading state\ * If `true` then text field has been contained the loading indicator, otherwise - nop */ readonly isLoading?: boolean; /** * Should the autocomplete element be cleared when blur and if no element is selected\ * **Default:** `true` */ readonly clearOnBlur?: boolean; /** * Show clear button if clearable is true\ * **Default:** `true` */ readonly clearable?: boolean; /** * should the Menu component opening when input focused\ * **Default:** `true` */ readonly openOnFocus?: boolean; /** * items render function */ readonly children: Children; /** * A function that returns a filtered array of values. which correspond to the entered query * Example: * ```tsx * * items.filter(item => item.name.toLocaleLowerCase().indexOf(query) !== -1) * } * ... * > * ``` * */ readonly filterItems?: FilterItems; /** * The function that will be called when an item is selected from the list */ readonly onChange?: OnChange; /** * A function that transforms the selected item into a string * Example: * ```tsx * item.name} // item is {id: 1, name: 'Oleg'} * ... * > * ... * * ``` */ readonly selectedItemToString: ItemToString; /** * A function that determines which of the elements is currently selected\ * Example: * ```tsx * item.id === value.id} */ readonly getOptionSelected?: GetOptionSelected; /** * The function that will be called at the moment when you want to close the autocomplete */ readonly onRequestClose?: OnRequestClose; /** * The function that will be called at the moment when you change the input value of input element */ readonly onInputChange?: React.ChangeEventHandler; /** * The function that will be called at the moment when you want to open the selectbox */ readonly onRequestOpen?: (event: React.KeyboardEvent | React.MouseEvent | React.FocusEvent | React.ChangeEvent) => void; /** * Overridable components map */ readonly overrides?: AutocompleteOverrides; } export interface AutocompleteOverrides { /** * Element wrapper */ readonly TextField?: React.ComponentType>; } export type Children = (data: { item: T; index: number; inputValue: string; }, itemProps: MenuItemProps) => React.ReactNode; export type ItemToString = (item: Multiple extends undefined ? T : readonly T[]) => string; export type OnChange = (item: Value) => void; export type FilterItems = (items: readonly T[], data: { readonly query: string; readonly inputValue: string; }) => readonly T[]; export type AutocompleteRef = { clear: () => void; }; declare const _default: (props: AutocompleteProps & { ref?: React.Ref | undefined; }) => JSX.Element; export default _default;