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,38 +5,18 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
5
5
|
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; }
|
|
6
6
|
|
|
7
7
|
import React, { forwardRef, isValidElement, useCallback, useContext, useMemo, useState, useRef, useEffect } from 'react';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
8
|
+
import { ThemeContext } from 'styled-components';
|
|
9
|
+
import { useKeyboard } from '../../utils';
|
|
10
10
|
import { defaultProps } from '../../default-props';
|
|
11
11
|
import { Box } from '../Box';
|
|
12
|
-
import { DropButton } from '../DropButton';
|
|
13
12
|
import { Keyboard } from '../Keyboard';
|
|
14
13
|
import { FormContext } from '../Form/FormContext';
|
|
15
|
-
import { TextInput } from '../TextInput';
|
|
16
14
|
import { SelectContainer } from './SelectContainer';
|
|
17
|
-
import {
|
|
15
|
+
import { HiddenInput, StyledSelectDropButton } from './StyledSelect';
|
|
16
|
+
import { applyKey, getNormalizedValue, changeEvent, getSelectIcon, getDisplayLabelKey, getIconColor } from './utils';
|
|
17
|
+
import { DefaultSelectTextInput } from './DefaultSelectTextInput';
|
|
18
18
|
import { MessageContext } from '../../contexts/MessageContext';
|
|
19
19
|
import { SelectPropTypes } from './propTypes';
|
|
20
|
-
var SelectTextInput = styled(TextInput).withConfig({
|
|
21
|
-
displayName: "Select__SelectTextInput",
|
|
22
|
-
componentId: "sc-17idtfo-0"
|
|
23
|
-
})(["cursor:", ";"], function (props) {
|
|
24
|
-
return props.defaultCursor ? 'default' : 'pointer';
|
|
25
|
-
});
|
|
26
|
-
var HiddenInput = styled.input.withConfig({
|
|
27
|
-
displayName: "Select__HiddenInput",
|
|
28
|
-
componentId: "sc-17idtfo-1"
|
|
29
|
-
})(["display:none;"]);
|
|
30
|
-
var StyledSelectDropButton = styled(DropButton).withConfig({
|
|
31
|
-
displayName: "Select__StyledSelectDropButton",
|
|
32
|
-
componentId: "sc-17idtfo-2"
|
|
33
|
-
})(["", ";", ";", ";"], function (props) {
|
|
34
|
-
return !props.callerPlain && controlBorderStyle;
|
|
35
|
-
}, function (props) {
|
|
36
|
-
return props.theme.select && props.theme.select.control && props.theme.select.control.extend;
|
|
37
|
-
}, function (props) {
|
|
38
|
-
return props.open && props.theme.select.control.open;
|
|
39
|
-
});
|
|
40
20
|
StyledSelectDropButton.defaultProps = {};
|
|
41
21
|
Object.setPrototypeOf(StyledSelectDropButton.defaultProps, defaultProps);
|
|
42
22
|
var defaultDropAlign = {
|
|
@@ -115,7 +95,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
115
95
|
initialValue: defaultValue || ''
|
|
116
96
|
}),
|
|
117
97
|
value = _formContext$useFormI[0],
|
|
118
|
-
setValue = _formContext$useFormI[1]; //
|
|
98
|
+
setValue = _formContext$useFormI[1]; // normalizedValue is the value mapped with any valueKey applied
|
|
119
99
|
// When the options array contains objects, this property indicates how
|
|
120
100
|
// to retrieve the value of each option.
|
|
121
101
|
// If a string is provided, it is used as the key to retrieve a
|
|
@@ -126,11 +106,8 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
126
106
|
// delivered via 'onChange'.
|
|
127
107
|
|
|
128
108
|
|
|
129
|
-
var
|
|
130
|
-
|
|
131
|
-
return valueKey && valueKey.reduce ? v : applyKey(v, valueKey);
|
|
132
|
-
});
|
|
133
|
-
return valueKey && valueKey.reduce ? value : applyKey(value, valueKey);
|
|
109
|
+
var normalizedValue = useMemo(function () {
|
|
110
|
+
return getNormalizedValue(value, valueKey);
|
|
134
111
|
}, [value, valueKey]); // search input value
|
|
135
112
|
|
|
136
113
|
var _useState = useState(),
|
|
@@ -158,18 +135,18 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
158
135
|
} else if (index === selected) {
|
|
159
136
|
result.push(index);
|
|
160
137
|
}
|
|
161
|
-
} else if (Array.isArray(
|
|
162
|
-
if (
|
|
138
|
+
} else if (Array.isArray(normalizedValue)) {
|
|
139
|
+
if (normalizedValue.some(function (v) {
|
|
163
140
|
return v === applyKey(option, valueKey);
|
|
164
141
|
})) {
|
|
165
142
|
result.push(index);
|
|
166
143
|
}
|
|
167
|
-
} else if (
|
|
144
|
+
} else if (normalizedValue === applyKey(option, valueKey)) {
|
|
168
145
|
result.push(index);
|
|
169
146
|
}
|
|
170
147
|
});
|
|
171
148
|
return result;
|
|
172
|
-
}, [allOptions, selected, valueKey,
|
|
149
|
+
}, [allOptions, selected, valueKey, normalizedValue]);
|
|
173
150
|
|
|
174
151
|
var _useState3 = useState(propOpen),
|
|
175
152
|
open = _useState3[0],
|
|
@@ -189,16 +166,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
189
166
|
setSearch();
|
|
190
167
|
}, [onClose]);
|
|
191
168
|
var triggerChangeEvent = useCallback(function (nextValue) {
|
|
192
|
-
|
|
193
|
-
// overrides setter `event.target.value =` and loses original event
|
|
194
|
-
// target fidelity.
|
|
195
|
-
// https://stackoverflow.com/a/46012210
|
|
196
|
-
var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
|
|
197
|
-
nativeInputValueSetter.call(inputRef.current, nextValue);
|
|
198
|
-
var event = new Event('input', {
|
|
199
|
-
bubbles: true
|
|
200
|
-
});
|
|
201
|
-
inputRef.current.dispatchEvent(event);
|
|
169
|
+
return changeEvent(inputRef, nextValue);
|
|
202
170
|
}, []);
|
|
203
171
|
var onSelectChange = useCallback(function (event, _ref2) {
|
|
204
172
|
var option = _ref2.option,
|
|
@@ -208,7 +176,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
208
176
|
// input. if it is an object, then the user has not provided necessary
|
|
209
177
|
// props to reduce object option
|
|
210
178
|
|
|
211
|
-
if (typeof nextValue !== 'object' && nextValue !== event.target.value && inputRef.current) {
|
|
179
|
+
if ((typeof nextValue !== 'object' || multiple) && nextValue !== event.target.value && inputRef.current) {
|
|
212
180
|
// select registers changing option as a click event or keydown.
|
|
213
181
|
// when in a form, we need to programatically trigger a change
|
|
214
182
|
// event in order for the change event to be registered upstream
|
|
@@ -248,22 +216,8 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
248
216
|
|
|
249
217
|
onChange(adjustedEvent);
|
|
250
218
|
}
|
|
251
|
-
}, [closeOnChange, onChange, onRequestClose, setValue, triggerChangeEvent]);
|
|
252
|
-
var SelectIcon;
|
|
253
|
-
|
|
254
|
-
switch (icon) {
|
|
255
|
-
case false:
|
|
256
|
-
break;
|
|
257
|
-
|
|
258
|
-
case true:
|
|
259
|
-
case undefined:
|
|
260
|
-
SelectIcon = open && theme.select.icons.up ? theme.select.icons.up : theme.select.icons.down;
|
|
261
|
-
break;
|
|
262
|
-
|
|
263
|
-
default:
|
|
264
|
-
SelectIcon = icon;
|
|
265
|
-
} // element to show, trumps inputValue
|
|
266
|
-
|
|
219
|
+
}, [closeOnChange, multiple, onChange, onRequestClose, setValue, triggerChangeEvent]);
|
|
220
|
+
var SelectIcon = getSelectIcon(icon, theme, open); // element to show, trumps inputValue
|
|
267
221
|
|
|
268
222
|
var selectValue = useMemo(function () {
|
|
269
223
|
if (valueLabel instanceof Function) {
|
|
@@ -272,14 +226,9 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
272
226
|
|
|
273
227
|
|
|
274
228
|
return undefined;
|
|
275
|
-
}, [value, valueLabel]);
|
|
276
|
-
// we should use the labelKey function to display the
|
|
277
|
-
// selected value
|
|
278
|
-
|
|
229
|
+
}, [value, valueLabel]);
|
|
279
230
|
var displayLabelKey = useMemo(function () {
|
|
280
|
-
|
|
281
|
-
if (!selectValue && optionIndexesInValue.length === 1 && typeof optionLabelKey === 'object') return optionLabelKey;
|
|
282
|
-
return undefined;
|
|
231
|
+
return getDisplayLabelKey(labelKey, allOptions, optionIndexesInValue, selectValue);
|
|
283
232
|
}, [labelKey, allOptions, optionIndexesInValue, selectValue]); // text to show
|
|
284
233
|
// When the options array contains objects, this property indicates how
|
|
285
234
|
// to retrieve the value of each option.
|
|
@@ -302,7 +251,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
302
251
|
|
|
303
252
|
return undefined;
|
|
304
253
|
}, [labelKey, messages, format, optionIndexesInValue, allOptions, selectValue]);
|
|
305
|
-
var iconColor =
|
|
254
|
+
var iconColor = getIconColor(theme);
|
|
306
255
|
return /*#__PURE__*/React.createElement(Keyboard, {
|
|
307
256
|
onDown: onRequestOpen,
|
|
308
257
|
onUp: onRequestOpen
|
|
@@ -358,7 +307,7 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
358
307
|
valueKey: valueKey
|
|
359
308
|
}, children) // StyledDropButton needs to know if the border should be shown
|
|
360
309
|
,
|
|
361
|
-
|
|
310
|
+
plainSelect: plain,
|
|
362
311
|
plain: true // Button should be plain
|
|
363
312
|
,
|
|
364
313
|
dropProps: dropProps,
|
|
@@ -379,29 +328,17 @@ var Select = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
379
328
|
value: inputValue,
|
|
380
329
|
ref: inputRef,
|
|
381
330
|
readOnly: true
|
|
382
|
-
})) : /*#__PURE__*/React.createElement(
|
|
383
|
-
a11yTitle: (ariaLabel || a11yTitle) && "" + (ariaLabel || a11yTitle) + (value && typeof value === 'string' ? ", " + value : '')
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
// We only want to disable the TextInput if the control
|
|
387
|
-
// button should be disabled which occurs when disabled
|
|
388
|
-
// equals true.
|
|
389
|
-
,
|
|
390
|
-
defaultCursor: disabled === true || undefined,
|
|
391
|
-
focusIndicator: false,
|
|
392
|
-
id: id ? id + "__input" : undefined,
|
|
331
|
+
})) : /*#__PURE__*/React.createElement(DefaultSelectTextInput, _extends({
|
|
332
|
+
a11yTitle: (ariaLabel || a11yTitle) && "" + (ariaLabel || a11yTitle) + (value && typeof value === 'string' ? ", " + value : ''),
|
|
333
|
+
disabled: disabled,
|
|
334
|
+
id: id,
|
|
393
335
|
name: name,
|
|
394
|
-
ref: inputRef
|
|
395
|
-
}, rest, {
|
|
396
|
-
tabIndex: "-1",
|
|
397
|
-
type: "text",
|
|
336
|
+
ref: inputRef,
|
|
398
337
|
placeholder: placeholder,
|
|
399
|
-
plain: true,
|
|
400
|
-
readOnly: true,
|
|
401
338
|
value: inputValue,
|
|
402
339
|
size: size,
|
|
403
340
|
theme: theme
|
|
404
|
-
}))), SelectIcon && /*#__PURE__*/React.createElement(Box, {
|
|
341
|
+
}, rest))), SelectIcon && /*#__PURE__*/React.createElement(Box, {
|
|
405
342
|
margin: theme.select.icons.margin,
|
|
406
343
|
flex: false,
|
|
407
344
|
style: {
|
|
@@ -6,7 +6,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
6
6
|
|
|
7
7
|
import React, { forwardRef, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
8
8
|
import styled, { ThemeContext } from 'styled-components';
|
|
9
|
-
import {
|
|
9
|
+
import { setFocusWithoutScroll, getHoverIndicatorStyle, containsFocus } from '../../utils';
|
|
10
10
|
import { defaultProps } from '../../default-props';
|
|
11
11
|
import { Box } from '../Box';
|
|
12
12
|
import { Button } from '../Button';
|
|
@@ -14,28 +14,13 @@ import { InfiniteScroll } from '../InfiniteScroll';
|
|
|
14
14
|
import { Keyboard } from '../Keyboard';
|
|
15
15
|
import { Text } from '../Text';
|
|
16
16
|
import { TextInput } from '../TextInput';
|
|
17
|
-
import { StyledContainer } from './StyledSelect';
|
|
18
|
-
import { applyKey } from './utils';
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
var OptionsBox = styled.div.withConfig({
|
|
22
|
-
displayName: "SelectContainer__OptionsBox",
|
|
23
|
-
componentId: "sc-1wi0ul8-0"
|
|
24
|
-
})(["position:relative;scroll-behavior:smooth;overflow:auto;outline:none;"]);
|
|
25
|
-
var SelectOption = styled(Button).withConfig({
|
|
26
|
-
displayName: "SelectContainer__SelectOption",
|
|
27
|
-
componentId: "sc-1wi0ul8-1"
|
|
28
|
-
})(["", " ", " &:focus{", "}display:block;width:100%;"], function (props) {
|
|
29
|
-
return props.selected && props.textComponent && selectedStyle;
|
|
30
|
-
}, function (props) {
|
|
31
|
-
return props.active && getHoverIndicatorStyle(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
32
|
-
}, function (props) {
|
|
33
|
-
return props.active && getHoverIndicatorStyle(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
34
|
-
}); // ensure ClearButton receives visual indication of keyboard
|
|
17
|
+
import { StyledContainer, OptionsContainer, SelectOption } from './StyledSelect';
|
|
18
|
+
import { applyKey, useDisabled, getOptionLabel, getOptionValue } from './utils';
|
|
19
|
+
import { EmptySearchOption } from './EmptySearchOption'; // ensure ClearButton receives visual indication of keyboard
|
|
35
20
|
|
|
36
21
|
var StyledButton = styled(Button).withConfig({
|
|
37
22
|
displayName: "SelectContainer__StyledButton",
|
|
38
|
-
componentId: "sc-1wi0ul8-
|
|
23
|
+
componentId: "sc-1wi0ul8-0"
|
|
39
24
|
})(["&:focus{", "}"], function (props) {
|
|
40
25
|
return getHoverIndicatorStyle('background', props.theme);
|
|
41
26
|
});
|
|
@@ -92,10 +77,11 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
92
77
|
replace = _ref2$replace === void 0 ? true : _ref2$replace;
|
|
93
78
|
var theme = useContext(ThemeContext) || defaultProps.theme;
|
|
94
79
|
var shouldShowClearButton = useCallback(function (position) {
|
|
95
|
-
var hasValue = Boolean(multiple ? value.length : value);
|
|
80
|
+
var hasValue = Boolean(multiple && value ? value.length : value);
|
|
96
81
|
var showAtPosition = position === 'bottom' ? (clear == null ? void 0 : clear.position) === 'bottom' : (clear == null ? void 0 : clear.position) !== 'bottom';
|
|
97
82
|
return clear && hasValue && showAtPosition;
|
|
98
83
|
}, [clear, multiple, value]);
|
|
84
|
+
var isDisabled = useDisabled(disabled, disabledKey, options, valueKey || labelKey);
|
|
99
85
|
|
|
100
86
|
var _useState = useState(usingKeyboard && !shouldShowClearButton('top') ? 0 : -1),
|
|
101
87
|
activeIndex = _useState[0],
|
|
@@ -140,29 +126,6 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
140
126
|
return clearTimeout(timer);
|
|
141
127
|
};
|
|
142
128
|
}, [onSearch, usingKeyboard, clear]);
|
|
143
|
-
var optionLabel = useCallback(function (index) {
|
|
144
|
-
return applyKey(options[index], labelKey || valueKey);
|
|
145
|
-
}, [labelKey, options, valueKey]);
|
|
146
|
-
var optionValue = useCallback(function (index) {
|
|
147
|
-
return applyKey(options[index], valueKey || labelKey);
|
|
148
|
-
}, [options, valueKey, labelKey]);
|
|
149
|
-
var isDisabled = useCallback(function (index) {
|
|
150
|
-
var option = options[index];
|
|
151
|
-
var result;
|
|
152
|
-
|
|
153
|
-
if (disabledKey) {
|
|
154
|
-
result = applyKey(option, disabledKey);
|
|
155
|
-
} else if (Array.isArray(disabled)) {
|
|
156
|
-
if (typeof disabled[0] === 'number') {
|
|
157
|
-
result = disabled.indexOf(index) !== -1;
|
|
158
|
-
} else {
|
|
159
|
-
var optionVal = optionValue(index);
|
|
160
|
-
result = disabled.indexOf(optionVal) !== -1;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return result;
|
|
165
|
-
}, [disabled, disabledKey, options, optionValue]);
|
|
166
129
|
var isSelected = useCallback(function (index) {
|
|
167
130
|
var result;
|
|
168
131
|
|
|
@@ -170,7 +133,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
170
133
|
// deprecated in favor of value
|
|
171
134
|
result = selected.indexOf(index) !== -1;
|
|
172
135
|
} else {
|
|
173
|
-
var optionVal =
|
|
136
|
+
var optionVal = getOptionValue(index, options, valueKey || labelKey);
|
|
174
137
|
|
|
175
138
|
if (Array.isArray(value)) {
|
|
176
139
|
if (value.length === 0) {
|
|
@@ -192,7 +155,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
192
155
|
}
|
|
193
156
|
|
|
194
157
|
return result;
|
|
195
|
-
}, [
|
|
158
|
+
}, [selected, value, valueKey, options, labelKey]);
|
|
196
159
|
var selectOption = useCallback(function (index) {
|
|
197
160
|
return function (event) {
|
|
198
161
|
if (onChange) {
|
|
@@ -246,7 +209,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
246
209
|
setActiveIndex(nextActiveIndex);
|
|
247
210
|
setKeyboardNavigation(true);
|
|
248
211
|
}
|
|
249
|
-
}, [activeIndex,
|
|
212
|
+
}, [activeIndex, options, isDisabled]);
|
|
250
213
|
var onPreviousOption = useCallback(function (event) {
|
|
251
214
|
event.preventDefault();
|
|
252
215
|
var nextActiveIndex = activeIndex - 1;
|
|
@@ -297,7 +260,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
297
260
|
if (onKeyDown) {
|
|
298
261
|
onKeyDown(event);
|
|
299
262
|
}
|
|
300
|
-
}, [
|
|
263
|
+
}, [isDisabled, labelKey, onKeyDown, options, onSearch]);
|
|
301
264
|
var onActiveOption = useCallback(function (index) {
|
|
302
265
|
return function () {
|
|
303
266
|
if (!keyboardNavigation) setActiveIndex(index);
|
|
@@ -358,7 +321,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
358
321
|
return setActiveIndex(-1);
|
|
359
322
|
},
|
|
360
323
|
theme: theme
|
|
361
|
-
}), /*#__PURE__*/React.createElement(
|
|
324
|
+
}), /*#__PURE__*/React.createElement(OptionsContainer, {
|
|
362
325
|
role: "listbox",
|
|
363
326
|
tabIndex: "-1",
|
|
364
327
|
ref: optionsRef,
|
|
@@ -389,7 +352,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
389
352
|
});
|
|
390
353
|
if (typeof child === 'string' || child.props && child.props.children && typeof child.props.children === 'string') textComponent = true;
|
|
391
354
|
} else if (theme.select.options) {
|
|
392
|
-
child = /*#__PURE__*/React.createElement(Box, selectOptionsStyle, /*#__PURE__*/React.createElement(Text, theme.select.options.text,
|
|
355
|
+
child = /*#__PURE__*/React.createElement(Box, selectOptionsStyle, /*#__PURE__*/React.createElement(Text, theme.select.options.text, getOptionLabel(index, options, labelKey || valueKey)));
|
|
393
356
|
textComponent = true;
|
|
394
357
|
} // if we have a child, turn on plain, and hoverIndicator
|
|
395
358
|
|
|
@@ -413,7 +376,7 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
413
376
|
plain: !child ? undefined : true,
|
|
414
377
|
align: "start",
|
|
415
378
|
kind: !child ? 'option' : undefined,
|
|
416
|
-
label: !child ?
|
|
379
|
+
label: !child ? getOptionLabel(index, options, labelKey || valueKey) : undefined,
|
|
417
380
|
disabled: optionDisabled || undefined,
|
|
418
381
|
active: optionActive,
|
|
419
382
|
selected: optionSelected // allow keyboard navigation to start from
|
|
@@ -426,13 +389,11 @@ var SelectContainer = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
|
426
389
|
onClick: !optionDisabled ? selectOption(index) : undefined,
|
|
427
390
|
textComponent: textComponent
|
|
428
391
|
}, child);
|
|
429
|
-
}) : /*#__PURE__*/React.createElement(
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
disabled: true
|
|
435
|
-
}, /*#__PURE__*/React.createElement(Box, selectOptionsStyle, /*#__PURE__*/React.createElement(Text, theme.select.container.text, emptySearchMessage)))), shouldShowClearButton('bottom') && /*#__PURE__*/React.createElement(ClearButton, {
|
|
392
|
+
}) : /*#__PURE__*/React.createElement(EmptySearchOption, {
|
|
393
|
+
emptySearchMessage: emptySearchMessage,
|
|
394
|
+
selectOptionsStyle: selectOptionsStyle,
|
|
395
|
+
theme: theme
|
|
396
|
+
})), shouldShowClearButton('bottom') && /*#__PURE__*/React.createElement(ClearButton, {
|
|
436
397
|
ref: clearRef,
|
|
437
398
|
clear: clear,
|
|
438
399
|
name: name,
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
|
-
import {
|
|
2
|
+
import { Button } from '../Button';
|
|
3
|
+
import { DropButton } from '../DropButton';
|
|
4
|
+
import { TextInput } from '../TextInput';
|
|
5
|
+
import { getHoverIndicatorStyle, selectedStyle, controlBorderStyle, sizeStyle } from '../../utils';
|
|
3
6
|
export var StyledContainer = styled.div.withConfig({
|
|
4
7
|
displayName: "StyledSelect__StyledContainer",
|
|
5
8
|
componentId: "sc-znp66n-0"
|
|
@@ -7,4 +10,45 @@ export var StyledContainer = styled.div.withConfig({
|
|
|
7
10
|
return props.dropHeight ? sizeStyle('max-height', props.dropHeight, props.theme) : 'max-height: inherit;';
|
|
8
11
|
}, function (props) {
|
|
9
12
|
return props.theme.select.container && props.theme.select.container.extend;
|
|
13
|
+
}); // position relative is so scroll can be managed correctly
|
|
14
|
+
|
|
15
|
+
export var OptionsContainer = styled.div.withConfig({
|
|
16
|
+
displayName: "StyledSelect__OptionsContainer",
|
|
17
|
+
componentId: "sc-znp66n-1"
|
|
18
|
+
})(["position:relative;scroll-behavior:smooth;overflow:auto;outline:none;"]);
|
|
19
|
+
export var HiddenInput = styled.input.withConfig({
|
|
20
|
+
displayName: "StyledSelect__HiddenInput",
|
|
21
|
+
componentId: "sc-znp66n-2"
|
|
22
|
+
})(["display:none;"]);
|
|
23
|
+
export var SelectOption = styled(Button).withConfig({
|
|
24
|
+
displayName: "StyledSelect__SelectOption",
|
|
25
|
+
componentId: "sc-znp66n-3"
|
|
26
|
+
})(["", " ", " &:focus{", "}display:block;width:100%;", ";"], function (props) {
|
|
27
|
+
return props.selected && props.textComponent && selectedStyle;
|
|
28
|
+
}, function (props) {
|
|
29
|
+
return props.active && getHoverIndicatorStyle(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
30
|
+
}, function (props) {
|
|
31
|
+
return props.active && getHoverIndicatorStyle(!props.children && !props.theme.select.options ? undefined : 'background', props.theme);
|
|
32
|
+
}, function (props) {
|
|
33
|
+
return props["aria-disabled"] && "cursor: default";
|
|
34
|
+
});
|
|
35
|
+
export var SelectTextInput = styled(TextInput).withConfig({
|
|
36
|
+
displayName: "StyledSelect__SelectTextInput",
|
|
37
|
+
componentId: "sc-znp66n-4"
|
|
38
|
+
})(["cursor:", ";"], function (props) {
|
|
39
|
+
return props.defaultCursor ? 'default' : 'pointer';
|
|
40
|
+
});
|
|
41
|
+
export var StyledSelectDropButton = styled(DropButton).withConfig({
|
|
42
|
+
displayName: "StyledSelect__StyledSelectDropButton",
|
|
43
|
+
componentId: "sc-znp66n-5"
|
|
44
|
+
})(["", ";", ";", ";"], function (props) {
|
|
45
|
+
return !props.plainSelect && controlBorderStyle;
|
|
46
|
+
}, function (props) {
|
|
47
|
+
var _props$theme$select, _props$theme$select$c;
|
|
48
|
+
|
|
49
|
+
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;
|
|
50
|
+
}, function (props) {
|
|
51
|
+
var _props$theme$select2, _props$theme$select2$;
|
|
52
|
+
|
|
53
|
+
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);
|
|
10
54
|
});
|
|
@@ -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
|
|
@@ -2,57 +2,59 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
2
2
|
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { genericProps } from '../../utils/general-prop-types';
|
|
5
|
+
export var genericSelectProps = _extends({}, genericProps, {
|
|
6
|
+
children: PropTypes.func,
|
|
7
|
+
disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.object]))]),
|
|
8
|
+
disabledKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
9
|
+
dropAlign: PropTypes.shape({
|
|
10
|
+
top: PropTypes.oneOf(['top', 'bottom']),
|
|
11
|
+
bottom: PropTypes.oneOf(['top', 'bottom']),
|
|
12
|
+
right: PropTypes.oneOf(['left', 'right']),
|
|
13
|
+
left: PropTypes.oneOf(['left', 'right'])
|
|
14
|
+
}),
|
|
15
|
+
dropHeight: PropTypes.oneOfType([PropTypes.oneOf(['xsmall', 'small', 'medium', 'large', 'xlarge']), PropTypes.string]),
|
|
16
|
+
dropTarget: PropTypes.object,
|
|
17
|
+
dropProps: PropTypes.object,
|
|
18
|
+
emptySearchMessage: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
19
|
+
focusIndicator: PropTypes.bool,
|
|
20
|
+
icon: PropTypes.oneOfType([PropTypes.bool, PropTypes.func, PropTypes.node, PropTypes.elementType]),
|
|
21
|
+
labelKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
22
|
+
messages: PropTypes.shape({
|
|
23
|
+
multiple: PropTypes.string
|
|
24
|
+
}),
|
|
25
|
+
name: PropTypes.string,
|
|
26
|
+
onChange: PropTypes.func,
|
|
27
|
+
onClose: PropTypes.func,
|
|
28
|
+
onOpen: PropTypes.func,
|
|
29
|
+
onSearch: PropTypes.func,
|
|
30
|
+
onMore: PropTypes.func,
|
|
31
|
+
options: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool, PropTypes.element, PropTypes.object])).isRequired,
|
|
32
|
+
open: PropTypes.bool,
|
|
33
|
+
placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.node]),
|
|
34
|
+
plain: PropTypes.bool,
|
|
35
|
+
replace: PropTypes.bool,
|
|
36
|
+
searchPlaceholder: PropTypes.string,
|
|
37
|
+
size: PropTypes.oneOfType([PropTypes.oneOf(['small', 'medium', 'large', 'xlarge']), PropTypes.string]),
|
|
38
|
+
valueLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
39
|
+
valueKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.shape({
|
|
40
|
+
key: PropTypes.string,
|
|
41
|
+
reduce: PropTypes.bool
|
|
42
|
+
})])
|
|
43
|
+
});
|
|
5
44
|
var PropType = {};
|
|
6
45
|
|
|
7
46
|
if (process.env.NODE_ENV !== 'production') {
|
|
8
|
-
PropType = _extends({},
|
|
9
|
-
children: PropTypes.func,
|
|
47
|
+
PropType = _extends({}, genericSelectProps, {
|
|
10
48
|
clear: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
|
|
11
49
|
position: PropTypes.oneOf(['top', 'bottom']),
|
|
12
50
|
label: PropTypes.string
|
|
13
51
|
})]),
|
|
14
52
|
closeOnChange: PropTypes.bool,
|
|
15
53
|
defaultValue: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number]))]),
|
|
16
|
-
disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string, PropTypes.object]))]),
|
|
17
|
-
disabledKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
18
|
-
dropAlign: PropTypes.shape({
|
|
19
|
-
top: PropTypes.oneOf(['top', 'bottom']),
|
|
20
|
-
bottom: PropTypes.oneOf(['top', 'bottom']),
|
|
21
|
-
right: PropTypes.oneOf(['left', 'right']),
|
|
22
|
-
left: PropTypes.oneOf(['left', 'right'])
|
|
23
|
-
}),
|
|
24
|
-
dropHeight: PropTypes.oneOfType([PropTypes.oneOf(['xsmall', 'small', 'medium', 'large', 'xlarge']), PropTypes.string]),
|
|
25
|
-
dropTarget: PropTypes.object,
|
|
26
|
-
dropProps: PropTypes.object,
|
|
27
|
-
focusIndicator: PropTypes.bool,
|
|
28
|
-
icon: PropTypes.oneOfType([PropTypes.bool, PropTypes.func, PropTypes.node, PropTypes.elementType]),
|
|
29
|
-
labelKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
30
|
-
messages: PropTypes.shape({
|
|
31
|
-
multiple: PropTypes.string
|
|
32
|
-
}),
|
|
33
54
|
multiple: PropTypes.bool,
|
|
34
|
-
name: PropTypes.string,
|
|
35
|
-
onChange: PropTypes.func,
|
|
36
|
-
onClose: PropTypes.func,
|
|
37
|
-
onOpen: PropTypes.func,
|
|
38
|
-
onSearch: PropTypes.func,
|
|
39
|
-
onMore: PropTypes.func,
|
|
40
|
-
options: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool, PropTypes.element, PropTypes.object])).isRequired,
|
|
41
|
-
open: PropTypes.bool,
|
|
42
|
-
placeholder: PropTypes.oneOfType([PropTypes.string, PropTypes.element, PropTypes.node]),
|
|
43
|
-
plain: PropTypes.bool,
|
|
44
|
-
replace: PropTypes.bool,
|
|
45
|
-
searchPlaceholder: PropTypes.string,
|
|
46
55
|
selected: PropTypes.oneOfType([PropTypes.number, PropTypes.arrayOf(PropTypes.number)]),
|
|
47
|
-
size: PropTypes.oneOfType([PropTypes.oneOf(['small', 'medium', 'large', 'xlarge']), PropTypes.string]),
|
|
48
56
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.element, // deprecated, use valueLabel
|
|
49
|
-
PropTypes.object, PropTypes.number, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number]))])
|
|
50
|
-
valueLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
51
|
-
valueKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.shape({
|
|
52
|
-
key: PropTypes.string,
|
|
53
|
-
reduce: PropTypes.bool
|
|
54
|
-
})]),
|
|
55
|
-
emptySearchMessage: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
|
|
57
|
+
PropTypes.object, PropTypes.number, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number]))])
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -1,8 +1,82 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { normalizeColor } from '../../utils';
|
|
1
3
|
export var applyKey = function applyKey(option, key) {
|
|
2
|
-
if (option === undefined) return undefined;
|
|
4
|
+
if (option === undefined || option === null) return undefined;
|
|
3
5
|
if (typeof key === 'object') return applyKey(option, key.key);
|
|
4
6
|
if (typeof key === 'function') return key(option);
|
|
5
7
|
if (key !== undefined) return option[key];
|
|
6
8
|
if (typeof option === 'object' && Object.keys(option)) return option[Object.keys(option)[0]];
|
|
7
9
|
return option;
|
|
10
|
+
};
|
|
11
|
+
export var getOptionLabel = function getOptionLabel(index, options, labelKey) {
|
|
12
|
+
return applyKey(options[index], labelKey);
|
|
13
|
+
};
|
|
14
|
+
export var getOptionValue = function getOptionValue(index, options, valueKey) {
|
|
15
|
+
return applyKey(options[index], valueKey);
|
|
16
|
+
};
|
|
17
|
+
export var useDisabled = function useDisabled(disabled, disabledKey, options, valueKey) {
|
|
18
|
+
return useCallback(function (index) {
|
|
19
|
+
var option = options[index];
|
|
20
|
+
var result;
|
|
21
|
+
|
|
22
|
+
if (disabledKey) {
|
|
23
|
+
result = applyKey(option, disabledKey);
|
|
24
|
+
} else if (Array.isArray(disabled)) {
|
|
25
|
+
if (typeof disabled[0] === 'number') {
|
|
26
|
+
result = disabled.indexOf(index) !== -1;
|
|
27
|
+
} else {
|
|
28
|
+
var optionVal = getOptionValue(index, options, valueKey);
|
|
29
|
+
result = disabled.indexOf(optionVal) !== -1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return result;
|
|
34
|
+
}, [disabled, disabledKey, options, valueKey]);
|
|
35
|
+
};
|
|
36
|
+
export var getNormalizedValue = function getNormalizedValue(value, valueKey) {
|
|
37
|
+
if (Array.isArray(value)) return value.map(function (v) {
|
|
38
|
+
return valueKey && valueKey.reduce ? v : applyKey(v, valueKey);
|
|
39
|
+
});
|
|
40
|
+
return valueKey && valueKey.reduce ? value : applyKey(value, valueKey);
|
|
41
|
+
};
|
|
42
|
+
export var changeEvent = function changeEvent(inputRef, nextValue) {
|
|
43
|
+
// Calling set value function directly on input because React library
|
|
44
|
+
// overrides setter `event.target.value =` and loses original event
|
|
45
|
+
// target fidelity.
|
|
46
|
+
// https://stackoverflow.com/a/46012210
|
|
47
|
+
var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
|
|
48
|
+
nativeInputValueSetter.call(inputRef.current, nextValue);
|
|
49
|
+
var event = new Event('input', {
|
|
50
|
+
bubbles: true
|
|
51
|
+
});
|
|
52
|
+
inputRef.current.dispatchEvent(event);
|
|
53
|
+
};
|
|
54
|
+
export var getSelectIcon = function getSelectIcon(icon, theme, open) {
|
|
55
|
+
var SelectIcon;
|
|
56
|
+
|
|
57
|
+
switch (icon) {
|
|
58
|
+
case false:
|
|
59
|
+
break;
|
|
60
|
+
|
|
61
|
+
case true:
|
|
62
|
+
case undefined:
|
|
63
|
+
SelectIcon = open && theme.select.icons.up ? theme.select.icons.up : theme.select.icons.down;
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
default:
|
|
67
|
+
SelectIcon = icon;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return SelectIcon;
|
|
71
|
+
}; // if labelKey is a function and valueLabel is not defined
|
|
72
|
+
// we should use the labelKey function to display the
|
|
73
|
+
// selected value
|
|
74
|
+
|
|
75
|
+
export var getDisplayLabelKey = function getDisplayLabelKey(labelKey, allOptions, optionIndexesInValue, selectValue) {
|
|
76
|
+
var optionLabelKey = applyKey(allOptions[optionIndexesInValue[0]], labelKey);
|
|
77
|
+
if (!selectValue && optionIndexesInValue.length === 1 && typeof optionLabelKey === 'object') return optionLabelKey;
|
|
78
|
+
return undefined;
|
|
79
|
+
};
|
|
80
|
+
export var getIconColor = function getIconColor(theme) {
|
|
81
|
+
return normalizeColor(theme.select.icons.color || 'control', theme);
|
|
8
82
|
};
|