import { ReactNode, CSSProperties, PropsWithChildren, ReactElement, HTMLAttributes } from 'react'; import { TriggerProps } from '../trigger'; import { SelectViewCommonProps } from '../_class/select-view'; import { AvailableVirtualListProps } from '../_class/virtual-list'; /** * @title Select */ export declare type OptionsType = SelectProps['options']; export declare type InputValueChangeReason = 'manual' | 'optionChecked' | 'optionListHide' | 'tokenSeparator'; export interface OptionInfo extends PropsWithChildren { child?: ReactElement; _valid: boolean; _index: number; _origin: 'children' | 'options' | 'userCreatedOptions' | 'userCreatingOption'; } export declare type LabeledValue = { value: string | number; label: ReactNode; }; export declare type SelectInnerStateValue = string | number | string[] | number[]; /** * @title Select */ export interface SelectProps extends SelectViewCommonProps { /** * 选择框的默认值 */ defaultValue?: string | string[] | number | number[] | LabeledValue | LabeledValue[]; /** * 选择器的值(受控模式) */ value?: string | string[] | number | number[] | LabeledValue | LabeledValue[]; /** * 输入框的值(受控模式) */ inputValue?: string; /** * 是否开启多选模式 */ multiple?: boolean; /** * 静态展示 */ quickStatic?: boolean; /** * 快速编辑(默认无边框) */ quickEdit?: boolean; /** * 指定可选项 */ options?: (string | number | { label: ReactNode | string; value: string | number; disabled?: boolean; extra?: any; })[]; /** * 设置 `onChange` 回调中 `value` 的格式。默认是string,设置为true时候,value格式为: { label: string, value: string } */ labelInValue?: boolean; /** * 是否根据输入的值筛选数据。如果传入函数的话,接收 `inputValue` 和 `option` 两个参数,当option符合筛选条件时,返回 `true`,反之返回 `false`。 * @defaultValue true */ filterOption?: boolean | ((inputValue: string, option: ReactElement) => boolean); /** * 定制回显内容。返回值将会显示在下拉框内。若 `value` 对应的 `Option` 不存在,则第一个参数是 null */ renderFormat?: (option: OptionInfo | null, value: string | number | LabeledValue) => ReactNode; /** * 是否默认高亮第一个选项 * @defaultValue true */ defaultActiveFirstOption?: boolean; /** * 是否允许通过输入创建新的选项。 */ allowCreate?: boolean | { formatter: (inputValue: string, creating: boolean) => SelectProps['options'][number]; }; /** * 是否在隐藏的时候销毁 DOM 结构 * @defaultValue true */ unmountOnExit?: boolean; /** * 下拉框是否默认打开。 */ defaultPopupVisible?: boolean; /** * 控制下拉框是否打开。 */ popupVisible?: boolean; /** * 没有数据时显示的内容 */ notFound?: ReactNode; /** * 在多选模式下自动分词的分隔符。 */ tokenSeparators?: string[]; /** * 弹出框挂载的父节点。 */ getPopupContainer?: (node: HTMLElement) => Element; /** * 触发方式。 * @defaultValue click */ trigger?: TriggerProps['trigger']; /** * 自定义触发元素。 */ triggerElement?: ReactNode | ((params: { value: any; option: OptionInfo | OptionInfo[]; }) => ReactNode); /** * 可以接受所有 `Trigger` 的 `Props` */ triggerProps?: Partial; /** * 自定义弹出内容。 */ dropdownRender?: (menu: ReactNode) => ReactNode; /** * 下拉列表的样式。 */ dropdownMenuStyle?: CSSProperties; /** * 下拉列表的类。 */ dropdownMenuClassName?: string | string[]; /** * 传递虚拟滚动属性。 */ virtualListProps?: AvailableVirtualListProps; /** * 点击选择框的回调 */ onChange?: (value: any, option: OptionInfo | OptionInfo[]) => void; /** * 选中选项时触发的回调,(只在 `multiple` 模式下触发)。 */ onSelect?: (value: string | number | LabeledValue, option: OptionInfo) => void; /** * 取消选中的时候触发的回调,(只在 `multiple` 模式下触发)。 */ onDeselect?: (value: string | number | LabeledValue, option: OptionInfo) => void; /** * 点击清除时触发,参数是当前下拉框的展开状态。 */ onClear?: (visible: boolean) => void; /** * 搜索时的回调 */ onSearch?: (value: string, reason: InputValueChangeReason) => void; /** * 获得焦点时的回调 */ onFocus?: (e: any) => void; /** * 失去焦点时的回调 */ onBlur?: (e: any) => void; /** * 下拉框的滚动监听函数,参数为滚动元素。 */ onPopupScroll?: (elem: any) => void; /** * 下拉框收起展开时触发 */ onVisibleChange?: (visible: boolean) => void; /** * 输入框文本改变的回调。 */ onInputValueChange?: (value: string, reason: InputValueChangeReason) => void; /** * 输入框文本粘贴的回调。 */ onPaste?: (e: any) => void; } /** * @title Select.Option */ export interface OptionProps extends Omit, 'className'> { _key?: any; style?: CSSProperties; children?: ReactNode; prefixCls?: string; className?: string | string[]; wrapperClassName?: string | string[]; /** * 是否禁用 */ disabled?: boolean; /** * 默认根据此属性值进行筛选 */ value: string | number; /** * 携带任意自定义数据。 */ extra?: any; isSelectOption?: boolean; _isMultipleMode?: boolean; _isUserCreatedOption?: boolean; _isUserCreatingOption?: boolean; _valueActive?: OptionProps['value']; _valueSelect?: SelectInnerStateValue; _onClick?: (value: OptionProps['value'], disabled: boolean) => void; _onMouseEnter?: (value: OptionProps['value']) => void; _onMouseLeave?: () => void; } /** * @title Select.OptGroup */ export interface OptGroupProps extends HTMLAttributes { _key?: any; children?: ReactNode; prefixCls?: string; /** * 组名 */ label?: ReactNode; isSelectOptGroup?: boolean; } /** * @title Select Reference Type */ export declare type SelectHandle = { /** * DOM 节点 */ dom: HTMLDivElement; /** * 使选择框聚焦 */ focus: () => void; /** * 使选择框失焦 */ blur: () => void; /** * 鼠标快捷操作的处理函数 */ hotkeyHandler: (event: KeyboardEvent) => void; /** * 处于悬浮态的选项的值 */ activeOptionValue: OptionProps['value']; /** * 获得选项信息的列表 */ getOptionInfoList: () => OptionInfo[]; /** * 根据选项值获得对应的选项信息 */ getOptionInfoByValue: (value: OptionProps['value']) => OptionInfo; /** * 将下拉列表滚动至指定选项 */ scrollIntoView: (value: OptionProps['value'], options?: ScrollIntoViewOptions) => void; };