@pingux/astro 2.71.0-alpha.1 → 2.71.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/lib/cjs/components/ListBox/ListBox.js +4 -2
- package/lib/cjs/components/ListBox/ListBox.styles.js +20 -0
- package/lib/cjs/components/ListBox/Option.js +47 -8
- package/lib/cjs/components/MultivaluesField/CondensedMultivaluesField.js +508 -0
- package/lib/cjs/components/MultivaluesField/DefaultMultivaluesField.js +616 -0
- package/lib/cjs/components/MultivaluesField/MultivaluesField.js +18 -481
- package/lib/cjs/components/MultivaluesField/MultivaluesField.stories.js +114 -2
- package/lib/cjs/components/MultivaluesField/MultivaluesField.test.js +251 -2
- package/lib/cjs/types/listBox.d.ts +6 -0
- package/lib/components/ListBox/ListBox.js +4 -2
- package/lib/components/ListBox/ListBox.styles.js +20 -0
- package/lib/components/ListBox/Option.js +47 -8
- package/lib/components/MultivaluesField/CondensedMultivaluesField.js +495 -0
- package/lib/components/MultivaluesField/DefaultMultivaluesField.js +603 -0
- package/lib/components/MultivaluesField/MultivaluesField.js +18 -480
- package/lib/components/MultivaluesField/MultivaluesField.stories.js +111 -1
- package/lib/components/MultivaluesField/MultivaluesField.test.js +250 -2
- package/package.json +1 -1
@@ -1,500 +1,38 @@
|
|
1
1
|
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
2
2
|
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
3
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
3
4
|
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
4
5
|
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
5
6
|
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
6
7
|
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
7
8
|
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
8
|
-
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
9
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
|
-
import
|
11
|
-
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["defaultSelectedKeys", "direction", "disabledKeys", "containerProps", "hasAutoFocus", "hasNoStatusIndicator", "helperText", "inputProps", "isDisabled", "isNotFlippable", "isReadOnly", "isRequired", "items", "label", "mode", "onBlur", "onFocus", "onInputChange", "onKeyDown", "onKeyUp", "onOpenChange", "onSelectionChange", "placeholder", "readOnlyKeys", "selectedKeys", "scrollBoxProps", "status"];
|
10
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
13
11
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
15
|
-
import
|
16
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
17
|
-
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
18
|
-
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/trim";
|
19
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
20
|
-
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
21
|
-
import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
|
22
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
23
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
24
|
-
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
25
|
-
import { DismissButton, FocusScope, useOverlayPosition } from 'react-aria';
|
26
|
-
import Clear from '@pingux/mdi-react/CloseIcon';
|
27
|
-
import { useFilter } from '@react-aria/i18n';
|
28
|
-
import { useLayoutEffect, useResizeObserver } from '@react-aria/utils';
|
29
|
-
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
30
|
-
import { useListState } from '@react-stately/list';
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
|
+
import React, { forwardRef, useMemo } from 'react';
|
31
14
|
import PropTypes from 'prop-types';
|
32
|
-
import { Badge, Box, Icon, IconButton, PopoverContainer, ScrollBox, Text, TextField } from '../..';
|
33
|
-
import { MultivaluesContext } from '../../context/MultivaluesContext';
|
34
|
-
import { usePropWarning } from '../../hooks';
|
35
|
-
import { getPendoID } from '../../utils/devUtils/constants/pendoID';
|
36
15
|
import { isIterableProp } from '../../utils/devUtils/props/isIterable';
|
37
16
|
import { ariaAttributesBasePropTypes } from '../../utils/docUtils/ariaAttributes';
|
38
17
|
import { inputFieldAttributesBasePropTypes } from '../../utils/docUtils/fieldAttributes';
|
39
18
|
import { statusDefaultProp, statusPropTypes } from '../../utils/docUtils/statusProp';
|
40
|
-
import
|
19
|
+
import CondensedMultivaluesField from './CondensedMultivaluesField';
|
20
|
+
import DefaultMultivaluesField from './DefaultMultivaluesField';
|
41
21
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
42
22
|
var MultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
43
|
-
var
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
hasAutoFocus = props.hasAutoFocus,
|
50
|
-
hasNoStatusIndicator = props.hasNoStatusIndicator,
|
51
|
-
helperText = props.helperText,
|
52
|
-
customInputProps = props.inputProps,
|
53
|
-
isDisabled = props.isDisabled,
|
54
|
-
isNotFlippable = props.isNotFlippable,
|
55
|
-
isReadOnly = props.isReadOnly,
|
56
|
-
isRequired = props.isRequired,
|
57
|
-
initialItems = props.items,
|
58
|
-
label = props.label,
|
59
|
-
mode = props.mode,
|
60
|
-
_onBlur = props.onBlur,
|
61
|
-
_onFocus = props.onFocus,
|
62
|
-
onInputChange = props.onInputChange,
|
63
|
-
onKeyDown = props.onKeyDown,
|
64
|
-
_onKeyUp = props.onKeyUp,
|
65
|
-
onOpenChange = props.onOpenChange,
|
66
|
-
onSelectionChange = props.onSelectionChange,
|
67
|
-
placeholder = props.placeholder,
|
68
|
-
_props$readOnlyKeys = props.readOnlyKeys,
|
69
|
-
readOnlyKeys = _props$readOnlyKeys === void 0 ? [] : _props$readOnlyKeys,
|
70
|
-
selectedKeys = props.selectedKeys,
|
71
|
-
scrollBoxProps = props.scrollBoxProps,
|
72
|
-
status = props.status,
|
73
|
-
others = _objectWithoutProperties(props, _excluded);
|
74
|
-
var hasCustomValue = mode === 'non-restrictive';
|
75
|
-
usePropWarning(props, 'disabled', 'isDisabled');
|
76
|
-
var _useState = useState([]),
|
77
|
-
_useState2 = _slicedToArray(_useState, 2),
|
78
|
-
customItems = _useState2[0],
|
79
|
-
setCustomItems = _useState2[1];
|
80
|
-
var _useState3 = useState(''),
|
81
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
82
|
-
filterString = _useState4[0],
|
83
|
-
setFilterString = _useState4[1];
|
84
|
-
var _useState5 = useState(false),
|
85
|
-
_useState6 = _slicedToArray(_useState5, 2),
|
86
|
-
isOpen = _useState6[0],
|
87
|
-
setIsOpen = _useState6[1];
|
88
|
-
var _useState7 = useState(initialItems),
|
89
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
90
|
-
items = _useState8[0],
|
91
|
-
setItems = _useState8[1];
|
92
|
-
var _useState9 = useState(''),
|
93
|
-
_useState10 = _slicedToArray(_useState9, 2),
|
94
|
-
activeDescendant = _useState10[0],
|
95
|
-
setActiveDescendant = _useState10[1];
|
96
|
-
var toggleItems = function toggleItems(keys) {
|
97
|
-
setItems(_filterInstanceProperty(initialItems).call(initialItems, function (item) {
|
98
|
-
var _context;
|
99
|
-
return !_includesInstanceProperty(_context = _Array$from(keys)).call(_context, item.key);
|
100
|
-
}));
|
101
|
-
setFilterString('');
|
102
|
-
if (onSelectionChange) onSelectionChange(keys);
|
103
|
-
};
|
104
|
-
var _useFilter = useFilter({
|
105
|
-
sensitivity: 'base'
|
106
|
-
}),
|
107
|
-
contains = _useFilter.contains;
|
108
|
-
var state = useListState(_objectSpread(_objectSpread({}, props), {}, {
|
109
|
-
filter: function filter(nodes) {
|
110
|
-
var _context2;
|
111
|
-
return _filterInstanceProperty(_context2 = _Array$from(nodes)).call(_context2, function (item) {
|
112
|
-
return contains(item.textValue, filterString);
|
113
|
-
});
|
114
|
-
},
|
115
|
-
items: _filterInstanceProperty(items).call(items, function (_ref) {
|
116
|
-
var key = _ref.key;
|
117
|
-
return !_includesInstanceProperty(readOnlyKeys).call(readOnlyKeys, key);
|
118
|
-
}),
|
119
|
-
onSelectionChange: toggleItems,
|
120
|
-
selectionMode: 'multiple'
|
121
|
-
}));
|
122
|
-
var selectionManager = state.selectionManager;
|
123
|
-
var filteredItems = useMemo(function () {
|
124
|
-
return _Array$from(state.collection);
|
125
|
-
}, [state.collection, filterString]);
|
126
|
-
var close = function close() {
|
127
|
-
return setIsOpen(false);
|
128
|
-
};
|
129
|
-
var closeBadgeRefs = useRef([]);
|
130
|
-
var inputWrapperRef = useRef();
|
131
|
-
var inputRef = useRef();
|
132
|
-
/* istanbul ignore next */
|
133
|
-
useImperativeHandle(ref, function () {
|
134
|
-
return inputWrapperRef.current;
|
135
|
-
});
|
136
|
-
useImperativeHandle(ref, function () {
|
137
|
-
return inputRef.current;
|
138
|
-
});
|
139
|
-
var listBoxRef = useRef();
|
140
|
-
var popoverRef = useRef();
|
141
|
-
var _useOverlayPosition = useOverlayPosition({
|
142
|
-
isOpen: isOpen,
|
143
|
-
onClose: close,
|
144
|
-
offset: 1,
|
145
|
-
overlayRef: popoverRef,
|
146
|
-
placement: "".concat(direction, " end"),
|
147
|
-
scrollRef: listBoxRef,
|
148
|
-
shouldFlip: !isNotFlippable,
|
149
|
-
targetRef: inputWrapperRef
|
150
|
-
}),
|
151
|
-
overlayProps = _useOverlayPosition.overlayProps,
|
152
|
-
placement = _useOverlayPosition.placement,
|
153
|
-
updatePosition = _useOverlayPosition.updatePosition;
|
154
|
-
|
155
|
-
// Update position once the ListBox has rendered. This ensures that
|
156
|
-
// it flips properly when it doesn't fit in the available space.
|
157
|
-
/* istanbul ignore next */
|
158
|
-
useLayoutEffect(function () {
|
159
|
-
if (isOpen) {
|
160
|
-
requestAnimationFrame(function () {
|
161
|
-
updatePosition();
|
162
|
-
});
|
163
|
-
}
|
164
|
-
}, [isOpen, selectionManager.selectedKeys, updatePosition]);
|
165
|
-
|
166
|
-
// Measure the width of the input to inform the width of the menu (below).
|
167
|
-
var _useState11 = useState(null),
|
168
|
-
_useState12 = _slicedToArray(_useState11, 2),
|
169
|
-
menuWidth = _useState12[0],
|
170
|
-
setMenuWidth = _useState12[1];
|
171
|
-
var onResize = useCallback(function () {
|
172
|
-
/* istanbul ignore next */
|
173
|
-
if (inputWrapperRef.current) {
|
174
|
-
setMenuWidth("".concat(inputWrapperRef.current.offsetWidth + 2, "px"));
|
175
|
-
}
|
176
|
-
}, [inputWrapperRef, isOpen, setMenuWidth]);
|
177
|
-
useResizeObserver({
|
178
|
-
ref: inputWrapperRef,
|
179
|
-
onResize: onResize
|
180
|
-
});
|
181
|
-
useLayoutEffect(onResize, [onResize]);
|
182
|
-
var style = _objectSpread(_objectSpread({}, overlayProps.style), {}, {
|
183
|
-
width: menuWidth,
|
184
|
-
minWidth: menuWidth
|
185
|
-
});
|
186
|
-
useEffect(function () {
|
187
|
-
if (defaultSelectedKeys) selectionManager.setSelectedKeys(defaultSelectedKeys);
|
188
|
-
}, []);
|
189
|
-
useEffect(function () {
|
190
|
-
if (selectedKeys) selectionManager.setSelectedKeys(selectedKeys);
|
191
|
-
}, []);
|
192
|
-
useEffect(function () {
|
193
|
-
if (onOpenChange) onOpenChange(isOpen);
|
194
|
-
if (!isOpen) setActiveDescendant('');
|
195
|
-
}, [isOpen]);
|
196
|
-
var addNewBadgeFromInput = function addNewBadgeFromInput(inputValue) {
|
197
|
-
var _context3, _context4;
|
198
|
-
var key = _trimInstanceProperty(inputValue).call(inputValue);
|
199
|
-
if (key === '') {
|
200
|
-
return;
|
201
|
-
}
|
202
|
-
if (state.selectionManager.isSelected(key)) {
|
203
|
-
return;
|
204
|
-
}
|
205
|
-
selectionManager.setSelectedKeys(_concatInstanceProperty(_context3 = []).call(_context3, _Array$from(selectionManager.state.selectedKeys), [key]));
|
206
|
-
setCustomItems(_concatInstanceProperty(_context4 = []).call(_context4, customItems, [{
|
207
|
-
id: key,
|
208
|
-
key: key,
|
209
|
-
name: key
|
210
|
-
}]));
|
211
|
-
setFilterString('');
|
212
|
-
};
|
213
|
-
|
214
|
-
// there actually is a test for this, but coverage is not picking it up.
|
215
|
-
/* istanbul ignore next */
|
216
|
-
var selectTheOnlyFilteredItem = function selectTheOnlyFilteredItem() {
|
217
|
-
var key = filteredItems[0].key;
|
218
|
-
if (!_includesInstanceProperty(disabledKeys).call(disabledKeys, key)) {
|
219
|
-
selectionManager.toggleSelection(filteredItems[0].key);
|
220
|
-
setFilterString('');
|
221
|
-
}
|
222
|
-
};
|
223
|
-
|
224
|
-
// there actually is a test for this, but coverage is not picking it up.
|
225
|
-
/* istanbul ignore next */
|
226
|
-
var onBlurTextField = function onBlurTextField() {
|
227
|
-
if (hasCustomValue && filteredItems.length === 1) {
|
228
|
-
selectTheOnlyFilteredItem();
|
229
|
-
} else if (hasCustomValue) {
|
230
|
-
addNewBadgeFromInput(filterString);
|
231
|
-
}
|
232
|
-
};
|
233
|
-
|
234
|
-
/* istanbul ignore next */
|
235
|
-
var keyDown = function keyDown(e) {
|
236
|
-
switch (e.key) {
|
237
|
-
case 'Enter':
|
238
|
-
{
|
239
|
-
e.preventDefault();
|
240
|
-
if (selectionManager.focusedKey) {
|
241
|
-
var key = selectionManager.focusedKey;
|
242
|
-
if (!_includesInstanceProperty(disabledKeys).call(disabledKeys, key)) {
|
243
|
-
selectionManager.toggleSelection(selectionManager.focusedKey);
|
244
|
-
setFilterString('');
|
245
|
-
}
|
246
|
-
} else if (hasCustomValue && !selectionManager.focusedKey) {
|
247
|
-
var _key = e.target.value;
|
248
|
-
if (_key === '') {
|
249
|
-
return;
|
250
|
-
}
|
251
|
-
addNewBadgeFromInput(e.target.value);
|
252
|
-
} else if (hasCustomValue && filteredItems.length === 1) {
|
253
|
-
selectTheOnlyFilteredItem();
|
254
|
-
} else if (!hasCustomValue) {
|
255
|
-
setFilterString('');
|
256
|
-
close();
|
257
|
-
}
|
258
|
-
break;
|
259
|
-
}
|
260
|
-
case 'ArrowDown':
|
261
|
-
{
|
262
|
-
var nextKey = state.collection.getKeyAfter(selectionManager.focusedKey) || state.collection.getFirstKey();
|
263
|
-
if (nextKey) selectionManager.setFocusedKey(nextKey);
|
264
|
-
break;
|
265
|
-
}
|
266
|
-
case 'ArrowUp':
|
267
|
-
{
|
268
|
-
var prevKey = state.collection.getKeyBefore(selectionManager.focusedKey) || state.collection.getLastKey();
|
269
|
-
if (prevKey) selectionManager.setFocusedKey(prevKey);
|
270
|
-
break;
|
271
|
-
}
|
272
|
-
case 'Escape':
|
273
|
-
{
|
274
|
-
setFilterString('');
|
275
|
-
close();
|
276
|
-
break;
|
277
|
-
}
|
23
|
+
var component = useMemo(function () {
|
24
|
+
switch (props.mode) {
|
25
|
+
case 'condensed':
|
26
|
+
return ___EmotionJSX(CondensedMultivaluesField, _extends({
|
27
|
+
ref: ref
|
28
|
+
}, props));
|
278
29
|
default:
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
};
|
283
|
-
var deleteItem = function deleteItem(key, e) {
|
284
|
-
var _context5;
|
285
|
-
var activeBadgesKeys = _reduceInstanceProperty(_context5 = closeBadgeRefs.current).call(_context5, function (result, item) {
|
286
|
-
if (item) {
|
287
|
-
result.push(item.dataset.item);
|
288
|
-
}
|
289
|
-
return result;
|
290
|
-
}, []);
|
291
|
-
selectionManager.toggleSelection(key);
|
292
|
-
if (e.pointerType !== 'keyboard') return;
|
293
|
-
if (activeBadgesKeys.length > 1) {
|
294
|
-
var badgeIndex = _findIndexInstanceProperty(activeBadgesKeys).call(activeBadgesKeys, function (item) {
|
295
|
-
return item === key;
|
296
|
-
});
|
297
|
-
var nextFocusBadgeIndex = badgeIndex === activeBadgesKeys.length - 1 ? badgeIndex - 1 : badgeIndex;
|
298
|
-
closeBadgeRefs.current[nextFocusBadgeIndex].focus();
|
299
|
-
} else {
|
300
|
-
inputRef.current.focus();
|
301
|
-
}
|
302
|
-
};
|
303
|
-
var readOnlyTextItem = function readOnlyTextItem(key, name) {
|
304
|
-
return ___EmotionJSX(Text, {
|
305
|
-
key: key,
|
306
|
-
role: "presentation",
|
307
|
-
label: name,
|
308
|
-
variant: "bodyStrong",
|
309
|
-
sx: {
|
310
|
-
bg: 'accent.95',
|
311
|
-
fontSize: 'sm',
|
312
|
-
alignSelf: 'center',
|
313
|
-
':not(:last-of-type):after': {
|
314
|
-
content: "\",\xA0\""
|
315
|
-
}
|
316
|
-
}
|
317
|
-
}, name);
|
318
|
-
};
|
319
|
-
var readOnlyInputEntry = isReadOnly && (readOnlyKeys.length ? _mapInstanceProperty(readOnlyKeys).call(readOnlyKeys, function (key) {
|
320
|
-
var _context6, _context7;
|
321
|
-
var item = _findInstanceProperty(_context6 = _concatInstanceProperty(_context7 = []).call(_context7, initialItems, customItems)).call(_context6, function (el) {
|
322
|
-
return el.key === key;
|
323
|
-
});
|
324
|
-
if (item) {
|
325
|
-
return readOnlyTextItem(item.key, item.name);
|
326
|
-
}
|
327
|
-
return null;
|
328
|
-
}) : _mapInstanceProperty(initialItems).call(initialItems, function (item) {
|
329
|
-
return readOnlyTextItem(item.key, item.name);
|
330
|
-
}));
|
331
|
-
var readOnlyItems = !isReadOnly && _mapInstanceProperty(readOnlyKeys).call(readOnlyKeys, function (key) {
|
332
|
-
var item = _findInstanceProperty(initialItems).call(initialItems, function (el) {
|
333
|
-
return el.key === key;
|
334
|
-
});
|
335
|
-
if (item) {
|
336
|
-
return ___EmotionJSX(Badge, {
|
337
|
-
key: item.key,
|
338
|
-
label: item.name,
|
339
|
-
variant: "readOnlyBadge",
|
340
|
-
bg: "white",
|
341
|
-
textProps: {
|
342
|
-
sx: {
|
343
|
-
color: 'text.primary',
|
344
|
-
tabIndex: '-1'
|
345
|
-
}
|
346
|
-
},
|
347
|
-
as: "li",
|
348
|
-
tabIndex: 0
|
349
|
-
});
|
350
|
-
}
|
351
|
-
return null;
|
352
|
-
});
|
353
|
-
var multivaluesFieldBadge = function multivaluesFieldBadge(item, index) {
|
354
|
-
return ___EmotionJSX(Box, {
|
355
|
-
as: "li",
|
356
|
-
key: "li ".concat(item.key)
|
357
|
-
}, ___EmotionJSX(Badge, _extends({
|
358
|
-
key: item.key,
|
359
|
-
role: "presentation",
|
360
|
-
variant: "selectedItemBadge",
|
361
|
-
bg: "active",
|
362
|
-
label: item.name,
|
363
|
-
slots: item.slots
|
364
|
-
}, item.badgeProps), ___EmotionJSX(IconButton, _extends({
|
365
|
-
"aria-label": "delete ".concat(item.name),
|
366
|
-
"data-item": item.name,
|
367
|
-
onPress: function onPress(e) {
|
368
|
-
return deleteItem(item.key, e);
|
369
|
-
},
|
370
|
-
ref: function ref(el) {
|
371
|
-
return closeBadgeRefs.current[index] = el;
|
372
|
-
} // eslint-disable-line
|
373
|
-
,
|
374
|
-
variant: "badge.deleteButton",
|
375
|
-
"aria-describedby": "selectedKeysState"
|
376
|
-
}, item.buttonProps), ___EmotionJSX(Icon, {
|
377
|
-
icon: Clear,
|
378
|
-
color: "white",
|
379
|
-
size: 14,
|
380
|
-
title: {
|
381
|
-
name: 'Clear Icon'
|
382
|
-
}
|
383
|
-
}))));
|
384
|
-
};
|
385
|
-
var selectedItems = ___EmotionJSX(React.Fragment, null, _mapInstanceProperty(_context8 = _Array$from(selectionManager.selectedKeys)).call(_context8, function (key, i) {
|
386
|
-
var _context9, _context10;
|
387
|
-
var item = _findInstanceProperty(_context9 = _concatInstanceProperty(_context10 = []).call(_context10, initialItems, customItems)).call(_context9, function (el) {
|
388
|
-
return el.key === key;
|
389
|
-
});
|
390
|
-
if (item) {
|
391
|
-
return multivaluesFieldBadge(item, i);
|
30
|
+
return ___EmotionJSX(DefaultMultivaluesField, _extends({
|
31
|
+
ref: ref
|
32
|
+
}, props));
|
392
33
|
}
|
393
|
-
|
394
|
-
|
395
|
-
var listbox = ___EmotionJSX(FocusScope, null, ___EmotionJSX(DismissButton, {
|
396
|
-
onDismiss: close
|
397
|
-
}), ___EmotionJSX(ScrollBox, scrollBoxProps, ___EmotionJSX(ListBox, {
|
398
|
-
ref: listBoxRef,
|
399
|
-
hasAutoFocus: hasAutoFocus,
|
400
|
-
hasVirtualFocus: true,
|
401
|
-
hasNoEmptySelection: true,
|
402
|
-
state: state,
|
403
|
-
"aria-label": "List of options"
|
404
|
-
})), ___EmotionJSX(DismissButton, {
|
405
|
-
onDismiss: close
|
406
|
-
}));
|
407
|
-
var visuallyHidden = ___EmotionJSX(VisuallyHidden, {
|
408
|
-
id: "selectedKeysState"
|
409
|
-
}, "Selected options:", _Array$from(selectionManager.selectedKeys).join(' '));
|
410
|
-
|
411
|
-
// the reason we are using two different visually hiddens, rather than one that updates it's value
|
412
|
-
// is because there are tests that break if an empty visually hidden is rendered in the TextField
|
413
|
-
var EmptyVisuallyHidden = function EmptyVisuallyHidden() {
|
414
|
-
return ___EmotionJSX(VisuallyHidden, {
|
415
|
-
id: "emptyKeysState"
|
416
|
-
}, "Nothing Selected");
|
417
|
-
};
|
418
|
-
var inputProps = _objectSpread(_objectSpread({}, customInputProps), {}, {
|
419
|
-
controlProps: {
|
420
|
-
'aria-activedescendant': activeDescendant,
|
421
|
-
'aria-controls': (_listBoxRef$current = listBoxRef.current) === null || _listBoxRef$current === void 0 ? void 0 : _listBoxRef$current.id,
|
422
|
-
'aria-expanded': isOpen,
|
423
|
-
role: 'combobox',
|
424
|
-
ref: inputRef
|
425
|
-
},
|
426
|
-
hasAutoFocus: hasAutoFocus,
|
427
|
-
hasNoStatusIndicator: hasNoStatusIndicator,
|
428
|
-
isDisabled: isDisabled,
|
429
|
-
isReadOnly: isReadOnly,
|
430
|
-
isRequired: isRequired,
|
431
|
-
label: label,
|
432
|
-
placeholder: placeholder,
|
433
|
-
wrapperProps: {
|
434
|
-
ref: inputWrapperRef,
|
435
|
-
variant: 'forms.input.multivaluesWrapper',
|
436
|
-
sx: isReadOnly && {
|
437
|
-
boxShadow: 'inset 0 0 0 100px #e5e9f8',
|
438
|
-
border: 'none'
|
439
|
-
}
|
440
|
-
},
|
441
|
-
status: status
|
442
|
-
});
|
443
|
-
return ___EmotionJSX(MultivaluesContext.Provider, {
|
444
|
-
value: setActiveDescendant
|
445
|
-
}, ___EmotionJSX(Box, containerProps, ___EmotionJSX(TextField, _extends({
|
446
|
-
onBlur: function onBlur(e) {
|
447
|
-
setIsOpen(false);
|
448
|
-
if (filterString !== '') onBlurTextField();
|
449
|
-
if (_onBlur) _onBlur(e.nativeEvent);
|
450
|
-
if (!hasCustomValue) setFilterString('');
|
451
|
-
},
|
452
|
-
onChange: function onChange(e) {
|
453
|
-
if (!isOpen) setIsOpen(true);
|
454
|
-
setFilterString(e.target.value);
|
455
|
-
if (onInputChange) onInputChange(e.target.value);
|
456
|
-
},
|
457
|
-
onFocus: function onFocus(e) {
|
458
|
-
if (!isReadOnly) {
|
459
|
-
setIsOpen(true);
|
460
|
-
}
|
461
|
-
if (_onFocus) _onFocus(e.nativeEvent);
|
462
|
-
},
|
463
|
-
onKeyDown: keyDown,
|
464
|
-
onKeyUp: function onKeyUp(e) {
|
465
|
-
return _onKeyUp && _onKeyUp(e.nativeEvent);
|
466
|
-
},
|
467
|
-
"aria-describedby": selectionManager.selectedKeys.size > 0 ? 'selectedKeysState' : 'emptyKeysState',
|
468
|
-
slots: {
|
469
|
-
beforeInput: ___EmotionJSX(React.Fragment, null, readOnlyItems && ___EmotionJSX(Box, {
|
470
|
-
as: "ul",
|
471
|
-
isRow: true,
|
472
|
-
sx: {
|
473
|
-
p: 0,
|
474
|
-
flexWrap: 'wrap'
|
475
|
-
}
|
476
|
-
}, readOnlyItems), ' ', selectedItems && ___EmotionJSX(Box, {
|
477
|
-
as: "ul",
|
478
|
-
isRow: true,
|
479
|
-
sx: {
|
480
|
-
p: 0,
|
481
|
-
flexWrap: 'wrap'
|
482
|
-
}
|
483
|
-
}, selectedItems), readOnlyInputEntry, selectionManager.selectedKeys.size > 0 && visuallyHidden)
|
484
|
-
} // eslint-disable-line
|
485
|
-
,
|
486
|
-
value: filterString,
|
487
|
-
helperText: helperText,
|
488
|
-
"aria-invalid": status === 'error' && true
|
489
|
-
}, getPendoID('MultivaluesField'), others, inputProps)), ___EmotionJSX(PopoverContainer, {
|
490
|
-
hasNoArrow: true,
|
491
|
-
isNonModal: true,
|
492
|
-
isOpen: !state.collection.size ? false : isOpen,
|
493
|
-
onClose: close,
|
494
|
-
placement: placement,
|
495
|
-
ref: popoverRef,
|
496
|
-
style: style
|
497
|
-
}, listbox), ___EmotionJSX(EmptyVisuallyHidden, null)));
|
34
|
+
}, [props.mode]);
|
35
|
+
return component;
|
498
36
|
});
|
499
37
|
MultivaluesField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
500
38
|
/** The initial selected keys in the collection (uncontrolled). */
|
@@ -536,7 +74,7 @@ MultivaluesField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
|
536
74
|
/** The rendered label for the field. */
|
537
75
|
label: PropTypes.string,
|
538
76
|
/** Whether the component allows to create new values or only choose from the selection list */
|
539
|
-
mode: PropTypes.oneOf(['restrictive', 'non-restrictive']),
|
77
|
+
mode: PropTypes.oneOf(['restrictive', 'non-restrictive', 'condensed']),
|
540
78
|
/**
|
541
79
|
* Handler that is called when the element loses focus.
|
542
80
|
*
|
@@ -13,7 +13,7 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
|
|
13
13
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
14
14
|
import React, { useState } from 'react';
|
15
15
|
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
16
|
-
import { Box, Icon, Item, MultivaluesField, OverlayProvider } from '../../index';
|
16
|
+
import { Box, Icon, Item, MultivaluesField, OverlayProvider, Section } from '../../index';
|
17
17
|
import { ariaAttributeBaseArgTypes } from '../../utils/docUtils/ariaAttributes';
|
18
18
|
import { inputFieldAttributeBaseArgTypes } from '../../utils/docUtils/fieldAttributes';
|
19
19
|
import { statusArgTypes } from '../../utils/docUtils/statusProp';
|
@@ -208,6 +208,60 @@ var items = [{
|
|
208
208
|
name: 'Shark',
|
209
209
|
key: 'Shark'
|
210
210
|
}];
|
211
|
+
var checkboxItems = [{
|
212
|
+
id: 1,
|
213
|
+
name: 'Option 1',
|
214
|
+
key: 'Option 1'
|
215
|
+
}, {
|
216
|
+
id: 2,
|
217
|
+
name: 'Option 2',
|
218
|
+
key: 'Option 2'
|
219
|
+
}, {
|
220
|
+
id: 3,
|
221
|
+
name: 'Option 3',
|
222
|
+
key: 'Option 3'
|
223
|
+
}, {
|
224
|
+
id: 4,
|
225
|
+
name: 'Option 4',
|
226
|
+
key: 'Option 4'
|
227
|
+
}, {
|
228
|
+
id: 5,
|
229
|
+
name: 'Option 5',
|
230
|
+
key: 'Option 5'
|
231
|
+
}, {
|
232
|
+
id: 6,
|
233
|
+
name: 'Option 6',
|
234
|
+
key: 'Option 6'
|
235
|
+
}, {
|
236
|
+
id: 7,
|
237
|
+
name: 'Option 7',
|
238
|
+
key: 'Option 7'
|
239
|
+
}];
|
240
|
+
var withSection = [{
|
241
|
+
name: 'Animals',
|
242
|
+
key: 'Animals',
|
243
|
+
children: [{
|
244
|
+
name: 'Option A1'
|
245
|
+
}, {
|
246
|
+
name: 'Option A2'
|
247
|
+
}, {
|
248
|
+
name: 'Option A3'
|
249
|
+
}, {
|
250
|
+
name: 'Option A4'
|
251
|
+
}, {
|
252
|
+
name: 'Option A5'
|
253
|
+
}]
|
254
|
+
}, {
|
255
|
+
name: 'People',
|
256
|
+
key: 'People',
|
257
|
+
children: [{
|
258
|
+
name: 'Option B1'
|
259
|
+
}, {
|
260
|
+
name: 'Option B2'
|
261
|
+
}, {
|
262
|
+
name: 'Option B3'
|
263
|
+
}]
|
264
|
+
}];
|
211
265
|
var itemsWithSlots = [{
|
212
266
|
id: 1,
|
213
267
|
name: 'Aardvark',
|
@@ -540,4 +594,60 @@ export var CustomSize = function CustomSize(args) {
|
|
540
594
|
"aria-label": item.name
|
541
595
|
}, item.name);
|
542
596
|
}))));
|
597
|
+
};
|
598
|
+
export var Condensed = function Condensed(args) {
|
599
|
+
var _useState23 = useState(false),
|
600
|
+
_useState24 = _slicedToArray(_useState23, 2),
|
601
|
+
isOpen = _useState24[0],
|
602
|
+
setIsOpen = _useState24[1];
|
603
|
+
var direction = args.direction;
|
604
|
+
var onOpenChange = function onOpenChange() {
|
605
|
+
setIsOpen(true);
|
606
|
+
};
|
607
|
+
return ___EmotionJSX(OverlayProvider
|
608
|
+
// note: spacing for demo purpose only so that the select list renders in the right place
|
609
|
+
, {
|
610
|
+
style: setOverlayStyle(direction, isOpen, '25%', '25%', '75%')
|
611
|
+
}, ___EmotionJSX(MultivaluesField, _extends({
|
612
|
+
items: checkboxItems
|
613
|
+
}, args, {
|
614
|
+
mode: "condensed",
|
615
|
+
onOpenChange: onOpenChange
|
616
|
+
}), function (item) {
|
617
|
+
return ___EmotionJSX(Item, {
|
618
|
+
key: item.key,
|
619
|
+
"data-id": item.name,
|
620
|
+
"aria-label": item.name
|
621
|
+
}, item.name);
|
622
|
+
}));
|
623
|
+
};
|
624
|
+
export var CondensedWithSection = function CondensedWithSection(args) {
|
625
|
+
var _useState25 = useState(false),
|
626
|
+
_useState26 = _slicedToArray(_useState25, 2),
|
627
|
+
isOpen = _useState26[0],
|
628
|
+
setIsOpen = _useState26[1];
|
629
|
+
var direction = args.direction;
|
630
|
+
var onOpenChange = function onOpenChange() {
|
631
|
+
setIsOpen(true);
|
632
|
+
};
|
633
|
+
return ___EmotionJSX(OverlayProvider
|
634
|
+
// note: spacing for demo purpose only so that the select list renders in the right place
|
635
|
+
, {
|
636
|
+
style: setOverlayStyle(direction, isOpen, '25%', '25%', '75%')
|
637
|
+
}, ___EmotionJSX(MultivaluesField, _extends({
|
638
|
+
items: withSection
|
639
|
+
}, args, {
|
640
|
+
mode: "condensed",
|
641
|
+
onOpenChange: onOpenChange
|
642
|
+
}), function (section) {
|
643
|
+
return ___EmotionJSX(Section, {
|
644
|
+
key: section.key,
|
645
|
+
items: section.children,
|
646
|
+
title: section.name
|
647
|
+
}, function (item) {
|
648
|
+
return ___EmotionJSX(Item, {
|
649
|
+
key: item.name
|
650
|
+
}, item.name);
|
651
|
+
});
|
652
|
+
}));
|
543
653
|
};
|