@rc-component/select 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +191 -0
  3. package/assets/index.css +306 -0
  4. package/assets/index.less +397 -0
  5. package/es/BaseSelect/Polite.d.ts +7 -0
  6. package/es/BaseSelect/Polite.js +26 -0
  7. package/es/BaseSelect/index.d.ts +118 -0
  8. package/es/BaseSelect/index.js +569 -0
  9. package/es/OptGroup.d.ts +12 -0
  10. package/es/OptGroup.js +6 -0
  11. package/es/Option.d.ts +14 -0
  12. package/es/Option.js +6 -0
  13. package/es/OptionList.d.ts +10 -0
  14. package/es/OptionList.js +379 -0
  15. package/es/Select.d.ts +114 -0
  16. package/es/Select.js +480 -0
  17. package/es/SelectContext.d.ts +23 -0
  18. package/es/SelectContext.js +6 -0
  19. package/es/SelectTrigger.d.ts +30 -0
  20. package/es/SelectTrigger.js +138 -0
  21. package/es/Selector/Input.d.ts +27 -0
  22. package/es/Selector/Input.js +114 -0
  23. package/es/Selector/MultipleSelector.d.ts +16 -0
  24. package/es/Selector/MultipleSelector.js +185 -0
  25. package/es/Selector/SingleSelector.d.ts +8 -0
  26. package/es/Selector/SingleSelector.js +104 -0
  27. package/es/Selector/index.d.ts +85 -0
  28. package/es/Selector/index.js +184 -0
  29. package/es/TransBtn.d.ts +12 -0
  30. package/es/TransBtn.js +30 -0
  31. package/es/hooks/useAllowClear.d.ts +8 -0
  32. package/es/hooks/useAllowClear.js +26 -0
  33. package/es/hooks/useBaseProps.d.ts +13 -0
  34. package/es/hooks/useBaseProps.js +10 -0
  35. package/es/hooks/useCache.d.ts +7 -0
  36. package/es/hooks/useCache.js +40 -0
  37. package/es/hooks/useDelayReset.d.ts +5 -0
  38. package/es/hooks/useDelayReset.js +24 -0
  39. package/es/hooks/useFilterOptions.d.ts +3 -0
  40. package/es/hooks/useFilterOptions.js +57 -0
  41. package/es/hooks/useId.d.ts +5 -0
  42. package/es/hooks/useId.js +29 -0
  43. package/es/hooks/useLayoutEffect.d.ts +5 -0
  44. package/es/hooks/useLayoutEffect.js +17 -0
  45. package/es/hooks/useLock.d.ts +7 -0
  46. package/es/hooks/useLock.js +27 -0
  47. package/es/hooks/useOptions.d.ts +12 -0
  48. package/es/hooks/useOptions.js +45 -0
  49. package/es/hooks/useRefFunc.d.ts +5 -0
  50. package/es/hooks/useRefFunc.js +14 -0
  51. package/es/hooks/useSelectTriggerControl.d.ts +1 -0
  52. package/es/hooks/useSelectTriggerControl.js +27 -0
  53. package/es/index.d.ts +10 -0
  54. package/es/index.js +7 -0
  55. package/es/interface.d.ts +23 -0
  56. package/es/interface.js +1 -0
  57. package/es/utils/__mocks__/platformUtil.d.ts +1 -0
  58. package/es/utils/__mocks__/platformUtil.js +3 -0
  59. package/es/utils/commonUtil.d.ts +9 -0
  60. package/es/utils/commonUtil.js +32 -0
  61. package/es/utils/keyUtil.d.ts +2 -0
  62. package/es/utils/keyUtil.js +16 -0
  63. package/es/utils/legacyUtil.d.ts +3 -0
  64. package/es/utils/legacyUtil.js +44 -0
  65. package/es/utils/platformUtil.d.ts +1 -0
  66. package/es/utils/platformUtil.js +4 -0
  67. package/es/utils/valueUtil.d.ts +24 -0
  68. package/es/utils/valueUtil.js +128 -0
  69. package/es/utils/warningPropsUtil.d.ts +4 -0
  70. package/es/utils/warningPropsUtil.js +119 -0
  71. package/lib/BaseSelect/Polite.d.ts +7 -0
  72. package/lib/BaseSelect/Polite.js +34 -0
  73. package/lib/BaseSelect/index.d.ts +118 -0
  74. package/lib/BaseSelect/index.js +579 -0
  75. package/lib/OptGroup.d.ts +12 -0
  76. package/lib/OptGroup.js +12 -0
  77. package/lib/Option.d.ts +14 -0
  78. package/lib/Option.js +12 -0
  79. package/lib/OptionList.d.ts +10 -0
  80. package/lib/OptionList.js +387 -0
  81. package/lib/Select.d.ts +114 -0
  82. package/lib/Select.js +487 -0
  83. package/lib/SelectContext.d.ts +23 -0
  84. package/lib/SelectContext.js +13 -0
  85. package/lib/SelectTrigger.d.ts +30 -0
  86. package/lib/SelectTrigger.js +147 -0
  87. package/lib/Selector/Input.d.ts +27 -0
  88. package/lib/Selector/Input.js +123 -0
  89. package/lib/Selector/MultipleSelector.d.ts +16 -0
  90. package/lib/Selector/MultipleSelector.js +194 -0
  91. package/lib/Selector/SingleSelector.d.ts +8 -0
  92. package/lib/Selector/SingleSelector.js +113 -0
  93. package/lib/Selector/index.d.ts +85 -0
  94. package/lib/Selector/index.js +191 -0
  95. package/lib/TransBtn.d.ts +12 -0
  96. package/lib/TransBtn.js +39 -0
  97. package/lib/hooks/useAllowClear.d.ts +8 -0
  98. package/lib/hooks/useAllowClear.js +34 -0
  99. package/lib/hooks/useBaseProps.d.ts +13 -0
  100. package/lib/hooks/useBaseProps.js +19 -0
  101. package/lib/hooks/useCache.d.ts +7 -0
  102. package/lib/hooks/useCache.js +49 -0
  103. package/lib/hooks/useDelayReset.d.ts +5 -0
  104. package/lib/hooks/useDelayReset.js +31 -0
  105. package/lib/hooks/useFilterOptions.d.ts +3 -0
  106. package/lib/hooks/useFilterOptions.js +66 -0
  107. package/lib/hooks/useId.d.ts +5 -0
  108. package/lib/hooks/useId.js +40 -0
  109. package/lib/hooks/useLayoutEffect.d.ts +5 -0
  110. package/lib/hooks/useLayoutEffect.js +25 -0
  111. package/lib/hooks/useLock.d.ts +7 -0
  112. package/lib/hooks/useLock.js +34 -0
  113. package/lib/hooks/useOptions.d.ts +12 -0
  114. package/lib/hooks/useOptions.js +52 -0
  115. package/lib/hooks/useRefFunc.d.ts +5 -0
  116. package/lib/hooks/useRefFunc.js +21 -0
  117. package/lib/hooks/useSelectTriggerControl.d.ts +1 -0
  118. package/lib/hooks/useSelectTriggerControl.js +35 -0
  119. package/lib/index.d.ts +10 -0
  120. package/lib/index.js +37 -0
  121. package/lib/interface.d.ts +23 -0
  122. package/lib/interface.js +5 -0
  123. package/lib/utils/__mocks__/platformUtil.d.ts +1 -0
  124. package/lib/utils/__mocks__/platformUtil.js +9 -0
  125. package/lib/utils/commonUtil.d.ts +9 -0
  126. package/lib/utils/commonUtil.js +42 -0
  127. package/lib/utils/keyUtil.d.ts +2 -0
  128. package/lib/utils/keyUtil.js +22 -0
  129. package/lib/utils/legacyUtil.d.ts +3 -0
  130. package/lib/utils/legacyUtil.js +53 -0
  131. package/lib/utils/platformUtil.d.ts +1 -0
  132. package/lib/utils/platformUtil.js +10 -0
  133. package/lib/utils/valueUtil.d.ts +24 -0
  134. package/lib/utils/valueUtil.js +140 -0
  135. package/lib/utils/warningPropsUtil.d.ts +4 -0
  136. package/lib/utils/warningPropsUtil.js +129 -0
  137. package/package.json +86 -0
@@ -0,0 +1,379 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
+ import classNames from 'classnames';
3
+ import KeyCode from "@rc-component/util/es/KeyCode";
4
+ import useMemo from "@rc-component/util/es/hooks/useMemo";
5
+ import omit from "@rc-component/util/es/omit";
6
+ import pickAttrs from "@rc-component/util/es/pickAttrs";
7
+ import List from 'rc-virtual-list';
8
+ import * as React from 'react';
9
+ import { useEffect } from 'react';
10
+ import SelectContext from "./SelectContext";
11
+ import TransBtn from "./TransBtn";
12
+ import useBaseProps from "./hooks/useBaseProps";
13
+ import { isPlatformMac } from "./utils/platformUtil";
14
+ import { isValidCount } from "./utils/valueUtil";
15
+
16
+ // export interface OptionListProps<OptionsType extends object[]> {
17
+
18
+ function isTitleType(content) {
19
+ return typeof content === 'string' || typeof content === 'number';
20
+ }
21
+
22
+ /**
23
+ * Using virtual list of option display.
24
+ * Will fallback to dom if use customize render.
25
+ */
26
+ const OptionList = (_, ref) => {
27
+ const {
28
+ prefixCls,
29
+ id,
30
+ open,
31
+ multiple,
32
+ mode,
33
+ searchValue,
34
+ toggleOpen,
35
+ notFoundContent,
36
+ onPopupScroll,
37
+ showScrollBar
38
+ } = useBaseProps();
39
+ const {
40
+ maxCount,
41
+ flattenOptions,
42
+ onActiveValue,
43
+ defaultActiveFirstOption,
44
+ onSelect,
45
+ menuItemSelectedIcon,
46
+ rawValues,
47
+ fieldNames,
48
+ virtual,
49
+ direction,
50
+ listHeight,
51
+ listItemHeight,
52
+ optionRender
53
+ } = React.useContext(SelectContext);
54
+ const itemPrefixCls = `${prefixCls}-item`;
55
+ const memoFlattenOptions = useMemo(() => flattenOptions, [open, flattenOptions], (prev, next) => next[0] && prev[1] !== next[1]);
56
+
57
+ // =========================== List ===========================
58
+ const listRef = React.useRef(null);
59
+ const overMaxCount = React.useMemo(() => multiple && isValidCount(maxCount) && rawValues?.size >= maxCount, [multiple, maxCount, rawValues?.size]);
60
+ const onListMouseDown = event => {
61
+ event.preventDefault();
62
+ };
63
+ const scrollIntoView = args => {
64
+ listRef.current?.scrollTo(typeof args === 'number' ? {
65
+ index: args
66
+ } : args);
67
+ };
68
+
69
+ // https://github.com/ant-design/ant-design/issues/34975
70
+ const isSelected = React.useCallback(value => {
71
+ if (mode === 'combobox') {
72
+ return false;
73
+ }
74
+ return rawValues.has(value);
75
+ }, [mode, [...rawValues].toString(), rawValues.size]);
76
+
77
+ // ========================== Active ==========================
78
+ const getEnabledActiveIndex = (index, offset = 1) => {
79
+ const len = memoFlattenOptions.length;
80
+ for (let i = 0; i < len; i += 1) {
81
+ const current = (index + i * offset + len) % len;
82
+ const {
83
+ group,
84
+ data
85
+ } = memoFlattenOptions[current] || {};
86
+ if (!group && !data?.disabled && (isSelected(data.value) || !overMaxCount)) {
87
+ return current;
88
+ }
89
+ }
90
+ return -1;
91
+ };
92
+ const [activeIndex, setActiveIndex] = React.useState(() => getEnabledActiveIndex(0));
93
+ const setActive = (index, fromKeyboard = false) => {
94
+ setActiveIndex(index);
95
+ const info = {
96
+ source: fromKeyboard ? 'keyboard' : 'mouse'
97
+ };
98
+
99
+ // Trigger active event
100
+ const flattenItem = memoFlattenOptions[index];
101
+ if (!flattenItem) {
102
+ onActiveValue(null, -1, info);
103
+ return;
104
+ }
105
+ onActiveValue(flattenItem.value, index, info);
106
+ };
107
+
108
+ // Auto active first item when list length or searchValue changed
109
+ useEffect(() => {
110
+ setActive(defaultActiveFirstOption !== false ? getEnabledActiveIndex(0) : -1);
111
+ }, [memoFlattenOptions.length, searchValue]);
112
+
113
+ // https://github.com/ant-design/ant-design/issues/48036
114
+ const isAriaSelected = React.useCallback(value => {
115
+ if (mode === 'combobox') {
116
+ return String(value).toLowerCase() === searchValue.toLowerCase();
117
+ }
118
+ return rawValues.has(value);
119
+ }, [mode, searchValue, [...rawValues].toString(), rawValues.size]);
120
+
121
+ // Auto scroll to item position in single mode
122
+ useEffect(() => {
123
+ /**
124
+ * React will skip `onChange` when component update.
125
+ * `setActive` function will call root accessibility state update which makes re-render.
126
+ * So we need to delay to let Input component trigger onChange first.
127
+ */
128
+ const timeoutId = setTimeout(() => {
129
+ if (!multiple && open && rawValues.size === 1) {
130
+ const value = Array.from(rawValues)[0];
131
+ const index = memoFlattenOptions.findIndex(({
132
+ data
133
+ }) => data.value === value);
134
+ if (index !== -1) {
135
+ setActive(index);
136
+ scrollIntoView(index);
137
+ }
138
+ }
139
+ });
140
+
141
+ // Force trigger scrollbar visible when open
142
+ if (open) {
143
+ listRef.current?.scrollTo(undefined);
144
+ }
145
+ return () => clearTimeout(timeoutId);
146
+ }, [open, searchValue]);
147
+
148
+ // ========================== Values ==========================
149
+ const onSelectValue = value => {
150
+ if (value !== undefined) {
151
+ onSelect(value, {
152
+ selected: !rawValues.has(value)
153
+ });
154
+ }
155
+
156
+ // Single mode should always close by select
157
+ if (!multiple) {
158
+ toggleOpen(false);
159
+ }
160
+ };
161
+
162
+ // ========================= Keyboard =========================
163
+ React.useImperativeHandle(ref, () => ({
164
+ onKeyDown: event => {
165
+ const {
166
+ which,
167
+ ctrlKey
168
+ } = event;
169
+ switch (which) {
170
+ // >>> Arrow keys & ctrl + n/p on Mac
171
+ case KeyCode.N:
172
+ case KeyCode.P:
173
+ case KeyCode.UP:
174
+ case KeyCode.DOWN:
175
+ {
176
+ let offset = 0;
177
+ if (which === KeyCode.UP) {
178
+ offset = -1;
179
+ } else if (which === KeyCode.DOWN) {
180
+ offset = 1;
181
+ } else if (isPlatformMac() && ctrlKey) {
182
+ if (which === KeyCode.N) {
183
+ offset = 1;
184
+ } else if (which === KeyCode.P) {
185
+ offset = -1;
186
+ }
187
+ }
188
+ if (offset !== 0) {
189
+ const nextActiveIndex = getEnabledActiveIndex(activeIndex + offset, offset);
190
+ scrollIntoView(nextActiveIndex);
191
+ setActive(nextActiveIndex, true);
192
+ }
193
+ break;
194
+ }
195
+
196
+ // >>> Select (Tab / Enter)
197
+ case KeyCode.TAB:
198
+ case KeyCode.ENTER:
199
+ {
200
+ // value
201
+ const item = memoFlattenOptions[activeIndex];
202
+ if (item && !item?.data?.disabled && !overMaxCount) {
203
+ onSelectValue(item.value);
204
+ } else {
205
+ onSelectValue(undefined);
206
+ }
207
+ if (open) {
208
+ event.preventDefault();
209
+ }
210
+ break;
211
+ }
212
+
213
+ // >>> Close
214
+ case KeyCode.ESC:
215
+ {
216
+ toggleOpen(false);
217
+ if (open) {
218
+ event.stopPropagation();
219
+ }
220
+ }
221
+ }
222
+ },
223
+ onKeyUp: () => {},
224
+ scrollTo: index => {
225
+ scrollIntoView(index);
226
+ }
227
+ }));
228
+
229
+ // ========================== Render ==========================
230
+ if (memoFlattenOptions.length === 0) {
231
+ return /*#__PURE__*/React.createElement("div", {
232
+ role: "listbox",
233
+ id: `${id}_list`,
234
+ className: `${itemPrefixCls}-empty`,
235
+ onMouseDown: onListMouseDown
236
+ }, notFoundContent);
237
+ }
238
+ const omitFieldNameList = Object.keys(fieldNames).map(key => fieldNames[key]);
239
+ const getLabel = item => item.label;
240
+ function getItemAriaProps(item, index) {
241
+ const {
242
+ group
243
+ } = item;
244
+ return {
245
+ role: group ? 'presentation' : 'option',
246
+ id: `${id}_list_${index}`
247
+ };
248
+ }
249
+ const renderItem = index => {
250
+ const item = memoFlattenOptions[index];
251
+ if (!item) {
252
+ return null;
253
+ }
254
+ const itemData = item.data || {};
255
+ const {
256
+ value
257
+ } = itemData;
258
+ const {
259
+ group
260
+ } = item;
261
+ const attrs = pickAttrs(itemData, true);
262
+ const mergedLabel = getLabel(item);
263
+ return item ? /*#__PURE__*/React.createElement("div", _extends({
264
+ "aria-label": typeof mergedLabel === 'string' && !group ? mergedLabel : null
265
+ }, attrs, {
266
+ key: index
267
+ }, getItemAriaProps(item, index), {
268
+ "aria-selected": isAriaSelected(value)
269
+ }), value) : null;
270
+ };
271
+ const a11yProps = {
272
+ role: 'listbox',
273
+ id: `${id}_list`
274
+ };
275
+ return /*#__PURE__*/React.createElement(React.Fragment, null, virtual && /*#__PURE__*/React.createElement("div", _extends({}, a11yProps, {
276
+ style: {
277
+ height: 0,
278
+ width: 0,
279
+ overflow: 'hidden'
280
+ }
281
+ }), renderItem(activeIndex - 1), renderItem(activeIndex), renderItem(activeIndex + 1)), /*#__PURE__*/React.createElement(List, {
282
+ itemKey: "key",
283
+ ref: listRef,
284
+ data: memoFlattenOptions,
285
+ height: listHeight,
286
+ itemHeight: listItemHeight,
287
+ fullHeight: false,
288
+ onMouseDown: onListMouseDown,
289
+ onScroll: onPopupScroll,
290
+ virtual: virtual,
291
+ direction: direction,
292
+ innerProps: virtual ? null : a11yProps,
293
+ showScrollBar: showScrollBar
294
+ }, (item, itemIndex) => {
295
+ const {
296
+ group,
297
+ groupOption,
298
+ data,
299
+ label,
300
+ value
301
+ } = item;
302
+ const {
303
+ key
304
+ } = data;
305
+
306
+ // Group
307
+ if (group) {
308
+ const groupTitle = data.title ?? (isTitleType(label) ? label.toString() : undefined);
309
+ return /*#__PURE__*/React.createElement("div", {
310
+ className: classNames(itemPrefixCls, `${itemPrefixCls}-group`, data.className),
311
+ title: groupTitle
312
+ }, label !== undefined ? label : key);
313
+ }
314
+ const {
315
+ disabled,
316
+ title,
317
+ children,
318
+ style,
319
+ className,
320
+ ...otherProps
321
+ } = data;
322
+ const passedProps = omit(otherProps, omitFieldNameList);
323
+
324
+ // Option
325
+ const selected = isSelected(value);
326
+ const mergedDisabled = disabled || !selected && overMaxCount;
327
+ const optionPrefixCls = `${itemPrefixCls}-option`;
328
+ const optionClassName = classNames(itemPrefixCls, optionPrefixCls, className, {
329
+ [`${optionPrefixCls}-grouped`]: groupOption,
330
+ [`${optionPrefixCls}-active`]: activeIndex === itemIndex && !mergedDisabled,
331
+ [`${optionPrefixCls}-disabled`]: mergedDisabled,
332
+ [`${optionPrefixCls}-selected`]: selected
333
+ });
334
+ const mergedLabel = getLabel(item);
335
+ const iconVisible = !menuItemSelectedIcon || typeof menuItemSelectedIcon === 'function' || selected;
336
+
337
+ // https://github.com/ant-design/ant-design/issues/34145
338
+ const content = typeof mergedLabel === 'number' ? mergedLabel : mergedLabel || value;
339
+ // https://github.com/ant-design/ant-design/issues/26717
340
+ let optionTitle = isTitleType(content) ? content.toString() : undefined;
341
+ if (title !== undefined) {
342
+ optionTitle = title;
343
+ }
344
+ return /*#__PURE__*/React.createElement("div", _extends({}, pickAttrs(passedProps), !virtual ? getItemAriaProps(item, itemIndex) : {}, {
345
+ "aria-selected": isAriaSelected(value),
346
+ className: optionClassName,
347
+ title: optionTitle,
348
+ onMouseMove: () => {
349
+ if (activeIndex === itemIndex || mergedDisabled) {
350
+ return;
351
+ }
352
+ setActive(itemIndex);
353
+ },
354
+ onClick: () => {
355
+ if (!mergedDisabled) {
356
+ onSelectValue(value);
357
+ }
358
+ },
359
+ style: style
360
+ }), /*#__PURE__*/React.createElement("div", {
361
+ className: `${optionPrefixCls}-content`
362
+ }, typeof optionRender === 'function' ? optionRender(item, {
363
+ index: itemIndex
364
+ }) : content), /*#__PURE__*/React.isValidElement(menuItemSelectedIcon) || selected, iconVisible && /*#__PURE__*/React.createElement(TransBtn, {
365
+ className: `${itemPrefixCls}-option-state`,
366
+ customizeIcon: menuItemSelectedIcon,
367
+ customizeIconProps: {
368
+ value,
369
+ disabled: mergedDisabled,
370
+ isSelected: selected
371
+ }
372
+ }, selected ? '✓' : null));
373
+ }));
374
+ };
375
+ const RefOptionList = /*#__PURE__*/React.forwardRef(OptionList);
376
+ if (process.env.NODE_ENV !== 'production') {
377
+ RefOptionList.displayName = 'OptionList';
378
+ }
379
+ export default RefOptionList;
package/es/Select.d.ts ADDED
@@ -0,0 +1,114 @@
1
+ /**
2
+ * To match accessibility requirement, we always provide an input in the component.
3
+ * Other element will not set `tabIndex` to avoid `onBlur` sequence problem.
4
+ * For focused select, we set `aria-live="polite"` to update the accessibility content.
5
+ *
6
+ * ref:
7
+ * - keyboard: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role#Keyboard_interactions
8
+ *
9
+ * New api:
10
+ * - listHeight
11
+ * - listItemHeight
12
+ * - component
13
+ *
14
+ * Remove deprecated api:
15
+ * - multiple
16
+ * - tags
17
+ * - combobox
18
+ * - firstActiveValue
19
+ * - dropdownMenuStyle
20
+ * - openClassName (Not list in api)
21
+ *
22
+ * Update:
23
+ * - `backfill` only support `combobox` mode
24
+ * - `combobox` mode not support `labelInValue` since it's meaningless
25
+ * - `getInputElement` only support `combobox` mode
26
+ * - `onChange` return OptionData instead of ReactNode
27
+ * - `filterOption` `onChange` `onSelect` accept OptionData instead of ReactNode
28
+ * - `combobox` mode trigger `onChange` will get `undefined` if no `value` match in Option
29
+ * - `combobox` mode not support `optionLabelProp`
30
+ */
31
+ import * as React from 'react';
32
+ import type { BaseSelectPropsWithoutPrivate, BaseSelectRef, DisplayValueType, RenderNode } from './BaseSelect';
33
+ import OptGroup from './OptGroup';
34
+ import Option from './Option';
35
+ import type { FlattenOptionData } from './interface';
36
+ export type OnActiveValue = (active: RawValueType, index: number, info?: {
37
+ source?: 'keyboard' | 'mouse';
38
+ }) => void;
39
+ export type OnInternalSelect = (value: RawValueType, info: {
40
+ selected: boolean;
41
+ }) => void;
42
+ export type RawValueType = string | number;
43
+ export interface LabelInValueType {
44
+ label: React.ReactNode;
45
+ value: RawValueType;
46
+ }
47
+ export type DraftValueType = RawValueType | LabelInValueType | DisplayValueType | (RawValueType | LabelInValueType | DisplayValueType)[];
48
+ export type FilterFunc<OptionType> = (inputValue: string, option?: OptionType) => boolean;
49
+ export interface FieldNames {
50
+ value?: string;
51
+ label?: string;
52
+ groupLabel?: string;
53
+ options?: string;
54
+ }
55
+ export interface BaseOptionType {
56
+ disabled?: boolean;
57
+ className?: string;
58
+ title?: string;
59
+ [name: string]: any;
60
+ }
61
+ export interface DefaultOptionType extends BaseOptionType {
62
+ label?: React.ReactNode;
63
+ value?: string | number | null;
64
+ children?: Omit<DefaultOptionType, 'children'>[];
65
+ }
66
+ export type SelectHandler<ValueType, OptionType extends BaseOptionType = DefaultOptionType> = (value: ValueType, option: OptionType) => void;
67
+ type ArrayElementType<T> = T extends (infer E)[] ? E : T;
68
+ export interface SelectProps<ValueType = any, OptionType extends BaseOptionType = DefaultOptionType> extends BaseSelectPropsWithoutPrivate {
69
+ prefixCls?: string;
70
+ id?: string;
71
+ backfill?: boolean;
72
+ fieldNames?: FieldNames;
73
+ searchValue?: string;
74
+ onSearch?: (value: string) => void;
75
+ autoClearSearchValue?: boolean;
76
+ onSelect?: SelectHandler<ArrayElementType<ValueType>, OptionType>;
77
+ onDeselect?: SelectHandler<ArrayElementType<ValueType>, OptionType>;
78
+ /**
79
+ * In Select, `false` means do nothing.
80
+ * In TreeSelect, `false` will highlight match item.
81
+ * It's by design.
82
+ */
83
+ filterOption?: boolean | FilterFunc<OptionType>;
84
+ filterSort?: (optionA: OptionType, optionB: OptionType, info: {
85
+ searchValue: string;
86
+ }) => number;
87
+ optionFilterProp?: string;
88
+ optionLabelProp?: string;
89
+ children?: React.ReactNode;
90
+ options?: OptionType[];
91
+ optionRender?: (oriOption: FlattenOptionData<OptionType>, info: {
92
+ index: number;
93
+ }) => React.ReactNode;
94
+ defaultActiveFirstOption?: boolean;
95
+ virtual?: boolean;
96
+ direction?: 'ltr' | 'rtl';
97
+ listHeight?: number;
98
+ listItemHeight?: number;
99
+ labelRender?: (props: LabelInValueType) => React.ReactNode;
100
+ menuItemSelectedIcon?: RenderNode;
101
+ mode?: 'combobox' | 'multiple' | 'tags';
102
+ labelInValue?: boolean;
103
+ value?: ValueType | null;
104
+ defaultValue?: ValueType | null;
105
+ maxCount?: number;
106
+ onChange?: (value: ValueType, option?: OptionType | OptionType[]) => void;
107
+ }
108
+ declare const TypedSelect: (<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(props: SelectProps<ValueType, OptionType> & {
109
+ children?: React.ReactNode;
110
+ } & React.RefAttributes<BaseSelectRef>) => React.ReactElement) & {
111
+ Option: typeof Option;
112
+ OptGroup: typeof OptGroup;
113
+ };
114
+ export default TypedSelect;