@pingux/astro 2.71.0-alpha.0 → 2.71.0-alpha.2
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/components/SelectFieldBase/SelectFieldBase.js +3 -1
- package/lib/cjs/recipes/DateTimeRangePicker.stories.js +182 -0
- package/lib/cjs/types/listBox.d.ts +6 -0
- package/lib/cjs/utils/designUtils/figmaLinks.d.ts +3 -0
- package/lib/cjs/utils/designUtils/figmaLinks.js +3 -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/lib/components/SelectFieldBase/SelectFieldBase.js +3 -1
- package/lib/recipes/DateTimeRangePicker.stories.js +167 -0
- package/lib/utils/designUtils/figmaLinks.js +3 -0
- package/package.json +1 -1
@@ -6,10 +6,10 @@ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/inst
|
|
6
6
|
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
7
7
|
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
8
8
|
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
9
|
-
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
10
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
|
11
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
12
|
+
var _excluded = ["item", "hasVirtualFocus", "isCondensed"],
|
13
13
|
_excluded2 = ["onPressStart", "onPressUp"];
|
14
14
|
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; }
|
15
15
|
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; }
|
@@ -22,10 +22,39 @@ import Box from '../Box';
|
|
22
22
|
import Icon from '../Icon';
|
23
23
|
import { ListBoxContext } from './ListBoxContext';
|
24
24
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
25
|
+
var UncheckedIcon = function UncheckedIcon(prop) {
|
26
|
+
return ___EmotionJSX("svg", _extends({
|
27
|
+
width: "24",
|
28
|
+
height: "24",
|
29
|
+
viewBox: "0 0 24 24",
|
30
|
+
fill: "none",
|
31
|
+
xmlns: "http://www.w3.org/2000/svg",
|
32
|
+
"aria-labelledby": "variable-icon-title"
|
33
|
+
}, prop), ___EmotionJSX("title", {
|
34
|
+
id: "variable-icon-title"
|
35
|
+
}, "Unchecked Icon"), ___EmotionJSX("path", {
|
36
|
+
d: "M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"
|
37
|
+
}));
|
38
|
+
};
|
39
|
+
var CheckedIcon = function CheckedIcon(prop) {
|
40
|
+
return ___EmotionJSX("svg", _extends({
|
41
|
+
width: "24",
|
42
|
+
height: "24",
|
43
|
+
viewBox: "0 0 24 24",
|
44
|
+
fill: "none",
|
45
|
+
xmlns: "http://www.w3.org/2000/svg",
|
46
|
+
"aria-labelledby": "variable-icon-title"
|
47
|
+
}, prop), ___EmotionJSX("title", {
|
48
|
+
id: "variable-icon-title"
|
49
|
+
}, "Checked Icon"), ___EmotionJSX("path", {
|
50
|
+
d: "M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
|
51
|
+
}));
|
52
|
+
};
|
25
53
|
var Option = /*#__PURE__*/forwardRef(function (props, ref) {
|
26
54
|
var _state$selectionManag;
|
27
55
|
var item = props.item,
|
28
56
|
hasVirtualFocus = props.hasVirtualFocus,
|
57
|
+
isCondensed = props.isCondensed,
|
29
58
|
others = _objectWithoutProperties(props, _excluded);
|
30
59
|
var key = item.key,
|
31
60
|
itemProps = item.props,
|
@@ -43,24 +72,27 @@ var Option = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
43
72
|
var _useOption = useOption(_objectSpread({
|
44
73
|
key: key,
|
45
74
|
shouldSelectOnPressUp: true,
|
46
|
-
shouldFocusOnHover:
|
47
|
-
shouldUseVirtualFocus: hasVirtualFocus,
|
75
|
+
shouldFocusOnHover: !isCondensed,
|
76
|
+
shouldUseVirtualFocus: isCondensed ? false : hasVirtualFocus,
|
48
77
|
isVirtualized: true
|
49
78
|
}, others), state, optionRef),
|
50
79
|
optionProps = _useOption.optionProps,
|
51
80
|
isDisabled = _useOption.isDisabled,
|
52
81
|
isSelected = _useOption.isSelected,
|
53
|
-
isFocused = _useOption.isFocused
|
82
|
+
isFocused = _useOption.isFocused,
|
83
|
+
isFocusVisible = _useOption.isFocusVisible;
|
54
84
|
var focused = isFocused || (state === null || state === void 0 || (_state$selectionManag = state.selectionManager) === null || _state$selectionManag === void 0 ? void 0 : _state$selectionManag.focusedKey) === item.key;
|
55
85
|
var setFocusOnHover = function setFocusOnHover() {
|
56
|
-
if (!focused) {
|
86
|
+
if (!focused && !isCondensed) {
|
57
87
|
state.selectionManager.setFocusedKey(item.key);
|
58
88
|
}
|
59
89
|
};
|
60
90
|
var _useStatusClasses = useStatusClasses(null, {
|
61
91
|
isDisabled: isDisabled || isSeparator,
|
62
92
|
isFocused: focused,
|
63
|
-
isSelected: isSelected
|
93
|
+
isSelected: isSelected,
|
94
|
+
isCondensed: isCondensed,
|
95
|
+
isFocusVisible: isFocusVisible
|
64
96
|
}),
|
65
97
|
classNames = _useStatusClasses.classNames;
|
66
98
|
var updateActiveDescendant = useMultivaluesContext();
|
@@ -87,7 +119,14 @@ var Option = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
87
119
|
onPointerOver: setFocusOnHover
|
88
120
|
}, theseOptionProps, others, {
|
89
121
|
"aria-label": ariaLabel
|
90
|
-
}),
|
122
|
+
}), isCondensed ? ___EmotionJSX(Icon, {
|
123
|
+
icon: isSelected ? CheckedIcon : UncheckedIcon,
|
124
|
+
color: "active",
|
125
|
+
size: "24px",
|
126
|
+
mr: "xs",
|
127
|
+
className: classNames,
|
128
|
+
variant: "listBox.checkboxIcon"
|
129
|
+
}) : isSelected && ___EmotionJSX(Icon, {
|
91
130
|
icon: CircleSmallIcon,
|
92
131
|
title: {
|
93
132
|
name: 'Circle Small Icon'
|
@@ -0,0 +1,495 @@
|
|
1
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
2
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
3
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
4
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
5
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
6
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
7
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
8
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
9
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
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", "selectedKeys", "scrollBoxProps", "status"];
|
13
|
+
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 _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
16
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
17
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
18
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
19
|
+
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
20
|
+
import _flatMapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/flat-map";
|
21
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
22
|
+
import { DismissButton, FocusScope, useOverlayPosition } from 'react-aria';
|
23
|
+
import MenuDown from '@pingux/mdi-react/MenuDownIcon';
|
24
|
+
import MenuUp from '@pingux/mdi-react/MenuUpIcon';
|
25
|
+
import { useFilter } from '@react-aria/i18n';
|
26
|
+
import { useLayoutEffect, useResizeObserver } from '@react-aria/utils';
|
27
|
+
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
28
|
+
import { useListState } from '@react-stately/list';
|
29
|
+
import PropTypes from 'prop-types';
|
30
|
+
import { Box, Button, Icon, PopoverContainer, ScrollBox, Text, TextField } from '../..';
|
31
|
+
import { MultivaluesContext } from '../../context/MultivaluesContext';
|
32
|
+
import { usePropWarning } from '../../hooks';
|
33
|
+
import { getPendoID } from '../../utils/devUtils/constants/pendoID';
|
34
|
+
import { isIterableProp } from '../../utils/devUtils/props/isIterable';
|
35
|
+
import { ariaAttributesBasePropTypes } from '../../utils/docUtils/ariaAttributes';
|
36
|
+
import { inputFieldAttributesBasePropTypes } from '../../utils/docUtils/fieldAttributes';
|
37
|
+
import { statusDefaultProp, statusPropTypes } from '../../utils/docUtils/statusProp';
|
38
|
+
import ListBox from '../ListBox';
|
39
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
40
|
+
var CondensedMultivaluesField = /*#__PURE__*/forwardRef(function (props, ref) {
|
41
|
+
var _selectionManager$sta, _selectionManager$sta2, _listBoxRef$current, _selectionManager$sta3;
|
42
|
+
var defaultSelectedKeys = props.defaultSelectedKeys,
|
43
|
+
direction = props.direction,
|
44
|
+
_props$disabledKeys = props.disabledKeys,
|
45
|
+
disabledKeys = _props$disabledKeys === void 0 ? [] : _props$disabledKeys,
|
46
|
+
containerProps = props.containerProps,
|
47
|
+
hasAutoFocus = props.hasAutoFocus,
|
48
|
+
hasNoStatusIndicator = props.hasNoStatusIndicator,
|
49
|
+
helperText = props.helperText,
|
50
|
+
customInputProps = props.inputProps,
|
51
|
+
isDisabled = props.isDisabled,
|
52
|
+
isNotFlippable = props.isNotFlippable,
|
53
|
+
isReadOnly = props.isReadOnly,
|
54
|
+
isRequired = props.isRequired,
|
55
|
+
items = props.items,
|
56
|
+
label = props.label,
|
57
|
+
mode = props.mode,
|
58
|
+
_onBlur = props.onBlur,
|
59
|
+
_onFocus = props.onFocus,
|
60
|
+
onInputChange = props.onInputChange,
|
61
|
+
onKeyDown = props.onKeyDown,
|
62
|
+
_onKeyUp = props.onKeyUp,
|
63
|
+
onOpenChange = props.onOpenChange,
|
64
|
+
onSelectionChange = props.onSelectionChange,
|
65
|
+
placeholder = props.placeholder,
|
66
|
+
selectedKeys = props.selectedKeys,
|
67
|
+
scrollBoxProps = props.scrollBoxProps,
|
68
|
+
status = props.status,
|
69
|
+
others = _objectWithoutProperties(props, _excluded);
|
70
|
+
usePropWarning(props, 'disabled', 'isDisabled');
|
71
|
+
var _useState = useState(''),
|
72
|
+
_useState2 = _slicedToArray(_useState, 2),
|
73
|
+
filterString = _useState2[0],
|
74
|
+
setFilterString = _useState2[1];
|
75
|
+
var _useState3 = useState(false),
|
76
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
77
|
+
isOpen = _useState4[0],
|
78
|
+
setIsOpen = _useState4[1];
|
79
|
+
var _useState5 = useState(''),
|
80
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
81
|
+
activeDescendant = _useState6[0],
|
82
|
+
setActiveDescendant = _useState6[1];
|
83
|
+
var inputWrapperRef = useRef();
|
84
|
+
var inputRef = useRef();
|
85
|
+
var buttonRef = useRef();
|
86
|
+
var toggleItems = function toggleItems(keys) {
|
87
|
+
setFilterString('');
|
88
|
+
if (onSelectionChange) onSelectionChange(keys);
|
89
|
+
};
|
90
|
+
var _useFilter = useFilter({
|
91
|
+
sensitivity: 'base'
|
92
|
+
}),
|
93
|
+
contains = _useFilter.contains;
|
94
|
+
var filterNodesWithChildren = function filterNodesWithChildren(iterableNode) {
|
95
|
+
var nodeArr = _Array$from(iterableNode);
|
96
|
+
// filters child items if they have sections
|
97
|
+
var filteredSections = _mapInstanceProperty(nodeArr).call(nodeArr, function f(nodeItem) {
|
98
|
+
var _context;
|
99
|
+
if ((nodeItem === null || nodeItem === void 0 ? void 0 : nodeItem.type) === 'item') {
|
100
|
+
var _nodeItem$value;
|
101
|
+
return contains((nodeItem === null || nodeItem === void 0 || (_nodeItem$value = nodeItem.value) === null || _nodeItem$value === void 0 ? void 0 : _nodeItem$value.name) || '', filterString) && nodeItem;
|
102
|
+
}
|
103
|
+
var childNodes = _filterInstanceProperty(_context = _Array$from(nodeItem.childNodes)).call(_context, f);
|
104
|
+
// Don't return sections without children, see UIP-5951
|
105
|
+
return childNodes.length !== 0 && _objectSpread(_objectSpread({}, nodeItem), {}, {
|
106
|
+
childNodes: childNodes
|
107
|
+
});
|
108
|
+
});
|
109
|
+
|
110
|
+
// we are filtering null items here since we were not able to filter them in previous function
|
111
|
+
return _filterInstanceProperty(filteredSections).call(filteredSections, function (item) {
|
112
|
+
return item;
|
113
|
+
});
|
114
|
+
};
|
115
|
+
var state = useListState(_objectSpread(_objectSpread({}, props), {}, {
|
116
|
+
filter: filterNodesWithChildren,
|
117
|
+
items: items,
|
118
|
+
onSelectionChange: toggleItems,
|
119
|
+
selectionMode: 'multiple'
|
120
|
+
}));
|
121
|
+
var selectionManager = state.selectionManager;
|
122
|
+
var close = function close() {
|
123
|
+
return setIsOpen(false);
|
124
|
+
};
|
125
|
+
|
126
|
+
/* istanbul ignore next */
|
127
|
+
useImperativeHandle(ref, function () {
|
128
|
+
return inputWrapperRef.current;
|
129
|
+
});
|
130
|
+
/* istanbul ignore next */
|
131
|
+
useImperativeHandle(ref, function () {
|
132
|
+
return inputRef.current;
|
133
|
+
});
|
134
|
+
var listBoxRef = useRef();
|
135
|
+
var popoverRef = useRef();
|
136
|
+
var _useOverlayPosition = useOverlayPosition({
|
137
|
+
isOpen: isOpen,
|
138
|
+
onClose: close,
|
139
|
+
offset: 1,
|
140
|
+
overlayRef: popoverRef,
|
141
|
+
placement: "".concat(direction, " end"),
|
142
|
+
scrollRef: listBoxRef,
|
143
|
+
shouldFlip: !isNotFlippable,
|
144
|
+
targetRef: inputWrapperRef
|
145
|
+
}),
|
146
|
+
overlayProps = _useOverlayPosition.overlayProps,
|
147
|
+
placement = _useOverlayPosition.placement,
|
148
|
+
updatePosition = _useOverlayPosition.updatePosition;
|
149
|
+
|
150
|
+
// Update position once the ListBox has rendered. This ensures that
|
151
|
+
// it flips properly when it doesn't fit in the available space.
|
152
|
+
/* istanbul ignore next */
|
153
|
+
useLayoutEffect(function () {
|
154
|
+
if (isOpen) {
|
155
|
+
requestAnimationFrame(function () {
|
156
|
+
updatePosition();
|
157
|
+
});
|
158
|
+
}
|
159
|
+
}, [isOpen, selectionManager.selectedKeys, updatePosition]);
|
160
|
+
|
161
|
+
// Measure the width of the input to inform the width of the menu (below).
|
162
|
+
var _useState7 = useState(null),
|
163
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
164
|
+
menuWidth = _useState8[0],
|
165
|
+
setMenuWidth = _useState8[1];
|
166
|
+
var onResize = useCallback(function () {
|
167
|
+
/* istanbul ignore next */
|
168
|
+
if (inputWrapperRef.current) {
|
169
|
+
setMenuWidth("".concat(inputWrapperRef.current.offsetWidth + 2, "px"));
|
170
|
+
}
|
171
|
+
}, [inputWrapperRef, isOpen, setMenuWidth]);
|
172
|
+
useResizeObserver({
|
173
|
+
ref: inputWrapperRef,
|
174
|
+
onResize: onResize
|
175
|
+
});
|
176
|
+
useLayoutEffect(onResize, [onResize]);
|
177
|
+
var style = _objectSpread(_objectSpread({}, overlayProps.style), {}, {
|
178
|
+
width: menuWidth,
|
179
|
+
minWidth: menuWidth
|
180
|
+
});
|
181
|
+
useEffect(function () {
|
182
|
+
if (defaultSelectedKeys) selectionManager.setSelectedKeys(defaultSelectedKeys);
|
183
|
+
}, []);
|
184
|
+
useEffect(function () {
|
185
|
+
if (selectedKeys) selectionManager.setSelectedKeys(selectedKeys);
|
186
|
+
}, []);
|
187
|
+
useEffect(function () {
|
188
|
+
if (onOpenChange) onOpenChange(isOpen);
|
189
|
+
if (!isOpen) setActiveDescendant('');
|
190
|
+
}, [isOpen]);
|
191
|
+
|
192
|
+
/* istanbul ignore next */
|
193
|
+
var keyDown = function keyDown(e) {
|
194
|
+
switch (e.key) {
|
195
|
+
case 'Enter':
|
196
|
+
{
|
197
|
+
e.preventDefault();
|
198
|
+
if (selectionManager.focusedKey) {
|
199
|
+
var key = selectionManager.focusedKey;
|
200
|
+
if (!_includesInstanceProperty(disabledKeys).call(disabledKeys, key)) {
|
201
|
+
selectionManager.toggleSelection(selectionManager.focusedKey);
|
202
|
+
setFilterString('');
|
203
|
+
}
|
204
|
+
} else {
|
205
|
+
setFilterString('');
|
206
|
+
}
|
207
|
+
break;
|
208
|
+
}
|
209
|
+
case 'ArrowDown':
|
210
|
+
{
|
211
|
+
var nextKey = state.collection.getKeyAfter(selectionManager.focusedKey) || state.collection.getFirstKey();
|
212
|
+
if (nextKey) selectionManager.setFocusedKey(nextKey);
|
213
|
+
break;
|
214
|
+
}
|
215
|
+
case 'ArrowUp':
|
216
|
+
{
|
217
|
+
var prevKey = state.collection.getKeyBefore(selectionManager.focusedKey) || state.collection.getLastKey();
|
218
|
+
if (prevKey) selectionManager.setFocusedKey(prevKey);
|
219
|
+
break;
|
220
|
+
}
|
221
|
+
case 'Escape':
|
222
|
+
{
|
223
|
+
setFilterString('');
|
224
|
+
close();
|
225
|
+
break;
|
226
|
+
}
|
227
|
+
default:
|
228
|
+
break;
|
229
|
+
}
|
230
|
+
if (onKeyDown) onKeyDown(e.nativeEvent);
|
231
|
+
};
|
232
|
+
var _useState9 = useState('Select All'),
|
233
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
234
|
+
selectionState = _useState10[0],
|
235
|
+
setSelectionState = _useState10[1];
|
236
|
+
var arrayItems = _Array$from(items);
|
237
|
+
var itemCount = _reduceInstanceProperty(arrayItems).call(arrayItems, function (count, obj) {
|
238
|
+
return count + (obj.children ? obj.children.length : 1);
|
239
|
+
}, 0);
|
240
|
+
var selectedKeysSize = selectionManager.selectedKeys.size;
|
241
|
+
var checkboxSelected = ((_selectionManager$sta = selectionManager.state.selectedKeys) === null || _selectionManager$sta === void 0 ? void 0 : _selectionManager$sta.size) !== 0 && ___EmotionJSX(Text, {
|
242
|
+
color: "text.secondary"
|
243
|
+
}, itemCount === selectedKeysSize ? 'All' : (_selectionManager$sta2 = selectionManager.state.selectedKeys) === null || _selectionManager$sta2 === void 0 ? void 0 : _selectionManager$sta2.size, ' ', "Selected");
|
244
|
+
useEffect(function () {
|
245
|
+
if (selectedKeysSize < itemCount) {
|
246
|
+
setSelectionState('Select All');
|
247
|
+
} else if (selectedKeysSize === itemCount) setSelectionState('Deselect All');
|
248
|
+
}, [itemCount, selectedKeysSize]);
|
249
|
+
var handleSelection = function handleSelection() {
|
250
|
+
if (selectedKeysSize < itemCount) {
|
251
|
+
var allItemNames = _flatMapInstanceProperty(arrayItems).call(arrayItems, function (obj) {
|
252
|
+
var _context2;
|
253
|
+
return obj.children ? _mapInstanceProperty(_context2 = obj.children).call(_context2, function (child) {
|
254
|
+
return child.name;
|
255
|
+
}) : obj.name;
|
256
|
+
});
|
257
|
+
selectionManager.setSelectedKeys(allItemNames);
|
258
|
+
setSelectionState('Deselect All');
|
259
|
+
} else if (selectionState === 'Deselect All') {
|
260
|
+
selectionManager.setSelectedKeys([]);
|
261
|
+
setSelectionState('Select All');
|
262
|
+
}
|
263
|
+
};
|
264
|
+
var listbox = ___EmotionJSX(FocusScope, null, filterString === '' && ___EmotionJSX(Button, {
|
265
|
+
onPress: handleSelection,
|
266
|
+
ref: buttonRef,
|
267
|
+
variant: "link",
|
268
|
+
mt: "sm",
|
269
|
+
ml: "14px",
|
270
|
+
sx: {
|
271
|
+
fontWeight: '400'
|
272
|
+
}
|
273
|
+
}, selectionState), ___EmotionJSX(DismissButton, {
|
274
|
+
onDismiss: close
|
275
|
+
}), ___EmotionJSX(ScrollBox, scrollBoxProps, ___EmotionJSX(ListBox, _extends({
|
276
|
+
ref: listBoxRef,
|
277
|
+
hasAutoFocus: hasAutoFocus,
|
278
|
+
hasNoEmptySelection: true,
|
279
|
+
state: state,
|
280
|
+
"aria-label": "List of options",
|
281
|
+
isCondensed: mode === 'condensed'
|
282
|
+
}, overlayProps))), ___EmotionJSX(DismissButton, {
|
283
|
+
onDismiss: close
|
284
|
+
}));
|
285
|
+
var visuallyHidden = ___EmotionJSX(VisuallyHidden, {
|
286
|
+
id: "selectedKeysState"
|
287
|
+
}, "Selected options:", _Array$from(selectionManager.selectedKeys).join(' '));
|
288
|
+
|
289
|
+
// the reason we are using two different visually hiddens, rather than one that updates it's value
|
290
|
+
// is because there are tests that break if an empty visually hidden is rendered in the TextField
|
291
|
+
var EmptyVisuallyHidden = function EmptyVisuallyHidden() {
|
292
|
+
return ___EmotionJSX(VisuallyHidden, {
|
293
|
+
id: "emptyKeysState"
|
294
|
+
}, "Nothing Selected");
|
295
|
+
};
|
296
|
+
var inputProps = _objectSpread(_objectSpread({}, customInputProps), {}, {
|
297
|
+
controlProps: {
|
298
|
+
'aria-activedescendant': activeDescendant,
|
299
|
+
'aria-controls': (_listBoxRef$current = listBoxRef.current) === null || _listBoxRef$current === void 0 ? void 0 : _listBoxRef$current.id,
|
300
|
+
'aria-expanded': isOpen,
|
301
|
+
role: 'combobox',
|
302
|
+
ref: inputRef,
|
303
|
+
sx: {
|
304
|
+
color: 'text.secondary'
|
305
|
+
}
|
306
|
+
},
|
307
|
+
hasAutoFocus: hasAutoFocus,
|
308
|
+
hasNoStatusIndicator: hasNoStatusIndicator,
|
309
|
+
isDisabled: isDisabled,
|
310
|
+
isReadOnly: isReadOnly,
|
311
|
+
isRequired: isRequired,
|
312
|
+
label: label,
|
313
|
+
placeholder: ((_selectionManager$sta3 = selectionManager.state.selectedKeys) === null || _selectionManager$sta3 === void 0 ? void 0 : _selectionManager$sta3.size) === 0 ? 'Select' : '',
|
314
|
+
wrapperProps: {
|
315
|
+
ref: inputWrapperRef,
|
316
|
+
variant: 'forms.input.multivaluesWrapper',
|
317
|
+
sx: isReadOnly && {
|
318
|
+
boxShadow: 'inset 0 0 0 100px #e5e9f8',
|
319
|
+
border: 'none'
|
320
|
+
}
|
321
|
+
},
|
322
|
+
status: status
|
323
|
+
});
|
324
|
+
var handleButtonPress = function handleButtonPress() {
|
325
|
+
if (!isOpen) {
|
326
|
+
setIsOpen(true);
|
327
|
+
inputRef.current.focus();
|
328
|
+
} else {
|
329
|
+
close();
|
330
|
+
}
|
331
|
+
};
|
332
|
+
var button = ___EmotionJSX(Box, {
|
333
|
+
as: "button",
|
334
|
+
variant: "forms.comboBox.button",
|
335
|
+
tabIndex: -1,
|
336
|
+
onClick: handleButtonPress,
|
337
|
+
sx: {
|
338
|
+
border: 'none'
|
339
|
+
}
|
340
|
+
}, ___EmotionJSX(Icon, {
|
341
|
+
icon: isOpen ? MenuUp : MenuDown,
|
342
|
+
title: {
|
343
|
+
name: isOpen ? 'Menu Up Icon' : 'Menu Down Icon'
|
344
|
+
}
|
345
|
+
}));
|
346
|
+
return ___EmotionJSX(MultivaluesContext.Provider, {
|
347
|
+
value: setActiveDescendant
|
348
|
+
}, ___EmotionJSX(Box, containerProps, ___EmotionJSX(TextField, _extends({
|
349
|
+
onBlur: function onBlur(e) {
|
350
|
+
var _popoverRef$current;
|
351
|
+
var blurIntoPopover = (_popoverRef$current = popoverRef.current) === null || _popoverRef$current === void 0 ? void 0 : _popoverRef$current.contains(e.relatedTarget);
|
352
|
+
if (blurIntoPopover) {
|
353
|
+
return;
|
354
|
+
}
|
355
|
+
setIsOpen(false);
|
356
|
+
setFilterString('');
|
357
|
+
if (_onBlur) _onBlur(e.nativeEvent);
|
358
|
+
},
|
359
|
+
onChange: function onChange(e) {
|
360
|
+
if (!isOpen) setIsOpen(true);
|
361
|
+
setFilterString(e.target.value);
|
362
|
+
if (onInputChange) onInputChange(e.target.value);
|
363
|
+
},
|
364
|
+
onFocus: function onFocus(e) {
|
365
|
+
setIsOpen(true);
|
366
|
+
if (_onFocus) _onFocus(e.nativeEvent);
|
367
|
+
},
|
368
|
+
onKeyDown: keyDown,
|
369
|
+
onKeyUp: function onKeyUp(e) {
|
370
|
+
return _onKeyUp && _onKeyUp(e.nativeEvent);
|
371
|
+
},
|
372
|
+
"aria-describedby": selectionManager.selectedKeys.size > 0 ? 'selectedKeysState' : 'emptyKeysState',
|
373
|
+
slots: {
|
374
|
+
inContainer: button,
|
375
|
+
beforeInput: ___EmotionJSX(React.Fragment, null, checkboxSelected, selectionManager.selectedKeys.size > 0 && visuallyHidden)
|
376
|
+
} // eslint-disable-line
|
377
|
+
,
|
378
|
+
value: filterString,
|
379
|
+
helperText: helperText,
|
380
|
+
"aria-invalid": status === 'error' && true
|
381
|
+
}, getPendoID('MultivaluesField'), others, inputProps)), ___EmotionJSX(PopoverContainer, {
|
382
|
+
hasNoArrow: true,
|
383
|
+
isNonModal: true,
|
384
|
+
isOpen: !state.collection.size ? false : isOpen,
|
385
|
+
onClose: close,
|
386
|
+
placement: placement,
|
387
|
+
ref: popoverRef,
|
388
|
+
style: style
|
389
|
+
}, listbox), ___EmotionJSX(EmptyVisuallyHidden, null)));
|
390
|
+
});
|
391
|
+
CondensedMultivaluesField.propTypes = _objectSpread(_objectSpread(_objectSpread({
|
392
|
+
/** The initial selected keys in the collection (uncontrolled). */
|
393
|
+
defaultSelectedKeys: isIterableProp,
|
394
|
+
/** Where the menu opens relative to its trigger. */
|
395
|
+
direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
|
396
|
+
/**
|
397
|
+
* The item keys that are disabled. These items cannot be selected.
|
398
|
+
*/
|
399
|
+
disabledKeys: isIterableProp,
|
400
|
+
/** Whether the element should receive focus on render. */
|
401
|
+
hasAutoFocus: PropTypes.bool,
|
402
|
+
/** Whether the field has a status indicator. */
|
403
|
+
hasNoStatusIndicator: PropTypes.bool,
|
404
|
+
/** Text rendered below the input. */
|
405
|
+
helperText: PropTypes.node,
|
406
|
+
/**
|
407
|
+
* Props that get passed as-is to the underlying TextField element
|
408
|
+
*/
|
409
|
+
inputProps: PropTypes.shape({}),
|
410
|
+
/** Whether the input is disabled. */
|
411
|
+
isDisabled: PropTypes.bool,
|
412
|
+
/**
|
413
|
+
* Whether the menu is prevented from flipping directions when insufficient space is
|
414
|
+
* available for the given `direction` placement.
|
415
|
+
*/
|
416
|
+
isNotFlippable: PropTypes.bool,
|
417
|
+
/** Whether the input can be selected but not changed by the user. */
|
418
|
+
isReadOnly: PropTypes.bool,
|
419
|
+
/** Whether user input is required on the input before form submission. */
|
420
|
+
isRequired: PropTypes.bool,
|
421
|
+
/** The list of items.
|
422
|
+
*
|
423
|
+
* **Note:** Every item needs to have key and name properties.
|
424
|
+
*
|
425
|
+
* `Array<{key: string, name: string}>`
|
426
|
+
*/
|
427
|
+
items: isIterableProp,
|
428
|
+
/** The rendered label for the field. */
|
429
|
+
label: PropTypes.string,
|
430
|
+
/** Whether the component allows to create new values or only choose from the selection list */
|
431
|
+
mode: PropTypes.oneOf(['restrictive', 'non-restrictive', 'condensed']),
|
432
|
+
/**
|
433
|
+
* Handler that is called when the element loses focus.
|
434
|
+
*
|
435
|
+
* `(e: FocusEvent) => void`
|
436
|
+
*/
|
437
|
+
onBlur: PropTypes.func,
|
438
|
+
/**
|
439
|
+
* Handler that is called when the element receives focus.
|
440
|
+
*
|
441
|
+
* `(e: FocusEvent) => void`
|
442
|
+
*/
|
443
|
+
onFocus: PropTypes.func,
|
444
|
+
/**
|
445
|
+
* Handler that is called when the input value changes.
|
446
|
+
*
|
447
|
+
* `(value: string) => void`
|
448
|
+
*/
|
449
|
+
onInputChange: PropTypes.func,
|
450
|
+
/**
|
451
|
+
* Handler that is called when a key is pressed.
|
452
|
+
*
|
453
|
+
* `(e: KeyboardEvent) => void`
|
454
|
+
*/
|
455
|
+
onKeyDown: PropTypes.func,
|
456
|
+
/**
|
457
|
+
* Handler that is called when a key is released.
|
458
|
+
*
|
459
|
+
* `(e: KeyboardEvent) => void`
|
460
|
+
*/
|
461
|
+
onKeyUp: PropTypes.func,
|
462
|
+
/**
|
463
|
+
* Method that is called when the open state of the menu changes.
|
464
|
+
*
|
465
|
+
* `(isOpen: boolean) => void`
|
466
|
+
*/
|
467
|
+
onOpenChange: PropTypes.func,
|
468
|
+
/**
|
469
|
+
* Handler that is called when the selection changes.
|
470
|
+
*
|
471
|
+
* `(keys: Iterable<Key>) => any`
|
472
|
+
*/
|
473
|
+
onSelectionChange: PropTypes.func,
|
474
|
+
/** Temporary text that occupies the text input when it is empty. */
|
475
|
+
placeholder: PropTypes.string,
|
476
|
+
/**
|
477
|
+
* The item keys that are readonly. These items cannot be changed or selected.
|
478
|
+
*/
|
479
|
+
readOnlyKeys: PropTypes.arrayOf(PropTypes.string),
|
480
|
+
/** The currently selected keys in the collection (controlled). */
|
481
|
+
selectedKeys: isIterableProp,
|
482
|
+
// /** Props object that is spread directly into the ScrollBox element. */
|
483
|
+
/** @ignore */
|
484
|
+
scrollBoxProps: PropTypes.shape({
|
485
|
+
maxHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number])
|
486
|
+
})
|
487
|
+
}, statusPropTypes), ariaAttributesBasePropTypes), inputFieldAttributesBasePropTypes);
|
488
|
+
CondensedMultivaluesField.defaultProps = _objectSpread({
|
489
|
+
direction: 'bottom',
|
490
|
+
isReadOnly: false,
|
491
|
+
scrollBoxProps: {
|
492
|
+
maxHeight: 300
|
493
|
+
}
|
494
|
+
}, statusDefaultProp);
|
495
|
+
export default CondensedMultivaluesField;
|