@carbon/react 1.7.0 → 1.9.0-rc.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/es/components/ComposedModal/ComposedModal.js +1 -1
- package/es/components/ComposedModal/index.js +4 -4
- package/es/components/ComposedModal/next/ComposedModal.js +1 -1
- package/es/components/DataTable/DataTable.js +1 -1
- package/es/components/DataTable/Table.js +10 -2
- package/es/components/DataTable/TableContainer.js +20 -5
- package/es/components/DataTable/TableContext.js +15 -0
- package/es/components/DataTable/TableSelectRow.js +1 -1
- package/es/components/FileUploader/FileUploader.js +8 -1
- package/es/components/FileUploader/FileUploaderButton.js +3 -1
- package/es/components/FileUploader/FileUploaderDropContainer.js +3 -1
- package/es/components/FileUploader/FileUploaderItem.js +3 -1
- package/es/components/InlineLoading/InlineLoading.js +9 -5
- package/es/components/Loading/Loading.js +7 -18
- package/es/components/Menu/Menu.js +1 -1
- package/es/components/Modal/Modal.js +204 -273
- package/es/components/Modal/index.js +2 -8
- package/es/components/ModalWrapper/ModalWrapper.js +1 -1
- package/es/components/MultiSelect/FilterableMultiSelect.js +345 -386
- package/es/components/MultiSelect/index.js +4 -8
- package/es/components/Notification/Notification.js +322 -189
- package/es/components/NumberInput/NumberInput.Skeleton.js +3 -4
- package/es/components/NumberInput/NumberInput.js +308 -359
- package/es/components/RadioButton/RadioButton.js +58 -99
- package/es/components/RadioButton/index.js +2 -8
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +72 -121
- package/es/components/RadioButtonGroup/index.js +2 -8
- package/es/components/Slider/Slider.js +2 -1
- package/es/components/Switch/Switch.js +0 -1
- package/es/components/TreeView/TreeView.js +19 -11
- package/es/components/UIShell/HeaderMenu.js +1 -1
- package/es/components/UIShell/HeaderMenuButton.js +4 -0
- package/es/components/UIShell/SideNavLink.js +6 -9
- package/es/index.js +10 -9
- package/es/internal/createClassWrapper.js +2 -5
- package/lib/components/ComposedModal/index.js +7 -7
- package/lib/components/ComposedModal/next/ComposedModal.js +1 -1
- package/lib/components/DataTable/DataTable.js +5 -5
- package/lib/components/DataTable/Table.js +9 -1
- package/lib/components/DataTable/TableContainer.js +19 -4
- package/lib/components/DataTable/TableContext.js +19 -0
- package/lib/components/DataTable/TableSelectRow.js +2 -2
- package/lib/components/FileUploader/FileUploader.js +8 -1
- package/lib/components/FileUploader/FileUploaderButton.js +3 -1
- package/lib/components/FileUploader/FileUploaderDropContainer.js +3 -1
- package/lib/components/FileUploader/FileUploaderItem.js +3 -1
- package/lib/components/InlineLoading/InlineLoading.js +9 -5
- package/lib/components/Loading/Loading.js +6 -17
- package/lib/components/Menu/Menu.js +1 -1
- package/lib/components/Modal/Modal.js +201 -270
- package/lib/components/Modal/index.js +2 -25
- package/lib/components/ModalWrapper/ModalWrapper.js +2 -2
- package/lib/components/MultiSelect/FilterableMultiSelect.js +341 -382
- package/lib/components/MultiSelect/index.js +5 -28
- package/lib/components/Notification/Notification.js +321 -188
- package/lib/components/NumberInput/NumberInput.Skeleton.js +3 -4
- package/lib/components/NumberInput/NumberInput.js +305 -376
- package/lib/components/RadioButton/RadioButton.js +57 -99
- package/lib/components/RadioButton/index.js +2 -25
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +68 -117
- package/lib/components/RadioButtonGroup/index.js +2 -25
- package/lib/components/Slider/Slider.js +2 -1
- package/lib/components/Switch/Switch.js +0 -1
- package/lib/components/TreeView/TreeView.js +18 -10
- package/lib/components/UIShell/HeaderMenu.js +1 -0
- package/lib/components/UIShell/HeaderMenuButton.js +4 -0
- package/lib/components/UIShell/SideNavLink.js +6 -9
- package/lib/index.js +95 -95
- package/lib/internal/createClassWrapper.js +2 -5
- package/package.json +7 -7
- package/scss/utilities/_hide-at-breakpoint.scss +9 -0
- package/es/components/Modal/next/Modal.js +0 -274
- package/es/components/MultiSelect/next/FilterableMultiSelect.js +0 -544
- package/es/components/Notification/index.js +0 -42
- package/es/components/Notification/next/Notification.js +0 -663
- package/es/components/RadioButton/next/RadioButton.js +0 -130
- package/es/components/RadioButtonGroup/next/RadioButtonGroup.js +0 -141
- package/es/internal/FeatureFlags.js +0 -52
- package/es/prop-types/requiredIfValueExists.js +0 -32
- package/lib/components/Modal/next/Modal.js +0 -284
- package/lib/components/MultiSelect/next/FilterableMultiSelect.js +0 -556
- package/lib/components/Notification/index.js +0 -51
- package/lib/components/Notification/next/Notification.js +0 -677
- package/lib/components/RadioButton/next/RadioButton.js +0 -140
- package/lib/components/RadioButtonGroup/next/RadioButtonGroup.js +0 -151
- package/lib/internal/FeatureFlags.js +0 -56
- package/lib/prop-types/requiredIfValueExists.js +0 -36
|
@@ -5,23 +5,23 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
9
|
import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
|
|
10
10
|
import cx from 'classnames';
|
|
11
11
|
import Downshift from 'downshift';
|
|
12
12
|
import isEqual from 'lodash.isequal';
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
|
-
import React__default from 'react';
|
|
14
|
+
import React__default, { useState, useRef } from 'react';
|
|
15
15
|
import { defaultFilterItems } from '../ComboBox/tools/filter.js';
|
|
16
16
|
import { sortingPropTypes } from './MultiSelectPropTypes.js';
|
|
17
17
|
import '../ListBox/index.js';
|
|
18
18
|
import Selection from '../../internal/Selection.js';
|
|
19
19
|
import { defaultItemToString } from './tools/itemToString.js';
|
|
20
20
|
import mergeRefs from '../../tools/mergeRefs.js';
|
|
21
|
-
import
|
|
21
|
+
import { useId } from '../../internal/useId.js';
|
|
22
22
|
import { defaultCompareItems, defaultSortItems } from './tools/sorting.js';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
23
|
+
import { useFeatureFlag } from '../FeatureFlags/index.js';
|
|
24
|
+
import { usePrefix } from '../../internal/usePrefix.js';
|
|
25
25
|
import { match } from '../../internal/keyboard/match.js';
|
|
26
26
|
import ListBoxSelection from '../ListBox/next/ListBoxSelection.js';
|
|
27
27
|
import ListBoxTrigger from '../ListBox/next/ListBoxTrigger.js';
|
|
@@ -29,403 +29,364 @@ import ListBox from '../ListBox/ListBox.js';
|
|
|
29
29
|
import { ListBoxSize } from '../ListBox/ListBoxPropTypes.js';
|
|
30
30
|
import { Space } from '../../internal/keyboard/keys.js';
|
|
31
31
|
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
var FilterableMultiSelect = /*#__PURE__*/React__default.forwardRef(function FilterableMultiSelect(_ref, ref) {
|
|
33
|
+
var _cx, _cx2, _cx3, _cx4;
|
|
34
|
+
|
|
35
|
+
var ariaLabel = _ref.ariaLabel,
|
|
36
|
+
containerClassName = _ref.className,
|
|
37
|
+
compareItems = _ref.compareItems,
|
|
38
|
+
direction = _ref.direction,
|
|
39
|
+
disabled = _ref.disabled,
|
|
40
|
+
downshiftProps = _ref.downshiftProps,
|
|
41
|
+
filterItems = _ref.filterItems,
|
|
42
|
+
helperText = _ref.helperText,
|
|
43
|
+
hideLabel = _ref.hideLabel,
|
|
44
|
+
id = _ref.id,
|
|
45
|
+
initialSelectedItems = _ref.initialSelectedItems,
|
|
46
|
+
invalid = _ref.invalid,
|
|
47
|
+
invalidText = _ref.invalidText,
|
|
48
|
+
items = _ref.items,
|
|
49
|
+
ItemToElement = _ref.itemToElement,
|
|
50
|
+
itemToString = _ref.itemToString,
|
|
51
|
+
light = _ref.light,
|
|
52
|
+
locale = _ref.locale,
|
|
53
|
+
onInputValueChange = _ref.onInputValueChange,
|
|
54
|
+
open = _ref.open,
|
|
55
|
+
onChange = _ref.onChange,
|
|
56
|
+
onMenuChange = _ref.onMenuChange,
|
|
57
|
+
placeholder = _ref.placeholder,
|
|
58
|
+
titleText = _ref.titleText,
|
|
59
|
+
type = _ref.type,
|
|
60
|
+
selectionFeedback = _ref.selectionFeedback,
|
|
61
|
+
size = _ref.size,
|
|
62
|
+
sortItems = _ref.sortItems,
|
|
63
|
+
translateWithId = _ref.translateWithId,
|
|
64
|
+
useTitleInItem = _ref.useTitleInItem,
|
|
65
|
+
warn = _ref.warn,
|
|
66
|
+
warnText = _ref.warnText;
|
|
67
|
+
|
|
68
|
+
var _useState = useState(open),
|
|
69
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
70
|
+
isOpen = _useState2[0],
|
|
71
|
+
setIsOpen = _useState2[1];
|
|
72
|
+
|
|
73
|
+
var _useState3 = useState(open),
|
|
74
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
75
|
+
prevOpen = _useState4[0],
|
|
76
|
+
setPrevOpen = _useState4[1];
|
|
77
|
+
|
|
78
|
+
var _useState5 = useState(''),
|
|
79
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
80
|
+
inputValue = _useState6[0],
|
|
81
|
+
setInputValue = _useState6[1];
|
|
82
|
+
|
|
83
|
+
var _useState7 = useState([]),
|
|
84
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
85
|
+
topItems = _useState8[0],
|
|
86
|
+
setTopItems = _useState8[1];
|
|
87
|
+
|
|
88
|
+
var _useState9 = useState(false),
|
|
89
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
90
|
+
inputFocused = _useState10[0],
|
|
91
|
+
setInputFocused = _useState10[1];
|
|
92
|
+
|
|
93
|
+
var _useState11 = useState(null),
|
|
94
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
95
|
+
highlightedIndex = _useState12[0],
|
|
96
|
+
setHighlightedIndex = _useState12[1];
|
|
97
|
+
|
|
98
|
+
var textInput = useRef();
|
|
99
|
+
var filterableMultiSelectInstanceId = useId();
|
|
100
|
+
var enabled = useFeatureFlag('enable-v11-release');
|
|
101
|
+
var prefix = usePrefix();
|
|
102
|
+
|
|
103
|
+
if (prevOpen !== open) {
|
|
104
|
+
setIsOpen(open);
|
|
105
|
+
setPrevOpen(open);
|
|
106
|
+
}
|
|
38
107
|
|
|
39
|
-
|
|
40
|
-
|
|
108
|
+
var inline = type === 'inline';
|
|
109
|
+
var showWarning = !invalid && warn;
|
|
110
|
+
var wrapperClasses = cx("".concat(prefix, "--multi-select__wrapper"), "".concat(prefix, "--list-box__wrapper"), [enabled ? containerClassName : null], (_cx = {}, _defineProperty(_cx, "".concat(prefix, "--multi-select__wrapper--inline"), inline), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--inline"), inline), _defineProperty(_cx, "".concat(prefix, "--multi-select__wrapper--inline--invalid"), inline && invalid), _defineProperty(_cx, "".concat(prefix, "--list-box__wrapper--inline--invalid"), inline && invalid), _defineProperty(_cx, "".concat(prefix, "--list-box--up"), direction === 'top'), _cx));
|
|
111
|
+
var helperId = !helperText ? undefined : "filterablemultiselect-helper-text-".concat(filterableMultiSelectInstanceId);
|
|
112
|
+
var labelId = "".concat(id, "-label");
|
|
113
|
+
var titleClasses = cx((_cx2 = {}, _defineProperty(_cx2, "".concat(prefix, "--label"), true), _defineProperty(_cx2, "".concat(prefix, "--label--disabled"), disabled), _defineProperty(_cx2, "".concat(prefix, "--visually-hidden"), hideLabel), _cx2));
|
|
114
|
+
var helperClasses = cx((_cx3 = {}, _defineProperty(_cx3, "".concat(prefix, "--form__helper-text"), true), _defineProperty(_cx3, "".concat(prefix, "--form__helper-text--disabled"), disabled), _cx3));
|
|
115
|
+
var inputClasses = cx((_cx4 = {}, _defineProperty(_cx4, "".concat(prefix, "--text-input"), true), _defineProperty(_cx4, "".concat(prefix, "--text-input--empty"), !inputValue), _defineProperty(_cx4, "".concat(prefix, "--text-input--light"), light), _cx4));
|
|
116
|
+
var helper = helperText ? /*#__PURE__*/React__default.createElement("div", {
|
|
117
|
+
id: helperId,
|
|
118
|
+
className: helperClasses
|
|
119
|
+
}, helperText) : null;
|
|
120
|
+
var menuId = "".concat(id, "__menu");
|
|
121
|
+
var inputId = "".concat(id, "-input");
|
|
122
|
+
|
|
123
|
+
function handleOnChange(changes) {
|
|
124
|
+
if (onChange) {
|
|
125
|
+
onChange(changes);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
41
128
|
|
|
42
|
-
|
|
129
|
+
function handleOnMenuChange(forceIsOpen) {
|
|
130
|
+
var nextIsOpen = forceIsOpen !== null && forceIsOpen !== void 0 ? forceIsOpen : !isOpen;
|
|
131
|
+
setIsOpen(nextIsOpen);
|
|
43
132
|
|
|
44
|
-
|
|
133
|
+
if (onMenuChange) {
|
|
134
|
+
onMenuChange(nextIsOpen);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
45
137
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
});
|
|
138
|
+
function handleOnOuterClick() {
|
|
139
|
+
handleOnMenuChange(false);
|
|
140
|
+
}
|
|
51
141
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
57
|
-
});
|
|
142
|
+
function handleOnStateChange(changes, downshift) {
|
|
143
|
+
if (changes.isOpen && !isOpen) {
|
|
144
|
+
setTopItems(downshift.selectedItem);
|
|
145
|
+
}
|
|
58
146
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
});
|
|
147
|
+
var type = changes.type;
|
|
148
|
+
var stateChangeTypes = Downshift.stateChangeTypes;
|
|
63
149
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
150
|
+
switch (type) {
|
|
151
|
+
case stateChangeTypes.keyDownArrowDown:
|
|
152
|
+
case stateChangeTypes.keyDownArrowUp:
|
|
153
|
+
case stateChangeTypes.keyDownHome:
|
|
154
|
+
case stateChangeTypes.keyDownEnd:
|
|
155
|
+
setHighlightedIndex(changes.highlightedIndex !== undefined ? changes.highlightedIndex : null);
|
|
67
156
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
topItems: downshift.selectedItem
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
var type = changes.type;
|
|
76
|
-
var stateChangeTypes = Downshift.stateChangeTypes;
|
|
77
|
-
|
|
78
|
-
switch (type) {
|
|
79
|
-
case stateChangeTypes.keyDownArrowDown:
|
|
80
|
-
case stateChangeTypes.keyDownArrowUp:
|
|
81
|
-
case stateChangeTypes.keyDownHome:
|
|
82
|
-
case stateChangeTypes.keyDownEnd:
|
|
83
|
-
_this.setState({
|
|
84
|
-
highlightedIndex: changes.highlightedIndex !== undefined ? changes.highlightedIndex : null
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (stateChangeTypes.keyDownArrowDown === type && !_this.state.isOpen) {
|
|
88
|
-
_this.handleOnMenuChange(true);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
break;
|
|
157
|
+
if (stateChangeTypes.keyDownArrowDown === type && !isOpen) {
|
|
158
|
+
handleOnMenuChange(true);
|
|
159
|
+
}
|
|
92
160
|
|
|
93
|
-
|
|
94
|
-
_this.handleOnMenuChange(false);
|
|
161
|
+
break;
|
|
95
162
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
163
|
+
case stateChangeTypes.keyDownEscape:
|
|
164
|
+
handleOnMenuChange(false);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
99
168
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
});
|
|
169
|
+
function handleOnInputValueChange(inputValue, _ref2) {
|
|
170
|
+
var type = _ref2.type;
|
|
103
171
|
|
|
104
|
-
|
|
105
|
-
|
|
172
|
+
if (onInputValueChange) {
|
|
173
|
+
onInputValueChange(inputValue);
|
|
174
|
+
}
|
|
106
175
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
176
|
+
if (type !== Downshift.stateChangeTypes.changeInput) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
110
179
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
180
|
+
if (Array.isArray(inputValue)) {
|
|
181
|
+
clearInputValue();
|
|
182
|
+
} else {
|
|
183
|
+
setInputValue(inputValue);
|
|
184
|
+
}
|
|
114
185
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
186
|
+
if (inputValue && !isOpen) {
|
|
187
|
+
handleOnMenuChange(true);
|
|
188
|
+
} else if (!inputValue && isOpen) {
|
|
189
|
+
handleOnMenuChange(false);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
121
192
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
};
|
|
125
|
-
});
|
|
193
|
+
function clearInputValue() {
|
|
194
|
+
setInputValue('');
|
|
126
195
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
_this.handleOnMenuChange(false);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
_defineProperty(_assertThisInitialized(_this), "clearInputValue", function () {
|
|
135
|
-
_this.setState({
|
|
136
|
-
inputValue: ''
|
|
137
|
-
}, function () {
|
|
138
|
-
if (_this.textInput.current) {
|
|
139
|
-
_this.textInput.current.focus();
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
_this.filterableMultiSelectInstanceId = getInstanceId();
|
|
145
|
-
_this.state = {
|
|
146
|
-
isOpen: props.open,
|
|
147
|
-
inputValue: '',
|
|
148
|
-
topItems: [],
|
|
149
|
-
inputFocused: false,
|
|
150
|
-
highlightedIndex: null
|
|
151
|
-
};
|
|
152
|
-
_this.textInput = /*#__PURE__*/React__default.createRef();
|
|
153
|
-
return _this;
|
|
196
|
+
if (textInput.current) {
|
|
197
|
+
textInput.current.focus();
|
|
198
|
+
}
|
|
154
199
|
}
|
|
155
200
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
var
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
201
|
+
return /*#__PURE__*/React__default.createElement(Selection, {
|
|
202
|
+
disabled: disabled,
|
|
203
|
+
onChange: handleOnChange,
|
|
204
|
+
initialSelectedItems: initialSelectedItems,
|
|
205
|
+
render: function render(_ref3) {
|
|
206
|
+
var selectedItems = _ref3.selectedItems,
|
|
207
|
+
onItemChange = _ref3.onItemChange,
|
|
208
|
+
_clearSelection = _ref3.clearSelection;
|
|
209
|
+
return /*#__PURE__*/React__default.createElement(Downshift, _extends({}, downshiftProps, {
|
|
210
|
+
highlightedIndex: highlightedIndex,
|
|
211
|
+
id: id,
|
|
212
|
+
isOpen: isOpen,
|
|
213
|
+
inputValue: inputValue,
|
|
214
|
+
onInputValueChange: handleOnInputValueChange,
|
|
215
|
+
onChange: function onChange(selectedItem) {
|
|
216
|
+
if (selectedItem !== null) {
|
|
217
|
+
onItemChange(selectedItem);
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
itemToString: itemToString,
|
|
221
|
+
onStateChange: handleOnStateChange,
|
|
222
|
+
onOuterClick: handleOnOuterClick,
|
|
223
|
+
selectedItem: selectedItems,
|
|
224
|
+
labelId: labelId,
|
|
225
|
+
menuId: menuId,
|
|
226
|
+
inputId: inputId
|
|
227
|
+
}), function (_ref4) {
|
|
228
|
+
var _cx5;
|
|
229
|
+
|
|
230
|
+
var getInputProps = _ref4.getInputProps,
|
|
231
|
+
getItemProps = _ref4.getItemProps,
|
|
232
|
+
getLabelProps = _ref4.getLabelProps,
|
|
233
|
+
getMenuProps = _ref4.getMenuProps,
|
|
234
|
+
getRootProps = _ref4.getRootProps,
|
|
235
|
+
getToggleButtonProps = _ref4.getToggleButtonProps,
|
|
236
|
+
isOpen = _ref4.isOpen,
|
|
237
|
+
inputValue = _ref4.inputValue,
|
|
238
|
+
selectedItem = _ref4.selectedItem;
|
|
239
|
+
var className = cx("".concat(prefix, "--multi-select"), "".concat(prefix, "--combo-box"), "".concat(prefix, "--multi-select--filterable"), [enabled ? null : containerClassName], (_cx5 = {}, _defineProperty(_cx5, "".concat(prefix, "--multi-select--invalid"), invalid), _defineProperty(_cx5, "".concat(prefix, "--multi-select--open"), isOpen), _defineProperty(_cx5, "".concat(prefix, "--multi-select--inline"), inline), _defineProperty(_cx5, "".concat(prefix, "--multi-select--selected"), selectedItem.length > 0), _defineProperty(_cx5, "".concat(prefix, "--multi-select--filterable--input-focused"), inputFocused), _cx5));
|
|
240
|
+
var rootProps = getRootProps({}, {
|
|
241
|
+
suppressRefError: true
|
|
242
|
+
});
|
|
243
|
+
var labelProps = getLabelProps();
|
|
244
|
+
var buttonProps = getToggleButtonProps({
|
|
245
|
+
disabled: disabled,
|
|
246
|
+
onClick: function onClick() {
|
|
247
|
+
handleOnMenuChange(!isOpen);
|
|
248
|
+
|
|
249
|
+
if (textInput.current) {
|
|
250
|
+
textInput.current.focus();
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
// When we moved the "root node" of Downshift to the <input> for
|
|
254
|
+
// ARIA 1.2 compliance, we unfortunately hit this branch for the
|
|
255
|
+
// "mouseup" event that downshift listens to:
|
|
256
|
+
// https://github.com/downshift-js/downshift/blob/v5.2.1/src/downshift.js#L1051-L1065
|
|
257
|
+
//
|
|
258
|
+
// As a result, it will reset the state of the component and so we
|
|
259
|
+
// stop the event from propagating to prevent this. This allows the
|
|
260
|
+
// toggleMenu behavior for the toggleButton to correctly open and
|
|
261
|
+
// close the menu.
|
|
262
|
+
onMouseUp: function onMouseUp(event) {
|
|
263
|
+
if (isOpen) {
|
|
264
|
+
event.stopPropagation();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
var inputProps = getInputProps({
|
|
269
|
+
'aria-controls': isOpen ? menuId : null,
|
|
270
|
+
'aria-describedby': helperText ? helperId : null,
|
|
271
|
+
// Remove excess aria `aria-labelledby`. HTML <label for>
|
|
272
|
+
// provides this aria information.
|
|
273
|
+
'aria-labelledby': null,
|
|
220
274
|
disabled: disabled,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
onItemChange(selectedItem);
|
|
236
|
-
}
|
|
237
|
-
},
|
|
238
|
-
itemToString: itemToString,
|
|
239
|
-
onStateChange: _this2.handleOnStateChange,
|
|
240
|
-
onOuterClick: _this2.handleOnOuterClick,
|
|
241
|
-
selectedItem: selectedItems,
|
|
242
|
-
labelId: labelId,
|
|
243
|
-
menuId: menuId,
|
|
244
|
-
inputId: inputId
|
|
245
|
-
}), function (_ref3) {
|
|
246
|
-
var _cx5;
|
|
247
|
-
|
|
248
|
-
var getInputProps = _ref3.getInputProps,
|
|
249
|
-
getItemProps = _ref3.getItemProps,
|
|
250
|
-
getLabelProps = _ref3.getLabelProps,
|
|
251
|
-
getMenuProps = _ref3.getMenuProps,
|
|
252
|
-
getRootProps = _ref3.getRootProps,
|
|
253
|
-
getToggleButtonProps = _ref3.getToggleButtonProps,
|
|
254
|
-
isOpen = _ref3.isOpen,
|
|
255
|
-
inputValue = _ref3.inputValue,
|
|
256
|
-
selectedItem = _ref3.selectedItem;
|
|
257
|
-
var className = cx("".concat(prefix, "--multi-select"), "".concat(prefix, "--combo-box"), "".concat(prefix, "--multi-select--filterable"), [enabled ? null : containerClassName], (_cx5 = {}, _defineProperty(_cx5, "".concat(prefix, "--multi-select--invalid"), invalid), _defineProperty(_cx5, "".concat(prefix, "--multi-select--open"), isOpen), _defineProperty(_cx5, "".concat(prefix, "--multi-select--inline"), inline), _defineProperty(_cx5, "".concat(prefix, "--multi-select--selected"), selectedItem.length > 0), _defineProperty(_cx5, "".concat(prefix, "--multi-select--filterable--input-focused"), _this2.state.inputFocused), _cx5));
|
|
258
|
-
var rootProps = getRootProps({}, {
|
|
259
|
-
suppressRefError: true
|
|
260
|
-
});
|
|
261
|
-
var labelProps = getLabelProps();
|
|
262
|
-
var buttonProps = getToggleButtonProps({
|
|
263
|
-
disabled: disabled,
|
|
264
|
-
onClick: function onClick() {
|
|
265
|
-
_this2.handleOnMenuChange(!_this2.state.isOpen);
|
|
266
|
-
|
|
267
|
-
if (_this2.textInput.current) {
|
|
268
|
-
_this2.textInput.current.focus();
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
// When we moved the "root node" of Downshift to the <input> for
|
|
272
|
-
// ARIA 1.2 compliance, we unfortunately hit this branch for the
|
|
273
|
-
// "mouseup" event that downshift listens to:
|
|
274
|
-
// https://github.com/downshift-js/downshift/blob/v5.2.1/src/downshift.js#L1051-L1065
|
|
275
|
-
//
|
|
276
|
-
// As a result, it will reset the state of the component and so we
|
|
277
|
-
// stop the event from propagating to prevent this. This allows the
|
|
278
|
-
// toggleMenu behavior for the toggleButton to correctly open and
|
|
279
|
-
// close the menu.
|
|
280
|
-
onMouseUp: function onMouseUp(event) {
|
|
281
|
-
event.stopPropagation();
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
var inputProps = getInputProps({
|
|
285
|
-
'aria-controls': isOpen ? menuId : null,
|
|
286
|
-
'aria-describedby': helperText ? helperId : null,
|
|
287
|
-
// Remove excess aria `aria-labelledby`. HTML <label for>
|
|
288
|
-
// provides this aria information.
|
|
289
|
-
'aria-labelledby': null,
|
|
290
|
-
disabled: disabled,
|
|
291
|
-
placeholder: placeholder,
|
|
292
|
-
onClick: function onClick() {
|
|
293
|
-
_this2.handleOnMenuChange(true);
|
|
294
|
-
},
|
|
295
|
-
onKeyDown: function onKeyDown(event) {
|
|
296
|
-
if (match(event, Space)) {
|
|
297
|
-
event.stopPropagation();
|
|
298
|
-
}
|
|
299
|
-
},
|
|
300
|
-
onFocus: function onFocus() {
|
|
301
|
-
_this2.setState({
|
|
302
|
-
inputFocused: true
|
|
303
|
-
});
|
|
304
|
-
},
|
|
305
|
-
onBlur: function onBlur() {
|
|
306
|
-
_this2.setState({
|
|
307
|
-
inputFocused: false
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
var menuProps = getMenuProps({
|
|
312
|
-
'aria-label': ariaLabel
|
|
313
|
-
}, {
|
|
314
|
-
suppressRefError: true
|
|
315
|
-
});
|
|
316
|
-
return /*#__PURE__*/React__default.createElement("div", {
|
|
317
|
-
className: wrapperClasses
|
|
318
|
-
}, titleText ? /*#__PURE__*/React__default.createElement("label", _extends({
|
|
319
|
-
className: titleClasses
|
|
320
|
-
}, labelProps), titleText) : null, /*#__PURE__*/React__default.createElement(ListBox, {
|
|
321
|
-
className: className,
|
|
322
|
-
disabled: disabled,
|
|
323
|
-
light: light,
|
|
324
|
-
invalid: invalid,
|
|
325
|
-
invalidText: invalidText,
|
|
326
|
-
warn: warn,
|
|
327
|
-
warnText: warnText,
|
|
328
|
-
isOpen: isOpen,
|
|
329
|
-
size: size
|
|
330
|
-
}, /*#__PURE__*/React__default.createElement("div", {
|
|
331
|
-
className: "".concat(prefix, "--list-box__field")
|
|
332
|
-
}, selectedItem.length > 0 && /*#__PURE__*/React__default.createElement(ListBoxSelection, {
|
|
333
|
-
clearSelection: function clearSelection() {
|
|
334
|
-
_clearSelection();
|
|
335
|
-
|
|
336
|
-
if (_this2.textInput.current) {
|
|
337
|
-
_this2.textInput.current.focus();
|
|
338
|
-
}
|
|
339
|
-
},
|
|
340
|
-
selectionCount: selectedItem.length,
|
|
341
|
-
translateWithId: translateWithId,
|
|
342
|
-
disabled: disabled
|
|
343
|
-
}), /*#__PURE__*/React__default.createElement("input", _extends({
|
|
344
|
-
className: inputClasses
|
|
345
|
-
}, rootProps, inputProps, {
|
|
346
|
-
ref: mergeRefs(_this2.textInput, rootProps.ref)
|
|
347
|
-
})), invalid && /*#__PURE__*/React__default.createElement(WarningFilled, {
|
|
348
|
-
className: "".concat(prefix, "--list-box__invalid-icon")
|
|
349
|
-
}), showWarning && /*#__PURE__*/React__default.createElement(WarningAltFilled, {
|
|
350
|
-
className: "".concat(prefix, "--list-box__invalid-icon ").concat(prefix, "--list-box__invalid-icon--warning")
|
|
351
|
-
}), inputValue && /*#__PURE__*/React__default.createElement(ListBoxSelection, {
|
|
352
|
-
clearSelection: _this2.clearInputValue,
|
|
353
|
-
disabled: disabled,
|
|
354
|
-
translateWithId: translateWithId,
|
|
355
|
-
onMouseUp: function onMouseUp(event) {
|
|
356
|
-
// If we do not stop this event from propagating,
|
|
357
|
-
// it seems like Downshift takes our event and
|
|
358
|
-
// prevents us from getting `onClick` /
|
|
359
|
-
// `clearSelection` from the underlying <button> in
|
|
360
|
-
// ListBoxSelection
|
|
361
|
-
event.stopPropagation();
|
|
362
|
-
}
|
|
363
|
-
}), /*#__PURE__*/React__default.createElement(ListBoxTrigger, _extends({}, buttonProps, {
|
|
364
|
-
isOpen: isOpen,
|
|
365
|
-
translateWithId: translateWithId
|
|
366
|
-
}))), isOpen ? /*#__PURE__*/React__default.createElement(ListBox.Menu, menuProps, sortItems(filterItems(items, {
|
|
367
|
-
itemToString: itemToString,
|
|
368
|
-
inputValue: inputValue
|
|
369
|
-
}), {
|
|
370
|
-
selectedItems: {
|
|
371
|
-
top: selectedItems,
|
|
372
|
-
fixed: [],
|
|
373
|
-
'top-after-reopen': _this2.state.topItems
|
|
374
|
-
}[_this2.props.selectionFeedback],
|
|
375
|
-
itemToString: itemToString,
|
|
376
|
-
compareItems: compareItems,
|
|
377
|
-
locale: locale
|
|
378
|
-
}).map(function (item, index) {
|
|
379
|
-
var itemProps = getItemProps({
|
|
380
|
-
item: item,
|
|
381
|
-
disabled: item.disabled
|
|
382
|
-
});
|
|
383
|
-
var itemText = itemToString(item);
|
|
384
|
-
var isChecked = selectedItem.filter(function (selected) {
|
|
385
|
-
return isEqual(selected, item);
|
|
386
|
-
}).length > 0;
|
|
387
|
-
return /*#__PURE__*/React__default.createElement(ListBox.MenuItem, _extends({
|
|
388
|
-
key: itemProps.id,
|
|
389
|
-
"aria-label": itemText,
|
|
390
|
-
isActive: isChecked,
|
|
391
|
-
isHighlighted: highlightedIndex === index,
|
|
392
|
-
title: itemText
|
|
393
|
-
}, itemProps), /*#__PURE__*/React__default.createElement("div", {
|
|
394
|
-
className: "".concat(prefix, "--checkbox-wrapper")
|
|
395
|
-
}, /*#__PURE__*/React__default.createElement("span", {
|
|
396
|
-
title: useTitleInItem ? itemText : null,
|
|
397
|
-
className: "".concat(prefix, "--checkbox-label"),
|
|
398
|
-
"data-contained-checkbox-state": isChecked,
|
|
399
|
-
id: "".concat(itemProps.id, "-item")
|
|
400
|
-
}, itemToElement ? /*#__PURE__*/React__default.createElement(ItemToElement, _extends({
|
|
401
|
-
key: itemProps.id
|
|
402
|
-
}, item)) : itemText)));
|
|
403
|
-
})) : null), !inline && !invalid && !warn ? helper : null);
|
|
404
|
-
});
|
|
275
|
+
placeholder: placeholder,
|
|
276
|
+
onClick: function onClick() {
|
|
277
|
+
handleOnMenuChange(true);
|
|
278
|
+
},
|
|
279
|
+
onKeyDown: function onKeyDown(event) {
|
|
280
|
+
if (match(event, Space)) {
|
|
281
|
+
event.stopPropagation();
|
|
282
|
+
}
|
|
283
|
+
},
|
|
284
|
+
onFocus: function onFocus() {
|
|
285
|
+
setInputFocused(true);
|
|
286
|
+
},
|
|
287
|
+
onBlur: function onBlur() {
|
|
288
|
+
setInputFocused(false);
|
|
405
289
|
}
|
|
406
290
|
});
|
|
291
|
+
var menuProps = getMenuProps({
|
|
292
|
+
'aria-label': ariaLabel
|
|
293
|
+
}, {
|
|
294
|
+
suppressRefError: true
|
|
295
|
+
});
|
|
296
|
+
return /*#__PURE__*/React__default.createElement("div", {
|
|
297
|
+
className: wrapperClasses
|
|
298
|
+
}, titleText ? /*#__PURE__*/React__default.createElement("label", _extends({
|
|
299
|
+
className: titleClasses
|
|
300
|
+
}, labelProps), titleText) : null, /*#__PURE__*/React__default.createElement(ListBox, {
|
|
301
|
+
className: className,
|
|
302
|
+
disabled: disabled,
|
|
303
|
+
light: light,
|
|
304
|
+
ref: ref,
|
|
305
|
+
invalid: invalid,
|
|
306
|
+
invalidText: invalidText,
|
|
307
|
+
warn: warn,
|
|
308
|
+
warnText: warnText,
|
|
309
|
+
isOpen: isOpen,
|
|
310
|
+
size: size
|
|
311
|
+
}, /*#__PURE__*/React__default.createElement("div", {
|
|
312
|
+
className: "".concat(prefix, "--list-box__field")
|
|
313
|
+
}, selectedItem.length > 0 && /*#__PURE__*/React__default.createElement(ListBoxSelection, {
|
|
314
|
+
clearSelection: function clearSelection() {
|
|
315
|
+
_clearSelection();
|
|
316
|
+
|
|
317
|
+
if (textInput.current) {
|
|
318
|
+
textInput.current.focus();
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
selectionCount: selectedItem.length,
|
|
322
|
+
translateWithId: translateWithId,
|
|
323
|
+
disabled: disabled
|
|
324
|
+
}), /*#__PURE__*/React__default.createElement("input", _extends({
|
|
325
|
+
className: inputClasses
|
|
326
|
+
}, rootProps, inputProps, {
|
|
327
|
+
ref: mergeRefs(textInput, rootProps.ref)
|
|
328
|
+
})), invalid && /*#__PURE__*/React__default.createElement(WarningFilled, {
|
|
329
|
+
className: "".concat(prefix, "--list-box__invalid-icon")
|
|
330
|
+
}), showWarning && /*#__PURE__*/React__default.createElement(WarningAltFilled, {
|
|
331
|
+
className: "".concat(prefix, "--list-box__invalid-icon ").concat(prefix, "--list-box__invalid-icon--warning")
|
|
332
|
+
}), inputValue && /*#__PURE__*/React__default.createElement(ListBoxSelection, {
|
|
333
|
+
clearSelection: clearInputValue,
|
|
334
|
+
disabled: disabled,
|
|
335
|
+
translateWithId: translateWithId,
|
|
336
|
+
onMouseUp: function onMouseUp(event) {
|
|
337
|
+
// If we do not stop this event from propagating,
|
|
338
|
+
// it seems like Downshift takes our event and
|
|
339
|
+
// prevents us from getting `onClick` /
|
|
340
|
+
// `clearSelection` from the underlying <button> in
|
|
341
|
+
// ListBoxSelection
|
|
342
|
+
event.stopPropagation();
|
|
343
|
+
}
|
|
344
|
+
}), /*#__PURE__*/React__default.createElement(ListBoxTrigger, _extends({}, buttonProps, {
|
|
345
|
+
isOpen: isOpen,
|
|
346
|
+
translateWithId: translateWithId
|
|
347
|
+
}))), isOpen ? /*#__PURE__*/React__default.createElement(ListBox.Menu, menuProps, sortItems(filterItems(items, {
|
|
348
|
+
itemToString: itemToString,
|
|
349
|
+
inputValue: inputValue
|
|
350
|
+
}), {
|
|
351
|
+
selectedItems: {
|
|
352
|
+
top: selectedItems,
|
|
353
|
+
fixed: [],
|
|
354
|
+
'top-after-reopen': topItems
|
|
355
|
+
}[selectionFeedback],
|
|
356
|
+
itemToString: itemToString,
|
|
357
|
+
compareItems: compareItems,
|
|
358
|
+
locale: locale
|
|
359
|
+
}).map(function (item, index) {
|
|
360
|
+
var itemProps = getItemProps({
|
|
361
|
+
item: item,
|
|
362
|
+
disabled: item.disabled
|
|
363
|
+
});
|
|
364
|
+
var itemText = itemToString(item);
|
|
365
|
+
var isChecked = selectedItem.filter(function (selected) {
|
|
366
|
+
return isEqual(selected, item);
|
|
367
|
+
}).length > 0;
|
|
368
|
+
return /*#__PURE__*/React__default.createElement(ListBox.MenuItem, _extends({
|
|
369
|
+
key: itemProps.id,
|
|
370
|
+
"aria-label": itemText,
|
|
371
|
+
isActive: isChecked,
|
|
372
|
+
isHighlighted: highlightedIndex === index,
|
|
373
|
+
title: itemText
|
|
374
|
+
}, itemProps), /*#__PURE__*/React__default.createElement("div", {
|
|
375
|
+
className: "".concat(prefix, "--checkbox-wrapper")
|
|
376
|
+
}, /*#__PURE__*/React__default.createElement("span", {
|
|
377
|
+
title: useTitleInItem ? itemText : null,
|
|
378
|
+
className: "".concat(prefix, "--checkbox-label"),
|
|
379
|
+
"data-contained-checkbox-state": isChecked,
|
|
380
|
+
id: "".concat(itemProps.id, "-item")
|
|
381
|
+
}, ItemToElement ? /*#__PURE__*/React__default.createElement(ItemToElement, _extends({
|
|
382
|
+
key: itemProps.id
|
|
383
|
+
}, item)) : itemText)));
|
|
384
|
+
})) : null), !inline && !invalid && !warn ? helper : null);
|
|
407
385
|
});
|
|
408
386
|
}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
var open = _ref4.open;
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* programmatically control this `open` prop
|
|
416
|
-
*/
|
|
417
|
-
var prevOpen = state.prevOpen;
|
|
418
|
-
return prevOpen === open ? null : {
|
|
419
|
-
isOpen: open,
|
|
420
|
-
prevOpen: open
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
}]);
|
|
424
|
-
|
|
425
|
-
return FilterableMultiSelect;
|
|
426
|
-
}(React__default.Component);
|
|
427
|
-
|
|
428
|
-
_defineProperty(FilterableMultiSelect, "propTypes", _objectSpread2(_objectSpread2({
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
FilterableMultiSelect.propTypes = _objectSpread2(_objectSpread2({
|
|
429
390
|
/**
|
|
430
391
|
* 'aria-label' of the ListBox component.
|
|
431
392
|
*/
|
|
@@ -529,7 +490,7 @@ _defineProperty(FilterableMultiSelect, "propTypes", _objectSpread2(_objectSpread
|
|
|
529
490
|
* Generic `placeholder` that will be used as the textual representation of
|
|
530
491
|
* what this field is for
|
|
531
492
|
*/
|
|
532
|
-
placeholder: PropTypes.string
|
|
493
|
+
placeholder: PropTypes.string,
|
|
533
494
|
|
|
534
495
|
/**
|
|
535
496
|
* Specify feedback (mode) of the selection.
|
|
@@ -563,11 +524,8 @@ _defineProperty(FilterableMultiSelect, "propTypes", _objectSpread2(_objectSpread
|
|
|
563
524
|
* Provide the text that is displayed when the control is in warning state
|
|
564
525
|
*/
|
|
565
526
|
warnText: PropTypes.node
|
|
566
|
-
})
|
|
567
|
-
|
|
568
|
-
_defineProperty(FilterableMultiSelect, "contextType", FeatureFlagContext);
|
|
569
|
-
|
|
570
|
-
_defineProperty(FilterableMultiSelect, "defaultProps", {
|
|
527
|
+
});
|
|
528
|
+
FilterableMultiSelect.defaultProps = {
|
|
571
529
|
ariaLabel: 'Choose an item',
|
|
572
530
|
compareItems: defaultCompareItems,
|
|
573
531
|
direction: 'bottom',
|
|
@@ -580,6 +538,7 @@ _defineProperty(FilterableMultiSelect, "defaultProps", {
|
|
|
580
538
|
light: false,
|
|
581
539
|
open: false,
|
|
582
540
|
selectionFeedback: 'top-after-reopen'
|
|
583
|
-
}
|
|
541
|
+
};
|
|
542
|
+
var FilterableMultiSelect$1 = FilterableMultiSelect;
|
|
584
543
|
|
|
585
|
-
export { FilterableMultiSelect as default };
|
|
544
|
+
export { FilterableMultiSelect$1 as default };
|