zent
Version:
一套前端设计语言和基于React的实现
128 lines (127 loc) • 6.93 kB
TypeScript
import { Component } from 'react';
import Popover from '../popover';
import { ISelectTagListProps } from './TagList';
import { IDisabledContext } from '../disabled';
import { II18nLocaleSelect } from '../i18n';
import { reviveSelectItem } from './reviver';
export interface ISelectItem<Key extends string | number = string | number> {
key: Key;
text: React.ReactNode;
disabled?: boolean;
type?: 'header' | 'divider' | 'reviver';
reviver?: (item: ISelectItem<Key>) => ISelectItem<Key> | null;
}
export interface IOptionRenderer<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>> {
(item: Item, index: number): React.ReactNode;
}
export interface ISelectKeywordChangeMeta {
source: 'user-clear' | 'user-change' | 'popup-close' | 'option-create';
}
export declare type ISelectSize = 'xs' | 's' | 'm' | 'l' | 'xl';
export interface ISelectCommonProps<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>> {
keyword?: string;
onKeywordChange?: (keyword: string, meta: ISelectKeywordChangeMeta) => void;
options: Item[];
isEqual?: (a: Item, b: Item) => boolean;
placeholder?: string;
notFoundContent?: string;
inline?: boolean;
width?: React.CSSProperties['width'];
size?: ISelectSize;
popupWidth?: React.CSSProperties['width'];
filter?: ((keyword: string, item: Item) => boolean) | false;
highlight?: (keyword: string, item: Item) => Item;
disabled?: boolean;
open?: boolean;
onOpenChange?: (open: boolean) => void;
renderValue?: (value: Item) => React.ReactNode;
renderOptionList?: (options: Item[], renderOption: IOptionRenderer<Key, Item>) => React.ReactNode;
renderOptionContent?: (value: Item) => React.ReactNode;
clearable?: boolean;
loading?: boolean;
creatable?: boolean;
onCreate?: (text: string) => Promise<void>;
isValidNewOption?: (keyword: string, options: Item[]) => boolean;
collapsable?: boolean;
collapseAt?: number;
hideCollapsePop?: boolean;
className?: string;
disableSearch?: boolean;
renderCollapsedContent?: (collapsedValue: Item[]) => React.ReactNode;
}
export interface ISelectSingleProps<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>> extends ISelectCommonProps<Key, Item> {
multiple?: false;
value?: Item | null;
onChange?: (value: Item | null) => void;
}
export interface ISelectMultiProps<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>> extends ISelectCommonProps<Key, Item> {
multiple: true;
value?: Item[];
onChange?: (value: Item[]) => void;
renderTagList?: (props: ISelectTagListProps<Key, Item>) => React.ReactNode;
}
export declare type ISelectProps<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>> = ISelectMultiProps<Key, Item> | ISelectSingleProps<Key, Item>;
export interface ISelectState<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>> {
open: boolean;
active: boolean;
keyword: string;
value: null | Item | Item[];
activeIndex: null | number;
prevOptions: Item[];
creating: boolean;
triggerWidth: React.CSSProperties['width'];
}
declare function defaultIsEqual<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>>(a: Item, b: Item): boolean;
declare function defaultFilter<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>>(keyword: string, option: Item): boolean;
declare function defaultRenderOptionList<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>>(options: Item[], renderOption: IOptionRenderer<Key, Item>): import("react").ReactNode[];
declare function defaultHighlight<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>>(keyword: string, option: Item): React.ReactNode;
declare function defaultIsValidNewOption<Key extends string | number = string | number>(keyword: string, options: ISelectItem<Key>[]): boolean;
export declare class Select<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>> extends Component<ISelectProps<Key, Item>, ISelectState<Key, Item>> {
static defaultProps: {
isEqual: typeof defaultIsEqual;
renderOptionList: typeof defaultRenderOptionList;
filter: typeof defaultFilter;
isValidNewOption: typeof defaultIsValidNewOption;
highlight: typeof defaultHighlight;
size: string;
multiple: boolean;
clearable: boolean;
loading: boolean;
creatable: boolean;
};
static contextType: import("react").Context<IDisabledContext>;
static reviveValue: typeof reviveSelectItem;
context: IDisabledContext;
triggerRef: import("react").RefObject<HTMLDivElement>;
popoverRef: import("react").RefObject<Popover>;
inputRef: import("react").RefObject<HTMLInputElement>;
constructor(props: ISelectProps<Key, Item>);
static getDerivedStateFromProps<Key extends string | number = string | number, Item extends ISelectItem<Key> = ISelectItem<Key>>(props: ISelectProps<Key, Item>, state: ISelectState<Key, Item>): Partial<ISelectState<Key, Item>> | null;
componentDidMount(): void;
componentDidUpdate(prevProps: ISelectProps<Key, Item>): void;
get disabled(): boolean;
tryReviveOption(props: ISelectProps<Key, Item>): void;
onVisibleChange: (open: boolean) => void;
onSelect: (item: Item) => void;
onKeywordChange: React.ChangeEventHandler<HTMLInputElement>;
resetKeyword(source: ISelectKeywordChangeMeta['source']): void;
setKeyword(keyword: string, source: ISelectKeywordChangeMeta['source']): void;
onRemove: (item: Item) => void;
onOptionMouseEnter: (index: number) => void;
onOptionMouseLeave: (index: number) => void;
selectCurrentIndex: () => void;
renderOption: IOptionRenderer<Key, Item>;
globalClick: (e: MouseEvent) => void;
onIndexChange: (delta: 1 | -1) => void;
renderValue(i18n: II18nLocaleSelect): import("react").ReactNode;
renderTagCollapsedTrigger(value: Item[]): JSX.Element;
renderTagList(value: Item[], i18n: II18nLocaleSelect): JSX.Element;
getSearchPlaceholder(): string;
onClear: (e: React.MouseEvent) => void;
onCreateClick: () => void;
filterOptions: (keyword: string, options: Item[], filter: false | ((keyword: string, item: Item) => boolean), creatable: boolean, isValidNewOption: (keyword: string, options: Item[]) => boolean, value: Item | Item[] | undefined) => Item[];
focusSearchInput: () => void;
renderPopoverContent(i18n: II18nLocaleSelect): React.ReactNode;
render(): JSX.Element;
}
export default Select;