@carbon/react 1.6.0 → 1.8.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.
Files changed (80) hide show
  1. package/es/components/ComposedModal/ComposedModal.js +1 -1
  2. package/es/components/ComposedModal/index.js +4 -4
  3. package/es/components/DataTable/DataTable.js +1 -1
  4. package/es/components/DataTable/Table.js +10 -2
  5. package/es/components/DataTable/TableContainer.js +20 -5
  6. package/es/components/DataTable/TableContext.js +15 -0
  7. package/es/components/DataTable/TableSelectRow.js +1 -1
  8. package/es/components/FileUploader/FileUploader.js +8 -1
  9. package/es/components/FileUploader/FileUploaderButton.js +3 -1
  10. package/es/components/FileUploader/FileUploaderDropContainer.js +3 -1
  11. package/es/components/FileUploader/FileUploaderItem.js +3 -1
  12. package/es/components/Form/Form.js +1 -1
  13. package/es/components/FormGroup/FormGroup.js +4 -4
  14. package/es/components/FormItem/FormItem.js +5 -6
  15. package/es/components/InlineLoading/InlineLoading.js +9 -5
  16. package/es/components/Loading/Loading.js +7 -18
  17. package/es/components/MultiSelect/FilterableMultiSelect.js +345 -386
  18. package/es/components/MultiSelect/index.js +4 -8
  19. package/es/components/Notification/Notification.js +322 -189
  20. package/es/components/Popover/index.js +137 -8
  21. package/es/components/ProgressBar/ProgressBar.js +6 -3
  22. package/es/components/RadioButton/RadioButton.js +58 -99
  23. package/es/components/RadioButton/index.js +2 -8
  24. package/es/components/RadioButtonGroup/RadioButtonGroup.js +72 -121
  25. package/es/components/RadioButtonGroup/index.js +2 -8
  26. package/es/components/Select/Select.js +14 -7
  27. package/es/components/Slider/Slider.js +2 -1
  28. package/es/components/Switch/Switch.js +0 -1
  29. package/es/components/TreeView/TreeView.js +19 -11
  30. package/es/components/UIShell/HeaderMenu.js +1 -1
  31. package/es/components/UIShell/HeaderMenuButton.js +4 -0
  32. package/es/components/UIShell/SideNavDetails.js +8 -3
  33. package/es/components/UIShell/SideNavLink.js +6 -9
  34. package/es/index.js +7 -6
  35. package/es/internal/createClassWrapper.js +2 -5
  36. package/lib/components/ComposedModal/index.js +7 -7
  37. package/lib/components/DataTable/DataTable.js +5 -5
  38. package/lib/components/DataTable/Table.js +9 -1
  39. package/lib/components/DataTable/TableContainer.js +19 -4
  40. package/lib/components/DataTable/TableContext.js +19 -0
  41. package/lib/components/DataTable/TableSelectRow.js +2 -2
  42. package/lib/components/FileUploader/FileUploader.js +8 -1
  43. package/lib/components/FileUploader/FileUploaderButton.js +3 -1
  44. package/lib/components/FileUploader/FileUploaderDropContainer.js +3 -1
  45. package/lib/components/FileUploader/FileUploaderItem.js +3 -1
  46. package/lib/components/Form/Form.js +1 -1
  47. package/lib/components/FormGroup/FormGroup.js +4 -4
  48. package/lib/components/FormItem/FormItem.js +5 -6
  49. package/lib/components/InlineLoading/InlineLoading.js +9 -5
  50. package/lib/components/Loading/Loading.js +6 -17
  51. package/lib/components/MultiSelect/FilterableMultiSelect.js +341 -382
  52. package/lib/components/MultiSelect/index.js +5 -28
  53. package/lib/components/Notification/Notification.js +321 -188
  54. package/lib/components/Popover/index.js +135 -6
  55. package/lib/components/ProgressBar/ProgressBar.js +6 -3
  56. package/lib/components/RadioButton/RadioButton.js +57 -99
  57. package/lib/components/RadioButton/index.js +2 -25
  58. package/lib/components/RadioButtonGroup/RadioButtonGroup.js +68 -117
  59. package/lib/components/RadioButtonGroup/index.js +2 -25
  60. package/lib/components/Select/Select.js +14 -7
  61. package/lib/components/Slider/Slider.js +2 -1
  62. package/lib/components/Switch/Switch.js +0 -1
  63. package/lib/components/TreeView/TreeView.js +18 -10
  64. package/lib/components/UIShell/HeaderMenu.js +1 -0
  65. package/lib/components/UIShell/HeaderMenuButton.js +4 -0
  66. package/lib/components/UIShell/SideNavDetails.js +8 -3
  67. package/lib/components/UIShell/SideNavLink.js +6 -9
  68. package/lib/index.js +83 -83
  69. package/lib/internal/createClassWrapper.js +2 -5
  70. package/package.json +8 -8
  71. package/es/components/MultiSelect/next/FilterableMultiSelect.js +0 -542
  72. package/es/components/Notification/index.js +0 -42
  73. package/es/components/Notification/next/Notification.js +0 -663
  74. package/es/components/RadioButton/next/RadioButton.js +0 -130
  75. package/es/components/RadioButtonGroup/next/RadioButtonGroup.js +0 -141
  76. package/lib/components/MultiSelect/next/FilterableMultiSelect.js +0 -554
  77. package/lib/components/Notification/index.js +0 -51
  78. package/lib/components/Notification/next/Notification.js +0 -677
  79. package/lib/components/RadioButton/next/RadioButton.js +0 -140
  80. package/lib/components/RadioButtonGroup/next/RadioButtonGroup.js +0 -151
@@ -5,23 +5,23 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { inherits as _inherits, createSuper as _createSuper, classCallCheck as _classCallCheck, defineProperty as _defineProperty, assertThisInitialized as _assertThisInitialized, createClass as _createClass, extends as _extends, objectSpread2 as _objectSpread2 } from '../../_virtual/_rollupPluginBabelHelpers.js';
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 setupGetInstanceId from '../../tools/setupGetInstanceId.js';
21
+ import { useId } from '../../internal/useId.js';
22
22
  import { defaultCompareItems, defaultSortItems } from './tools/sorting.js';
23
- import { FeatureFlagContext } from '../FeatureFlags/index.js';
24
- import { PrefixContext } from '../../internal/usePrefix.js';
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 getInstanceId = setupGetInstanceId();
33
-
34
- var FilterableMultiSelect = /*#__PURE__*/function (_React$Component) {
35
- _inherits(FilterableMultiSelect, _React$Component);
36
-
37
- var _super = _createSuper(FilterableMultiSelect);
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
- function FilterableMultiSelect(props) {
40
- var _this;
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
- _classCallCheck(this, FilterableMultiSelect);
129
+ function handleOnMenuChange(forceIsOpen) {
130
+ var nextIsOpen = forceIsOpen !== null && forceIsOpen !== void 0 ? forceIsOpen : !isOpen;
131
+ setIsOpen(nextIsOpen);
43
132
 
44
- _this = _super.call(this, props);
133
+ if (onMenuChange) {
134
+ onMenuChange(nextIsOpen);
135
+ }
136
+ }
45
137
 
46
- _defineProperty(_assertThisInitialized(_this), "handleOnChange", function (changes) {
47
- if (_this.props.onChange) {
48
- _this.props.onChange(changes);
49
- }
50
- });
138
+ function handleOnOuterClick() {
139
+ handleOnMenuChange(false);
140
+ }
51
141
 
52
- _defineProperty(_assertThisInitialized(_this), "handleOnMenuChange", function (isOpen) {
53
- _this.setState(function (state) {
54
- return {
55
- isOpen: isOpen !== null && isOpen !== void 0 ? isOpen : !state.isOpen
56
- };
57
- });
142
+ function handleOnStateChange(changes, downshift) {
143
+ if (changes.isOpen && !isOpen) {
144
+ setTopItems(downshift.selectedItem);
145
+ }
58
146
 
59
- if (_this.props.onMenuChange) {
60
- _this.props.onMenuChange(isOpen);
61
- }
62
- });
147
+ var type = changes.type;
148
+ var stateChangeTypes = Downshift.stateChangeTypes;
63
149
 
64
- _defineProperty(_assertThisInitialized(_this), "handleOnOuterClick", function () {
65
- _this.handleOnMenuChange(false);
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
- _defineProperty(_assertThisInitialized(_this), "handleOnStateChange", function (changes, downshift) {
69
- if (changes.isOpen && !_this.state.isOpen) {
70
- _this.setState({
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
- case stateChangeTypes.keyDownEscape:
94
- _this.handleOnMenuChange(false);
161
+ break;
95
162
 
96
- break;
97
- }
98
- });
163
+ case stateChangeTypes.keyDownEscape:
164
+ handleOnMenuChange(false);
165
+ break;
166
+ }
167
+ }
99
168
 
100
- _defineProperty(_assertThisInitialized(_this), "handleOnInputKeyDown", function (event) {
101
- event.stopPropagation();
102
- });
169
+ function handleOnInputValueChange(inputValue, _ref2) {
170
+ var type = _ref2.type;
103
171
 
104
- _defineProperty(_assertThisInitialized(_this), "handleOnInputValueChange", function (inputValue, _ref) {
105
- var type = _ref.type;
172
+ if (onInputValueChange) {
173
+ onInputValueChange(inputValue);
174
+ }
106
175
 
107
- if (_this.props.onInputValueChange) {
108
- _this.props.onInputValueChange(inputValue);
109
- }
176
+ if (type !== Downshift.stateChangeTypes.changeInput) {
177
+ return;
178
+ }
110
179
 
111
- if (type !== Downshift.stateChangeTypes.changeInput) {
112
- return;
113
- }
180
+ if (Array.isArray(inputValue)) {
181
+ clearInputValue();
182
+ } else {
183
+ setInputValue(inputValue);
184
+ }
114
185
 
115
- _this.setState(function () {
116
- if (Array.isArray(inputValue)) {
117
- return {
118
- inputValue: ''
119
- };
120
- }
186
+ if (inputValue && !isOpen) {
187
+ handleOnMenuChange(true);
188
+ } else if (!inputValue && isOpen) {
189
+ handleOnMenuChange(false);
190
+ }
191
+ }
121
192
 
122
- return {
123
- inputValue: inputValue || ''
124
- };
125
- });
193
+ function clearInputValue() {
194
+ setInputValue('');
126
195
 
127
- if (inputValue && !_this.state.isOpen) {
128
- _this.handleOnMenuChange(true);
129
- } else if (!inputValue && _this.state.isOpen) {
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
- _createClass(FilterableMultiSelect, [{
157
- key: "render",
158
- value: function render() {
159
- var _this2 = this;
160
-
161
- var _this$state = this.state,
162
- highlightedIndex = _this$state.highlightedIndex,
163
- isOpen = _this$state.isOpen,
164
- inputValue = _this$state.inputValue;
165
- var _this$props = this.props,
166
- ariaLabel = _this$props.ariaLabel,
167
- containerClassName = _this$props.className,
168
- direction = _this$props.direction,
169
- disabled = _this$props.disabled,
170
- filterItems = _this$props.filterItems,
171
- items = _this$props.items,
172
- itemToElement = _this$props.itemToElement,
173
- itemToString = _this$props.itemToString,
174
- titleText = _this$props.titleText,
175
- hideLabel = _this$props.hideLabel,
176
- helperText = _this$props.helperText,
177
- type = _this$props.type,
178
- initialSelectedItems = _this$props.initialSelectedItems,
179
- id = _this$props.id,
180
- locale = _this$props.locale,
181
- size = _this$props.size,
182
- placeholder = _this$props.placeholder,
183
- sortItems = _this$props.sortItems,
184
- compareItems = _this$props.compareItems,
185
- light = _this$props.light,
186
- invalid = _this$props.invalid,
187
- invalidText = _this$props.invalidText,
188
- warn = _this$props.warn,
189
- warnText = _this$props.warnText,
190
- useTitleInItem = _this$props.useTitleInItem,
191
- translateWithId = _this$props.translateWithId,
192
- downshiftProps = _this$props.downshiftProps;
193
- var inline = type === 'inline';
194
- var showWarning = !invalid && warn; // needs to be capitalized for react to render it correctly
195
-
196
- var ItemToElement = itemToElement;
197
- var scope = this.context;
198
- var enabled;
199
-
200
- if (scope.enabled) {
201
- enabled = scope.enabled('enable-v11-release');
202
- }
203
-
204
- return /*#__PURE__*/React__default.createElement(PrefixContext.Consumer, null, function (prefix) {
205
- var _cx, _cx2, _cx3, _cx4;
206
-
207
- 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));
208
- var helperId = !helperText ? undefined : "filterablemultiselect-helper-text-".concat(_this2.filterableMultiSelectInstanceId);
209
- var labelId = "".concat(id, "-label");
210
- 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));
211
- var helperClasses = cx((_cx3 = {}, _defineProperty(_cx3, "".concat(prefix, "--form__helper-text"), true), _defineProperty(_cx3, "".concat(prefix, "--form__helper-text--disabled"), disabled), _cx3));
212
- var inputClasses = cx((_cx4 = {}, _defineProperty(_cx4, "".concat(prefix, "--text-input"), true), _defineProperty(_cx4, "".concat(prefix, "--text-input--empty"), !_this2.state.inputValue), _defineProperty(_cx4, "".concat(prefix, "--text-input--light"), light), _cx4));
213
- var helper = helperText ? /*#__PURE__*/React__default.createElement("div", {
214
- id: helperId,
215
- className: helperClasses
216
- }, helperText) : null;
217
- var menuId = "".concat(id, "__menu");
218
- var inputId = "".concat(id, "-input");
219
- return /*#__PURE__*/React__default.createElement(Selection, {
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
- onChange: _this2.handleOnChange,
222
- initialSelectedItems: initialSelectedItems,
223
- render: function render(_ref2) {
224
- var selectedItems = _ref2.selectedItems,
225
- onItemChange = _ref2.onItemChange,
226
- _clearSelection = _ref2.clearSelection;
227
- return /*#__PURE__*/React__default.createElement(Downshift, _extends({}, downshiftProps, {
228
- highlightedIndex: highlightedIndex,
229
- id: id,
230
- isOpen: isOpen,
231
- inputValue: inputValue,
232
- onInputValueChange: _this2.handleOnInputValueChange,
233
- onChange: function onChange(selectedItem) {
234
- if (selectedItem !== null) {
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
- key: "getDerivedStateFromProps",
411
- value: function getDerivedStateFromProps(_ref4, state) {
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.isRequired,
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 };