grommet 2.25.3 → 2.27.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/all/stories/AllComponents.js +19 -126
- package/components/Accordion/stories/CustomHeader.js +3 -1
- package/components/Avatar/Avatar.js +22 -9
- package/components/Box/stories/BackgroundThemed.js +54 -0
- package/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
- package/components/Calendar/Calendar.js +2 -1
- package/components/CheckBox/StyledCheckBox.js +9 -5
- package/components/CheckBoxGroup/CheckBoxGroup.js +3 -2
- package/components/CheckBoxGroup/index.d.ts +2 -1
- package/components/CheckBoxGroup/propTypes.js +1 -0
- package/components/DataChart/Detail.js +3 -1
- package/components/DataTable/index.d.ts +6 -6
- package/components/DateInput/DateInput.js +1 -1
- package/components/Diagram/Diagram.js +2 -1
- package/components/Drop/stories/Inline.js +1 -1
- package/components/Drop/stories/Overflow.js +1 -1
- package/components/Drop/stories/Plain.js +1 -1
- package/components/Drop/stories/Simple.js +1 -1
- package/components/Drop/stories/Styled.js +1 -1
- 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/List/List.js +125 -41
- package/components/List/index.d.ts +1 -0
- package/components/List/propTypes.js +1 -0
- package/components/List/stories/Order.js +1 -0
- package/components/List/stories/Pinned.js +37 -0
- package/components/List/stories/Selection.js +1 -0
- package/components/List/stories/onClickItem.js +1 -0
- package/components/Notification/Notification.js +2 -2
- package/components/Notification/index.d.ts +1 -1
- package/components/Notification/propTypes.js +1 -1
- package/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
- package/components/RadioButton/README.md +1 -279
- package/components/RadioButton/RadioButton.js +1 -0
- package/components/Select/DefaultSelectTextInput.js +43 -0
- package/components/Select/EmptySearchOption.js +34 -0
- package/components/Select/Select.js +38 -99
- package/components/Select/SelectContainer.js +20 -60
- 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 +129 -3
- package/components/SelectMultiple/README.md +2 -0
- package/components/SelectMultiple/SelectMultiple.js +476 -0
- package/components/SelectMultiple/SelectMultipleContainer.js +483 -0
- package/components/SelectMultiple/SelectMultipleValue.js +163 -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 +104 -0
- package/components/SelectMultiple/stories/ShowSelectedInline.js +76 -0
- package/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
- package/components/Sidebar/stories/Labels.js +4 -1
- package/components/TextArea/stories/NonResizable.js +1 -0
- package/components/TextArea/stories/Simple.js +1 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +8 -0
- package/es6/all/stories/AllComponents.js +21 -121
- package/es6/components/Accordion/stories/CustomHeader.js +3 -1
- package/es6/components/Avatar/Avatar.js +21 -9
- package/es6/components/Box/stories/BackgroundThemed.js +39 -0
- package/es6/components/Box/stories/CustomThemed/ThemedBackground.tsx +176 -0
- package/es6/components/Calendar/Calendar.js +2 -1
- package/es6/components/CheckBox/StyledCheckBox.js +9 -5
- 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/DataChart/Detail.js +3 -1
- package/es6/components/DataTable/index.d.ts +6 -6
- package/es6/components/DateInput/DateInput.js +1 -1
- package/es6/components/Diagram/Diagram.js +2 -1
- package/es6/components/Drop/stories/Inline.js +1 -1
- package/es6/components/Drop/stories/Overflow.js +1 -1
- package/es6/components/Drop/stories/Plain.js +1 -1
- package/es6/components/Drop/stories/Simple.js +1 -1
- package/es6/components/Drop/stories/Styled.js +1 -1
- 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/List/List.js +126 -42
- package/es6/components/List/index.d.ts +1 -0
- package/es6/components/List/propTypes.js +1 -0
- package/es6/components/List/stories/Order.js +1 -0
- package/es6/components/List/stories/Pinned.js +22 -0
- package/es6/components/List/stories/Selection.js +1 -0
- package/es6/components/List/stories/onClickItem.js +1 -0
- package/es6/components/Notification/Notification.js +2 -2
- package/es6/components/Notification/index.d.ts +1 -1
- package/es6/components/Notification/propTypes.js +1 -1
- package/es6/components/Notification/stories/CustomThemed/ThemedNotification.tsx +2 -2
- package/es6/components/RadioButton/README.md +1 -279
- package/es6/components/RadioButton/RadioButton.js +1 -0
- package/es6/components/Select/DefaultSelectTextInput.js +31 -0
- package/es6/components/Select/EmptySearchOption.js +21 -0
- package/es6/components/Select/Select.js +34 -93
- package/es6/components/Select/SelectContainer.js +20 -59
- 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 +95 -1
- package/es6/components/SelectMultiple/README.md +2 -0
- package/es6/components/SelectMultiple/SelectMultiple.js +447 -0
- package/es6/components/SelectMultiple/SelectMultipleContainer.js +455 -0
- package/es6/components/SelectMultiple/SelectMultipleValue.js +149 -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 +88 -0
- package/es6/components/SelectMultiple/stories/ShowSelectedInline.js +61 -0
- package/es6/components/SelectMultiple/stories/typescript/Children.tsx +106 -0
- package/es6/components/Sidebar/stories/Labels.js +4 -1
- package/es6/components/TextArea/stories/NonResizable.js +1 -0
- package/es6/components/TextArea/stories/Simple.js +1 -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 +16 -5
- package/es6/themes/base.js +60 -39
- package/es6/themes/grommet.js +15 -0
- package/es6/themes/hacktoberfest2022.js +129 -0
- package/es6/themes/index.js +2 -1
- 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/es6/utils/styles.js +3 -1
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +1 -0
- package/package.json +44 -41
- package/themes/base.d.ts +16 -5
- package/themes/base.js +61 -39
- package/themes/grommet.js +15 -0
- package/themes/hacktoberfest2022.js +137 -0
- package/themes/index.js +6 -2
- package/tools/grommet-babel-preset-es2015.js +1 -12
- package/tools/pack.js +1 -94
- package/tools/release-stable.js +1 -27
- package/utils/background.js +64 -12
- package/utils/general-prop-types.js +2 -0
- package/utils/index.d.ts +2 -0
- package/utils/styles.js +3 -1
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
var _excluded = ["a11yTitle", "aria-label", "alignSelf", "children", "defaultValue", "disabled", "disabledKey", "dropAlign", "dropHeight", "dropProps", "dropTarget", "emptySearchMessage", "focusIndicator", "gridArea", "help", "id", "icon", "labelKey", "limit", "margin", "messages", "name", "onBlur", "onChange", "onClick", "onClose", "onFocus", "onKeyDown", "onMore", "onOpen", "onSearch", "open", "options", "placeholder", "plain", "replace", "searchPlaceholder", "size", "sortSelectedOnClose", "value", "valueKey", "valueLabel", "showSelectedInline", "width"];
|
|
2
|
+
|
|
3
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
import React, { forwardRef, isValidElement, useCallback, useContext, useMemo, useState, useRef, useEffect } from 'react';
|
|
8
|
+
import styled, { ThemeContext } from 'styled-components';
|
|
9
|
+
import { controlBorderStyle, useKeyboard, useForwardedRef } from '../../utils';
|
|
10
|
+
import { defaultProps } from '../../default-props';
|
|
11
|
+
import { Box } from '../Box';
|
|
12
|
+
import { DropButton } from '../DropButton';
|
|
13
|
+
import { Keyboard } from '../Keyboard';
|
|
14
|
+
import { FormContext } from '../Form/FormContext';
|
|
15
|
+
import { SelectMultipleValue } from './SelectMultipleValue';
|
|
16
|
+
import { SelectMultipleContainer } from './SelectMultipleContainer';
|
|
17
|
+
import { HiddenInput, SelectTextInput, StyledSelectDropButton } from '../Select/StyledSelect';
|
|
18
|
+
import { applyKey, getNormalizedValue, changeEvent, getSelectIcon, getIconColor, getDisplayLabelKey, arrayIncludes } from '../Select/utils';
|
|
19
|
+
import { DefaultSelectTextInput } from '../Select/DefaultSelectTextInput';
|
|
20
|
+
import { MessageContext } from '../../contexts/MessageContext';
|
|
21
|
+
import { SelectMultiplePropTypes } from './propTypes';
|
|
22
|
+
var StyledSelectBox = styled(Box).withConfig({
|
|
23
|
+
displayName: "SelectMultiple__StyledSelectBox",
|
|
24
|
+
componentId: "sc-18zwyth-0"
|
|
25
|
+
})(["", ";", ";", ";"], function (props) {
|
|
26
|
+
return !props.plainSelect && controlBorderStyle;
|
|
27
|
+
}, function (props) {
|
|
28
|
+
var _props$theme$select, _props$theme$select$c;
|
|
29
|
+
|
|
30
|
+
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;
|
|
31
|
+
}, function (props) {
|
|
32
|
+
var _props$theme$select$c2;
|
|
33
|
+
|
|
34
|
+
return props.open && ((_props$theme$select$c2 = props.theme.select.control) == null ? void 0 : _props$theme$select$c2.open);
|
|
35
|
+
});
|
|
36
|
+
StyledSelectDropButton.defaultProps = {};
|
|
37
|
+
Object.setPrototypeOf(StyledSelectDropButton.defaultProps, defaultProps);
|
|
38
|
+
var SelectMultiple = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
39
|
+
var a11yTitle = _ref.a11yTitle,
|
|
40
|
+
ariaLabel = _ref['aria-label'],
|
|
41
|
+
alignSelf = _ref.alignSelf,
|
|
42
|
+
children = _ref.children,
|
|
43
|
+
defaultValue = _ref.defaultValue,
|
|
44
|
+
disabled = _ref.disabled,
|
|
45
|
+
disabledKey = _ref.disabledKey,
|
|
46
|
+
dropAlign = _ref.dropAlign,
|
|
47
|
+
dropHeight = _ref.dropHeight,
|
|
48
|
+
dropProps = _ref.dropProps,
|
|
49
|
+
dropTarget = _ref.dropTarget,
|
|
50
|
+
emptySearchMessage = _ref.emptySearchMessage,
|
|
51
|
+
focusIndicator = _ref.focusIndicator,
|
|
52
|
+
gridArea = _ref.gridArea,
|
|
53
|
+
help = _ref.help,
|
|
54
|
+
id = _ref.id,
|
|
55
|
+
icon = _ref.icon,
|
|
56
|
+
labelKey = _ref.labelKey,
|
|
57
|
+
limit = _ref.limit,
|
|
58
|
+
margin = _ref.margin,
|
|
59
|
+
messages = _ref.messages,
|
|
60
|
+
name = _ref.name,
|
|
61
|
+
onBlur = _ref.onBlur,
|
|
62
|
+
onChange = _ref.onChange,
|
|
63
|
+
onClick = _ref.onClick,
|
|
64
|
+
onClose = _ref.onClose,
|
|
65
|
+
onFocus = _ref.onFocus,
|
|
66
|
+
onKeyDown = _ref.onKeyDown,
|
|
67
|
+
onMore = _ref.onMore,
|
|
68
|
+
onOpen = _ref.onOpen,
|
|
69
|
+
onSearch = _ref.onSearch,
|
|
70
|
+
openProp = _ref.open,
|
|
71
|
+
optionsProp = _ref.options,
|
|
72
|
+
placeholder = _ref.placeholder,
|
|
73
|
+
plain = _ref.plain,
|
|
74
|
+
replace = _ref.replace,
|
|
75
|
+
searchPlaceholder = _ref.searchPlaceholder,
|
|
76
|
+
size = _ref.size,
|
|
77
|
+
_ref$sortSelectedOnCl = _ref.sortSelectedOnClose,
|
|
78
|
+
sortSelectedOnClose = _ref$sortSelectedOnCl === void 0 ? true : _ref$sortSelectedOnCl,
|
|
79
|
+
valueProp = _ref.value,
|
|
80
|
+
valueKey = _ref.valueKey,
|
|
81
|
+
valueLabel = _ref.valueLabel,
|
|
82
|
+
_ref$showSelectedInli = _ref.showSelectedInline,
|
|
83
|
+
showSelectedInline = _ref$showSelectedInli === void 0 ? false : _ref$showSelectedInli,
|
|
84
|
+
width = _ref.width,
|
|
85
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
86
|
+
|
|
87
|
+
var theme = useContext(ThemeContext) || defaultProps.theme;
|
|
88
|
+
var inputRef = useRef();
|
|
89
|
+
var formContext = useContext(FormContext);
|
|
90
|
+
|
|
91
|
+
var _useContext = useContext(MessageContext),
|
|
92
|
+
format = _useContext.format;
|
|
93
|
+
|
|
94
|
+
var selectBoxRef = useRef();
|
|
95
|
+
var dropButtonRef = useForwardedRef(ref);
|
|
96
|
+
var usingKeyboard = useKeyboard(); // value is used for what we receive in valueProp and the basis for
|
|
97
|
+
// what we send with onChange
|
|
98
|
+
// When 'valueKey' sets 'reduce', the value(s) here should match
|
|
99
|
+
// what the 'valueKey' would return for the corresponding
|
|
100
|
+
// selected option object.
|
|
101
|
+
// Otherwise, the value(s) should match the selected options.
|
|
102
|
+
|
|
103
|
+
var _formContext$useFormI = formContext.useFormInput({
|
|
104
|
+
name: name,
|
|
105
|
+
value: valueProp,
|
|
106
|
+
initialValue: defaultValue || ''
|
|
107
|
+
}),
|
|
108
|
+
value = _formContext$useFormI[0],
|
|
109
|
+
setValue = _formContext$useFormI[1]; // normalizedValue is the value mapped with any valueKey applied
|
|
110
|
+
// When the options array contains objects, this property indicates how
|
|
111
|
+
// to retrieve the value of each option.
|
|
112
|
+
// If a string is provided, it is used as the key to retrieve a
|
|
113
|
+
// property of an option object.
|
|
114
|
+
// If a function is provided, it is called with the option and should
|
|
115
|
+
// return the value.
|
|
116
|
+
// If reduce is true, this value will be used for the 'value'
|
|
117
|
+
// delivered via 'onChange'.
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
var normalizedValue = useMemo(function () {
|
|
121
|
+
return getNormalizedValue(value, valueKey);
|
|
122
|
+
}, [value, valueKey]); // search input value
|
|
123
|
+
|
|
124
|
+
var _useState = useState(),
|
|
125
|
+
search = _useState[0],
|
|
126
|
+
setSearch = _useState[1]; // All select option indices and values
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
var _useState2 = useState(optionsProp),
|
|
130
|
+
allOptions = _useState2[0],
|
|
131
|
+
setAllOptions = _useState2[1];
|
|
132
|
+
|
|
133
|
+
var _useState3 = useState(),
|
|
134
|
+
orderedOptions = _useState3[0],
|
|
135
|
+
setOrderedOptions = _useState3[1]; // Track changes to options property, except when options are being
|
|
136
|
+
// updated due to search activity. Allows option's initial index value
|
|
137
|
+
// to be referenced when filtered by search.
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
useEffect(function () {
|
|
141
|
+
if (!search) setAllOptions(optionsProp);
|
|
142
|
+
}, [optionsProp, search]);
|
|
143
|
+
useEffect(function () {
|
|
144
|
+
if (!search && sortSelectedOnClose) setOrderedOptions(optionsProp);
|
|
145
|
+
}, [optionsProp, search, sortSelectedOnClose]); // the option indexes present in the value
|
|
146
|
+
|
|
147
|
+
var optionIndexesInValue = useMemo(function () {
|
|
148
|
+
var result = [];
|
|
149
|
+
allOptions.forEach(function (option, index) {
|
|
150
|
+
if (normalizedValue != null && normalizedValue.some != null && normalizedValue.some(function (v) {
|
|
151
|
+
return v === applyKey(option, valueKey);
|
|
152
|
+
})) {
|
|
153
|
+
result.push(index);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return result;
|
|
157
|
+
}, [allOptions, valueKey, normalizedValue]);
|
|
158
|
+
|
|
159
|
+
var _useState4 = useState(openProp),
|
|
160
|
+
open = _useState4[0],
|
|
161
|
+
setOpen = _useState4[1];
|
|
162
|
+
|
|
163
|
+
useEffect(function () {
|
|
164
|
+
return setOpen(openProp);
|
|
165
|
+
}, [openProp]);
|
|
166
|
+
var onRequestOpen = useCallback(function () {
|
|
167
|
+
if (open) return;
|
|
168
|
+
setOpen(true);
|
|
169
|
+
if (onOpen) onOpen();
|
|
170
|
+
}, [onOpen, open]);
|
|
171
|
+
useEffect(function () {
|
|
172
|
+
if (sortSelectedOnClose && (open && search || !open)) {
|
|
173
|
+
var selectedOptions = optionsProp.filter(function (option) {
|
|
174
|
+
return arrayIncludes(value, valueKey && valueKey.reduce ? applyKey(option, valueKey) : option, valueKey || labelKey);
|
|
175
|
+
});
|
|
176
|
+
var unselectedOptions = optionsProp.filter(function (i) {
|
|
177
|
+
return !arrayIncludes(selectedOptions, i, valueKey || labelKey);
|
|
178
|
+
});
|
|
179
|
+
var nextOrderedOptions = selectedOptions.concat(unselectedOptions);
|
|
180
|
+
setOrderedOptions(nextOrderedOptions);
|
|
181
|
+
}
|
|
182
|
+
}, [labelKey, open, sortSelectedOnClose, optionsProp, value, valueKey, search]);
|
|
183
|
+
var onRequestClose = useCallback(function () {
|
|
184
|
+
setOpen(false);
|
|
185
|
+
if (onClose) onClose();
|
|
186
|
+
setSearch();
|
|
187
|
+
}, [onClose]);
|
|
188
|
+
var triggerChangeEvent = useCallback(function (nextValue) {
|
|
189
|
+
return changeEvent(inputRef, nextValue);
|
|
190
|
+
}, []);
|
|
191
|
+
var onSelectChange = useCallback(function (event, _ref2) {
|
|
192
|
+
var option = _ref2.option,
|
|
193
|
+
nextValue = _ref2.value;
|
|
194
|
+
|
|
195
|
+
// nextValue must not be of type object to set value directly on the
|
|
196
|
+
// input. if it is an object, then the user has not provided necessary
|
|
197
|
+
// props to reduce object option
|
|
198
|
+
if (typeof nextValue !== 'object' && nextValue !== event.target.value && inputRef.current) {
|
|
199
|
+
// select registers changing option as a click event or keydown.
|
|
200
|
+
// when in a form, we need to programatically trigger a change
|
|
201
|
+
// event in order for the change event to be registered upstream
|
|
202
|
+
// necessary for change validation in form
|
|
203
|
+
triggerChangeEvent(nextValue);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
setValue(nextValue);
|
|
207
|
+
|
|
208
|
+
if (onChange) {
|
|
209
|
+
event.persist();
|
|
210
|
+
var adjustedEvent; // support for native event used by Preact
|
|
211
|
+
|
|
212
|
+
if (event instanceof Event) {
|
|
213
|
+
adjustedEvent = new event.constructor(event.type, event);
|
|
214
|
+
Object.defineProperties(adjustedEvent, {
|
|
215
|
+
target: {
|
|
216
|
+
value: inputRef.current
|
|
217
|
+
},
|
|
218
|
+
value: {
|
|
219
|
+
value: nextValue
|
|
220
|
+
},
|
|
221
|
+
option: {
|
|
222
|
+
value: option
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
} else {
|
|
226
|
+
adjustedEvent = event;
|
|
227
|
+
adjustedEvent.target = inputRef.current;
|
|
228
|
+
adjustedEvent.value = nextValue;
|
|
229
|
+
adjustedEvent.option = option;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
onChange(adjustedEvent);
|
|
233
|
+
}
|
|
234
|
+
}, [onChange, setValue, triggerChangeEvent]);
|
|
235
|
+
var SelectIcon = getSelectIcon(icon, theme, open); // element to show, trumps inputValue
|
|
236
|
+
|
|
237
|
+
var selectValue = useMemo(function () {
|
|
238
|
+
var result;
|
|
239
|
+
|
|
240
|
+
if (valueLabel) {
|
|
241
|
+
result = value && valueLabel instanceof Function ? valueLabel(value) : valueLabel;
|
|
242
|
+
} else if ((value == null ? void 0 : value.length) > 0 && showSelectedInline) {
|
|
243
|
+
result = /*#__PURE__*/React.createElement(SelectMultipleValue, {
|
|
244
|
+
allOptions: allOptions,
|
|
245
|
+
disabled: disabled,
|
|
246
|
+
disabledKey: disabledKey,
|
|
247
|
+
dropButtonRef: dropButtonRef,
|
|
248
|
+
labelKey: labelKey,
|
|
249
|
+
onRequestOpen: onRequestOpen,
|
|
250
|
+
onSelectChange: onSelectChange,
|
|
251
|
+
theme: theme,
|
|
252
|
+
value: value,
|
|
253
|
+
valueKey: valueKey
|
|
254
|
+
}, children);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return result;
|
|
258
|
+
}, [valueKey, value, valueLabel, showSelectedInline, onRequestOpen, allOptions, children, labelKey, onSelectChange, disabled, disabledKey, dropButtonRef, theme]);
|
|
259
|
+
var displayLabelKey = useMemo(function () {
|
|
260
|
+
return getDisplayLabelKey(labelKey, allOptions, optionIndexesInValue, selectValue);
|
|
261
|
+
}, [labelKey, allOptions, optionIndexesInValue, selectValue]); // text to show
|
|
262
|
+
// When the options array contains objects, this property indicates how
|
|
263
|
+
// to retrieve the value of each option.
|
|
264
|
+
// If a string is provided, it is used as the key to retrieve a
|
|
265
|
+
// property of an option object.
|
|
266
|
+
// If a function is provided, it is called with the option and should
|
|
267
|
+
// return the value.
|
|
268
|
+
// If reduce is true, this value will be used for the 'value'
|
|
269
|
+
// delivered via 'onChange'.
|
|
270
|
+
|
|
271
|
+
var inputValue = useMemo(function () {
|
|
272
|
+
if (!selectValue) {
|
|
273
|
+
if (optionIndexesInValue.length === 0) return '';
|
|
274
|
+
if (optionIndexesInValue.length === 1) return applyKey(allOptions[optionIndexesInValue[0]], labelKey);
|
|
275
|
+
if (messages) return format({
|
|
276
|
+
id: 'select.multiple',
|
|
277
|
+
messages: messages
|
|
278
|
+
});
|
|
279
|
+
return optionIndexesInValue.length + " selected";
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return undefined;
|
|
283
|
+
}, [labelKey, messages, format, optionIndexesInValue, allOptions, selectValue]);
|
|
284
|
+
var iconColor = getIconColor(theme);
|
|
285
|
+
var dropContent = /*#__PURE__*/React.createElement(SelectMultipleContainer, {
|
|
286
|
+
allOptions: allOptions,
|
|
287
|
+
disabled: disabled,
|
|
288
|
+
disabledKey: disabledKey,
|
|
289
|
+
dropHeight: dropHeight,
|
|
290
|
+
emptySearchMessage: emptySearchMessage,
|
|
291
|
+
help: help,
|
|
292
|
+
id: id,
|
|
293
|
+
labelKey: labelKey,
|
|
294
|
+
limit: limit,
|
|
295
|
+
onChange: onSelectChange,
|
|
296
|
+
onClose: onRequestClose,
|
|
297
|
+
onKeyDown: onKeyDown,
|
|
298
|
+
onMore: onMore,
|
|
299
|
+
onSearch: onSearch,
|
|
300
|
+
options: orderedOptions || optionsProp,
|
|
301
|
+
optionIndexesInValue: optionIndexesInValue,
|
|
302
|
+
replace: replace,
|
|
303
|
+
searchPlaceholder: searchPlaceholder,
|
|
304
|
+
search: search,
|
|
305
|
+
setSearch: setSearch,
|
|
306
|
+
usingKeyboard: usingKeyboard,
|
|
307
|
+
value: value,
|
|
308
|
+
valueKey: valueKey,
|
|
309
|
+
showSelectedInline: showSelectedInline
|
|
310
|
+
}, children);
|
|
311
|
+
var dropButtonProps = {
|
|
312
|
+
ref: dropButtonRef,
|
|
313
|
+
a11yTitle: (ariaLabel || a11yTitle || placeholder || 'Open Drop') + ". " + ((value == null ? void 0 : value.length) || 0) + " selected.",
|
|
314
|
+
'aria-expanded': Boolean(open),
|
|
315
|
+
'aria-haspopup': 'listbox',
|
|
316
|
+
id: id,
|
|
317
|
+
disabled: disabled === true || undefined,
|
|
318
|
+
open: open,
|
|
319
|
+
focusIndicator: focusIndicator,
|
|
320
|
+
onFocus: onFocus,
|
|
321
|
+
onBlur: onBlur,
|
|
322
|
+
gridArea: gridArea,
|
|
323
|
+
margin: margin,
|
|
324
|
+
onOpen: onRequestOpen,
|
|
325
|
+
onClose: onRequestClose,
|
|
326
|
+
onClick: onClick,
|
|
327
|
+
plainSelect: plain,
|
|
328
|
+
plain: plain,
|
|
329
|
+
// Button should be plain
|
|
330
|
+
dropProps: dropProps,
|
|
331
|
+
dropContent: dropContent,
|
|
332
|
+
theme: theme
|
|
333
|
+
};
|
|
334
|
+
var displaySelectIcon = SelectIcon && /*#__PURE__*/React.createElement(Box, {
|
|
335
|
+
alignSelf: "center",
|
|
336
|
+
margin: theme.select.icons.margin,
|
|
337
|
+
width: {
|
|
338
|
+
min: 'auto'
|
|
339
|
+
}
|
|
340
|
+
}, /*#__PURE__*/isValidElement(SelectIcon) ? SelectIcon : /*#__PURE__*/React.createElement(SelectIcon, {
|
|
341
|
+
color: iconColor,
|
|
342
|
+
size: size
|
|
343
|
+
}));
|
|
344
|
+
return /*#__PURE__*/React.createElement(Keyboard, {
|
|
345
|
+
onDown: onRequestOpen,
|
|
346
|
+
onUp: onRequestOpen
|
|
347
|
+
}, showSelectedInline ? /*#__PURE__*/React.createElement(StyledSelectBox, {
|
|
348
|
+
disabled: disabled === true || undefined,
|
|
349
|
+
alignSelf: alignSelf,
|
|
350
|
+
direction: "row",
|
|
351
|
+
alignContent: "start",
|
|
352
|
+
background: theme.select.background,
|
|
353
|
+
ref: selectBoxRef,
|
|
354
|
+
flex: false,
|
|
355
|
+
plainSelect: plain,
|
|
356
|
+
width: width
|
|
357
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
358
|
+
width: "100%"
|
|
359
|
+
}, /*#__PURE__*/React.createElement(DropButton, _extends({
|
|
360
|
+
fill: "horizontal",
|
|
361
|
+
alignSelf: "start"
|
|
362
|
+
}, dropButtonProps, {
|
|
363
|
+
dropAlign: dropAlign || {
|
|
364
|
+
top: 'top',
|
|
365
|
+
right: 'right',
|
|
366
|
+
left: 'left'
|
|
367
|
+
},
|
|
368
|
+
dropTarget: dropTarget || selectBoxRef.current
|
|
369
|
+
}), selectValue || displayLabelKey ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Box, {
|
|
370
|
+
direction: "row"
|
|
371
|
+
}, /*#__PURE__*/React.createElement(SelectTextInput, _extends({
|
|
372
|
+
a11yTitle: ariaLabel || a11yTitle,
|
|
373
|
+
defaultCursor: disabled === true || undefined,
|
|
374
|
+
focusIndicator: false,
|
|
375
|
+
id: id ? id + "__input" : undefined,
|
|
376
|
+
name: name,
|
|
377
|
+
width: "100%"
|
|
378
|
+
}, rest, {
|
|
379
|
+
tabIndex: "-1",
|
|
380
|
+
type: "text",
|
|
381
|
+
placeholder: // eslint-disable-next-line no-nested-ternary
|
|
382
|
+
!value || (value == null ? void 0 : value.length) === 0 ? placeholder || selectValue || displayLabelKey : onMore ? ((value == null ? void 0 : value.length) || '0') + " selected" : ((value == null ? void 0 : value.length) || '0') + " selected of " + allOptions.length,
|
|
383
|
+
plain: true,
|
|
384
|
+
readOnly: true,
|
|
385
|
+
value: "",
|
|
386
|
+
theme: theme
|
|
387
|
+
})), displaySelectIcon), /*#__PURE__*/React.createElement(HiddenInput, {
|
|
388
|
+
type: "text",
|
|
389
|
+
name: name,
|
|
390
|
+
id: id ? id + "__input" : undefined,
|
|
391
|
+
value: inputValue,
|
|
392
|
+
ref: inputRef,
|
|
393
|
+
readOnly: true
|
|
394
|
+
})) : /*#__PURE__*/React.createElement(Box, {
|
|
395
|
+
direction: "row"
|
|
396
|
+
}, /*#__PURE__*/React.createElement(DefaultSelectTextInput, _extends({
|
|
397
|
+
a11yTitle: ariaLabel || a11yTitle,
|
|
398
|
+
disabled: disabled,
|
|
399
|
+
id: id,
|
|
400
|
+
name: name,
|
|
401
|
+
ref: inputRef,
|
|
402
|
+
placeholder: placeholder || 'Select',
|
|
403
|
+
value: inputValue,
|
|
404
|
+
size: size,
|
|
405
|
+
theme: theme
|
|
406
|
+
}, rest)), displaySelectIcon)), !open && (value == null ? void 0 : value.length) > 0 && (selectValue || displayLabelKey))) : /*#__PURE__*/React.createElement(Box, {
|
|
407
|
+
width: width
|
|
408
|
+
}, /*#__PURE__*/React.createElement(StyledSelectDropButton, _extends({}, dropButtonProps, {
|
|
409
|
+
dropAlign: dropAlign || {
|
|
410
|
+
top: 'bottom',
|
|
411
|
+
left: 'left'
|
|
412
|
+
},
|
|
413
|
+
dropTarget: dropTarget,
|
|
414
|
+
alignSelf: alignSelf,
|
|
415
|
+
tabIndex: "0"
|
|
416
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
417
|
+
align: "center",
|
|
418
|
+
direction: "row",
|
|
419
|
+
justify: "between",
|
|
420
|
+
background: theme.select.background
|
|
421
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
422
|
+
direction: "row",
|
|
423
|
+
flex: true,
|
|
424
|
+
basis: "auto"
|
|
425
|
+
}, selectValue || displayLabelKey ? /*#__PURE__*/React.createElement(React.Fragment, null, selectValue || displayLabelKey, /*#__PURE__*/React.createElement(HiddenInput, {
|
|
426
|
+
type: "text",
|
|
427
|
+
name: name,
|
|
428
|
+
id: id ? id + "__input" : undefined,
|
|
429
|
+
value: inputValue,
|
|
430
|
+
ref: inputRef,
|
|
431
|
+
readOnly: true
|
|
432
|
+
})) : /*#__PURE__*/React.createElement(DefaultSelectTextInput, _extends({
|
|
433
|
+
a11yTitle: ariaLabel || a11yTitle,
|
|
434
|
+
disabled: disabled,
|
|
435
|
+
id: id,
|
|
436
|
+
name: name,
|
|
437
|
+
ref: inputRef,
|
|
438
|
+
placeholder: placeholder,
|
|
439
|
+
value: inputValue,
|
|
440
|
+
size: size,
|
|
441
|
+
theme: theme
|
|
442
|
+
}, rest))), displaySelectIcon))));
|
|
443
|
+
});
|
|
444
|
+
SelectMultiple.defaultProps = _extends({}, defaultProps);
|
|
445
|
+
SelectMultiple.displayName = 'SelectMultiple';
|
|
446
|
+
SelectMultiple.propTypes = SelectMultiplePropTypes;
|
|
447
|
+
export { SelectMultiple };
|