UNPKG

5.34 kBTypeScriptView Raw
1import type { BuildInPlacements } from '@rc-component/trigger/lib/interface';
2import type { BaseSelectPropsWithoutPrivate, BaseSelectRef } from 'rc-select';
3import type { Placement } from 'rc-select/lib/BaseSelect';
4import * as React from 'react';
5import Panel from './Panel';
6import { SHOW_CHILD, SHOW_PARENT } from './utils/commonUtil';
7export interface BaseOptionType {
8 disabled?: boolean;
9 disableCheckbox?: boolean;
10 label?: React.ReactNode;
11 value?: string | number | null;
12 children?: DefaultOptionType[];
13}
14export type DefaultOptionType = BaseOptionType & Record<string, any>;
15export interface ShowSearchType<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> {
16 filter?: (inputValue: string, options: OptionType[], fieldNames: FieldNames<OptionType, ValueField>) => boolean;
17 render?: (inputValue: string, path: OptionType[], prefixCls: string, fieldNames: FieldNames<OptionType, ValueField>) => React.ReactNode;
18 sort?: (a: OptionType[], b: OptionType[], inputValue: string, fieldNames: FieldNames<OptionType, ValueField>) => number;
19 matchInputWidth?: boolean;
20 limit?: number | false;
21}
22export type ShowCheckedStrategy = typeof SHOW_PARENT | typeof SHOW_CHILD;
23interface BaseCascaderProps<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> extends Omit<BaseSelectPropsWithoutPrivate, 'tokenSeparators' | 'labelInValue' | 'mode' | 'showSearch'> {
24 id?: string;
25 prefixCls?: string;
26 fieldNames?: FieldNames<OptionType, ValueField>;
27 optionRender?: (option: OptionType) => React.ReactNode;
28 children?: React.ReactElement;
29 changeOnSelect?: boolean;
30 displayRender?: (label: string[], selectedOptions?: OptionType[]) => React.ReactNode;
31 checkable?: boolean | React.ReactNode;
32 showCheckedStrategy?: ShowCheckedStrategy;
33 autoClearSearchValue?: boolean;
34 showSearch?: boolean | ShowSearchType<OptionType>;
35 searchValue?: string;
36 onSearch?: (value: string) => void;
37 expandTrigger?: 'hover' | 'click';
38 options?: OptionType[];
39 /** @private Internal usage. Do not use in your production. */
40 dropdownPrefixCls?: string;
41 loadData?: (selectOptions: OptionType[]) => void;
42 /** @deprecated Use `open` instead */
43 popupVisible?: boolean;
44 /** @deprecated Use `dropdownClassName` instead */
45 popupClassName?: string;
46 dropdownClassName?: string;
47 dropdownMenuColumnStyle?: React.CSSProperties;
48 /** @deprecated Use `placement` instead */
49 popupPlacement?: Placement;
50 placement?: Placement;
51 builtinPlacements?: BuildInPlacements;
52 /** @deprecated Use `onDropdownVisibleChange` instead */
53 onPopupVisibleChange?: (open: boolean) => void;
54 onDropdownVisibleChange?: (open: boolean) => void;
55 expandIcon?: React.ReactNode;
56 loadingIcon?: React.ReactNode;
57}
58export interface FieldNames<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> {
59 label?: keyof OptionType;
60 value?: keyof OptionType | ValueField;
61 children?: keyof OptionType;
62}
63export type ValueType<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType> = keyof OptionType extends ValueField ? unknown extends OptionType['value'] ? OptionType[ValueField] : OptionType['value'] : OptionType[ValueField];
64export type GetValueType<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType, Multiple extends boolean | React.ReactNode = false> = false extends Multiple ? ValueType<Required<OptionType>, ValueField>[] : ValueType<Required<OptionType>, ValueField>[][];
65export interface CascaderProps<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType, Multiple extends boolean | React.ReactNode = false> extends BaseCascaderProps<OptionType, ValueField> {
66 checkable?: Multiple;
67 value?: GetValueType<OptionType, ValueField, Multiple>;
68 defaultValue?: GetValueType<OptionType, ValueField, Multiple>;
69 onChange?: (value: GetValueType<OptionType, ValueField, Multiple>, selectOptions: OptionType[]) => void;
70}
71export type SingleValueType = (string | number)[];
72export type InternalValueType = SingleValueType | SingleValueType[];
73export interface InternalFieldNames extends Required<FieldNames> {
74 key: string;
75}
76export type InternalCascaderProps = Omit<CascaderProps, 'onChange' | 'value' | 'defaultValue'> & {
77 value?: InternalValueType;
78 defaultValue?: InternalValueType;
79 onChange?: (value: InternalValueType, selectOptions: BaseOptionType[] | BaseOptionType[][]) => void;
80};
81export type CascaderRef = Omit<BaseSelectRef, 'scrollTo'>;
82declare const Cascader: (<OptionType extends DefaultOptionType = DefaultOptionType, ValueField extends keyof OptionType = keyof OptionType, Multiple extends React.ReactNode = false>(props: CascaderProps<OptionType, ValueField, Multiple> & {
83 children?: React.ReactNode;
84} & {
85 ref?: React.Ref<CascaderRef> | undefined;
86}) => React.ReactElement) & {
87 displayName?: string | undefined;
88 SHOW_PARENT: typeof SHOW_PARENT;
89 SHOW_CHILD: typeof SHOW_CHILD;
90 Panel: typeof Panel;
91};
92export default Cascader;