UNPKG

4.77 kBTypeScriptView Raw
1/// <reference types="react" />
2
3import * as React from 'react';
4import CommonProps from '../util';
5import { PopupProps } from '../overlay';
6import { TreeProps } from '../tree';
7
8interface HTMLAttributesWeak extends React.HTMLAttributes<HTMLElement> {
9 defaultValue?: any;
10 onChange?: any;
11}
12
13export interface TreeSelectProps extends HTMLAttributesWeak, CommonProps {
14 /**
15 * 树节点
16 */
17 children?: React.ReactNode;
18
19 /**
20 * 选择框大小
21 */
22 size?: 'small' | 'medium' | 'large';
23
24 /**
25 * 选择框占位符
26 */
27 placeholder?: string;
28
29 /**
30 * 是否禁用
31 */
32 disabled?: boolean;
33
34 /**
35 * 是否有下拉箭头
36 */
37 hasArrow?: boolean;
38
39 /**
40 * 是否有边框
41 */
42 hasBorder?: boolean;
43
44 /**
45 * 是否有清空按钮
46 */
47 hasClear?: boolean;
48
49 /**
50 * 自定义内联 label
51 */
52 label?: React.ReactNode;
53
54 /**
55 * 是否只读,只读模式下可以展开弹层但不能选择
56 */
57 readOnly?: boolean;
58
59 /**
60 * 下拉框是否与选择器对齐
61 */
62 autoWidth?: boolean;
63
64 /**
65 * 数据源,该属性优先级高于 children
66 */
67 dataSource?: Array<any>;
68
69 /**
70 * (受控)当前值
71 */
72 value?: string | object | Array<any>;
73
74 /**
75 * (非受控)默认值
76 */
77 defaultValue?: string | object | Array<any>;
78
79 /**
80 * value/defaultValue 在 dataSource 中不存在时,是否展示
81 */
82 preserveNonExistentValue?: boolean;
83
84 /**
85 * 选中值改变时触发的回调函数
86 */
87 onChange?: (value: string | Array<any>, data: any | Array<any>) => void;
88
89 /**
90 * 是否一行显示,仅在 multiple 和 treeCheckable 为 true 时生效
91 */
92 tagInline?: boolean;
93
94 /**
95 * 隐藏多余 tag 时显示的内容,在 tagInline 生效时起作用
96 * @param {Object[]} selectedValues 当前已选中的元素
97 * @param {Object[]} [totalValues] 总待选元素,treeCheckedStrategy = 'parent' 时为 undefined
98 */
99 maxTagPlaceholder?: (selectedValues: any[], totalValues?: any[]) => React.ReactNode | HTMLElement;
100
101 /**
102 * 是否显示搜索框
103 */
104 showSearch?: boolean;
105
106 /**
107 * 在搜索框中输入时触发的回调函数
108 */
109 onSearch?: (keyword: string) => void;
110 onSearchClear?: (actionType: string) => void;
111 /**
112 * 无数据时显示内容
113 */
114 notFoundContent?: React.ReactNode;
115
116 /**
117 * 是否支持多选
118 */
119 multiple?: boolean;
120
121 /**
122 * 下拉框中的树是否支持勾选节点的复选框
123 */
124 treeCheckable?: boolean;
125
126 /**
127 * 下拉框中的树勾选节点复选框是否完全受控(父子节点选中状态不再关联)
128 */
129 treeCheckStrictly?: boolean;
130
131 /**
132 * 定义选中时回填的方式
133 */
134 treeCheckedStrategy?: 'all' | 'parent' | 'child';
135
136 /**
137 * 下拉框中的树是否默认展开所有节点
138 */
139 treeDefaultExpandAll?: boolean;
140
141 /**
142 * 下拉框中的树默认展开节点key的数组
143 */
144 treeDefaultExpandedKeys?: Array<any>;
145
146 /**
147 * 下拉框中的树异步加载数据的函数,使用请参考[Tree的异步加载数据Demo](https://fusion.design/pc/component/basic/tree#%E5%BC%82%E6%AD%A5%E5%8A%A0%E8%BD%BD%E6%95%B0%E6%8D%AE)
148 */
149 treeLoadData?: (node: React.ReactElement<any>) => void;
150
151 /**
152 * 透传到 Tree 的属性对象
153 */
154 treeProps?: TreeProps;
155
156 /**
157 * 初始下拉框是否显示
158 */
159 defaultVisible?: boolean;
160
161 /**
162 * 当前下拉框是否显示
163 */
164 visible?: boolean;
165
166 /**
167 * 下拉框显示或关闭时触发事件的回调函数
168 */
169 onVisibleChange?: (visible: boolean, type: string) => void;
170
171 /**
172 * 下拉框自定义样式对象
173 */
174 popupStyle?: React.CSSProperties;
175
176 /**
177 * 下拉框样式自定义类名
178 */
179 popupClassName?: string;
180
181 /**
182 * 下拉框挂载的容器节点
183 */
184 popupContainer?: string | HTMLElement | ((target: HTMLElement) => HTMLElement);
185
186 /**
187 * 透传到 Popup 的属性对象
188 */
189 popupProps?: PopupProps;
190 /**
191 * 是否跟随滚动
192 */
193 followTrigger?: boolean;
194
195 /**
196 * 是否为预览态
197 */
198 isPreview?: boolean;
199
200 /**
201 * 预览态模式下渲染的内容
202 * @param {Array<data>} value 选择值 { label: , value:}
203 */
204 renderPreview?: (data: string | Array<any>, props: any | Array<any>) => React.ReactNode;
205
206 /**
207 * 是否开启虚拟滚动
208 */
209 useVirtual?: boolean;
210
211 immutable?: boolean;
212}
213
214export default class TreeSelect extends React.Component<TreeSelectProps, any> {}