carbon-addons-iot-react 2.98.2 → 2.100.1
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/css/carbon-addons-iot-react.css +39 -33
- package/css/carbon-addons-iot-react.css.map +1 -1
- package/es/node_modules/carbon-components-react/es/components/ListBox/ListBox.js +98 -0
- package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxField.js +57 -0
- package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenu.js +43 -0
- package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenuIcon.js +55 -0
- package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenuItem.js +58 -0
- package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxPropTypes.js +12 -0
- package/es/node_modules/carbon-components-react/es/components/ListBox/ListBoxSelection.js +96 -0
- package/es/node_modules/carbon-components-react/es/components/ListBox/index.js +21 -0
- package/es/node_modules/carbon-components-react/es/prop-types/childrenOfType.js +36 -0
- package/es/node_modules/carbon-components-react/es/prop-types/tools/createChainableTypeChecker.js +38 -0
- package/es/node_modules/carbon-components-react/es/prop-types/tools/getDisplayName.js +37 -0
- package/es/src/components/ComboBox/CarbonComboBox.jsx +882 -0
- package/es/src/components/ComboBox/ComboBox.jsx +375 -0
- package/es/src/components/ComposedModal/ComposedModal.jsx +5 -1
- package/es/src/index.js +2 -1
- package/lib/css/carbon-addons-iot-react.css +39 -33
- package/lib/css/carbon-addons-iot-react.css.map +1 -1
- package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBox.js +103 -0
- package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxField.js +62 -0
- package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenu.js +48 -0
- package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenuIcon.js +60 -0
- package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxMenuItem.js +63 -0
- package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxPropTypes.js +17 -0
- package/lib/node_modules/carbon-components-react/es/components/ListBox/ListBoxSelection.js +101 -0
- package/lib/node_modules/carbon-components-react/es/components/ListBox/index.js +23 -0
- package/lib/node_modules/carbon-components-react/es/prop-types/childrenOfType.js +41 -0
- package/lib/node_modules/carbon-components-react/es/prop-types/tools/createChainableTypeChecker.js +40 -0
- package/lib/node_modules/carbon-components-react/es/prop-types/tools/getDisplayName.js +39 -0
- package/lib/scss/components/ComboBox/_combo-box.scss +43 -0
- package/lib/scss/components/ComposedModal/_composed-modal.scss +5 -0
- package/lib/scss/components/Tag/_tag.scss +11 -0
- package/lib/scss/styles.scss +1 -44
- package/lib/src/components/ComboBox/CarbonComboBox.jsx +889 -0
- package/lib/src/components/ComboBox/ComboBox.jsx +380 -0
- package/lib/src/components/ComposedModal/ComposedModal.jsx +5 -1
- package/lib/src/index.js +2 -1
- package/package.json +7 -5
- package/scss/components/ComboBox/_combo-box.scss +43 -0
- package/scss/components/ComposedModal/_composed-modal.scss +5 -0
- package/scss/components/Tag/_tag.scss +11 -0
- package/scss/styles.scss +1 -44
- package/umd/carbon-addons-iot-react.js +3327 -237
|
@@ -0,0 +1,882 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import classnames from 'classnames';
|
|
4
|
+
import { WarningFilled16, Checkmark16 } from '@carbon/icons-react';
|
|
5
|
+
import 'core-js/modules/es.array.filter';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
7
|
+
import { settings } from 'carbon-components';
|
|
8
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
9
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
10
|
+
import 'core-js/modules/es.array.map';
|
|
11
|
+
import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
|
|
12
|
+
import _createClass from '@babel/runtime/helpers/createClass';
|
|
13
|
+
import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
|
|
14
|
+
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
15
|
+
import _assertThisInitialized from '@babel/runtime/helpers/assertThisInitialized';
|
|
16
|
+
import _inherits from '@babel/runtime/helpers/inherits';
|
|
17
|
+
import 'core-js/modules/es.array.index-of';
|
|
18
|
+
import Downshift from 'downshift';
|
|
19
|
+
import ListBox from '../../../node_modules/carbon-components-react/es/components/ListBox/index.js';
|
|
20
|
+
|
|
21
|
+
var keys = {
|
|
22
|
+
Tab: {
|
|
23
|
+
key: 'Tab',
|
|
24
|
+
which: 9,
|
|
25
|
+
keyCode: 9
|
|
26
|
+
},
|
|
27
|
+
Enter: {
|
|
28
|
+
key: 'Enter',
|
|
29
|
+
which: 13,
|
|
30
|
+
keyCode: 13
|
|
31
|
+
},
|
|
32
|
+
Escape: {
|
|
33
|
+
key: ['Escape', // IE11 Escape
|
|
34
|
+
'Esc'],
|
|
35
|
+
which: 27,
|
|
36
|
+
keyCode: 27
|
|
37
|
+
},
|
|
38
|
+
Space: {
|
|
39
|
+
key: ' ',
|
|
40
|
+
which: 32,
|
|
41
|
+
keyCode: 32
|
|
42
|
+
},
|
|
43
|
+
PageUp: {
|
|
44
|
+
key: 'PageUp',
|
|
45
|
+
which: 33,
|
|
46
|
+
keyCode: 33
|
|
47
|
+
},
|
|
48
|
+
PageDown: {
|
|
49
|
+
key: 'PageDown',
|
|
50
|
+
which: 34,
|
|
51
|
+
keyCode: 34
|
|
52
|
+
},
|
|
53
|
+
End: {
|
|
54
|
+
key: 'End',
|
|
55
|
+
which: 35,
|
|
56
|
+
keyCode: 35
|
|
57
|
+
},
|
|
58
|
+
Home: {
|
|
59
|
+
key: 'Home',
|
|
60
|
+
which: 36,
|
|
61
|
+
keyCode: 36
|
|
62
|
+
},
|
|
63
|
+
ArrowLeft: {
|
|
64
|
+
key: 'ArrowLeft',
|
|
65
|
+
which: 37,
|
|
66
|
+
keyCode: 37
|
|
67
|
+
},
|
|
68
|
+
ArrowUp: {
|
|
69
|
+
key: 'ArrowUp',
|
|
70
|
+
which: 38,
|
|
71
|
+
keyCode: 38
|
|
72
|
+
},
|
|
73
|
+
ArrowRight: {
|
|
74
|
+
key: 'ArrowRight',
|
|
75
|
+
which: 39,
|
|
76
|
+
keyCode: 39
|
|
77
|
+
},
|
|
78
|
+
ArrowDown: {
|
|
79
|
+
key: 'ArrowDown',
|
|
80
|
+
which: 40,
|
|
81
|
+
keyCode: 40
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var ListBoxPropTypes = {
|
|
85
|
+
ListBoxType: PropTypes.oneOf(['default', 'inline']),
|
|
86
|
+
ListBoxSize: PropTypes.oneOf(['sm', 'xl'])
|
|
87
|
+
};
|
|
88
|
+
var prefix = settings.prefix;
|
|
89
|
+
/**
|
|
90
|
+
* Check to see if the given key matches the corresponding keyboard event. Also
|
|
91
|
+
* supports passing in the value directly if you can't used the given event.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* import * as keys from '../keys';
|
|
95
|
+
* import { matches } from '../match';
|
|
96
|
+
*
|
|
97
|
+
* function handleOnKeyDown(event) {
|
|
98
|
+
* if (match(event, keys.Enter) {
|
|
99
|
+
* // ...
|
|
100
|
+
* }
|
|
101
|
+
* }
|
|
102
|
+
*
|
|
103
|
+
* @param {Event|number|string} eventOrCode
|
|
104
|
+
* @param {Key} key
|
|
105
|
+
* @returns {boolean}
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
/* istanbul ignore next */
|
|
109
|
+
|
|
110
|
+
function match(eventOrCode) {
|
|
111
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
112
|
+
key = _ref.key,
|
|
113
|
+
which = _ref.which,
|
|
114
|
+
keyCode = _ref.keyCode;
|
|
115
|
+
|
|
116
|
+
if (typeof eventOrCode === 'string') {
|
|
117
|
+
return eventOrCode === key;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (typeof eventOrCode === 'number') {
|
|
121
|
+
return eventOrCode === which || eventOrCode === keyCode;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (eventOrCode.key && Array.isArray(key)) {
|
|
125
|
+
return key.indexOf(eventOrCode.key) !== -1;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return eventOrCode.key === key || eventOrCode.which === which || eventOrCode.keyCode === keyCode;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Generic utility to initialize a method that will return a unique instance id
|
|
132
|
+
* for a component.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
function setupGetInstanceId() {
|
|
136
|
+
var instanceId = 0;
|
|
137
|
+
return function getInstanceId() {
|
|
138
|
+
return ++instanceId; // eslint-disable-line no-plusplus
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
var defaultItemToString = function defaultItemToString(item) {
|
|
142
|
+
if (typeof item === 'string') {
|
|
143
|
+
return item;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return item && item.label;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
var defaultShouldFilterItem = function defaultShouldFilterItem() {
|
|
150
|
+
return true;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
var getInputValue = function getInputValue(props, state) {
|
|
154
|
+
if (props.selectedItem) {
|
|
155
|
+
return props.itemToString(props.selectedItem);
|
|
156
|
+
} // TODO: consistent `initialSelectedItem` behavior with other listbox components in v11
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
if (props.initialSelectedItem) {
|
|
160
|
+
return props.itemToString(props.initialSelectedItem);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return state.inputValue || '';
|
|
164
|
+
}; // Since we always provide a func this will never be hit
|
|
165
|
+
|
|
166
|
+
/* istanbul ignore next */
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
var defaultFindHighlightedIndex = function defaultFindHighlightedIndex(_ref2, inputValue) {
|
|
170
|
+
var items = _ref2.items,
|
|
171
|
+
itemToString = _ref2.itemToString;
|
|
172
|
+
|
|
173
|
+
if (!inputValue) {
|
|
174
|
+
return -1;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
var searchValue = inputValue.toLowerCase(); // eslint-disable-next-line no-plusplus
|
|
178
|
+
|
|
179
|
+
for (var i = 0; i < items.length; i++) {
|
|
180
|
+
var item = itemToString(items[i]).toLowerCase();
|
|
181
|
+
|
|
182
|
+
if (item.indexOf(searchValue) !== -1 && searchValue.length > 1) {
|
|
183
|
+
return i;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return -1;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
var getInstanceId = setupGetInstanceId();
|
|
191
|
+
/* eslint react/require-default-props: 0 */
|
|
192
|
+
|
|
193
|
+
var ComboBox = /*#__PURE__*/function (_React$Component) {
|
|
194
|
+
_inherits(ComboBox, _React$Component);
|
|
195
|
+
|
|
196
|
+
_createClass(ComboBox, null, [{
|
|
197
|
+
key: "getDerivedStateFromProps",
|
|
198
|
+
value: function getDerivedStateFromProps(nextProps, state) {
|
|
199
|
+
var prevSelectedItem = state.prevSelectedItem,
|
|
200
|
+
doneInitialSelectedItem = state.doneInitialSelectedItem;
|
|
201
|
+
var selectedItem = nextProps.selectedItem;
|
|
202
|
+
|
|
203
|
+
if (!doneInitialSelectedItem || prevSelectedItem !== selectedItem) {
|
|
204
|
+
return {
|
|
205
|
+
doneInitialSelectedItem: true,
|
|
206
|
+
prevSelectedItem: selectedItem,
|
|
207
|
+
inputValue: getInputValue(nextProps, state)
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}]);
|
|
214
|
+
|
|
215
|
+
function ComboBox(props) {
|
|
216
|
+
var _this;
|
|
217
|
+
|
|
218
|
+
_classCallCheck(this, ComboBox);
|
|
219
|
+
|
|
220
|
+
_this = _possibleConstructorReturn(this, _getPrototypeOf(ComboBox).call(this, props));
|
|
221
|
+
|
|
222
|
+
_defineProperty(_assertThisInitialized(_this), "filterItems", function (items, itemToString, inputValue) {
|
|
223
|
+
return items.filter(function (item) {
|
|
224
|
+
return _this.props.shouldFilterItem({
|
|
225
|
+
item: item,
|
|
226
|
+
itemToString: itemToString,
|
|
227
|
+
inputValue: inputValue
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
_defineProperty(_assertThisInitialized(_this), "handleOnChange", function (selectedItem) {
|
|
233
|
+
if (_this.props.onChange) {
|
|
234
|
+
_this.props.onChange({
|
|
235
|
+
selectedItem: selectedItem
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
_defineProperty(_assertThisInitialized(_this), "handleOnInputValueChange", function (inputValue) {
|
|
241
|
+
var onInputChange = _this.props.onInputChange;
|
|
242
|
+
|
|
243
|
+
_this.setState(function () {
|
|
244
|
+
return {
|
|
245
|
+
// Default to empty string if we have a false-y `inputValue`
|
|
246
|
+
inputValue: inputValue || ''
|
|
247
|
+
};
|
|
248
|
+
}, function () {
|
|
249
|
+
if (onInputChange) {
|
|
250
|
+
onInputChange(inputValue);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
_defineProperty(_assertThisInitialized(_this), "handleOnStateChange", function (newState, _ref3) {
|
|
256
|
+
var setHighlightedIndex = _ref3.setHighlightedIndex,
|
|
257
|
+
highlightedIndex = _ref3.highlightedIndex;
|
|
258
|
+
|
|
259
|
+
_this.props.onHighligtedIndexChange(highlightedIndex);
|
|
260
|
+
|
|
261
|
+
var findHighlightedIndex = _this.props.findHighlightedIndex || defaultFindHighlightedIndex;
|
|
262
|
+
|
|
263
|
+
if (Object.prototype.hasOwnProperty.call(newState, 'inputValue')) {
|
|
264
|
+
var inputValue = newState.inputValue;
|
|
265
|
+
setHighlightedIndex(findHighlightedIndex(_this.props, inputValue));
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
_defineProperty(_assertThisInitialized(_this), "onToggleClick", function (isOpen) {
|
|
270
|
+
return function (event) {
|
|
271
|
+
if (event.target === _this.textInput.current && isOpen) {
|
|
272
|
+
// eslint-disable-next-line no-param-reassign
|
|
273
|
+
event.preventDownshiftDefault = true;
|
|
274
|
+
event.persist();
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
_this.textInput = /*#__PURE__*/React.createRef();
|
|
280
|
+
_this.comboBoxInstanceId = getInstanceId();
|
|
281
|
+
_this.state = {
|
|
282
|
+
inputValue: getInputValue(props, {})
|
|
283
|
+
};
|
|
284
|
+
return _this;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
_createClass(ComboBox, [{
|
|
288
|
+
key: "render",
|
|
289
|
+
value: function render() {
|
|
290
|
+
var _this2 = this;
|
|
291
|
+
|
|
292
|
+
var _this$props = this.props,
|
|
293
|
+
containerClassName = _this$props.className,
|
|
294
|
+
disabled = _this$props.disabled,
|
|
295
|
+
id = _this$props.id,
|
|
296
|
+
items = _this$props.items,
|
|
297
|
+
itemToString = _this$props.itemToString,
|
|
298
|
+
itemToElement = _this$props.itemToElement,
|
|
299
|
+
titleText = _this$props.titleText,
|
|
300
|
+
helperText = _this$props.helperText,
|
|
301
|
+
placeholder = _this$props.placeholder,
|
|
302
|
+
initialSelectedItem = _this$props.initialSelectedItem,
|
|
303
|
+
selectedItem = _this$props.selectedItem,
|
|
304
|
+
ariaLabel = _this$props.ariaLabel,
|
|
305
|
+
translateWithId = _this$props.translateWithId,
|
|
306
|
+
invalid = _this$props.invalid,
|
|
307
|
+
invalidText = _this$props.invalidText,
|
|
308
|
+
light = _this$props.light,
|
|
309
|
+
type = _this$props.type,
|
|
310
|
+
size = _this$props.size,
|
|
311
|
+
shouldFilterItem = _this$props.shouldFilterItem,
|
|
312
|
+
onChange = _this$props.onChange,
|
|
313
|
+
onInputChange = _this$props.onInputChange,
|
|
314
|
+
downshiftProps = _this$props.downshiftProps,
|
|
315
|
+
direction = _this$props.direction,
|
|
316
|
+
onHighligtedIndexChange = _this$props.onHighligtedIndexChange,
|
|
317
|
+
findHighlightedIndex = _this$props.findHighlightedIndex,
|
|
318
|
+
editOptionText = _this$props.editOptionText,
|
|
319
|
+
rest = _objectWithoutProperties(_this$props, ["className", "disabled", "id", "items", "itemToString", "itemToElement", "titleText", "helperText", "placeholder", "initialSelectedItem", "selectedItem", "ariaLabel", "translateWithId", "invalid", "invalidText", "light", "type", "size", "shouldFilterItem", "onChange", "onInputChange", "downshiftProps", "direction", "onHighligtedIndexChange", "findHighlightedIndex", "editOptionText"]);
|
|
320
|
+
|
|
321
|
+
var inputValue = this.state.inputValue;
|
|
322
|
+
var className = classnames("".concat(prefix, "--combo-box"), containerClassName, _defineProperty({}, "".concat(prefix, "--list-box--up"), direction === 'top'));
|
|
323
|
+
var titleClasses = classnames("".concat(prefix, "--label"), _defineProperty({}, "".concat(prefix, "--label--disabled"), disabled));
|
|
324
|
+
var comboBoxHelperId = !helperText ? undefined : "combobox-helper-text-".concat(this.comboBoxInstanceId);
|
|
325
|
+
var comboBoxLabelId = "combobox-label-".concat(this.comboBoxInstanceId);
|
|
326
|
+
var title = titleText ?
|
|
327
|
+
/*#__PURE__*/
|
|
328
|
+
// eslint-disable-next-line jsx-a11y/label-has-for
|
|
329
|
+
React.createElement("label", {
|
|
330
|
+
id: comboBoxLabelId,
|
|
331
|
+
htmlFor: id,
|
|
332
|
+
className: titleClasses
|
|
333
|
+
}, titleText) : null;
|
|
334
|
+
var helperClasses = classnames("".concat(prefix, "--form__helper-text"), _defineProperty({}, "".concat(prefix, "--form__helper-text--disabled"), disabled));
|
|
335
|
+
var helper = helperText ? /*#__PURE__*/React.createElement("div", {
|
|
336
|
+
id: comboBoxHelperId,
|
|
337
|
+
className: helperClasses
|
|
338
|
+
}, helperText) : null;
|
|
339
|
+
var wrapperClasses = classnames("".concat(prefix, "--list-box__wrapper"));
|
|
340
|
+
var comboBoxA11yId = "combobox-a11y-".concat(this.comboBoxInstanceId);
|
|
341
|
+
var inputClasses = classnames("".concat(prefix, "--text-input"), _defineProperty({}, "".concat(prefix, "--text-input--empty"), !inputValue)); // needs to be Capitalized for react to render it correctly
|
|
342
|
+
|
|
343
|
+
var ItemToElement = itemToElement;
|
|
344
|
+
var input = /*#__PURE__*/React.createElement(Downshift, _extends({}, downshiftProps, {
|
|
345
|
+
onChange: this.handleOnChange,
|
|
346
|
+
onInputValueChange: this.handleOnInputValueChange,
|
|
347
|
+
onStateChange: this.handleOnStateChange,
|
|
348
|
+
inputValue: inputValue || '',
|
|
349
|
+
itemToString: itemToString,
|
|
350
|
+
initialIsOpen: false,
|
|
351
|
+
defaultSelectedItem: initialSelectedItem,
|
|
352
|
+
selectedItem: selectedItem
|
|
353
|
+
}), function (_ref4) {
|
|
354
|
+
var getButtonProps = _ref4.getButtonProps,
|
|
355
|
+
getInputProps = _ref4.getInputProps,
|
|
356
|
+
getItemProps = _ref4.getItemProps,
|
|
357
|
+
getRootProps = _ref4.getRootProps,
|
|
358
|
+
isOpen = _ref4.isOpen,
|
|
359
|
+
inputValue = _ref4.inputValue,
|
|
360
|
+
selectedItem = _ref4.selectedItem,
|
|
361
|
+
highlightedIndex = _ref4.highlightedIndex,
|
|
362
|
+
clearSelection = _ref4.clearSelection,
|
|
363
|
+
toggleMenu = _ref4.toggleMenu;
|
|
364
|
+
// console.log({ highlightedIndex });
|
|
365
|
+
return /*#__PURE__*/React.createElement(ListBox, _extends({
|
|
366
|
+
className: className,
|
|
367
|
+
disabled: disabled,
|
|
368
|
+
invalid: invalid,
|
|
369
|
+
id: comboBoxA11yId,
|
|
370
|
+
"aria-label": ariaLabel,
|
|
371
|
+
invalidText: invalidText,
|
|
372
|
+
isOpen: isOpen,
|
|
373
|
+
light: light,
|
|
374
|
+
size: size
|
|
375
|
+
}, getRootProps({
|
|
376
|
+
refKey: 'innerRef'
|
|
377
|
+
})), /*#__PURE__*/React.createElement(ListBox.Field, _extends({
|
|
378
|
+
id: id,
|
|
379
|
+
disabled: disabled,
|
|
380
|
+
"aria-labelledby": comboBoxLabelId,
|
|
381
|
+
"aria-describedby": comboBoxHelperId
|
|
382
|
+
}, getButtonProps({
|
|
383
|
+
disabled: disabled,
|
|
384
|
+
onClick: _this2.onToggleClick(isOpen)
|
|
385
|
+
})), /*#__PURE__*/React.createElement("input", _extends({
|
|
386
|
+
className: inputClasses,
|
|
387
|
+
"aria-labelledby": comboBoxA11yId,
|
|
388
|
+
tabIndex: "0",
|
|
389
|
+
"aria-disabled": disabled,
|
|
390
|
+
"aria-controls": isOpen ? "".concat(id, "__menu") : null,
|
|
391
|
+
"aria-owns": isOpen ? "".concat(id, "__menu") : null,
|
|
392
|
+
"aria-autocomplete": "list",
|
|
393
|
+
ref: _this2.textInput,
|
|
394
|
+
title: inputValue
|
|
395
|
+
}, rest, getInputProps({
|
|
396
|
+
disabled: disabled,
|
|
397
|
+
id: id,
|
|
398
|
+
placeholder: placeholder,
|
|
399
|
+
onKeyDown: function onKeyDown(event) {
|
|
400
|
+
if (match(event, keys.Space)) {
|
|
401
|
+
event.stopPropagation();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (match(event, keys.Enter)) {
|
|
405
|
+
toggleMenu();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}))), invalid && /*#__PURE__*/React.createElement(WarningFilled16, {
|
|
409
|
+
className: "".concat(prefix, "--list-box__invalid-icon")
|
|
410
|
+
}), inputValue && /*#__PURE__*/React.createElement(ListBox.Selection, {
|
|
411
|
+
clearSelection: clearSelection,
|
|
412
|
+
translateWithId: translateWithId,
|
|
413
|
+
disabled: disabled
|
|
414
|
+
}), /*#__PURE__*/React.createElement(ListBox.MenuIcon, {
|
|
415
|
+
isOpen: isOpen,
|
|
416
|
+
translateWithId: translateWithId
|
|
417
|
+
})), /*#__PURE__*/React.createElement(ListBox.Menu, {
|
|
418
|
+
"aria-label": ariaLabel,
|
|
419
|
+
id: id
|
|
420
|
+
}, _this2.filterItems(items, itemToString, inputValue).map(function (item, index) {
|
|
421
|
+
var itemProps = getItemProps({
|
|
422
|
+
item: item,
|
|
423
|
+
index: index
|
|
424
|
+
});
|
|
425
|
+
return /*#__PURE__*/React.createElement(ListBox.MenuItem, _extends({
|
|
426
|
+
key: itemProps.id,
|
|
427
|
+
"data-text": editOptionText,
|
|
428
|
+
isActive: selectedItem === item,
|
|
429
|
+
isHighlighted: highlightedIndex === index || selectedItem && selectedItem.id === item.id || false,
|
|
430
|
+
title: itemToElement ? item.text : itemToString(item)
|
|
431
|
+
}, itemProps), itemToElement ? /*#__PURE__*/React.createElement(ItemToElement, _extends({
|
|
432
|
+
key: itemProps.id
|
|
433
|
+
}, item)) : itemToString(item), selectedItem === item && /*#__PURE__*/React.createElement(Checkmark16, {
|
|
434
|
+
className: "".concat(prefix, "--list-box__menu-item__selected-icon")
|
|
435
|
+
}));
|
|
436
|
+
})));
|
|
437
|
+
});
|
|
438
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
439
|
+
className: wrapperClasses
|
|
440
|
+
}, title, helper, input);
|
|
441
|
+
}
|
|
442
|
+
}]);
|
|
443
|
+
|
|
444
|
+
return ComboBox;
|
|
445
|
+
}(React.Component);
|
|
446
|
+
|
|
447
|
+
_defineProperty(ComboBox, "propTypes", {
|
|
448
|
+
/**
|
|
449
|
+
* 'aria-label' of the ListBox component.
|
|
450
|
+
*/
|
|
451
|
+
ariaLabel: PropTypes.string,
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* An optional className to add to the container node
|
|
455
|
+
*/
|
|
456
|
+
className: PropTypes.string,
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Specify if the control should be disabled, or not
|
|
460
|
+
*/
|
|
461
|
+
disabled: PropTypes.bool,
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Specify a custom `id` for the input
|
|
465
|
+
*/
|
|
466
|
+
id: PropTypes.string.isRequired,
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Allow users to pass in an arbitrary item or a string (in case their items are an array of strings)
|
|
470
|
+
* from their collection that are pre-selected
|
|
471
|
+
*/
|
|
472
|
+
initialSelectedItem: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* We try to stay as generic as possible here to allow individuals to pass
|
|
476
|
+
* in a collection of whatever kind of data structure they prefer
|
|
477
|
+
*/
|
|
478
|
+
items: PropTypes.array.isRequired,
|
|
479
|
+
// eslint-disable-line react/forbid-prop-types
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Helper function passed to downshift that allows the library to render a
|
|
483
|
+
* given item to a string label. By default, it extracts the `label` field
|
|
484
|
+
* from a given item to serve as the item label in the list
|
|
485
|
+
*/
|
|
486
|
+
itemToString: PropTypes.func,
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Optional function to render items as custom components instead of strings.
|
|
490
|
+
* Defaults to null and is overriden by a getter
|
|
491
|
+
*/
|
|
492
|
+
itemToElement: PropTypes.func,
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* `onChange` is a utility for this controlled component to communicate to a
|
|
496
|
+
* consuming component when a specific dropdown item is selected.
|
|
497
|
+
* @param {{ selectedItem }}
|
|
498
|
+
*/
|
|
499
|
+
onChange: PropTypes.func.isRequired,
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Used to provide a placeholder text node before a user enters any input.
|
|
503
|
+
* This is only present if the control has no items selected
|
|
504
|
+
*/
|
|
505
|
+
placeholder: PropTypes.string.isRequired,
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Specify your own filtering logic by passing in a `shouldFilterItem`
|
|
509
|
+
* function that takes in the current input and an item and passes back
|
|
510
|
+
* whether or not the item should be filtered.
|
|
511
|
+
*/
|
|
512
|
+
shouldFilterItem: PropTypes.func,
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Specify if the currently selected value is invalid.
|
|
516
|
+
*/
|
|
517
|
+
invalid: PropTypes.bool,
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Message which is displayed if the value is invalid.
|
|
521
|
+
*/
|
|
522
|
+
invalidText: PropTypes.string,
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* For full control of the selection
|
|
526
|
+
*/
|
|
527
|
+
selectedItem: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Specify a custom translation function that takes in a message identifier
|
|
531
|
+
* and returns the localized string for the message
|
|
532
|
+
*/
|
|
533
|
+
translateWithId: PropTypes.func,
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Currently supports either the default type, or an inline variant
|
|
537
|
+
*/
|
|
538
|
+
type: ListBoxPropTypes.ListBoxType,
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Specify the size of the ListBox. Currently supports either `sm`, `lg` or `xl` as an option.
|
|
542
|
+
*/
|
|
543
|
+
size: ListBoxPropTypes.ListBoxSize,
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Callback function to notify consumer when the text input changes.
|
|
547
|
+
* This provides support to change available items based on the text.
|
|
548
|
+
* @param {string} inputText
|
|
549
|
+
*/
|
|
550
|
+
onInputChange: PropTypes.func,
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* should use "light theme" (white background)?
|
|
554
|
+
*/
|
|
555
|
+
light: PropTypes.bool,
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Additional props passed to Downshift
|
|
559
|
+
*/
|
|
560
|
+
downshiftProps: PropTypes.shape(Downshift.propTypes),
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Specify the direction of the combobox dropdown. Can be either top or bottom.
|
|
564
|
+
*/
|
|
565
|
+
direction: PropTypes.oneOf(['top', 'bottom']),
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Optional callback to pass the highlighted index to parent
|
|
569
|
+
*/
|
|
570
|
+
onHighligtedIndexChange: PropTypes.func,
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Optional func to change behavior of highlighted index
|
|
574
|
+
*/
|
|
575
|
+
findHighlightedIndex: PropTypes.func,
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* String to pass to input field option
|
|
579
|
+
*/
|
|
580
|
+
editOptionText: PropTypes.string
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
_defineProperty(ComboBox, "defaultProps", {
|
|
584
|
+
disabled: false,
|
|
585
|
+
itemToString: defaultItemToString,
|
|
586
|
+
itemToElement: null,
|
|
587
|
+
shouldFilterItem: defaultShouldFilterItem,
|
|
588
|
+
type: 'default',
|
|
589
|
+
ariaLabel: 'Choose an item',
|
|
590
|
+
light: false,
|
|
591
|
+
direction: 'bottom',
|
|
592
|
+
editOptionText: '+ Add'
|
|
593
|
+
});
|
|
594
|
+
ComboBox.__docgenInfo = {
|
|
595
|
+
"description": "",
|
|
596
|
+
"methods": [{
|
|
597
|
+
"name": "filterItems",
|
|
598
|
+
"docblock": null,
|
|
599
|
+
"modifiers": [],
|
|
600
|
+
"params": [{
|
|
601
|
+
"name": "items",
|
|
602
|
+
"type": null
|
|
603
|
+
}, {
|
|
604
|
+
"name": "itemToString",
|
|
605
|
+
"type": null
|
|
606
|
+
}, {
|
|
607
|
+
"name": "inputValue",
|
|
608
|
+
"type": null
|
|
609
|
+
}],
|
|
610
|
+
"returns": null
|
|
611
|
+
}, {
|
|
612
|
+
"name": "handleOnChange",
|
|
613
|
+
"docblock": null,
|
|
614
|
+
"modifiers": [],
|
|
615
|
+
"params": [{
|
|
616
|
+
"name": "selectedItem",
|
|
617
|
+
"type": null
|
|
618
|
+
}],
|
|
619
|
+
"returns": null
|
|
620
|
+
}, {
|
|
621
|
+
"name": "handleOnInputValueChange",
|
|
622
|
+
"docblock": null,
|
|
623
|
+
"modifiers": [],
|
|
624
|
+
"params": [{
|
|
625
|
+
"name": "inputValue",
|
|
626
|
+
"type": null
|
|
627
|
+
}],
|
|
628
|
+
"returns": null
|
|
629
|
+
}, {
|
|
630
|
+
"name": "handleOnStateChange",
|
|
631
|
+
"docblock": null,
|
|
632
|
+
"modifiers": [],
|
|
633
|
+
"params": [{
|
|
634
|
+
"name": "newState",
|
|
635
|
+
"type": null
|
|
636
|
+
}, {
|
|
637
|
+
"name": "{ setHighlightedIndex, highlightedIndex }",
|
|
638
|
+
"type": null
|
|
639
|
+
}],
|
|
640
|
+
"returns": null
|
|
641
|
+
}, {
|
|
642
|
+
"name": "onToggleClick",
|
|
643
|
+
"docblock": null,
|
|
644
|
+
"modifiers": [],
|
|
645
|
+
"params": [{
|
|
646
|
+
"name": "isOpen",
|
|
647
|
+
"type": null
|
|
648
|
+
}],
|
|
649
|
+
"returns": null
|
|
650
|
+
}],
|
|
651
|
+
"displayName": "ComboBox",
|
|
652
|
+
"props": {
|
|
653
|
+
"disabled": {
|
|
654
|
+
"defaultValue": {
|
|
655
|
+
"value": "false",
|
|
656
|
+
"computed": false
|
|
657
|
+
},
|
|
658
|
+
"type": {
|
|
659
|
+
"name": "bool"
|
|
660
|
+
},
|
|
661
|
+
"required": false,
|
|
662
|
+
"description": "Specify if the control should be disabled, or not"
|
|
663
|
+
},
|
|
664
|
+
"itemToString": {
|
|
665
|
+
"defaultValue": {
|
|
666
|
+
"value": "item => {\n if (typeof item === 'string') {\n return item;\n }\n\n return item && item.label;\n}",
|
|
667
|
+
"computed": false
|
|
668
|
+
},
|
|
669
|
+
"type": {
|
|
670
|
+
"name": "func"
|
|
671
|
+
},
|
|
672
|
+
"required": false,
|
|
673
|
+
"description": "Helper function passed to downshift that allows the library to render a\ngiven item to a string label. By default, it extracts the `label` field\nfrom a given item to serve as the item label in the list"
|
|
674
|
+
},
|
|
675
|
+
"itemToElement": {
|
|
676
|
+
"defaultValue": {
|
|
677
|
+
"value": "null",
|
|
678
|
+
"computed": false
|
|
679
|
+
},
|
|
680
|
+
"type": {
|
|
681
|
+
"name": "func"
|
|
682
|
+
},
|
|
683
|
+
"required": false,
|
|
684
|
+
"description": "Optional function to render items as custom components instead of strings.\nDefaults to null and is overriden by a getter"
|
|
685
|
+
},
|
|
686
|
+
"shouldFilterItem": {
|
|
687
|
+
"defaultValue": {
|
|
688
|
+
"value": "() => true",
|
|
689
|
+
"computed": false
|
|
690
|
+
},
|
|
691
|
+
"type": {
|
|
692
|
+
"name": "func"
|
|
693
|
+
},
|
|
694
|
+
"required": false,
|
|
695
|
+
"description": "Specify your own filtering logic by passing in a `shouldFilterItem`\nfunction that takes in the current input and an item and passes back\nwhether or not the item should be filtered."
|
|
696
|
+
},
|
|
697
|
+
"type": {
|
|
698
|
+
"defaultValue": {
|
|
699
|
+
"value": "'default'",
|
|
700
|
+
"computed": false
|
|
701
|
+
},
|
|
702
|
+
"type": {
|
|
703
|
+
"name": "custom",
|
|
704
|
+
"raw": "ListBoxPropTypes.ListBoxType"
|
|
705
|
+
},
|
|
706
|
+
"required": false,
|
|
707
|
+
"description": "Currently supports either the default type, or an inline variant"
|
|
708
|
+
},
|
|
709
|
+
"ariaLabel": {
|
|
710
|
+
"defaultValue": {
|
|
711
|
+
"value": "'Choose an item'",
|
|
712
|
+
"computed": false
|
|
713
|
+
},
|
|
714
|
+
"type": {
|
|
715
|
+
"name": "string"
|
|
716
|
+
},
|
|
717
|
+
"required": false,
|
|
718
|
+
"description": "'aria-label' of the ListBox component."
|
|
719
|
+
},
|
|
720
|
+
"light": {
|
|
721
|
+
"defaultValue": {
|
|
722
|
+
"value": "false",
|
|
723
|
+
"computed": false
|
|
724
|
+
},
|
|
725
|
+
"type": {
|
|
726
|
+
"name": "bool"
|
|
727
|
+
},
|
|
728
|
+
"required": false,
|
|
729
|
+
"description": "should use \"light theme\" (white background)?"
|
|
730
|
+
},
|
|
731
|
+
"direction": {
|
|
732
|
+
"defaultValue": {
|
|
733
|
+
"value": "'bottom'",
|
|
734
|
+
"computed": false
|
|
735
|
+
},
|
|
736
|
+
"type": {
|
|
737
|
+
"name": "enum",
|
|
738
|
+
"value": [{
|
|
739
|
+
"value": "'top'",
|
|
740
|
+
"computed": false
|
|
741
|
+
}, {
|
|
742
|
+
"value": "'bottom'",
|
|
743
|
+
"computed": false
|
|
744
|
+
}]
|
|
745
|
+
},
|
|
746
|
+
"required": false,
|
|
747
|
+
"description": "Specify the direction of the combobox dropdown. Can be either top or bottom."
|
|
748
|
+
},
|
|
749
|
+
"editOptionText": {
|
|
750
|
+
"defaultValue": {
|
|
751
|
+
"value": "'+ Add'",
|
|
752
|
+
"computed": false
|
|
753
|
+
},
|
|
754
|
+
"type": {
|
|
755
|
+
"name": "string"
|
|
756
|
+
},
|
|
757
|
+
"required": false,
|
|
758
|
+
"description": "String to pass to input field option"
|
|
759
|
+
},
|
|
760
|
+
"className": {
|
|
761
|
+
"type": {
|
|
762
|
+
"name": "string"
|
|
763
|
+
},
|
|
764
|
+
"required": false,
|
|
765
|
+
"description": "An optional className to add to the container node"
|
|
766
|
+
},
|
|
767
|
+
"id": {
|
|
768
|
+
"type": {
|
|
769
|
+
"name": "string"
|
|
770
|
+
},
|
|
771
|
+
"required": true,
|
|
772
|
+
"description": "Specify a custom `id` for the input"
|
|
773
|
+
},
|
|
774
|
+
"initialSelectedItem": {
|
|
775
|
+
"type": {
|
|
776
|
+
"name": "union",
|
|
777
|
+
"value": [{
|
|
778
|
+
"name": "object"
|
|
779
|
+
}, {
|
|
780
|
+
"name": "string"
|
|
781
|
+
}]
|
|
782
|
+
},
|
|
783
|
+
"required": false,
|
|
784
|
+
"description": "Allow users to pass in an arbitrary item or a string (in case their items are an array of strings)\nfrom their collection that are pre-selected"
|
|
785
|
+
},
|
|
786
|
+
"items": {
|
|
787
|
+
"type": {
|
|
788
|
+
"name": "array"
|
|
789
|
+
},
|
|
790
|
+
"required": true,
|
|
791
|
+
"description": "We try to stay as generic as possible here to allow individuals to pass\nin a collection of whatever kind of data structure they prefer"
|
|
792
|
+
},
|
|
793
|
+
"onChange": {
|
|
794
|
+
"type": {
|
|
795
|
+
"name": "func"
|
|
796
|
+
},
|
|
797
|
+
"required": true,
|
|
798
|
+
"description": "`onChange` is a utility for this controlled component to communicate to a\nconsuming component when a specific dropdown item is selected.\n@param {{ selectedItem }}"
|
|
799
|
+
},
|
|
800
|
+
"placeholder": {
|
|
801
|
+
"type": {
|
|
802
|
+
"name": "string"
|
|
803
|
+
},
|
|
804
|
+
"required": true,
|
|
805
|
+
"description": "Used to provide a placeholder text node before a user enters any input.\nThis is only present if the control has no items selected"
|
|
806
|
+
},
|
|
807
|
+
"invalid": {
|
|
808
|
+
"type": {
|
|
809
|
+
"name": "bool"
|
|
810
|
+
},
|
|
811
|
+
"required": false,
|
|
812
|
+
"description": "Specify if the currently selected value is invalid."
|
|
813
|
+
},
|
|
814
|
+
"invalidText": {
|
|
815
|
+
"type": {
|
|
816
|
+
"name": "string"
|
|
817
|
+
},
|
|
818
|
+
"required": false,
|
|
819
|
+
"description": "Message which is displayed if the value is invalid."
|
|
820
|
+
},
|
|
821
|
+
"selectedItem": {
|
|
822
|
+
"type": {
|
|
823
|
+
"name": "union",
|
|
824
|
+
"value": [{
|
|
825
|
+
"name": "object"
|
|
826
|
+
}, {
|
|
827
|
+
"name": "string"
|
|
828
|
+
}]
|
|
829
|
+
},
|
|
830
|
+
"required": false,
|
|
831
|
+
"description": "For full control of the selection"
|
|
832
|
+
},
|
|
833
|
+
"translateWithId": {
|
|
834
|
+
"type": {
|
|
835
|
+
"name": "func"
|
|
836
|
+
},
|
|
837
|
+
"required": false,
|
|
838
|
+
"description": "Specify a custom translation function that takes in a message identifier\nand returns the localized string for the message"
|
|
839
|
+
},
|
|
840
|
+
"size": {
|
|
841
|
+
"type": {
|
|
842
|
+
"name": "custom",
|
|
843
|
+
"raw": "ListBoxPropTypes.ListBoxSize"
|
|
844
|
+
},
|
|
845
|
+
"required": false,
|
|
846
|
+
"description": "Specify the size of the ListBox. Currently supports either `sm`, `lg` or `xl` as an option."
|
|
847
|
+
},
|
|
848
|
+
"onInputChange": {
|
|
849
|
+
"type": {
|
|
850
|
+
"name": "func"
|
|
851
|
+
},
|
|
852
|
+
"required": false,
|
|
853
|
+
"description": "Callback function to notify consumer when the text input changes.\nThis provides support to change available items based on the text.\n@param {string} inputText"
|
|
854
|
+
},
|
|
855
|
+
"downshiftProps": {
|
|
856
|
+
"type": {
|
|
857
|
+
"name": "shape",
|
|
858
|
+
"value": "Downshift.propTypes",
|
|
859
|
+
"computed": true
|
|
860
|
+
},
|
|
861
|
+
"required": false,
|
|
862
|
+
"description": "Additional props passed to Downshift"
|
|
863
|
+
},
|
|
864
|
+
"onHighligtedIndexChange": {
|
|
865
|
+
"type": {
|
|
866
|
+
"name": "func"
|
|
867
|
+
},
|
|
868
|
+
"required": false,
|
|
869
|
+
"description": "Optional callback to pass the highlighted index to parent"
|
|
870
|
+
},
|
|
871
|
+
"findHighlightedIndex": {
|
|
872
|
+
"type": {
|
|
873
|
+
"name": "func"
|
|
874
|
+
},
|
|
875
|
+
"required": false,
|
|
876
|
+
"description": "Optional func to change behavior of highlighted index"
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
export default ComboBox;
|
|
882
|
+
export { match, setupGetInstanceId, defaultItemToString };
|