1 | import type { BuildInPlacements } from '@rc-component/trigger/lib/interface';
|
2 | import type { BaseSelectPropsWithoutPrivate, BaseSelectRef } from 'rc-select';
|
3 | import type { Placement } from 'rc-select/lib/BaseSelect';
|
4 | import * as React from 'react';
|
5 | import Panel from './Panel';
|
6 | import { SHOW_CHILD, SHOW_PARENT } from './utils/commonUtil';
|
7 | export interface BaseOptionType {
|
8 | disabled?: boolean;
|
9 | disableCheckbox?: boolean;
|
10 | label?: React.ReactNode;
|
11 | value?: string | number | null;
|
12 | children?: DefaultOptionType[];
|
13 | }
|
14 | export type DefaultOptionType = BaseOptionType & Record<string, any>;
|
15 | export 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 | }
|
22 | export type ShowCheckedStrategy = typeof SHOW_PARENT | typeof SHOW_CHILD;
|
23 | interface 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 |
|
40 | dropdownPrefixCls?: string;
|
41 | loadData?: (selectOptions: OptionType[]) => void;
|
42 |
|
43 | popupVisible?: boolean;
|
44 |
|
45 | popupClassName?: string;
|
46 | dropdownClassName?: string;
|
47 | dropdownMenuColumnStyle?: React.CSSProperties;
|
48 |
|
49 | popupPlacement?: Placement;
|
50 | placement?: Placement;
|
51 | builtinPlacements?: BuildInPlacements;
|
52 |
|
53 | onPopupVisibleChange?: (open: boolean) => void;
|
54 | onDropdownVisibleChange?: (open: boolean) => void;
|
55 | expandIcon?: React.ReactNode;
|
56 | loadingIcon?: React.ReactNode;
|
57 | }
|
58 | export 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 | }
|
63 | export 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];
|
64 | export 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>[][];
|
65 | export 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 | }
|
71 | export type SingleValueType = (string | number)[];
|
72 | export type InternalValueType = SingleValueType | SingleValueType[];
|
73 | export interface InternalFieldNames extends Required<FieldNames> {
|
74 | key: string;
|
75 | }
|
76 | export type InternalCascaderProps = Omit<CascaderProps, 'onChange' | 'value' | 'defaultValue'> & {
|
77 | value?: InternalValueType;
|
78 | defaultValue?: InternalValueType;
|
79 | onChange?: (value: InternalValueType, selectOptions: BaseOptionType[] | BaseOptionType[][]) => void;
|
80 | };
|
81 | export type CascaderRef = Omit<BaseSelectRef, 'scrollTo'>;
|
82 | declare 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 | };
|
92 | export default Cascader;
|