@rescui/select 0.11.6 → 0.11.8
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/check.js +8 -9
- package/lib/_virtual/close.js +8 -9
- package/lib/_virtual/down.js +8 -9
- package/lib/_virtual/index.css.js +7 -7
- package/lib/_virtual/loading.js +8 -9
- package/lib/_virtual/warning.js +8 -9
- package/lib/common-prop-types.js +6 -6
- package/lib/index.css +184 -263
- package/lib/key-codes.js +7 -7
- package/lib/parts/common-select.p.module.css.js +12 -12
- package/lib/parts/foldable.js +158 -220
- package/lib/parts/form-trigger-wrapper.js +20 -16
- package/lib/parts/form-trigger.p.module.css.js +10 -10
- package/lib/parts/multiselect.js +130 -201
- package/lib/parts/native-select.js +85 -117
- package/lib/parts/native-select.p.module.css.js +6 -6
- package/lib/parts/throttle.js +9 -12
- package/lib/parts/trigger.js +86 -118
- package/lib/parts/trigger.p.module.css.js +27 -27
- package/lib/parts/use-observable-force-rerender.js +5 -12
- package/lib/select.js +118 -195
- package/lib/utils.js +44 -90
- package/package.json +10 -11
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray";
|
|
2
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
3
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
4
|
-
|
|
5
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
-
|
|
7
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
-
|
|
9
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
10
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
11
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
12
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
13
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
14
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
15
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
16
|
-
import "core-js/modules/es.object.to-string.js";
|
|
17
|
-
import "core-js/modules/es.array.join.js";
|
|
18
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
19
|
-
import "core-js/modules/es.function.name.js";
|
|
20
1
|
import React, { useState } from 'react';
|
|
21
2
|
import PropTypes from 'prop-types';
|
|
22
3
|
import cn from 'classnames';
|
|
@@ -25,52 +6,52 @@ import { nativeOptionType, nativeOptionsGroupType, noOptionsMessageType } from '
|
|
|
25
6
|
import SelectTrigger from './trigger.js';
|
|
26
7
|
import FormTriggerWrapper from './form-trigger-wrapper.js';
|
|
27
8
|
import styles from './native-select.p.module.css.js';
|
|
28
|
-
|
|
9
|
+
const DEFAULT_NO_OPTIONS_MESSAGES = {
|
|
29
10
|
noOptions: 'No options',
|
|
30
11
|
loading: 'Loading...'
|
|
31
12
|
};
|
|
32
|
-
|
|
13
|
+
const PLACEHOLDER_VALUE = '__placeholder__';
|
|
33
14
|
|
|
34
15
|
function isString(s) {
|
|
35
16
|
return Object.prototype.toString.call(s) === '[object String]';
|
|
36
17
|
}
|
|
37
18
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
disabled = _ref2$disabled === void 0 ? false : _ref2$disabled;
|
|
19
|
+
const isOptionsGroup = optionOrGroup => typeof optionOrGroup.options !== 'undefined';
|
|
20
|
+
|
|
21
|
+
const collectOptionGroupValues = options => options.map(_ref => {
|
|
22
|
+
let {
|
|
23
|
+
value
|
|
24
|
+
} = _ref;
|
|
25
|
+
return value;
|
|
26
|
+
}).join('-');
|
|
27
|
+
|
|
28
|
+
const Option = _ref2 => {
|
|
29
|
+
let {
|
|
30
|
+
value,
|
|
31
|
+
label,
|
|
32
|
+
disabled = false
|
|
33
|
+
} = _ref2;
|
|
54
34
|
return /*#__PURE__*/React.createElement("option", {
|
|
55
35
|
value: value,
|
|
56
36
|
disabled: disabled
|
|
57
37
|
}, label);
|
|
58
38
|
};
|
|
59
39
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
disabled = _ref3$disabled === void 0 ? false : _ref3$disabled;
|
|
40
|
+
const OptionGroup = _ref3 => {
|
|
41
|
+
let {
|
|
42
|
+
options = [],
|
|
43
|
+
label = '',
|
|
44
|
+
disabled = false
|
|
45
|
+
} = _ref3;
|
|
67
46
|
return /*#__PURE__*/React.createElement("optgroup", {
|
|
68
47
|
label: label,
|
|
69
48
|
disabled: disabled
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
49
|
+
}, options.map(_ref4 => {
|
|
50
|
+
let {
|
|
51
|
+
value,
|
|
52
|
+
label: optionLabel,
|
|
53
|
+
disabled: optionDisabled
|
|
54
|
+
} = _ref4;
|
|
74
55
|
return /*#__PURE__*/React.createElement(Option, {
|
|
75
56
|
key: value,
|
|
76
57
|
value: value,
|
|
@@ -80,22 +61,22 @@ var OptionGroup = function OptionGroup(_ref3) {
|
|
|
80
61
|
}));
|
|
81
62
|
};
|
|
82
63
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
64
|
+
const OptionsWithGroups = _ref5 => {
|
|
65
|
+
let {
|
|
66
|
+
optionsWithGroups
|
|
67
|
+
} = _ref5;
|
|
68
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, optionsWithGroups.map(optionOrGroup => {
|
|
86
69
|
if (isOptionsGroup(optionOrGroup)) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var group = optionOrGroup;
|
|
70
|
+
const group = optionOrGroup;
|
|
90
71
|
return /*#__PURE__*/React.createElement(OptionGroup, {
|
|
91
|
-
key:
|
|
72
|
+
key: `group--${group.label}--${collectOptionGroupValues(group.options)}`,
|
|
92
73
|
options: group.options,
|
|
93
74
|
disabled: group.disabled,
|
|
94
75
|
label: group.label
|
|
95
76
|
});
|
|
96
77
|
}
|
|
97
78
|
|
|
98
|
-
|
|
79
|
+
const option = optionOrGroup;
|
|
99
80
|
return /*#__PURE__*/React.createElement(Option, {
|
|
100
81
|
key: option.value,
|
|
101
82
|
value: option.value,
|
|
@@ -106,20 +87,20 @@ var OptionsWithGroups = function OptionsWithGroups(_ref5) {
|
|
|
106
87
|
};
|
|
107
88
|
|
|
108
89
|
function findSelectedOption(options, selectedValue) {
|
|
109
|
-
|
|
90
|
+
let result = null;
|
|
110
91
|
|
|
111
|
-
|
|
92
|
+
const checkOption = option => {
|
|
112
93
|
if (result === null || option.value === selectedValue) {
|
|
113
94
|
result = option;
|
|
114
95
|
}
|
|
115
96
|
};
|
|
116
97
|
|
|
117
|
-
options.forEach(
|
|
98
|
+
options.forEach(optionOrGroup => {
|
|
118
99
|
if (isOptionsGroup(optionOrGroup)) {
|
|
119
100
|
var _group$options;
|
|
120
101
|
|
|
121
|
-
|
|
122
|
-
(_group$options = group.options) === null || _group$options === void 0
|
|
102
|
+
const group = optionOrGroup;
|
|
103
|
+
(_group$options = group.options) === null || _group$options === void 0 || _group$options.forEach(checkOption);
|
|
123
104
|
} else {
|
|
124
105
|
checkOption(optionOrGroup);
|
|
125
106
|
}
|
|
@@ -128,11 +109,14 @@ function findSelectedOption(options, selectedValue) {
|
|
|
128
109
|
}
|
|
129
110
|
|
|
130
111
|
function getNoOptionsMessage(noOptionsMessage, isLoading) {
|
|
131
|
-
|
|
112
|
+
const {
|
|
113
|
+
noOptions,
|
|
114
|
+
loading
|
|
115
|
+
} = isString(noOptionsMessage) ? { ...DEFAULT_NO_OPTIONS_MESSAGES,
|
|
132
116
|
noOptions: noOptionsMessage
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
117
|
+
} : { ...DEFAULT_NO_OPTIONS_MESSAGES,
|
|
118
|
+
...noOptionsMessage
|
|
119
|
+
};
|
|
136
120
|
|
|
137
121
|
if (isLoading) {
|
|
138
122
|
return loading;
|
|
@@ -141,70 +125,60 @@ function getNoOptionsMessage(noOptionsMessage, isLoading) {
|
|
|
141
125
|
}
|
|
142
126
|
}
|
|
143
127
|
|
|
144
|
-
|
|
128
|
+
const SIZE_STYLES = {
|
|
145
129
|
s: styles.sizeS,
|
|
146
130
|
m: styles.sizeM,
|
|
147
131
|
l: styles.sizeL
|
|
148
132
|
}; // eslint-disable-next-line complexity
|
|
149
133
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
var theme = useThemeWithUndefined(themeFromProps);
|
|
177
|
-
|
|
178
|
-
var _useState = useState(false),
|
|
179
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
180
|
-
hovered = _useState2[0],
|
|
181
|
-
setHovered = _useState2[1];
|
|
182
|
-
|
|
183
|
-
var handleChange = function handleChange(event) {
|
|
184
|
-
var newValue = event.target.value;
|
|
185
|
-
var selectedOption = findSelectedOption(options, newValue);
|
|
134
|
+
const NativeSelect = _ref6 => {
|
|
135
|
+
let {
|
|
136
|
+
options = [],
|
|
137
|
+
size = 'm',
|
|
138
|
+
theme: themeFromProps,
|
|
139
|
+
className = null,
|
|
140
|
+
style,
|
|
141
|
+
value = undefined,
|
|
142
|
+
onChange,
|
|
143
|
+
placeholder,
|
|
144
|
+
isLoading = false,
|
|
145
|
+
isDisabled = false,
|
|
146
|
+
trigger,
|
|
147
|
+
label,
|
|
148
|
+
note,
|
|
149
|
+
error,
|
|
150
|
+
noOptionsMessage,
|
|
151
|
+
name,
|
|
152
|
+
boldLabel
|
|
153
|
+
} = _ref6;
|
|
154
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
155
|
+
const [hovered, setHovered] = useState(false);
|
|
156
|
+
|
|
157
|
+
const handleChange = event => {
|
|
158
|
+
const newValue = event.target.value;
|
|
159
|
+
const selectedOption = findSelectedOption(options, newValue);
|
|
186
160
|
|
|
187
161
|
if (onChange) {
|
|
188
162
|
onChange(selectedOption);
|
|
189
163
|
}
|
|
190
164
|
};
|
|
191
165
|
|
|
192
|
-
|
|
193
|
-
optionsWithGroups: placeholder !== null ?
|
|
166
|
+
const optionList = /*#__PURE__*/React.createElement(OptionsWithGroups, {
|
|
167
|
+
optionsWithGroups: placeholder !== null ? [{
|
|
194
168
|
value: PLACEHOLDER_VALUE,
|
|
195
169
|
label: options.length > 0 ? placeholder : getNoOptionsMessage(noOptionsMessage, isLoading),
|
|
196
170
|
disabled: true
|
|
197
|
-
}
|
|
171
|
+
}, ...options] : options
|
|
198
172
|
});
|
|
199
173
|
|
|
200
|
-
|
|
174
|
+
let _trigger;
|
|
201
175
|
|
|
202
176
|
if (trigger) {
|
|
203
177
|
_trigger = trigger({
|
|
204
178
|
selectedLabel: value === null || value === void 0 ? void 0 : value.label,
|
|
205
179
|
selectedValue: value === null || value === void 0 ? void 0 : value.value,
|
|
206
|
-
placeholder
|
|
207
|
-
hovered
|
|
180
|
+
placeholder,
|
|
181
|
+
hovered
|
|
208
182
|
});
|
|
209
183
|
} else {
|
|
210
184
|
_trigger = /*#__PURE__*/React.createElement(SelectTrigger, {
|
|
@@ -228,18 +202,12 @@ var NativeSelect = function NativeSelect(_ref7) {
|
|
|
228
202
|
error: error,
|
|
229
203
|
label: label,
|
|
230
204
|
note: note,
|
|
231
|
-
onKeyDown:
|
|
232
|
-
return false;
|
|
233
|
-
},
|
|
205
|
+
onKeyDown: () => false,
|
|
234
206
|
boldLabel: boldLabel
|
|
235
207
|
}, /*#__PURE__*/React.createElement("div", {
|
|
236
208
|
className: styles.wrapper,
|
|
237
|
-
onMouseEnter:
|
|
238
|
-
|
|
239
|
-
},
|
|
240
|
-
onMouseLeave: function onMouseLeave() {
|
|
241
|
-
return setHovered(false);
|
|
242
|
-
},
|
|
209
|
+
onMouseEnter: () => setHovered(true),
|
|
210
|
+
onMouseLeave: () => setHovered(false),
|
|
243
211
|
style: style,
|
|
244
212
|
"data-test": "native-select"
|
|
245
213
|
}, _trigger, /*#__PURE__*/React.createElement("select", {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"sizeS": "
|
|
3
|
-
"sizeM": "
|
|
4
|
-
"sizeL": "
|
|
5
|
-
"main": "
|
|
6
|
-
"wrapper": "
|
|
7
|
-
"select": "
|
|
2
|
+
"sizeS": "_sizeS_c1oqaa_6",
|
|
3
|
+
"sizeM": "_sizeM_c1oqaa_9",
|
|
4
|
+
"sizeL": "_sizeL_c1oqaa_12",
|
|
5
|
+
"main": "_main_c1oqaa_16",
|
|
6
|
+
"wrapper": "_wrapper_c1oqaa_20",
|
|
7
|
+
"select": "_select_c1oqaa_24"
|
|
8
8
|
};
|
|
9
9
|
export { styles as default };
|
package/lib/parts/throttle.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/esm/toConsumableArray";
|
|
2
|
-
import "core-js/modules/es.number.constructor.js";
|
|
3
|
-
|
|
4
1
|
function throttle(func, wait) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
let argsToApply;
|
|
3
|
+
let result;
|
|
4
|
+
let timeout = null;
|
|
5
|
+
let previous = 0;
|
|
9
6
|
|
|
10
|
-
|
|
7
|
+
const later = () => {
|
|
11
8
|
previous = Number(Date.now());
|
|
12
9
|
timeout = null;
|
|
13
|
-
result = func
|
|
10
|
+
result = func(...argsToApply);
|
|
14
11
|
argsToApply = null;
|
|
15
12
|
};
|
|
16
13
|
|
|
17
14
|
return function () {
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
const now = Number(Date.now());
|
|
16
|
+
const remaining = wait - (now - previous);
|
|
20
17
|
|
|
21
18
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
22
19
|
args[_key] = arguments[_key];
|
|
@@ -31,7 +28,7 @@ function throttle(func, wait) {
|
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
previous = now;
|
|
34
|
-
result = func
|
|
31
|
+
result = func(...argsToApply);
|
|
35
32
|
argsToApply = null;
|
|
36
33
|
} else if (!timeout) {
|
|
37
34
|
timeout = setTimeout(later, remaining);
|
package/lib/parts/trigger.js
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
import "core-js/modules/es.object.to-string.js";
|
|
2
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
3
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
4
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
5
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
6
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
7
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
8
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
9
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
10
|
-
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
11
|
-
var _excluded = ["size", "mode", "theme", "className", "triggerRef", "isOpen", "selected", "placeholder", "isClearable", "isLoading", "isDisabled", "isSingleLine", "searchInput", "isSearchable", "onClearClick", "onItemClearClick", "onSearchChange", "error"];
|
|
12
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
13
|
-
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
-
|
|
18
1
|
import React, { useRef, useState } from 'react';
|
|
19
2
|
import PropTypes from 'prop-types';
|
|
20
3
|
import cn from 'classnames';
|
|
@@ -29,97 +12,83 @@ import Foldable from './foldable.js';
|
|
|
29
12
|
import styles from './trigger.p.module.css.js';
|
|
30
13
|
/* eslint-disable no-nested-ternary */
|
|
31
14
|
|
|
32
|
-
|
|
15
|
+
const THEME_STYLES = {
|
|
33
16
|
light: styles.themeLight,
|
|
34
17
|
dark: styles.themeDark
|
|
35
18
|
};
|
|
36
|
-
|
|
19
|
+
const SIZE_STYLES = {
|
|
37
20
|
s: styles.sizeS,
|
|
38
21
|
m: styles.sizeM,
|
|
39
22
|
l: styles.sizeL
|
|
40
23
|
};
|
|
41
|
-
|
|
24
|
+
const MODE_STYLES = {
|
|
42
25
|
classic: styles.classic,
|
|
43
26
|
rock: styles.rock
|
|
44
27
|
}; // eslint-disable-next-line complexity
|
|
45
28
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
setIsSearchFocused = _useState2[1];
|
|
75
|
-
|
|
76
|
-
var _useState3 = useState(false),
|
|
77
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
78
|
-
isFocused = _useState4[0],
|
|
79
|
-
setIsFocused = _useState4[1];
|
|
80
|
-
|
|
81
|
-
var _useState5 = useState(false),
|
|
82
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
|
83
|
-
isSearchKeyFocused = _useState6[0],
|
|
84
|
-
setIsSearchKeyFocused = _useState6[1];
|
|
85
|
-
|
|
86
|
-
var isMulti = selected ? Boolean(selected.length) : false;
|
|
29
|
+
const SelectTrigger = /*#__PURE__*/React.memo(props => {
|
|
30
|
+
const {
|
|
31
|
+
size,
|
|
32
|
+
mode,
|
|
33
|
+
theme: themeFromProps,
|
|
34
|
+
className,
|
|
35
|
+
triggerRef,
|
|
36
|
+
isOpen,
|
|
37
|
+
selected = null,
|
|
38
|
+
placeholder,
|
|
39
|
+
isClearable,
|
|
40
|
+
isLoading,
|
|
41
|
+
isDisabled,
|
|
42
|
+
isSingleLine,
|
|
43
|
+
searchInput,
|
|
44
|
+
isSearchable,
|
|
45
|
+
onClearClick,
|
|
46
|
+
onItemClearClick,
|
|
47
|
+
onSearchChange,
|
|
48
|
+
error,
|
|
49
|
+
...restProps
|
|
50
|
+
} = props;
|
|
51
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
52
|
+
const inputRef = useRef(null);
|
|
53
|
+
const [isSearchFocused, setIsSearchFocused] = useState(false);
|
|
54
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
55
|
+
const [isSearchKeyFocused, setIsSearchKeyFocused] = useState(false);
|
|
56
|
+
const isMulti = selected ? Boolean(selected.length) : false;
|
|
87
57
|
|
|
88
|
-
|
|
89
|
-
|
|
58
|
+
const handleChange = event => {
|
|
59
|
+
const newValue = event.target.value;
|
|
90
60
|
onSearchChange(newValue);
|
|
91
61
|
};
|
|
92
62
|
|
|
93
|
-
|
|
63
|
+
const handleBlur = () => {
|
|
94
64
|
if (isSearchable && inputRef.current) {
|
|
95
65
|
setIsSearchFocused(false);
|
|
96
66
|
setIsSearchKeyFocused(false);
|
|
97
67
|
}
|
|
98
68
|
};
|
|
99
69
|
|
|
100
|
-
|
|
70
|
+
const handleFocus = e => {
|
|
101
71
|
if (isSearchable && inputRef.current) {
|
|
102
72
|
setIsSearchFocused(true);
|
|
103
|
-
|
|
73
|
+
const target = e.target;
|
|
104
74
|
setIsSearchKeyFocused(target.getAttribute('data-focus-method') === 'key');
|
|
105
75
|
}
|
|
106
76
|
};
|
|
107
77
|
|
|
108
|
-
|
|
109
|
-
return /*#__PURE__*/React.createElement("div",
|
|
78
|
+
const isThemeReversed = mode === 'rock' && (isSearchFocused || isFocused || isOpen);
|
|
79
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
110
80
|
tabIndex: isSearchable || isDisabled ? -1 : 0,
|
|
111
81
|
className: cn(styles.main, SIZE_STYLES[size], MODE_STYLES[mode], THEME_STYLES[theme], isMulti && styles.isMulti, isSearchFocused && styles.searchFocused, isSearchKeyFocused && styles.searchKeyFocused, isOpen && styles.open, isDisabled ? styles.disabled : styles.enabled, Boolean(error) && styles.error, isFocused && styles.focused, className),
|
|
112
|
-
onFocus:
|
|
113
|
-
|
|
82
|
+
onFocus: e => {
|
|
83
|
+
const target = e.target;
|
|
114
84
|
setIsFocused(target.getAttribute('data-focus-method') === 'key');
|
|
115
85
|
},
|
|
116
|
-
onBlur:
|
|
117
|
-
return setIsFocused(false);
|
|
118
|
-
},
|
|
86
|
+
onBlur: () => setIsFocused(false),
|
|
119
87
|
ref: triggerRef,
|
|
120
88
|
"data-test": "select",
|
|
121
|
-
"data-rs-internal": 'select-trigger'
|
|
122
|
-
|
|
89
|
+
"data-rs-internal": 'select-trigger',
|
|
90
|
+
...restProps
|
|
91
|
+
}, isMulti ? /*#__PURE__*/React.createElement(MultiselectOptions, {
|
|
123
92
|
selected: selected,
|
|
124
93
|
isDisabled: isDisabled,
|
|
125
94
|
isSingleLine: isSingleLine,
|
|
@@ -151,44 +120,41 @@ var SelectTrigger = /*#__PURE__*/React.memo(function (props) {
|
|
|
151
120
|
});
|
|
152
121
|
SelectTrigger.displayName = 'SelectTrigger';
|
|
153
122
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
123
|
+
const MultiselectOptions = _ref => {
|
|
124
|
+
let {
|
|
125
|
+
isSingleLine,
|
|
126
|
+
selected,
|
|
127
|
+
isThemeReversed,
|
|
128
|
+
isDisabled,
|
|
129
|
+
onItemClearClick,
|
|
130
|
+
theme
|
|
131
|
+
} = _ref;
|
|
132
|
+
const selectedOptions = selected.map(s => {
|
|
133
|
+
const key = s.value ? s.value : s.label;
|
|
164
134
|
return /*#__PURE__*/React.createElement(RemovableTag, {
|
|
165
135
|
key: key,
|
|
166
|
-
"data-test":
|
|
136
|
+
"data-test": `selected-tag-${key}`,
|
|
167
137
|
className: styles.tag,
|
|
168
138
|
disabled: isDisabled,
|
|
169
|
-
onRemoveClick:
|
|
170
|
-
return onItemClearClick(s);
|
|
171
|
-
},
|
|
139
|
+
onRemoveClick: () => onItemClearClick(s),
|
|
172
140
|
"data-rs-internal": 'select-trigger__removable-tag',
|
|
173
141
|
wrap: !isSingleLine,
|
|
174
142
|
theme: isThemeReversed ? reverseTheme(theme) : theme
|
|
175
143
|
}, s.label);
|
|
176
144
|
});
|
|
177
|
-
|
|
178
|
-
var tagTheme = isThemeReversed ? reverseTheme(theme) : theme;
|
|
145
|
+
const tagTheme = isThemeReversed ? reverseTheme(theme) : theme;
|
|
179
146
|
return /*#__PURE__*/React.createElement("div", {
|
|
180
147
|
className: styles.multi,
|
|
181
148
|
"data-test": "multi"
|
|
182
149
|
}, isSingleLine ? /*#__PURE__*/React.createElement(Foldable, {
|
|
183
150
|
className: styles.tagsContainer,
|
|
184
|
-
renderHiddenCounter:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
151
|
+
renderHiddenCounter: (n, ref) => /*#__PURE__*/React.createElement(Tag, {
|
|
152
|
+
className: styles.tag,
|
|
153
|
+
key: "+",
|
|
154
|
+
ref: ref,
|
|
155
|
+
"data-rs-internal": 'select-trigger__tag',
|
|
156
|
+
...presets[`filled-${tagTheme}`]
|
|
157
|
+
}, `+${n}`)
|
|
192
158
|
}, selectedOptions) : /*#__PURE__*/React.createElement("div", {
|
|
193
159
|
className: styles.tagsContainer
|
|
194
160
|
}, selectedOptions));
|
|
@@ -203,18 +169,18 @@ function isSelectedEmpty(selected) {
|
|
|
203
169
|
} // eslint-disable-next-line complexity
|
|
204
170
|
|
|
205
171
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
172
|
+
const SelectedOption = _ref2 => {
|
|
173
|
+
let {
|
|
174
|
+
selected,
|
|
175
|
+
searchInput = '',
|
|
176
|
+
placeholder = '',
|
|
177
|
+
isSearchable,
|
|
178
|
+
isDisabled,
|
|
179
|
+
inputRef,
|
|
180
|
+
handleBlur,
|
|
181
|
+
handleFocus,
|
|
182
|
+
handleChange
|
|
183
|
+
} = _ref2;
|
|
218
184
|
return /*#__PURE__*/React.createElement("div", {
|
|
219
185
|
className: styles.labelWrapper
|
|
220
186
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -237,12 +203,14 @@ var SelectedOption = function SelectedOption(_ref2) {
|
|
|
237
203
|
}));
|
|
238
204
|
};
|
|
239
205
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
206
|
+
const ClearOrLoading = _ref3 => {
|
|
207
|
+
let {
|
|
208
|
+
isClearable,
|
|
209
|
+
isLoading,
|
|
210
|
+
isDisabled,
|
|
211
|
+
onClearClick,
|
|
212
|
+
selected
|
|
213
|
+
} = _ref3;
|
|
246
214
|
|
|
247
215
|
if (isLoading) {
|
|
248
216
|
return /*#__PURE__*/React.createElement(LoadingIcon, {
|
|
@@ -257,7 +225,7 @@ var ClearOrLoading = function ClearOrLoading(_ref3) {
|
|
|
257
225
|
type: "button",
|
|
258
226
|
className: cn(styles.icon, styles.clearIcon),
|
|
259
227
|
"data-test": "clear-icon",
|
|
260
|
-
onClick:
|
|
228
|
+
onClick: e => {
|
|
261
229
|
e.stopPropagation();
|
|
262
230
|
onClearClick();
|
|
263
231
|
}
|