grommet 2.25.2 → 2.26.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.
- package/components/Anchor/Anchor.js +1 -1
- package/components/Box/stories/BackgroundThemed.js +54 -0
- package/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
- package/components/Button/Button.js +2 -2
- package/components/Calendar/Calendar.js +2 -1
- package/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
- package/components/CheckBoxGroup/index.d.ts +2 -1
- package/components/CheckBoxGroup/propTypes.js +1 -0
- package/components/FormField/FormField.js +1 -1
- package/components/Heading/Heading.js +31 -2
- package/components/Heading/StyledHeading.js +1 -1
- package/components/Heading/index.d.ts +1 -0
- package/components/Heading/propTypes.js +1 -0
- package/components/Heading/stories/All.js +4 -1
- package/components/Layer/LayerContainer.js +16 -9
- package/components/List/List.js +131 -33
- package/components/List/index.d.ts +1 -0
- package/components/List/propTypes.js +1 -0
- package/components/List/stories/Pinned.js +36 -0
- package/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
- package/components/Select/DefaultSelectTextInput.js +43 -0
- package/components/Select/EmptySearchOption.js +34 -0
- package/components/Select/Select.js +30 -95
- package/components/Select/SelectContainer.js +19 -59
- package/components/Select/StyledSelect.js +58 -2
- package/components/Select/index.d.ts +11 -9
- package/components/Select/propTypes.js +44 -40
- package/components/Select/utils.js +103 -3
- package/components/SelectMultiple/README.md +2 -0
- package/components/SelectMultiple/SelectMultiple.js +476 -0
- package/components/SelectMultiple/SelectMultipleContainer.js +481 -0
- package/components/SelectMultiple/SelectMultipleValue.js +166 -0
- package/components/SelectMultiple/SelectionSummary.js +104 -0
- package/components/SelectMultiple/index.d.ts +21 -0
- package/components/SelectMultiple/index.js +8 -0
- package/components/SelectMultiple/propTypes.js +28 -0
- package/components/SelectMultiple/stories/Default.js +76 -0
- package/components/SelectMultiple/stories/Disabled.js +84 -0
- package/components/SelectMultiple/stories/FormField.js +66 -0
- package/components/SelectMultiple/stories/Limited.js +68 -0
- package/components/SelectMultiple/stories/LongList.js +76 -0
- package/components/SelectMultiple/stories/ObjectOptions.js +80 -0
- package/components/SelectMultiple/stories/ShowSelectedInline.js +76 -0
- package/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +8 -0
- package/es6/components/Anchor/Anchor.js +2 -2
- package/es6/components/Box/stories/BackgroundThemed.js +39 -0
- package/es6/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
- package/es6/components/Button/Button.js +3 -3
- package/es6/components/Calendar/Calendar.js +2 -1
- package/es6/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
- package/es6/components/CheckBoxGroup/index.d.ts +2 -1
- package/es6/components/CheckBoxGroup/propTypes.js +1 -0
- package/es6/components/FormField/FormField.js +1 -1
- package/es6/components/Heading/Heading.js +30 -3
- package/es6/components/Heading/StyledHeading.js +1 -1
- package/es6/components/Heading/index.d.ts +1 -0
- package/es6/components/Heading/propTypes.js +1 -0
- package/es6/components/Heading/stories/All.js +4 -1
- package/es6/components/Layer/LayerContainer.js +16 -9
- package/es6/components/List/List.js +131 -34
- package/es6/components/List/index.d.ts +1 -0
- package/es6/components/List/propTypes.js +1 -0
- package/es6/components/List/stories/Pinned.js +21 -0
- package/es6/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
- package/es6/components/Select/DefaultSelectTextInput.js +31 -0
- package/es6/components/Select/EmptySearchOption.js +21 -0
- package/es6/components/Select/Select.js +26 -89
- package/es6/components/Select/SelectContainer.js +19 -58
- package/es6/components/Select/StyledSelect.js +45 -1
- package/es6/components/Select/index.d.ts +11 -9
- package/es6/components/Select/propTypes.js +41 -39
- package/es6/components/Select/utils.js +75 -1
- package/es6/components/SelectMultiple/README.md +2 -0
- package/es6/components/SelectMultiple/SelectMultiple.js +447 -0
- package/es6/components/SelectMultiple/SelectMultipleContainer.js +453 -0
- package/es6/components/SelectMultiple/SelectMultipleValue.js +152 -0
- package/es6/components/SelectMultiple/SelectionSummary.js +91 -0
- package/es6/components/SelectMultiple/index.d.ts +21 -0
- package/es6/components/SelectMultiple/index.js +1 -0
- package/es6/components/SelectMultiple/propTypes.js +18 -0
- package/es6/components/SelectMultiple/stories/Default.js +60 -0
- package/es6/components/SelectMultiple/stories/Disabled.js +68 -0
- package/es6/components/SelectMultiple/stories/FormField.js +50 -0
- package/es6/components/SelectMultiple/stories/Limited.js +53 -0
- package/es6/components/SelectMultiple/stories/LongList.js +63 -0
- package/es6/components/SelectMultiple/stories/ObjectOptions.js +64 -0
- package/es6/components/SelectMultiple/stories/ShowSelectedInline.js +61 -0
- package/es6/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
- package/es6/components/index.d.ts +1 -0
- package/es6/components/index.js +1 -0
- package/es6/index.d.ts +1 -0
- package/es6/themes/base.d.ts +8 -2
- package/es6/themes/base.js +54 -38
- package/es6/themes/grommet.js +15 -0
- package/es6/utils/DOM.js +4 -0
- package/es6/utils/background.js +65 -12
- package/es6/utils/general-prop-types.js +2 -0
- package/es6/utils/index.d.ts +2 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +1 -0
- package/package.json +7 -6
- package/themes/base.d.ts +8 -2
- package/themes/base.js +55 -38
- package/themes/grommet.js +15 -0
- package/utils/DOM.js +9 -2
- package/utils/background.js +64 -12
- package/utils/general-prop-types.js +2 -0
- package/utils/index.d.ts +2 -0
|
@@ -5,7 +5,7 @@ exports.Select = void 0;
|
|
|
5
5
|
|
|
6
6
|
var _react = _interopRequireWildcard(require("react"));
|
|
7
7
|
|
|
8
|
-
var _styledComponents =
|
|
8
|
+
var _styledComponents = require("styled-components");
|
|
9
9
|
|
|
10
10
|
var _utils = require("../../utils");
|
|
11
11
|
|
|
@@ -13,18 +13,18 @@ var _defaultProps = require("../../default-props");
|
|
|
13
13
|
|
|
14
14
|
var _Box = require("../Box");
|
|
15
15
|
|
|
16
|
-
var _DropButton = require("../DropButton");
|
|
17
|
-
|
|
18
16
|
var _Keyboard = require("../Keyboard");
|
|
19
17
|
|
|
20
18
|
var _FormContext = require("../Form/FormContext");
|
|
21
19
|
|
|
22
|
-
var _TextInput = require("../TextInput");
|
|
23
|
-
|
|
24
20
|
var _SelectContainer = require("./SelectContainer");
|
|
25
21
|
|
|
22
|
+
var _StyledSelect = require("./StyledSelect");
|
|
23
|
+
|
|
26
24
|
var _utils2 = require("./utils");
|
|
27
25
|
|
|
26
|
+
var _DefaultSelectTextInput = require("./DefaultSelectTextInput");
|
|
27
|
+
|
|
28
28
|
var _MessageContext = require("../../contexts/MessageContext");
|
|
29
29
|
|
|
30
30
|
var _propTypes = require("./propTypes");
|
|
@@ -39,30 +39,8 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
39
39
|
|
|
40
40
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
componentId: "sc-17idtfo-0"
|
|
45
|
-
})(["cursor:", ";"], function (props) {
|
|
46
|
-
return props.defaultCursor ? 'default' : 'pointer';
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
var HiddenInput = _styledComponents["default"].input.withConfig({
|
|
50
|
-
displayName: "Select__HiddenInput",
|
|
51
|
-
componentId: "sc-17idtfo-1"
|
|
52
|
-
})(["display:none;"]);
|
|
53
|
-
|
|
54
|
-
var StyledSelectDropButton = (0, _styledComponents["default"])(_DropButton.DropButton).withConfig({
|
|
55
|
-
displayName: "Select__StyledSelectDropButton",
|
|
56
|
-
componentId: "sc-17idtfo-2"
|
|
57
|
-
})(["", ";", ";", ";"], function (props) {
|
|
58
|
-
return !props.callerPlain && _utils.controlBorderStyle;
|
|
59
|
-
}, function (props) {
|
|
60
|
-
return props.theme.select && props.theme.select.control && props.theme.select.control.extend;
|
|
61
|
-
}, function (props) {
|
|
62
|
-
return props.open && props.theme.select.control.open;
|
|
63
|
-
});
|
|
64
|
-
StyledSelectDropButton.defaultProps = {};
|
|
65
|
-
Object.setPrototypeOf(StyledSelectDropButton.defaultProps, _defaultProps.defaultProps);
|
|
42
|
+
_StyledSelect.StyledSelectDropButton.defaultProps = {};
|
|
43
|
+
Object.setPrototypeOf(_StyledSelect.StyledSelectDropButton.defaultProps, _defaultProps.defaultProps);
|
|
66
44
|
var defaultDropAlign = {
|
|
67
45
|
top: 'bottom',
|
|
68
46
|
left: 'left'
|
|
@@ -140,7 +118,7 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
140
118
|
initialValue: defaultValue || ''
|
|
141
119
|
}),
|
|
142
120
|
value = _formContext$useFormI[0],
|
|
143
|
-
setValue = _formContext$useFormI[1]; //
|
|
121
|
+
setValue = _formContext$useFormI[1]; // normalizedValue is the value mapped with any valueKey applied
|
|
144
122
|
// When the options array contains objects, this property indicates how
|
|
145
123
|
// to retrieve the value of each option.
|
|
146
124
|
// If a string is provided, it is used as the key to retrieve a
|
|
@@ -151,11 +129,8 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
151
129
|
// delivered via 'onChange'.
|
|
152
130
|
|
|
153
131
|
|
|
154
|
-
var
|
|
155
|
-
|
|
156
|
-
return valueKey && valueKey.reduce ? v : (0, _utils2.applyKey)(v, valueKey);
|
|
157
|
-
});
|
|
158
|
-
return valueKey && valueKey.reduce ? value : (0, _utils2.applyKey)(value, valueKey);
|
|
132
|
+
var normalizedValue = (0, _react.useMemo)(function () {
|
|
133
|
+
return (0, _utils2.getNormalizedValue)(value, valueKey);
|
|
159
134
|
}, [value, valueKey]); // search input value
|
|
160
135
|
|
|
161
136
|
var _useState = (0, _react.useState)(),
|
|
@@ -183,18 +158,18 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
183
158
|
} else if (index === selected) {
|
|
184
159
|
result.push(index);
|
|
185
160
|
}
|
|
186
|
-
} else if (Array.isArray(
|
|
187
|
-
if (
|
|
161
|
+
} else if (Array.isArray(normalizedValue)) {
|
|
162
|
+
if (normalizedValue.some(function (v) {
|
|
188
163
|
return v === (0, _utils2.applyKey)(option, valueKey);
|
|
189
164
|
})) {
|
|
190
165
|
result.push(index);
|
|
191
166
|
}
|
|
192
|
-
} else if (
|
|
167
|
+
} else if (normalizedValue === (0, _utils2.applyKey)(option, valueKey)) {
|
|
193
168
|
result.push(index);
|
|
194
169
|
}
|
|
195
170
|
});
|
|
196
171
|
return result;
|
|
197
|
-
}, [allOptions, selected, valueKey,
|
|
172
|
+
}, [allOptions, selected, valueKey, normalizedValue]);
|
|
198
173
|
|
|
199
174
|
var _useState3 = (0, _react.useState)(propOpen),
|
|
200
175
|
open = _useState3[0],
|
|
@@ -214,16 +189,7 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
214
189
|
setSearch();
|
|
215
190
|
}, [onClose]);
|
|
216
191
|
var triggerChangeEvent = (0, _react.useCallback)(function (nextValue) {
|
|
217
|
-
|
|
218
|
-
// overrides setter `event.target.value =` and loses original event
|
|
219
|
-
// target fidelity.
|
|
220
|
-
// https://stackoverflow.com/a/46012210
|
|
221
|
-
var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
|
|
222
|
-
nativeInputValueSetter.call(inputRef.current, nextValue);
|
|
223
|
-
var event = new Event('input', {
|
|
224
|
-
bubbles: true
|
|
225
|
-
});
|
|
226
|
-
inputRef.current.dispatchEvent(event);
|
|
192
|
+
return (0, _utils2.changeEvent)(inputRef, nextValue);
|
|
227
193
|
}, []);
|
|
228
194
|
var onSelectChange = (0, _react.useCallback)(function (event, _ref2) {
|
|
229
195
|
var option = _ref2.option,
|
|
@@ -233,7 +199,7 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
233
199
|
// input. if it is an object, then the user has not provided necessary
|
|
234
200
|
// props to reduce object option
|
|
235
201
|
|
|
236
|
-
if (typeof nextValue !== 'object' && nextValue !== event.target.value && inputRef.current) {
|
|
202
|
+
if ((typeof nextValue !== 'object' || multiple) && nextValue !== event.target.value && inputRef.current) {
|
|
237
203
|
// select registers changing option as a click event or keydown.
|
|
238
204
|
// when in a form, we need to programatically trigger a change
|
|
239
205
|
// event in order for the change event to be registered upstream
|
|
@@ -273,22 +239,8 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
273
239
|
|
|
274
240
|
onChange(adjustedEvent);
|
|
275
241
|
}
|
|
276
|
-
}, [closeOnChange, onChange, onRequestClose, setValue, triggerChangeEvent]);
|
|
277
|
-
var SelectIcon;
|
|
278
|
-
|
|
279
|
-
switch (icon) {
|
|
280
|
-
case false:
|
|
281
|
-
break;
|
|
282
|
-
|
|
283
|
-
case true:
|
|
284
|
-
case undefined:
|
|
285
|
-
SelectIcon = open && theme.select.icons.up ? theme.select.icons.up : theme.select.icons.down;
|
|
286
|
-
break;
|
|
287
|
-
|
|
288
|
-
default:
|
|
289
|
-
SelectIcon = icon;
|
|
290
|
-
} // element to show, trumps inputValue
|
|
291
|
-
|
|
242
|
+
}, [closeOnChange, multiple, onChange, onRequestClose, setValue, triggerChangeEvent]);
|
|
243
|
+
var SelectIcon = (0, _utils2.getSelectIcon)(icon, theme, open); // element to show, trumps inputValue
|
|
292
244
|
|
|
293
245
|
var selectValue = (0, _react.useMemo)(function () {
|
|
294
246
|
if (valueLabel instanceof Function) {
|
|
@@ -297,14 +249,9 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
297
249
|
|
|
298
250
|
|
|
299
251
|
return undefined;
|
|
300
|
-
}, [value, valueLabel]);
|
|
301
|
-
// we should use the labelKey function to display the
|
|
302
|
-
// selected value
|
|
303
|
-
|
|
252
|
+
}, [value, valueLabel]);
|
|
304
253
|
var displayLabelKey = (0, _react.useMemo)(function () {
|
|
305
|
-
|
|
306
|
-
if (!selectValue && optionIndexesInValue.length === 1 && typeof optionLabelKey === 'object') return optionLabelKey;
|
|
307
|
-
return undefined;
|
|
254
|
+
return (0, _utils2.getDisplayLabelKey)(labelKey, allOptions, optionIndexesInValue, selectValue);
|
|
308
255
|
}, [labelKey, allOptions, optionIndexesInValue, selectValue]); // text to show
|
|
309
256
|
// When the options array contains objects, this property indicates how
|
|
310
257
|
// to retrieve the value of each option.
|
|
@@ -327,11 +274,11 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
327
274
|
|
|
328
275
|
return undefined;
|
|
329
276
|
}, [labelKey, messages, format, optionIndexesInValue, allOptions, selectValue]);
|
|
330
|
-
var iconColor = (0,
|
|
277
|
+
var iconColor = (0, _utils2.getIconColor)(theme);
|
|
331
278
|
return /*#__PURE__*/_react["default"].createElement(_Keyboard.Keyboard, {
|
|
332
279
|
onDown: onRequestOpen,
|
|
333
280
|
onUp: onRequestOpen
|
|
334
|
-
}, /*#__PURE__*/_react["default"].createElement(StyledSelectDropButton, {
|
|
281
|
+
}, /*#__PURE__*/_react["default"].createElement(_StyledSelect.StyledSelectDropButton, {
|
|
335
282
|
ref: ref,
|
|
336
283
|
a11yTitle: "" + (ariaLabel || a11yTitle || placeholder || 'Open Drop') + (value ? format({
|
|
337
284
|
id: 'select.selected',
|
|
@@ -383,7 +330,7 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
383
330
|
valueKey: valueKey
|
|
384
331
|
}, children) // StyledDropButton needs to know if the border should be shown
|
|
385
332
|
,
|
|
386
|
-
|
|
333
|
+
plainSelect: plain,
|
|
387
334
|
plain: true // Button should be plain
|
|
388
335
|
,
|
|
389
336
|
dropProps: dropProps,
|
|
@@ -397,36 +344,24 @@ var Select = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
|
|
|
397
344
|
direction: "row",
|
|
398
345
|
flex: true,
|
|
399
346
|
basis: "auto"
|
|
400
|
-
}, selectValue || displayLabelKey ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, selectValue || displayLabelKey, /*#__PURE__*/_react["default"].createElement(HiddenInput, {
|
|
347
|
+
}, selectValue || displayLabelKey ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, selectValue || displayLabelKey, /*#__PURE__*/_react["default"].createElement(_StyledSelect.HiddenInput, {
|
|
401
348
|
type: "text",
|
|
402
349
|
name: name,
|
|
403
350
|
id: id ? id + "__input" : undefined,
|
|
404
351
|
value: inputValue,
|
|
405
352
|
ref: inputRef,
|
|
406
353
|
readOnly: true
|
|
407
|
-
})) : /*#__PURE__*/_react["default"].createElement(
|
|
408
|
-
a11yTitle: (ariaLabel || a11yTitle) && "" + (ariaLabel || a11yTitle) + (value && typeof value === 'string' ? ", " + value : '')
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
// We only want to disable the TextInput if the control
|
|
412
|
-
// button should be disabled which occurs when disabled
|
|
413
|
-
// equals true.
|
|
414
|
-
,
|
|
415
|
-
defaultCursor: disabled === true || undefined,
|
|
416
|
-
focusIndicator: false,
|
|
417
|
-
id: id ? id + "__input" : undefined,
|
|
354
|
+
})) : /*#__PURE__*/_react["default"].createElement(_DefaultSelectTextInput.DefaultSelectTextInput, _extends({
|
|
355
|
+
a11yTitle: (ariaLabel || a11yTitle) && "" + (ariaLabel || a11yTitle) + (value && typeof value === 'string' ? ", " + value : ''),
|
|
356
|
+
disabled: disabled,
|
|
357
|
+
id: id,
|
|
418
358
|
name: name,
|
|
419
|
-
ref: inputRef
|
|
420
|
-
}, rest, {
|
|
421
|
-
tabIndex: "-1",
|
|
422
|
-
type: "text",
|
|
359
|
+
ref: inputRef,
|
|
423
360
|
placeholder: placeholder,
|
|
424
|
-
plain: true,
|
|
425
|
-
readOnly: true,
|
|
426
361
|
value: inputValue,
|
|
427
362
|
size: size,
|
|
428
363
|
theme: theme
|
|
429
|
-
}))), SelectIcon && /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
364
|
+
}, rest))), SelectIcon && /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
430
365
|
margin: theme.select.icons.margin,
|
|
431
366
|
flex: false,
|
|
432
367
|
style: {
|
|
@@ -27,7 +27,7 @@ var _StyledSelect = require("./StyledSelect");
|
|
|
27
27
|
|
|
28
28
|
var _utils2 = require("./utils");
|
|
29
29
|
|
|
30
|
-
var
|
|
30
|
+
var _EmptySearchOption = require("./EmptySearchOption");
|
|
31
31
|
|
|
32
32
|
var _excluded = ["clear", "onClear", "name", "theme"];
|
|
33
33
|
|
|
@@ -39,26 +39,10 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
39
39
|
|
|
40
40
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
41
41
|
|
|
42
|
-
//
|
|
43
|
-
var OptionsBox = _styledComponents["default"].div.withConfig({
|
|
44
|
-
displayName: "SelectContainer__OptionsBox",
|
|
45
|
-
componentId: "sc-1wi0ul8-0"
|
|
46
|
-
})(["position:relative;scroll-behavior:smooth;overflow:auto;outline:none;"]);
|
|
47
|
-
|
|
48
|
-
var SelectOption = (0, _styledComponents["default"])(_Button.Button).withConfig({
|
|
49
|
-
displayName: "SelectContainer__SelectOption",
|
|
50
|
-
componentId: "sc-1wi0ul8-1"
|
|
51
|
-
})(["", " ", " &:focus{", "}display:block;width:100%;"], function (props) {
|
|
52
|
-
return props.selected && props.textComponent && _utils.selectedStyle;
|
|
53
|
-
}, function (props) {
|
|
54
|
-
return props.active && (0, _utils.getHoverIndicatorStyle)(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
55
|
-
}, function (props) {
|
|
56
|
-
return props.active && (0, _utils.getHoverIndicatorStyle)(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
57
|
-
}); // ensure ClearButton receives visual indication of keyboard
|
|
58
|
-
|
|
42
|
+
// ensure ClearButton receives visual indication of keyboard
|
|
59
43
|
var StyledButton = (0, _styledComponents["default"])(_Button.Button).withConfig({
|
|
60
44
|
displayName: "SelectContainer__StyledButton",
|
|
61
|
-
componentId: "sc-1wi0ul8-
|
|
45
|
+
componentId: "sc-1wi0ul8-0"
|
|
62
46
|
})(["&:focus{", "}"], function (props) {
|
|
63
47
|
return (0, _utils.getHoverIndicatorStyle)('background', props.theme);
|
|
64
48
|
});
|
|
@@ -117,10 +101,11 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
117
101
|
var theme = (0, _react.useContext)(_styledComponents.ThemeContext) || _defaultProps.defaultProps.theme;
|
|
118
102
|
|
|
119
103
|
var shouldShowClearButton = (0, _react.useCallback)(function (position) {
|
|
120
|
-
var hasValue = Boolean(multiple ? value.length : value);
|
|
104
|
+
var hasValue = Boolean(multiple && value ? value.length : value);
|
|
121
105
|
var showAtPosition = position === 'bottom' ? (clear == null ? void 0 : clear.position) === 'bottom' : (clear == null ? void 0 : clear.position) !== 'bottom';
|
|
122
106
|
return clear && hasValue && showAtPosition;
|
|
123
107
|
}, [clear, multiple, value]);
|
|
108
|
+
var isDisabled = (0, _utils2.useDisabled)(disabled, disabledKey, options, valueKey || labelKey);
|
|
124
109
|
|
|
125
110
|
var _useState = (0, _react.useState)(usingKeyboard && !shouldShowClearButton('top') ? 0 : -1),
|
|
126
111
|
activeIndex = _useState[0],
|
|
@@ -165,29 +150,6 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
165
150
|
return clearTimeout(timer);
|
|
166
151
|
};
|
|
167
152
|
}, [onSearch, usingKeyboard, clear]);
|
|
168
|
-
var optionLabel = (0, _react.useCallback)(function (index) {
|
|
169
|
-
return (0, _utils2.applyKey)(options[index], labelKey || valueKey);
|
|
170
|
-
}, [labelKey, options, valueKey]);
|
|
171
|
-
var optionValue = (0, _react.useCallback)(function (index) {
|
|
172
|
-
return (0, _utils2.applyKey)(options[index], valueKey || labelKey);
|
|
173
|
-
}, [options, valueKey, labelKey]);
|
|
174
|
-
var isDisabled = (0, _react.useCallback)(function (index) {
|
|
175
|
-
var option = options[index];
|
|
176
|
-
var result;
|
|
177
|
-
|
|
178
|
-
if (disabledKey) {
|
|
179
|
-
result = (0, _utils2.applyKey)(option, disabledKey);
|
|
180
|
-
} else if (Array.isArray(disabled)) {
|
|
181
|
-
if (typeof disabled[0] === 'number') {
|
|
182
|
-
result = disabled.indexOf(index) !== -1;
|
|
183
|
-
} else {
|
|
184
|
-
var optionVal = optionValue(index);
|
|
185
|
-
result = disabled.indexOf(optionVal) !== -1;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return result;
|
|
190
|
-
}, [disabled, disabledKey, options, optionValue]);
|
|
191
153
|
var isSelected = (0, _react.useCallback)(function (index) {
|
|
192
154
|
var result;
|
|
193
155
|
|
|
@@ -195,7 +157,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
195
157
|
// deprecated in favor of value
|
|
196
158
|
result = selected.indexOf(index) !== -1;
|
|
197
159
|
} else {
|
|
198
|
-
var optionVal =
|
|
160
|
+
var optionVal = (0, _utils2.getOptionValue)(index, options, valueKey || labelKey);
|
|
199
161
|
|
|
200
162
|
if (Array.isArray(value)) {
|
|
201
163
|
if (value.length === 0) {
|
|
@@ -217,7 +179,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
217
179
|
}
|
|
218
180
|
|
|
219
181
|
return result;
|
|
220
|
-
}, [
|
|
182
|
+
}, [selected, value, valueKey, options, labelKey]);
|
|
221
183
|
var selectOption = (0, _react.useCallback)(function (index) {
|
|
222
184
|
return function (event) {
|
|
223
185
|
if (onChange) {
|
|
@@ -271,7 +233,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
271
233
|
setActiveIndex(nextActiveIndex);
|
|
272
234
|
setKeyboardNavigation(true);
|
|
273
235
|
}
|
|
274
|
-
}, [activeIndex,
|
|
236
|
+
}, [activeIndex, options, isDisabled]);
|
|
275
237
|
var onPreviousOption = (0, _react.useCallback)(function (event) {
|
|
276
238
|
event.preventDefault();
|
|
277
239
|
var nextActiveIndex = activeIndex - 1;
|
|
@@ -322,14 +284,14 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
322
284
|
if (onKeyDown) {
|
|
323
285
|
onKeyDown(event);
|
|
324
286
|
}
|
|
325
|
-
}, [
|
|
287
|
+
}, [isDisabled, labelKey, onKeyDown, options, onSearch]);
|
|
326
288
|
var onActiveOption = (0, _react.useCallback)(function (index) {
|
|
327
289
|
return function () {
|
|
328
290
|
if (!keyboardNavigation) setActiveIndex(index);
|
|
329
291
|
};
|
|
330
292
|
}, [keyboardNavigation]);
|
|
331
293
|
var onSelectOption = (0, _react.useCallback)(function (event) {
|
|
332
|
-
if ((shouldShowClearButton('bottom') || shouldShowClearButton('top')) && (0,
|
|
294
|
+
if ((shouldShowClearButton('bottom') || shouldShowClearButton('top')) && (0, _utils.containsFocus)(clearRef.current)) {
|
|
333
295
|
onChange(event, {
|
|
334
296
|
option: undefined,
|
|
335
297
|
value: '',
|
|
@@ -383,7 +345,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
383
345
|
return setActiveIndex(-1);
|
|
384
346
|
},
|
|
385
347
|
theme: theme
|
|
386
|
-
}), /*#__PURE__*/_react["default"].createElement(
|
|
348
|
+
}), /*#__PURE__*/_react["default"].createElement(_StyledSelect.OptionsContainer, {
|
|
387
349
|
role: "listbox",
|
|
388
350
|
tabIndex: "-1",
|
|
389
351
|
ref: optionsRef,
|
|
@@ -414,12 +376,12 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
414
376
|
});
|
|
415
377
|
if (typeof child === 'string' || child.props && child.props.children && typeof child.props.children === 'string') textComponent = true;
|
|
416
378
|
} else if (theme.select.options) {
|
|
417
|
-
child = /*#__PURE__*/_react["default"].createElement(_Box.Box, selectOptionsStyle, /*#__PURE__*/_react["default"].createElement(_Text.Text, theme.select.options.text,
|
|
379
|
+
child = /*#__PURE__*/_react["default"].createElement(_Box.Box, selectOptionsStyle, /*#__PURE__*/_react["default"].createElement(_Text.Text, theme.select.options.text, (0, _utils2.getOptionLabel)(index, options, labelKey || valueKey)));
|
|
418
380
|
textComponent = true;
|
|
419
381
|
} // if we have a child, turn on plain, and hoverIndicator
|
|
420
382
|
|
|
421
383
|
|
|
422
|
-
return /*#__PURE__*/_react["default"].createElement(SelectOption // eslint-disable-next-line react/no-array-index-key
|
|
384
|
+
return /*#__PURE__*/_react["default"].createElement(_StyledSelect.SelectOption // eslint-disable-next-line react/no-array-index-key
|
|
423
385
|
, {
|
|
424
386
|
key: index // merge optionRef and activeRef
|
|
425
387
|
,
|
|
@@ -438,7 +400,7 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
438
400
|
plain: !child ? undefined : true,
|
|
439
401
|
align: "start",
|
|
440
402
|
kind: !child ? 'option' : undefined,
|
|
441
|
-
label: !child ?
|
|
403
|
+
label: !child ? (0, _utils2.getOptionLabel)(index, options, labelKey || valueKey) : undefined,
|
|
442
404
|
disabled: optionDisabled || undefined,
|
|
443
405
|
active: optionActive,
|
|
444
406
|
selected: optionSelected // allow keyboard navigation to start from
|
|
@@ -451,13 +413,11 @@ var SelectContainer = /*#__PURE__*/(0, _react.forwardRef)(function (_ref2, ref)
|
|
|
451
413
|
onClick: !optionDisabled ? selectOption(index) : undefined,
|
|
452
414
|
textComponent: textComponent
|
|
453
415
|
}, child);
|
|
454
|
-
}) : /*#__PURE__*/_react["default"].createElement(
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
disabled: true
|
|
460
|
-
}, /*#__PURE__*/_react["default"].createElement(_Box.Box, selectOptionsStyle, /*#__PURE__*/_react["default"].createElement(_Text.Text, theme.select.container.text, emptySearchMessage)))), shouldShowClearButton('bottom') && /*#__PURE__*/_react["default"].createElement(ClearButton, {
|
|
416
|
+
}) : /*#__PURE__*/_react["default"].createElement(_EmptySearchOption.EmptySearchOption, {
|
|
417
|
+
emptySearchMessage: emptySearchMessage,
|
|
418
|
+
selectOptionsStyle: selectOptionsStyle,
|
|
419
|
+
theme: theme
|
|
420
|
+
})), shouldShowClearButton('bottom') && /*#__PURE__*/_react["default"].createElement(ClearButton, {
|
|
461
421
|
ref: clearRef,
|
|
462
422
|
clear: clear,
|
|
463
423
|
name: name,
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.StyledContainer = void 0;
|
|
4
|
+
exports.StyledSelectDropButton = exports.StyledContainer = exports.SelectTextInput = exports.SelectOption = exports.OptionsContainer = exports.HiddenInput = void 0;
|
|
5
5
|
|
|
6
6
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
7
7
|
|
|
8
|
+
var _Button = require("../Button");
|
|
9
|
+
|
|
10
|
+
var _DropButton = require("../DropButton");
|
|
11
|
+
|
|
12
|
+
var _TextInput = require("../TextInput");
|
|
13
|
+
|
|
8
14
|
var _utils = require("../../utils");
|
|
9
15
|
|
|
10
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -16,6 +22,56 @@ var StyledContainer = _styledComponents["default"].div.withConfig({
|
|
|
16
22
|
return props.dropHeight ? (0, _utils.sizeStyle)('max-height', props.dropHeight, props.theme) : 'max-height: inherit;';
|
|
17
23
|
}, function (props) {
|
|
18
24
|
return props.theme.select.container && props.theme.select.container.extend;
|
|
25
|
+
}); // position relative is so scroll can be managed correctly
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
exports.StyledContainer = StyledContainer;
|
|
29
|
+
|
|
30
|
+
var OptionsContainer = _styledComponents["default"].div.withConfig({
|
|
31
|
+
displayName: "StyledSelect__OptionsContainer",
|
|
32
|
+
componentId: "sc-znp66n-1"
|
|
33
|
+
})(["position:relative;scroll-behavior:smooth;overflow:auto;outline:none;"]);
|
|
34
|
+
|
|
35
|
+
exports.OptionsContainer = OptionsContainer;
|
|
36
|
+
|
|
37
|
+
var HiddenInput = _styledComponents["default"].input.withConfig({
|
|
38
|
+
displayName: "StyledSelect__HiddenInput",
|
|
39
|
+
componentId: "sc-znp66n-2"
|
|
40
|
+
})(["display:none;"]);
|
|
41
|
+
|
|
42
|
+
exports.HiddenInput = HiddenInput;
|
|
43
|
+
var SelectOption = (0, _styledComponents["default"])(_Button.Button).withConfig({
|
|
44
|
+
displayName: "StyledSelect__SelectOption",
|
|
45
|
+
componentId: "sc-znp66n-3"
|
|
46
|
+
})(["", " ", " &:focus{", "}display:block;width:100%;", ";"], function (props) {
|
|
47
|
+
return props.selected && props.textComponent && _utils.selectedStyle;
|
|
48
|
+
}, function (props) {
|
|
49
|
+
return props.active && (0, _utils.getHoverIndicatorStyle)(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
50
|
+
}, function (props) {
|
|
51
|
+
return props.active && (0, _utils.getHoverIndicatorStyle)(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
52
|
+
}, function (props) {
|
|
53
|
+
return props["aria-disabled"] && "cursor: default";
|
|
54
|
+
});
|
|
55
|
+
exports.SelectOption = SelectOption;
|
|
56
|
+
var SelectTextInput = (0, _styledComponents["default"])(_TextInput.TextInput).withConfig({
|
|
57
|
+
displayName: "StyledSelect__SelectTextInput",
|
|
58
|
+
componentId: "sc-znp66n-4"
|
|
59
|
+
})(["cursor:", ";"], function (props) {
|
|
60
|
+
return props.defaultCursor ? 'default' : 'pointer';
|
|
19
61
|
});
|
|
62
|
+
exports.SelectTextInput = SelectTextInput;
|
|
63
|
+
var StyledSelectDropButton = (0, _styledComponents["default"])(_DropButton.DropButton).withConfig({
|
|
64
|
+
displayName: "StyledSelect__StyledSelectDropButton",
|
|
65
|
+
componentId: "sc-znp66n-5"
|
|
66
|
+
})(["", ";", ";", ";"], function (props) {
|
|
67
|
+
return !props.plainSelect && _utils.controlBorderStyle;
|
|
68
|
+
}, function (props) {
|
|
69
|
+
var _props$theme$select, _props$theme$select$c;
|
|
70
|
+
|
|
71
|
+
return (_props$theme$select = props.theme.select) == null ? void 0 : (_props$theme$select$c = _props$theme$select.control) == null ? void 0 : _props$theme$select$c.extend;
|
|
72
|
+
}, function (props) {
|
|
73
|
+
var _props$theme$select2, _props$theme$select2$;
|
|
20
74
|
|
|
21
|
-
|
|
75
|
+
return props.open && ((_props$theme$select2 = props.theme.select) == null ? void 0 : (_props$theme$select2$ = _props$theme$select2.control) == null ? void 0 : _props$theme$select2$.open);
|
|
76
|
+
});
|
|
77
|
+
exports.StyledSelectDropButton = StyledSelectDropButton;
|
|
@@ -8,14 +8,11 @@ import {
|
|
|
8
8
|
PlaceHolderType,
|
|
9
9
|
} from '../../utils';
|
|
10
10
|
|
|
11
|
-
export interface
|
|
11
|
+
export interface BasicSelectProps {
|
|
12
12
|
a11yTitle?: A11yTitleType;
|
|
13
13
|
alignSelf?: AlignSelfType;
|
|
14
14
|
gridArea?: GridAreaType;
|
|
15
15
|
children?: (...args: any[]) => any;
|
|
16
|
-
clear?: boolean | { position?: 'top' | 'bottom'; label?: string };
|
|
17
|
-
closeOnChange?: boolean;
|
|
18
|
-
defaultValue?: string | number | object | (string | number | object)[];
|
|
19
16
|
disabled?: boolean | (number | string | object)[];
|
|
20
17
|
disabledKey?: string | ((...args: any[]) => any);
|
|
21
18
|
dropAlign?: {
|
|
@@ -27,13 +24,13 @@ export interface SelectProps {
|
|
|
27
24
|
dropHeight?: 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | string;
|
|
28
25
|
dropTarget?: object;
|
|
29
26
|
dropProps?: DropProps;
|
|
27
|
+
emptySearchMessage?: string | React.ReactNode;
|
|
30
28
|
focusIndicator?: boolean;
|
|
31
29
|
icon?: boolean | ((...args: any[]) => any) | React.ReactNode | React.FC;
|
|
32
30
|
id?: string;
|
|
33
31
|
labelKey?: string | ((...args: any[]) => string | React.ReactNode);
|
|
34
32
|
margin?: MarginType;
|
|
35
33
|
messages?: { multiple?: string };
|
|
36
|
-
multiple?: boolean;
|
|
37
34
|
name?: string;
|
|
38
35
|
onChange?: (...args: any[]) => void;
|
|
39
36
|
onClose?: (...args: any[]) => any;
|
|
@@ -46,15 +43,20 @@ export interface SelectProps {
|
|
|
46
43
|
plain?: boolean;
|
|
47
44
|
replace?: boolean;
|
|
48
45
|
searchPlaceholder?: string;
|
|
49
|
-
selected?: number | number[];
|
|
50
46
|
size?: 'small' | 'medium' | 'large' | 'xlarge' | string;
|
|
51
|
-
value?: string | JSX.Element | object | (string | number | object)[];
|
|
52
|
-
valueLabel?: React.ReactNode | ((...args: any[]) => string | React.ReactNode);
|
|
53
47
|
valueKey?:
|
|
54
48
|
| string
|
|
55
49
|
| { key: string; reduce?: boolean }
|
|
56
50
|
| ((...args: any[]) => string);
|
|
57
|
-
|
|
51
|
+
valueLabel?: React.ReactNode | ((...args: any[]) => string | React.ReactNode);
|
|
52
|
+
}
|
|
53
|
+
export interface SelectProps extends BasicSelectProps {
|
|
54
|
+
clear?: boolean | { position?: 'top' | 'bottom'; label?: string };
|
|
55
|
+
closeOnChange?: boolean;
|
|
56
|
+
defaultValue?: string | number | object | (string | number | object)[];
|
|
57
|
+
multiple?: boolean;
|
|
58
|
+
selected?: number | number[];
|
|
59
|
+
value?: string | JSX.Element | object | (string | number | object)[];
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
// Try without Omit<> to see where we define our own attributes for overrides
|