import React, { HTMLAttributes, ComponentType } from 'react';
import { CustomStyledComponentResult, RcBaseProps, RcClassesProps } from '../../foundation';
import { RcIconButtonProps } from '../Buttons/IconButton';
import { RcTextFieldProps } from '../Forms/TextField';
import { RcPopperProps } from '../Popper';
import { WithTooltipProps } from '../Tooltip';
import { RcDownshiftInput } from './styles';
import { RcSuggestionListProps } from './SuggestionList';
import { RcDownshiftDefaultFilterOptions, RcDownshiftFilterOptions, RcDownshiftGroupedOption, RcDownshiftSelectedItem, RcDownshiftSelectedItemAdditionProps } from './utils';
import { TransitionProps as MuiTransitionProps } from '@material-ui/core/transitions';
export interface RcDownshiftRenderOptionState {
/** current input value */
inputValue?: string;
/** is that item selected */
selected: boolean;
/** is that item be show highlighted style */
highlighted: boolean;
/** that item index */
index: number;
/** sort index in option own group */
indexInOwnGroup?: number;
/** if that item is group title, that have that `expanded` state */
expanded?: boolean;
/** if that item is group title, that will have that `expandIconProps` */
expandIconProps?: Partial;
}
export declare type RcDownshiftCloseReason = 'toggleInput' | 'escape' | 'select-option' | 'blur';
declare type RcDownshiftProps = {
/**
* display mode,
* when be `autocomplete`, that `multiple` will be `false`
*
* @default tags
*/
variant?: 'tags' | 'autocomplete';
/**
* @requires
* this is required, must have options, but because need with old code suggestionItems, so make that to be optional
*/
options?: T[];
/** selectedItems array list */
value?: T[];
/**
* If `true`, will allow disabled items highlightable.
*/
disabledItemsHighlightable?: boolean;
/** emit tags change event */
onChange?: (selectedItems: T[]) => void;
/** is that can select multiple, default is `false` */
multiple?: boolean;
/** If `true`, the popup will ignore the blur event. You can inspect the popup markup with your browser tools. Consider this option when you need to customize the component. */
debug?: boolean;
/** This is the initial isOpen value when downshift is initialized. */
initialIsOpen?: boolean;
/**
* If `true`, the popup won't close when a value is selected.
*/
disableCloseOnSelect?: boolean;
/**
* Used to determine the string value for a given option.
* It's used to fill the input (and the list box options if `renderOption` is not provided).
*
* @param {T} option
* @returns {string}
*/
getOptionLabel?: (option: T) => string;
/**
* A filter function that determines the options that are eligible.
*
* @param {T[]} options The options to render.
* @param {object} state The state of the component.
* @returns {T[]}
*/
filterOptions?: RcDownshiftFilterOptions;
/** emit current input value */
onInputChange?: (value: string) => any;
/**
* Render the option, use `getOptionLabel` by default.
*
* @param {T} option The option to render.
* @param {object} state The state of the component.
* @returns {ReactNode}
*/
renderOption?: (option: T & RcDownshiftSelectedItemAdditionProps, state: RcDownshiftRenderOptionState) => React.ReactNode;
/**
* group layout mode
*
* - `normal`: use group name as group title
* - `expanded`: use first-item as group title, and that is `clickable`
*
* @default 'normal'
*/
groupVariant?: 'normal' | 'expanded';
/**
* group expanded state, you can control expanded state by that
*
* - `true`: expand all
* - `false`: collapse all
* - `{key: boolean}`: control group state
*/
groupExpanded?: Record | boolean;
/**
* group default expanded state
*
* - `true`: expand all
* - `false`: collapse all
* - `{key: boolean}`: control group state
*/
groupDefaultExpanded?: Record | boolean;
/**
* If provided, the options will be grouped under the returned string.
* The groupBy value is also used as the text for group headings when `renderGroup` is not provided.
*
* @param {T} option The options to group.
* @returns {string} The group key
*/
groupBy?: (option: T) => string;
/**
* Render the group title item, also with for toggle button props.
*
* > when you have set custom `renderOption`, the `renderGroup` must be set.
*
* @param {T} option The option to render.
* @param {object} state The state of the component.
* @returns {ReactNode}
*/
renderGroup?: (option: T & RcDownshiftSelectedItemAdditionProps, state: RcDownshiftRenderOptionState) => React.ReactNode;
/**
* Trigger when group item expanded state change.
*
* @param {object} group The state of the group.
* @param {object} groupStateMap The whole group state
*/
onGroupExpanded?: (group: RcDownshiftGroupedOption, groupStateMap: Record) => any;
/** SuggestionList VirtualizedList Props */
SuggestionListProps?: RcSuggestionListProps;
/**
* @param event keydown event
* @param highlightedIndex current menu highlightedIndex
*/
onKeyDown?: (event: React.KeyboardEvent, highlightedIndex?: number | null) => void;
/**
* If `true`, the RcDownshift is free solo, meaning that the user input is not bound to provided options.
*/
freeSolo?: boolean;
/**
* Render the selected value.
*
* @param {T[]} value The `value` provided to the component.
* @param {function} getTagProps A tag props getter.
* @returns {ReactNode}
*/
renderTags?: (selectedItems: T[], getTagProps: (selectedItem: T, index: number) => Omit, 'children'> & {
onDelete?: React.EventHandler;
}) => React.ReactNode;
/**
* Render when search no have any options.
*
* @param {object} additionItems
* render when not have any options,
* if set that the freeSolo auto add items will not be cover
*/
renderNoOptions?: (getNoOptionsProps: (additionProps?: HTMLAttributes) => HTMLAttributes, additionItem: RcDownshiftSelectedItem | null) => React.ReactNode;
/**
* one of that character, also can be confirm a tag
* @default
* [',', ';', '↵']
*/
keyToTags?: string[];
/**
* max number of tags,
* @default 20
*/
maxFreeSolo?: number;
/** emit when bigger than maxFreeSolo number */
onMaxFreeSolo?: (max?: number) => any;
/**
* If `true`, the selected option becomes the value of the input
* when the input loses focus unless the user chooses
* a different option or changes the character string in the input.
*/
autoSelect?: boolean;
/**
* custom PopperComponent for render
*
* @default RcPopper
*/
PopperComponent?: ComponentType;
/** props for apply on `RcPopper` */
PopperProps?: RcBaseProps, 'open' | 'keepMounted' | 'anchorEl'> & {
/**
* typeof that popper `anchorEl` binding when menu open
*
* - `root`: on that whole TextField
* - `input`: on that inside input
* @default 'root'
*/
anchorElType?: 'root' | 'input';
/**
* The component used for the transition.
*
* default will base on `SuggestionListProps.virtualize`
* @default virtualize ? `RcFade` : `RcGrow`
*/
TransitionComponent?: React.JSXElementConstructor;
}>;
/**
* Set to 'auto' to automatically calculate transition time based on height.
* @default 'auto'
*/
transitionDuration?: MuiTransitionProps['timeout'] | 'auto';
/**
* Props applied to the transition element.
* By default, the element is based on this [`Transition`](http://reactcommunity.org/react-transition-group/transition/) component.
* @default {}
*/
TransitionProps?: MuiTransitionProps;
};
/** is have ToggleButton */
toggleButton?: boolean;
/** Props for apply on ToggleButton */
ToggleButtonProps?: RcIconButtonProps & WithTooltipProps;
/**
* get custom `ToggleButtonProps` with menu open state.
*
* that can be use when you need custom toggle button icon, that will override props you pass inside `ToggleButtonProps`
*/
getToggleButtonProps?: (isOpen: boolean) => RcDownshiftProps['ToggleButtonProps'];
/**
* A ref for imperative actions.
*
* - `getActiveIndex`: get current active index
* - `setActiveIndex`: set current active index;
* - `getFilterResultItems`: get current filter result option items;
* - `getHighlightedIndex`: get current highlight index;
* - `setHighlightedIndex`: set current highlight index;
* - `openMenu`: open the listbox menu
* - `closeMenu`: close the listbox menu
* - `focus`: focus on text field input
* - `reset(isFocus)`: reset whole downshift, `isFocus` default is `false`
*/
action?: React.Ref>;
/** auto close menu when options filter result is zero */
autoClose?: boolean;
/**
* If `true`, the popup will open on input focus.
* and that also set `disableCloseOnSelect` to `true`
*/
openOnFocus?: boolean;
/**
* If `true`, the input element can be click to toggle that selection list
*
* When be `autocomplete`, that `toggleWithInput` default will be `true`
*/
toggleWithInput?: boolean;
/** get expand addition props */
getExpandIconProps?: (group: RcDownshiftGroupedOption) => Partial;
/**
* If `true`, the first option is automatically highlighted.
* @default true
*/
autoHighlight?: boolean;
/**
* Used to determine the disabled state for a given option.
*
* @param {T} option The option to test.
* @returns {boolean}
*/
getOptionDisabled?: (option: T) => boolean;
/**
* Props applied to the Input element
*/
InputProps?: RcClassesProps<'container'>;
/**
* Render the input, default is `RcTextField`
*/
renderInput?: (params: Partial) => React.ReactNode;
/**
* Control the popup` open state.
*/
open?: boolean;
/**
* Callback fired when the popup requests to be opened.
* Use in controlled mode (see open).
*
* @param {object} event The event source of the callback.
*/
onOpen?: (event: React.ChangeEvent<{}>) => void;
/**
* Callback fired when the popup requests to be closed.
* Use in controlled mode (see open).
*
* @param {object} event The event source of the callback.
* @param {string} reason Can be: `"toggleInput"`, `"escape"`, `"select-option"`, `"blur"`.
*/
onClose?: (event: React.ChangeEvent<{}>, reason: RcDownshiftCloseReason) => void;
} & RcBaseProps, 'children' | 'value' | 'onChange' | 'onKeyDown' | 'variant' | 'radius' | 'size' | 'defaultValue' | 'multiline' | 'rows' | 'minRows' | 'maxRows' | 'align' | 'textVariant' | 'autoSelect' | 'focusOnMount' | 'selectOnMount' | 'autoFocusDelay' | 'clearLabel' | 'clearAriaLabel'> & {
/**
* @deprecated
* if you don't want close popup when select, use `disableCloseOnSelect` with `true` to replace that
*/
defaultIsOpen?: boolean;
/** @deprecated should use `onChange` */
onSelectChange?: (selectedItems: T[]) => void;
/** @deprecated should use `options` to replace */
suggestionItems?: T[];
/** @deprecated not need any more */
selectedItems?: T[];
/** @deprecated use `getOptionLabel` to replace that */
itemToString?: (item: T) => string;
/** @deprecated should use `renderOption` to replace that */
MenuItem?: React.ComponentType;
/** @deprecated suggestion list row min height for virtual list, please replace with `estimatedItemSize` */
minRowHeight?: number;
/** @deprecated enable free chip mode, should use `freeSolo` to replace that */
enableFreeChips?: boolean;
/** @deprecated please use `label` to replace that */
inputLabel?: RcTextFieldProps['label'];
/** current text field input value */
inputValue?: string;
/** @deprecated input element placeholder attribute */
inputPlaceholder?: RcTextFieldProps['placeholder'];
/** @deprecated input element maxlength, please use `TextFieldProps.inputProps.maxLength` */
maxLength?: number;
/**
* @deprecated you not need that props,
* use `FormHelperTextProps['aria-label']` and `useAnnouncer` by yourself
*/
screenReader?: {
entry: string;
entries: string;
};
/** @deprecated wrapper automationId, should use `data-test-automation-id` directly */
automationId?: string;
/** @deprecated just use the `renderTags` to render whole tags */
InputItem?: React.ComponentType;
/**
* @deprecated
* just use the `helperText` to control helper text
*/
allowPlainHelperText?: boolean;
/** @deprecated please calculate error outside by your self with `renderTags`, or prepare ready items with error field */
emailError?: string;
/** @deprecated please calculate error outside by your self with `renderTags`, or prepare ready items with error field */
errorSelectedItems?: (string | number | undefined)[];
/** @deprecated replace to `error` */
nameError?: boolean;
/**
* @deprecated
* ! no have any function
*/
autoSwitchEmail?: boolean;
/** @deprecated rename to `keyToTags` */
keyToChips?: string[];
/** @deprecated should use `max` */
limitOfFreeChips?: number;
/** @deprecated should use `autoSelect` */
enableAutoTransform?: boolean;
/** @deprecated should use `inputRef` */
messageRef?: RcTextFieldProps['inputRef'];
/** @deprecated TextField props */
TextFieldProps?: Pick;
};
declare type RcDownshiftRef = {
/** get current active index */
getActiveIndex: () => number;
/** set current active index */
setActiveIndex: (index: number) => void;
/** get current filter result option items; */
getFilterResultItems: () => T[];
/** get current highlight index */
getHighlightedIndex: () => number;
/** set current highlight index */
setHighlightedIndex: (index: number) => void;
/**
* keep highlightedIndex for next render when options change,
* can use when lazy load more options
*/
keepHighlightedIndex: () => void;
/** open the listbox menu */
openMenu: () => void;
/** close the listbox menu */
closeMenu: () => void;
/** focus on text field input */
focus: () => void;
/** reset whole downshift, isFocus default is `false` */
reset: (isFocus?: boolean) => void;
/** method to clean input value */
clearInput: () => void;
};
declare const ExportType: (props: RcDownshiftProps) => JSX.Element & CustomStyledComponentResult>;
export { ExportType as RcDownshift, RcDownshiftDefaultFilterOptions, RcDownshiftInput, };
export type { RcDownshiftProps, RcDownshiftRef };