@rescui/select 0.15.0 → 0.15.1-RUI-280-Update-select-component-026338d06.52
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.
- package/lib/_virtual/index.css.js +12 -12
- package/lib/common-prop-types.d.ts +9 -14
- package/lib/common-prop-types.js +4 -3
- package/lib/constants.d.ts +7 -0
- package/lib/constants.js +8 -0
- package/lib/hooks/use-css-context-transfer.d.ts +14 -0
- package/lib/hooks/use-css-context-transfer.js +40 -0
- package/lib/hooks/use-label-focus.d.ts +11 -0
- package/lib/hooks/use-label-focus.js +28 -0
- package/lib/hooks/use-multi-option-serialization.d.ts +10 -0
- package/lib/hooks/use-multi-option-serialization.js +82 -0
- package/lib/hooks/use-option-serialization.d.ts +10 -0
- package/lib/hooks/use-option-serialization.js +59 -0
- package/lib/index.css +2004 -837
- package/lib/index.d.ts +4 -6
- package/lib/index.js +3 -3
- package/lib/multiselect.d.ts +29 -0
- package/lib/multiselect.js +239 -0
- package/lib/native-select.d.ts +4 -0
- package/lib/native-select.js +182 -0
- package/lib/parts/foldable.js +5 -7
- package/lib/parts/form-trigger-wrapper.d.ts +7 -7
- package/lib/parts/form-trigger-wrapper.js +16 -34
- package/lib/parts/icons.d.ts +17 -0
- package/lib/parts/icons.js +75 -0
- package/lib/parts/list-box.d.ts +19 -0
- package/lib/parts/list-box.js +146 -0
- package/lib/parts/multi-trigger.d.ts +11 -0
- package/lib/parts/multi-trigger.js +62 -0
- package/lib/parts/native-select-options-with-groups.d.ts +8 -0
- package/lib/parts/native-select-options-with-groups.js +76 -0
- package/lib/parts/native-select-trigger.d.ts +18 -0
- package/lib/parts/native-select-trigger.js +54 -0
- package/lib/parts/popover.d.ts +12 -0
- package/lib/parts/popover.js +62 -0
- package/lib/parts/popup-content.d.ts +19 -0
- package/lib/parts/popup-content.js +76 -0
- package/lib/public-api.p.css +486 -444
- package/lib/public-api.pcss +486 -444
- package/lib/select-basic.d.ts +3 -0
- package/lib/select-basic.js +143 -0
- package/lib/select-searchable.d.ts +3 -0
- package/lib/select-searchable.js +168 -0
- package/lib/select.d.ts +27 -91
- package/lib/select.js +53 -360
- package/lib/styles/common.p.module.css.js +27 -0
- package/lib/styles/form-trigger.p.module.css.js +15 -0
- package/lib/styles/list-box.p.module.css.js +16 -0
- package/lib/styles/native-select-trigger.p.module.css.js +17 -0
- package/lib/styles/native-select.p.module.css.js +9 -0
- package/lib/styles/popover.p.module.css.js +10 -0
- package/lib/types.d.ts +167 -4
- package/lib/utils/calculate-max-height-by-items.d.ts +13 -0
- package/lib/utils/calculate-max-height-by-items.js +22 -0
- package/lib/utils/convert-options.d.ts +3 -0
- package/lib/utils/convert-options.js +52 -0
- package/lib/utils/convert-placement.d.ts +3 -0
- package/lib/utils/convert-placement.js +22 -0
- package/lib/utils/css-vars-utils.d.ts +3 -0
- package/lib/utils/css-vars-utils.js +20 -0
- package/lib/utils/get-empty-message.d.ts +6 -0
- package/lib/utils/get-empty-message.js +32 -0
- package/lib/utils/get-option-value.d.ts +2 -0
- package/lib/utils/get-option-value.js +11 -0
- package/lib/utils/get-real-items-cnt.d.ts +2 -0
- package/lib/utils/get-real-items-cnt.js +21 -0
- package/lib/utils/get-text-from-nodes.d.ts +2 -0
- package/lib/utils/get-text-from-nodes.js +28 -0
- package/lib/utils/is-option-a-group.d.ts +2 -0
- package/lib/utils/is-option-a-group.js +5 -0
- package/lib/utils/throttle.d.ts +1 -0
- package/package.json +14 -11
- package/lib/key-codes.d.ts +0 -7
- package/lib/key-codes.js +0 -8
- package/lib/parts/common-select.p.module.css.js +0 -15
- package/lib/parts/form-trigger.p.module.css.js +0 -15
- package/lib/parts/multiselect.d.ts +0 -86
- package/lib/parts/multiselect.js +0 -455
- package/lib/parts/native-select.d.ts +0 -36
- package/lib/parts/native-select.js +0 -257
- package/lib/parts/native-select.p.module.css.js +0 -9
- package/lib/parts/throttle.d.ts +0 -1
- package/lib/parts/trigger.d.ts +0 -37
- package/lib/parts/trigger.js +0 -255
- package/lib/parts/trigger.p.module.css.js +0 -31
- package/lib/parts/use-backward-compatible-id.d.ts +0 -4
- package/lib/parts/use-backward-compatible-id.js +0 -14
- package/lib/utils.d.ts +0 -22
- package/lib/utils.js +0 -201
- /package/lib/{parts → hooks}/use-observable-force-rerender.d.ts +0 -0
- /package/lib/{parts → hooks}/use-observable-force-rerender.js +0 -0
- /package/lib/{parts → utils}/throttle.js +0 -0
package/lib/parts/multiselect.js
DELETED
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
|
-
import React, { useState, useRef, useEffect, useMemo, useCallback } from 'react';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import cn from 'classnames';
|
|
6
|
-
import scrollIntoView from 'scroll-into-view-if-needed';
|
|
7
|
-
import { Dropdown } from '@rescui/dropdown';
|
|
8
|
-
import { Menu, MenuItem, Divider, GroupHeader } from '@rescui/menu';
|
|
9
|
-
import { ErrorMessage } from '@rescui/form-field';
|
|
10
|
-
import { useThemeWithUndefined } from '@rescui/ui-contexts';
|
|
11
|
-
import CheckOutlineIcon from '../_virtual/check-outline.js';
|
|
12
|
-
import { useStrongMemo, getDefaultCursorIndex, isGroupsEmpty, getOptionValue, getMovedCursorIndex, shouldOpenSelect, isIndexMatchCursor, withoutGroupsLabel, getPlainOptionsFromGroups, getEmptyMessage, OptionGroupTypes, convertToOptionGroupsIfNeeded, calculateMaxHeight } from '../utils.js';
|
|
13
|
-
import { optionType, optionsGroupType, noOptionsMessageType } from '../common-prop-types.js';
|
|
14
|
-
import { ARROW_DOWN, ARROW_UP, ENTER, SPACE, TAB, ESCAPE, BACKSPACE } from '../key-codes.js';
|
|
15
|
-
import SelectTrigger from './trigger.js';
|
|
16
|
-
import FormTriggerWrapper from './form-trigger-wrapper.js';
|
|
17
|
-
import { useObservableForceRerender } from './use-observable-force-rerender.js';
|
|
18
|
-
import { useBackwardCompatibleId } from './use-backward-compatible-id.js';
|
|
19
|
-
import styles from './common-select.p.module.css.js'; // eslint-disable-next-line complexity
|
|
20
|
-
|
|
21
|
-
const Option = _ref => {
|
|
22
|
-
let {
|
|
23
|
-
selected,
|
|
24
|
-
cursorIndex,
|
|
25
|
-
item,
|
|
26
|
-
isSingleLine,
|
|
27
|
-
isLastItem,
|
|
28
|
-
highlightedItemRef,
|
|
29
|
-
handleHighlightIndex,
|
|
30
|
-
handleSelectIndex
|
|
31
|
-
} = _ref;
|
|
32
|
-
|
|
33
|
-
if (item.type === OptionGroupTypes.OPTION) {
|
|
34
|
-
const {
|
|
35
|
-
index,
|
|
36
|
-
label
|
|
37
|
-
} = item;
|
|
38
|
-
const value = getOptionValue(item);
|
|
39
|
-
const isItemSelected = Boolean(selected && selected.length && selected.some(s => value === getOptionValue(s)));
|
|
40
|
-
const isHighlighted = isIndexMatchCursor(cursorIndex, index);
|
|
41
|
-
const icon = isSingleLine && isItemSelected ? /*#__PURE__*/React.createElement(CheckOutlineIcon, {
|
|
42
|
-
className: styles.checkIcon,
|
|
43
|
-
"data-render-all-sizes": true
|
|
44
|
-
}) : null;
|
|
45
|
-
return /*#__PURE__*/React.createElement(MenuItem, {
|
|
46
|
-
selected: isItemSelected,
|
|
47
|
-
highlighted: isHighlighted,
|
|
48
|
-
ref: isHighlighted ? highlightedItemRef : null,
|
|
49
|
-
onMouseMove: () => handleHighlightIndex(index),
|
|
50
|
-
onClick: () => handleSelectIndex(index),
|
|
51
|
-
className: cn(isLastItem && styles.lastOption),
|
|
52
|
-
icon: icon
|
|
53
|
-
}, label);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (item.type === OptionGroupTypes.DIVIDER) {
|
|
57
|
-
return /*#__PURE__*/React.createElement(Divider, {
|
|
58
|
-
className: styles.divider
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (item.type === OptionGroupTypes.HEADER) {
|
|
63
|
-
const {
|
|
64
|
-
label
|
|
65
|
-
} = item;
|
|
66
|
-
return /*#__PURE__*/React.createElement(GroupHeader, {
|
|
67
|
-
text: label
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return null;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const getOptionKey = (item, i) => {
|
|
75
|
-
if (item.type === OptionGroupTypes.OPTION) {
|
|
76
|
-
const value = getOptionValue(item);
|
|
77
|
-
return `${value}_${item.index[0]}`;
|
|
78
|
-
} else if (item.type === OptionGroupTypes.DIVIDER) {
|
|
79
|
-
return `divider${i}`;
|
|
80
|
-
} else if (item.type === OptionGroupTypes.HEADER) {
|
|
81
|
-
return `header${i}`;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return null;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
function filterSelected(groups, selected) {
|
|
88
|
-
const selectedValues = {};
|
|
89
|
-
|
|
90
|
-
if (selected) {
|
|
91
|
-
selected.forEach(s => {
|
|
92
|
-
selectedValues[getOptionValue(s)] = true;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return groups.map(g => {
|
|
97
|
-
let newOptions = [];
|
|
98
|
-
|
|
99
|
-
if (g.options) {
|
|
100
|
-
newOptions = g.options.filter(opt => !selectedValues[getOptionValue(opt)]);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return { ...g,
|
|
104
|
-
options: newOptions
|
|
105
|
-
};
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const NativeSelectedOptions = _ref2 => {
|
|
110
|
-
let {
|
|
111
|
-
name,
|
|
112
|
-
selected
|
|
113
|
-
} = _ref2;
|
|
114
|
-
|
|
115
|
-
if (!selected || !Array.isArray(selected) || !selected.length) {
|
|
116
|
-
return /*#__PURE__*/React.createElement("input", {
|
|
117
|
-
type: "hidden",
|
|
118
|
-
name: name,
|
|
119
|
-
value: ""
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, selected.map(_ref3 => {
|
|
124
|
-
let {
|
|
125
|
-
value
|
|
126
|
-
} = _ref3;
|
|
127
|
-
return /*#__PURE__*/React.createElement("input", {
|
|
128
|
-
key: value,
|
|
129
|
-
type: "hidden",
|
|
130
|
-
name: name,
|
|
131
|
-
value: value
|
|
132
|
-
});
|
|
133
|
-
}));
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
const SIZE_STYLES = {
|
|
137
|
-
s: styles.sizeS,
|
|
138
|
-
m: styles.sizeM,
|
|
139
|
-
l: styles.sizeL
|
|
140
|
-
};
|
|
141
|
-
const MENU_SIZE_STYLES = {
|
|
142
|
-
s: styles.menuSizeS,
|
|
143
|
-
m: styles.menuSizeM,
|
|
144
|
-
l: styles.menuSizeL
|
|
145
|
-
}; // eslint-disable-next-line complexity
|
|
146
|
-
|
|
147
|
-
const Multiselect = _ref4 => {
|
|
148
|
-
let {
|
|
149
|
-
options,
|
|
150
|
-
size = 'm',
|
|
151
|
-
mode = 'classic',
|
|
152
|
-
theme: themeFromProps,
|
|
153
|
-
className = null,
|
|
154
|
-
id,
|
|
155
|
-
value = undefined,
|
|
156
|
-
onChange,
|
|
157
|
-
placeholder,
|
|
158
|
-
isSingleLine = false,
|
|
159
|
-
isClearable = false,
|
|
160
|
-
isLoading = false,
|
|
161
|
-
isDisabled = false,
|
|
162
|
-
noOptionsMessage,
|
|
163
|
-
error,
|
|
164
|
-
reserveErrorLine = false,
|
|
165
|
-
placement = 'bottom',
|
|
166
|
-
boldLabel = true,
|
|
167
|
-
...restProps
|
|
168
|
-
} = _ref4;
|
|
169
|
-
const [triggerFormWrapperRef, setTriggerFormWrapperRef] = useState(null);
|
|
170
|
-
const dropdownRef = useRef(null);
|
|
171
|
-
const highlightedItemRef = useRef();
|
|
172
|
-
const theme = useThemeWithUndefined(themeFromProps);
|
|
173
|
-
const [isKeyboardNavigating, setIsKeyboardNavigating] = useState(false);
|
|
174
|
-
const skipScrollingRef = useRef(false);
|
|
175
|
-
const groups = useStrongMemo(() => convertToOptionGroupsIfNeeded(options), [options]);
|
|
176
|
-
const filteredGroups = useStrongMemo(() => {
|
|
177
|
-
if (isSingleLine) {
|
|
178
|
-
return groups;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return filterSelected(groups, value);
|
|
182
|
-
}, [isSingleLine, value, groups]);
|
|
183
|
-
const [menuIsOpen, setMenuIsOpen] = useState(false);
|
|
184
|
-
const [cursorIndex, setCursorIndex] = useState(() => getDefaultCursorIndex(filteredGroups));
|
|
185
|
-
useEffect(() => {
|
|
186
|
-
setCursorIndex(getDefaultCursorIndex(filteredGroups));
|
|
187
|
-
}, [filteredGroups, value]);
|
|
188
|
-
const isEmptyMenu = useMemo(() => isGroupsEmpty(filteredGroups), [filteredGroups]);
|
|
189
|
-
const handleSelectIndex = useCallback(index => {
|
|
190
|
-
const selectedOption = filteredGroups[index[0]].options[index[1]];
|
|
191
|
-
const selectedOptionValue = getOptionValue(selectedOption);
|
|
192
|
-
const optionAdded = !value.some(option => getOptionValue(option) === selectedOptionValue);
|
|
193
|
-
const newSelected = optionAdded ? [...value, selectedOption] : value.filter(option => getOptionValue(option) !== selectedOptionValue);
|
|
194
|
-
|
|
195
|
-
if (onChange) {
|
|
196
|
-
onChange(newSelected);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
setMenuIsOpen(false);
|
|
200
|
-
setIsKeyboardNavigating(false);
|
|
201
|
-
}, [onChange, filteredGroups, value]);
|
|
202
|
-
useEffect(() => {
|
|
203
|
-
if (dropdownRef.current) {
|
|
204
|
-
dropdownRef.current.scheduleUpdate();
|
|
205
|
-
}
|
|
206
|
-
}, [value]);
|
|
207
|
-
const handleMouseMove = useCallback(() => setIsKeyboardNavigating(false), []);
|
|
208
|
-
useEffect(() => {
|
|
209
|
-
if (isKeyboardNavigating) {
|
|
210
|
-
document.addEventListener('mousemove', handleMouseMove);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return () => document.removeEventListener('mousemove', handleMouseMove);
|
|
214
|
-
}, [handleMouseMove, isKeyboardNavigating]);
|
|
215
|
-
useEffect(() => {
|
|
216
|
-
if (isKeyboardNavigating && highlightedItemRef.current) {
|
|
217
|
-
if (skipScrollingRef.current) {
|
|
218
|
-
skipScrollingRef.current = false;
|
|
219
|
-
} else {
|
|
220
|
-
let elementToScrollTo = highlightedItemRef.current;
|
|
221
|
-
|
|
222
|
-
if (cursorIndex[0] === 0 && cursorIndex[1] === 0) {
|
|
223
|
-
const groupHeader = highlightedItemRef.current.previousSibling;
|
|
224
|
-
|
|
225
|
-
if (groupHeader) {
|
|
226
|
-
elementToScrollTo = groupHeader;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
scrollIntoView(elementToScrollTo, {
|
|
231
|
-
behavior: 'instant',
|
|
232
|
-
scrollMode: 'if-needed',
|
|
233
|
-
block: 'nearest',
|
|
234
|
-
inline: 'nearest'
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}, [highlightedItemRef, cursorIndex, isKeyboardNavigating]);
|
|
239
|
-
const handleClose = useCallback(() => {
|
|
240
|
-
setMenuIsOpen(false);
|
|
241
|
-
setIsKeyboardNavigating(false);
|
|
242
|
-
}, []);
|
|
243
|
-
const handleKeyNavigation = useCallback( // eslint-disable-next-line complexity
|
|
244
|
-
e => {
|
|
245
|
-
if (e.key === ARROW_DOWN || e.key === ARROW_UP) {
|
|
246
|
-
const isDownDirection = e.key === ARROW_DOWN;
|
|
247
|
-
setCursorIndex(getMovedCursorIndex(filteredGroups, cursorIndex, isDownDirection));
|
|
248
|
-
setIsKeyboardNavigating(true);
|
|
249
|
-
e.preventDefault();
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (e.key === ENTER || e.key === SPACE) {
|
|
253
|
-
if (cursorIndex !== null) {
|
|
254
|
-
handleSelectIndex(cursorIndex);
|
|
255
|
-
} else {
|
|
256
|
-
handleClose();
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
e.preventDefault();
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (e.key === TAB) {
|
|
263
|
-
handleClose();
|
|
264
|
-
}
|
|
265
|
-
}, [filteredGroups, cursorIndex, handleClose, handleSelectIndex]);
|
|
266
|
-
const handleClick = useCallback(() => {
|
|
267
|
-
if (isDisabled) {
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
setMenuIsOpen(currentMenuIsOpen => !currentMenuIsOpen);
|
|
272
|
-
}, [isDisabled]);
|
|
273
|
-
const handleClearClick = useCallback(() => {
|
|
274
|
-
setCursorIndex(getDefaultCursorIndex(groups));
|
|
275
|
-
setMenuIsOpen(false);
|
|
276
|
-
|
|
277
|
-
if (onChange) {
|
|
278
|
-
onChange([]);
|
|
279
|
-
}
|
|
280
|
-
}, [groups, onChange]); // eslint-disable-next-line complexity
|
|
281
|
-
|
|
282
|
-
const handleTriggerKeyDown = useCallback(e => {
|
|
283
|
-
if (e.key === ESCAPE) {
|
|
284
|
-
handleClose();
|
|
285
|
-
e.preventDefault();
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (isDisabled) {
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
if (menuIsOpen) {
|
|
293
|
-
handleKeyNavigation(e);
|
|
294
|
-
} else {
|
|
295
|
-
const target = e.target;
|
|
296
|
-
const trigger = target.closest('[data-target="trigger"]');
|
|
297
|
-
const isTriggerTarget = trigger === target;
|
|
298
|
-
|
|
299
|
-
if (shouldOpenSelect(e.key, isTriggerTarget)) {
|
|
300
|
-
setMenuIsOpen(true);
|
|
301
|
-
setIsKeyboardNavigating(true);
|
|
302
|
-
skipScrollingRef.current = true;
|
|
303
|
-
trigger.focus();
|
|
304
|
-
e.preventDefault();
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (e.key === BACKSPACE && isClearable) {
|
|
308
|
-
handleClearClick();
|
|
309
|
-
trigger.focus();
|
|
310
|
-
e.preventDefault();
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}, [handleClearClick, handleClose, handleKeyNavigation, isClearable, isDisabled, menuIsOpen]);
|
|
314
|
-
const handleUnselectClick = useCallback(unselectedOption => {
|
|
315
|
-
const unselectedOptionValue = getOptionValue(unselectedOption);
|
|
316
|
-
const newSelected = value.filter(option => getOptionValue(option) !== unselectedOptionValue);
|
|
317
|
-
|
|
318
|
-
if (onChange) {
|
|
319
|
-
onChange(newSelected);
|
|
320
|
-
}
|
|
321
|
-
}, [onChange, value]);
|
|
322
|
-
const handleHighlightIndex = useCallback(index => {
|
|
323
|
-
if (!isIndexMatchCursor(cursorIndex, index)) {
|
|
324
|
-
setCursorIndex(index);
|
|
325
|
-
}
|
|
326
|
-
}, [cursorIndex]); // We use invisible and "untouchable" dummy element to observe `size` changes from css to trigger force rerenders
|
|
327
|
-
|
|
328
|
-
const observableRef = useObservableForceRerender();
|
|
329
|
-
let sizeFromCss = null;
|
|
330
|
-
|
|
331
|
-
if (triggerFormWrapperRef && menuIsOpen) {
|
|
332
|
-
var _context;
|
|
333
|
-
|
|
334
|
-
// In theory this part of the code might cause issues with SSR.
|
|
335
|
-
// But in this specific context, because of checking ref "triggerFormWrapperRef",
|
|
336
|
-
// we are sure that the value will still be "null" on the first render.
|
|
337
|
-
// Therefore, the first render on the client will be the same as on the server.
|
|
338
|
-
// Also, there will be no layout shifts on the following renders because
|
|
339
|
-
// it's a dropdown-content and in most cases it opens only on-demand.
|
|
340
|
-
// In additional, we use "observable" el to watch size changes between rerenders (@media query case).
|
|
341
|
-
const triggerFormWrapperStyles = getComputedStyle(triggerFormWrapperRef);
|
|
342
|
-
const rawSizeFromCss = triggerFormWrapperStyles.getPropertyValue('--_rs-select-size');
|
|
343
|
-
sizeFromCss = _includesInstanceProperty(_context = ['s', 'm', 'l']).call(_context, rawSizeFromCss) ? rawSizeFromCss : null;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const actualSize = sizeFromCss || size;
|
|
347
|
-
const maxHeight = calculateMaxHeight(actualSize);
|
|
348
|
-
const withGroupsLabel = !withoutGroupsLabel(filteredGroups);
|
|
349
|
-
const uniqueId = `multiselect-${useBackwardCompatibleId()}`;
|
|
350
|
-
const errorId = `${id ? id : uniqueId}-error`;
|
|
351
|
-
return /*#__PURE__*/React.createElement(Dropdown, {
|
|
352
|
-
theme: theme,
|
|
353
|
-
onRequestClose: handleClose,
|
|
354
|
-
placement: placement,
|
|
355
|
-
mode: mode,
|
|
356
|
-
ref: dropdownRef,
|
|
357
|
-
cancelCloseAnimation: true,
|
|
358
|
-
minWidth: "trigger",
|
|
359
|
-
maxWidth: "trigger",
|
|
360
|
-
maxHeight: maxHeight,
|
|
361
|
-
leastMaxHeight: maxHeight,
|
|
362
|
-
disableFocusLock: true,
|
|
363
|
-
trigger: _ref5 => {
|
|
364
|
-
let {
|
|
365
|
-
ref
|
|
366
|
-
} = _ref5;
|
|
367
|
-
return /*#__PURE__*/React.createElement(FormTriggerWrapper, {
|
|
368
|
-
ref: setTriggerFormWrapperRef,
|
|
369
|
-
className: cn(className, SIZE_STYLES[size]),
|
|
370
|
-
id: id,
|
|
371
|
-
errorId: errorId,
|
|
372
|
-
theme: theme,
|
|
373
|
-
size: size,
|
|
374
|
-
disabled: isDisabled,
|
|
375
|
-
error: error,
|
|
376
|
-
reserveErrorLine: reserveErrorLine,
|
|
377
|
-
label: restProps.label,
|
|
378
|
-
note: restProps.note,
|
|
379
|
-
onKeyDown: handleTriggerKeyDown,
|
|
380
|
-
boldLabel: boldLabel,
|
|
381
|
-
role: "listbox",
|
|
382
|
-
"aria-errormessage": error ? errorId : undefined,
|
|
383
|
-
"aria-invalid": Boolean(error),
|
|
384
|
-
"aria-multiselectable": true
|
|
385
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
386
|
-
ref: observableRef,
|
|
387
|
-
className: styles.observable
|
|
388
|
-
}), restProps.name && /*#__PURE__*/React.createElement(NativeSelectedOptions, {
|
|
389
|
-
name: restProps.name,
|
|
390
|
-
selected: value
|
|
391
|
-
}), /*#__PURE__*/React.createElement(SelectTrigger, {
|
|
392
|
-
theme: theme,
|
|
393
|
-
mode: mode,
|
|
394
|
-
size: size,
|
|
395
|
-
isOpen: menuIsOpen,
|
|
396
|
-
triggerRef: ref,
|
|
397
|
-
selected: value,
|
|
398
|
-
placeholder: placeholder,
|
|
399
|
-
isClearable: isClearable,
|
|
400
|
-
isLoading: isLoading,
|
|
401
|
-
isDisabled: isDisabled,
|
|
402
|
-
isSingleLine: isSingleLine,
|
|
403
|
-
onClick: handleClick,
|
|
404
|
-
onClearClick: handleClearClick,
|
|
405
|
-
onItemClearClick: handleUnselectClick,
|
|
406
|
-
error: Boolean(error),
|
|
407
|
-
"data-target": "trigger"
|
|
408
|
-
}));
|
|
409
|
-
},
|
|
410
|
-
isOpen: menuIsOpen
|
|
411
|
-
}, /*#__PURE__*/React.createElement(Menu, {
|
|
412
|
-
"data-test": "option-list",
|
|
413
|
-
size: actualSize,
|
|
414
|
-
className: cn(styles.menu, withGroupsLabel && styles.withGroupsLabel, MENU_SIZE_STYLES[actualSize]),
|
|
415
|
-
disableCursor: isKeyboardNavigating,
|
|
416
|
-
iconPlacement: 'right',
|
|
417
|
-
enableKeyboardNavigation: false
|
|
418
|
-
}, !isEmptyMenu ? getPlainOptionsFromGroups(filteredGroups).map((item, i, collection) => /*#__PURE__*/React.createElement(Option, {
|
|
419
|
-
key: getOptionKey(item, i),
|
|
420
|
-
selected: value,
|
|
421
|
-
cursorIndex: cursorIndex,
|
|
422
|
-
item: item,
|
|
423
|
-
isSingleLine: isSingleLine,
|
|
424
|
-
isLastItem: i === collection.length - 1,
|
|
425
|
-
highlightedItemRef: highlightedItemRef,
|
|
426
|
-
handleSelectIndex: handleSelectIndex,
|
|
427
|
-
handleHighlightIndex: handleHighlightIndex
|
|
428
|
-
})) : /*#__PURE__*/React.createElement(MenuItem, {
|
|
429
|
-
disabled: true
|
|
430
|
-
}, getEmptyMessage(isLoading, false, noOptionsMessage))));
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
Multiselect.propTypes = {
|
|
434
|
-
className: PropTypes.string,
|
|
435
|
-
options: PropTypes.arrayOf(PropTypes.oneOfType([optionType, optionsGroupType])),
|
|
436
|
-
value: PropTypes.arrayOf(optionType),
|
|
437
|
-
onChange: PropTypes.func,
|
|
438
|
-
size: PropTypes.oneOf(['m', 's', 'l']),
|
|
439
|
-
mode: PropTypes.oneOf(['classic', 'rock']),
|
|
440
|
-
theme: PropTypes.oneOf(['light', 'dark']),
|
|
441
|
-
placeholder: PropTypes.string,
|
|
442
|
-
isSingleLine: PropTypes.bool,
|
|
443
|
-
isClearable: PropTypes.bool,
|
|
444
|
-
isDisabled: PropTypes.bool,
|
|
445
|
-
isLoading: PropTypes.bool,
|
|
446
|
-
error: ErrorMessage.propTypes.children,
|
|
447
|
-
label: PropTypes.node,
|
|
448
|
-
note: PropTypes.node,
|
|
449
|
-
id: PropTypes.string,
|
|
450
|
-
noOptionsMessage: noOptionsMessageType,
|
|
451
|
-
placement: PropTypes.oneOf(['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start']),
|
|
452
|
-
name: PropTypes.string,
|
|
453
|
-
boldLabel: PropTypes.bool
|
|
454
|
-
};
|
|
455
|
-
export { Multiselect as default };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Theme } from '@rescui/ui-contexts';
|
|
3
|
-
import type { NativeSelectOption, SelectSize, NativeSelectOptionOrGroup, NoOptionsMessage } from '../types';
|
|
4
|
-
export declare type TriggerFunc = (props: {
|
|
5
|
-
selectedLabel: string;
|
|
6
|
-
selectedValue: string;
|
|
7
|
-
placeholder: string;
|
|
8
|
-
hovered: boolean;
|
|
9
|
-
}) => React.ReactNode;
|
|
10
|
-
export declare type NativeSelectProps = {
|
|
11
|
-
options?: NativeSelectOptionOrGroup[];
|
|
12
|
-
size?: SelectSize;
|
|
13
|
-
theme?: Theme;
|
|
14
|
-
className?: string;
|
|
15
|
-
id?: string;
|
|
16
|
-
style?: object;
|
|
17
|
-
value: NativeSelectOption;
|
|
18
|
-
onChange?: (newValue: NativeSelectOption) => void;
|
|
19
|
-
placeholder?: string;
|
|
20
|
-
isLoading?: boolean;
|
|
21
|
-
isDisabled?: boolean;
|
|
22
|
-
trigger?: TriggerFunc;
|
|
23
|
-
label?: React.ReactNode;
|
|
24
|
-
note?: React.ReactNode;
|
|
25
|
-
error?: boolean | React.ReactNode;
|
|
26
|
-
/**
|
|
27
|
-
* If `true`, there will be reserved a space for a 1-line error message. Subsequent lines will be placed below normally.
|
|
28
|
-
* If `false`, there will be no reservation.
|
|
29
|
-
*/
|
|
30
|
-
reserveErrorLine?: boolean;
|
|
31
|
-
noOptionsMessage?: NoOptionsMessage;
|
|
32
|
-
name?: string;
|
|
33
|
-
boldLabel?: boolean;
|
|
34
|
-
};
|
|
35
|
-
declare const NativeSelect: React.FC<NativeSelectProps>;
|
|
36
|
-
export default NativeSelect;
|