@telus-uds/components-web 2.18.0 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/component-docs.json +381 -471
  3. package/lib/NavigationBar/NavigationSubMenu.js +2 -4
  4. package/lib/baseExports.js +12 -0
  5. package/lib/index.js +0 -18
  6. package/lib/utils/useOverlaidPosition.js +2 -2
  7. package/lib-module/NavigationBar/NavigationSubMenu.js +1 -2
  8. package/lib-module/baseExports.js +1 -1
  9. package/lib-module/index.js +0 -2
  10. package/lib-module/utils/useOverlaidPosition.js +2 -2
  11. package/package.json +2 -2
  12. package/src/NavigationBar/NavigationSubMenu.jsx +1 -2
  13. package/src/baseExports.js +2 -0
  14. package/src/index.js +0 -2
  15. package/src/utils/useOverlaidPosition.js +2 -2
  16. package/lib/Autocomplete/Autocomplete.js +0 -430
  17. package/lib/Autocomplete/Loading.js +0 -46
  18. package/lib/Autocomplete/Suggestions.js +0 -81
  19. package/lib/Autocomplete/constants.js +0 -19
  20. package/lib/Autocomplete/dictionary.js +0 -19
  21. package/lib/Autocomplete/index.js +0 -13
  22. package/lib/Listbox/GroupControl.js +0 -110
  23. package/lib/Listbox/Listbox.js +0 -185
  24. package/lib/Listbox/ListboxGroup.js +0 -145
  25. package/lib/Listbox/ListboxItem.js +0 -101
  26. package/lib/Listbox/ListboxOverlay.js +0 -91
  27. package/lib/Listbox/index.js +0 -13
  28. package/lib-module/Autocomplete/Autocomplete.js +0 -406
  29. package/lib-module/Autocomplete/Loading.js +0 -32
  30. package/lib-module/Autocomplete/Suggestions.js +0 -64
  31. package/lib-module/Autocomplete/constants.js +0 -5
  32. package/lib-module/Autocomplete/dictionary.js +0 -12
  33. package/lib-module/Autocomplete/index.js +0 -2
  34. package/lib-module/Listbox/GroupControl.js +0 -96
  35. package/lib-module/Listbox/Listbox.js +0 -164
  36. package/lib-module/Listbox/ListboxGroup.js +0 -122
  37. package/lib-module/Listbox/ListboxItem.js +0 -77
  38. package/lib-module/Listbox/ListboxOverlay.js +0 -69
  39. package/lib-module/Listbox/index.js +0 -2
  40. package/src/Autocomplete/Autocomplete.jsx +0 -375
  41. package/src/Autocomplete/Loading.jsx +0 -15
  42. package/src/Autocomplete/Suggestions.jsx +0 -52
  43. package/src/Autocomplete/constants.js +0 -6
  44. package/src/Autocomplete/dictionary.js +0 -12
  45. package/src/Autocomplete/index.js +0 -3
  46. package/src/Listbox/GroupControl.jsx +0 -82
  47. package/src/Listbox/Listbox.jsx +0 -169
  48. package/src/Listbox/ListboxGroup.jsx +0 -125
  49. package/src/Listbox/ListboxItem.jsx +0 -80
  50. package/src/Listbox/ListboxOverlay.jsx +0 -72
  51. package/src/Listbox/index.js +0 -3
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
- var _componentsBase = require("@telus-uds/components-base");
13
-
14
- var _Spinner = _interopRequireDefault(require("../Spinner"));
15
-
16
- var _jsxRuntime = require("react/jsx-runtime");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- const Loading = _ref => {
21
- let {
22
- label
23
- } = _ref;
24
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Box, {
25
- space: 3,
26
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.StackView, {
27
- direction: "row",
28
- space: 2,
29
- tokens: {
30
- alignItems: 'center'
31
- },
32
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {
33
- inline: true,
34
- show: true,
35
- label: label,
36
- labelPosition: "right"
37
- })
38
- })
39
- });
40
- };
41
-
42
- Loading.propTypes = {
43
- label: _propTypes.default.string
44
- };
45
- var _default = Loading;
46
- exports.default = _default;
@@ -1,81 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
- var _componentsBase = require("@telus-uds/components-base");
13
-
14
- var _Listbox = _interopRequireDefault(require("../Listbox"));
15
-
16
- var _jsxRuntime = require("react/jsx-runtime");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
-
22
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
-
24
- const Suggestions = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
25
- let {
26
- hasResults,
27
- items = [],
28
- noResults,
29
- onClose,
30
- onSelect,
31
- parentRef
32
- } = _ref;
33
- const pressableItems = items.map(_ref2 => {
34
- let {
35
- id,
36
- ...rest
37
- } = _ref2;
38
- return {
39
- id,
40
- onPress: () => onSelect(id),
41
- ...rest
42
- };
43
- });
44
- if (items !== null && items !== void 0 && items.length) return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
45
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.A11yText, {
46
- accessibilityLiveRegion: "polite",
47
- text: hasResults
48
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Listbox.default, {
49
- items: pressableItems,
50
- firstItemRef: ref,
51
- parentRef: parentRef,
52
- onClose: onClose
53
- })]
54
- });
55
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Box, {
56
- space: 3,
57
- children: typeof noResults === 'string' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
58
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Typography, {
59
- accessibilityLiveRegion: "polite",
60
- variant: {
61
- size: 'small'
62
- },
63
- children: noResults
64
- })
65
- }) : noResults
66
- });
67
- });
68
- Suggestions.displayName = 'Suggestions';
69
- Suggestions.propTypes = {
70
- hasResults: _propTypes.default.string.isRequired,
71
- items: _propTypes.default.arrayOf(_propTypes.default.shape({
72
- id: _propTypes.default.string,
73
- label: _propTypes.default.node
74
- })).isRequired,
75
- noResults: _propTypes.default.node.isRequired,
76
- onClose: _propTypes.default.func.isRequired,
77
- onSelect: _propTypes.default.func.isRequired,
78
- parentRef: _propTypes.default.object.isRequired
79
- };
80
- var _default = Suggestions;
81
- exports.default = _default;
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.MIN_LISTBOX_WIDTH = exports.INPUT_LEFT_PADDING = exports.DEFAULT_MIN_TO_SUGGESTION = exports.DEFAULT_MAX_SUGGESTIONS = void 0;
7
-
8
- var _palette = _interopRequireDefault(require("@telus-uds/palette-allium/build/web/palette"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- const DEFAULT_MIN_TO_SUGGESTION = 1;
13
- exports.DEFAULT_MIN_TO_SUGGESTION = DEFAULT_MIN_TO_SUGGESTION;
14
- const DEFAULT_MAX_SUGGESTIONS = 5;
15
- exports.DEFAULT_MAX_SUGGESTIONS = DEFAULT_MAX_SUGGESTIONS;
16
- const INPUT_LEFT_PADDING = _palette.default.size.size16;
17
- exports.INPUT_LEFT_PADDING = INPUT_LEFT_PADDING;
18
- const MIN_LISTBOX_WIDTH = _palette.default.size.size288;
19
- exports.MIN_LISTBOX_WIDTH = MIN_LISTBOX_WIDTH;
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _default = {
8
- en: {
9
- hasResults: 'Some results are available',
10
- loading: 'Searching...',
11
- noResults: 'No results found'
12
- },
13
- fr: {
14
- hasResults: 'Quelques suggestions sont disponible',
15
- loading: 'Recherche...',
16
- noResults: 'Aucun résultat trouvé'
17
- }
18
- };
19
- exports.default = _default;
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _Autocomplete = _interopRequireDefault(require("./Autocomplete"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- var _default = _Autocomplete.default;
13
- exports.default = _default;
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _styledComponents = _interopRequireDefault(require("styled-components"));
11
-
12
- var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
- var _componentsBase = require("@telus-uds/components-base");
15
-
16
- var _jsxRuntime = require("react/jsx-runtime");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- const StyledControlWrapper = /*#__PURE__*/_styledComponents.default.div.withConfig({
21
- displayName: "GroupControl__StyledControlWrapper",
22
- componentId: "components-web__sc-1r7ts3q-0"
23
- })(_ref => {
24
- let {
25
- groupFontName,
26
- groupFontWeight,
27
- groupFontSize,
28
- groupColor,
29
- groupBackgroundColor,
30
- groupBorderColor,
31
- groupBorderWidth,
32
- groupBorderRadius,
33
- groupPaddingLeft,
34
- groupPaddingRight,
35
- groupPaddingTop,
36
- groupPaddingBottom,
37
- itemTextDecoration,
38
- itemOutline,
39
- groupHeight
40
- } = _ref;
41
- return {
42
- fontFamily: `${groupFontName}${groupFontWeight}normal`,
43
- fontSize: groupFontSize,
44
- color: groupColor,
45
- textDecoration: itemTextDecoration,
46
- backgroundColor: groupBackgroundColor,
47
- outline: itemOutline,
48
- width: '100%',
49
- height: groupHeight,
50
- display: 'flex',
51
- alignItems: 'center',
52
- justifyContent: 'space-between',
53
- boxSizing: 'border-box',
54
- border: `${groupBorderWidth}px solid ${groupBorderColor}`,
55
- borderRadius: groupBorderRadius,
56
- paddingLeft: groupPaddingLeft - groupBorderWidth,
57
- paddingRight: groupPaddingRight - groupBorderWidth,
58
- paddingTop: groupPaddingTop - groupBorderWidth,
59
- paddingBottom: groupPaddingBottom - groupBorderWidth
60
- };
61
- });
62
-
63
- const GroupControl = _ref2 => {
64
- let {
65
- expanded,
66
- pressed,
67
- hover,
68
- focus,
69
- label,
70
- id
71
- } = _ref2;
72
- const {
73
- selectedId,
74
- setSelectedId
75
- } = (0, _componentsBase.useListboxContext)();
76
- const tokens = (0, _componentsBase.useThemeTokens)('Listbox', {}, {}, {
77
- expanded,
78
- pressed,
79
- hover,
80
- current: selectedId === id && id !== undefined,
81
- focus
82
- });
83
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledControlWrapper, {
84
- onClick: () => setSelectedId(id),
85
- ...tokens,
86
- children: [label, /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Spacer, {
87
- space: 1,
88
- direction: "row"
89
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Icon, {
90
- icon: tokens.groupIcon,
91
- tokens: {
92
- color: tokens.groupColor
93
- },
94
- variant: {
95
- size: 'micro'
96
- }
97
- })]
98
- });
99
- };
100
-
101
- GroupControl.propTypes = {
102
- id: _propTypes.default.string,
103
- expanded: _propTypes.default.bool,
104
- pressed: _propTypes.default.bool,
105
- hover: _propTypes.default.bool,
106
- focus: _propTypes.default.bool,
107
- label: _propTypes.default.string
108
- };
109
- var _default = GroupControl;
110
- exports.default = _default;
@@ -1,185 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
- var _styledComponents = _interopRequireDefault(require("styled-components"));
13
-
14
- var _componentsBase = require("@telus-uds/components-base");
15
-
16
- var _ListboxGroup = _interopRequireDefault(require("./ListboxGroup"));
17
-
18
- var _ListboxItem = _interopRequireDefault(require("./ListboxItem"));
19
-
20
- var _ListboxOverlay = _interopRequireDefault(require("./ListboxOverlay"));
21
-
22
- var _jsxRuntime = require("react/jsx-runtime");
23
-
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
-
28
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
- const StyledList = /*#__PURE__*/_styledComponents.default.ul.withConfig({
31
- displayName: "Listbox__StyledList",
32
- componentId: "components-web__sc-1564thh-0"
33
- })({
34
- margin: 0,
35
- padding: 0,
36
- listStyle: 'none'
37
- });
38
-
39
- const getInitialOpen = (items, selectedId) => items.filter(item => item.items && item.items.some(nestedItem => (nestedItem.id ?? nestedItem.label) === selectedId)).map(item => item.id ?? item.label);
40
-
41
- const Listbox = _ref => {
42
- let {
43
- items = [],
44
- firstItemRef = null,
45
- // focus will be moved to this one once within the menu
46
- parentRef = null,
47
- // to return focus to after leaving the last menu item
48
- selectedId: defaultSelectedId,
49
- LinkRouter,
50
- itemRouterProps,
51
- onClose,
52
- variant,
53
- tokens
54
- } = _ref;
55
- const initialOpen = getInitialOpen(items, defaultSelectedId);
56
- const [selectedId, setSelectedId] = (0, _react.useState)(defaultSelectedId);
57
- const {
58
- minHeight,
59
- minWidth
60
- } = (0, _componentsBase.useThemeTokens)('Listbox', variant, tokens); // We need to keep track of each item's ref in order to be able to
61
- // focus on a specific item via keyboard navigation
62
-
63
- const itemRefs = (0, _react.useRef)([]);
64
- if (firstItemRef !== null && firstItemRef !== void 0 && firstItemRef.current) itemRefs.current[0] = firstItemRef.current;
65
- const [focusedIndex, setFocusedIndex] = (0, _react.useState)(0);
66
- const handleKeydown = (0, _react.useCallback)(event => {
67
- const nextItemRef = itemRefs.current[focusedIndex + 1];
68
- const prevItemRef = itemRefs.current[focusedIndex - 1];
69
-
70
- if (event.key === 'ArrowUp' || event.shiftKey && event.key === 'Tab') {
71
- var _parentRef$current;
72
-
73
- // Move the focus to the previous item or to the parent one if on the first
74
- if (prevItemRef) {
75
- event.preventDefault();
76
- prevItemRef.focus();
77
- } else if (parentRef) (_parentRef$current = parentRef.current) === null || _parentRef$current === void 0 ? void 0 : _parentRef$current.focus();
78
-
79
- setFocusedIndex(focusedIndex - 1);
80
- } else if ((event.key === 'ArrowDown' || event.key === 'Tab') && nextItemRef) {
81
- event.preventDefault();
82
- setFocusedIndex(focusedIndex + 1);
83
- nextItemRef.focus();
84
- } else if (event.key === 'Escape') {
85
- var _parentRef$current2, _parentRef$current3;
86
-
87
- // Close the dropdown
88
- parentRef === null || parentRef === void 0 ? void 0 : (_parentRef$current2 = parentRef.current) === null || _parentRef$current2 === void 0 ? void 0 : _parentRef$current2.click(); // Return focus to the dropdown control after leaving the last item
89
-
90
- parentRef === null || parentRef === void 0 ? void 0 : (_parentRef$current3 = parentRef.current) === null || _parentRef$current3 === void 0 ? void 0 : _parentRef$current3.focus();
91
- if (onClose) onClose(event);
92
- }
93
- }, [focusedIndex, onClose, parentRef]); // Add listeners for mouse clicks outside and for key presses
94
-
95
- (0, _react.useEffect)(() => {
96
- window.addEventListener('click', onClose);
97
- window.addEventListener('keydown', handleKeydown);
98
- window.addEventListener('touchstart', onClose);
99
- return () => {
100
- window.removeEventListener('click', onClose);
101
- window.removeEventListener('keydown', handleKeydown);
102
- window.removeEventListener('touchstart', onClose);
103
- };
104
- }, [onClose, handleKeydown]);
105
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.ListboxContext.Provider, {
106
- value: {
107
- selectedId,
108
- setSelectedId
109
- },
110
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.ExpandCollapse, {
111
- initialOpen: initialOpen,
112
- maxOpen: 1,
113
- children: expandProps => /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledList, {
114
- role: "listbox",
115
- style: {
116
- minHeight,
117
- minWidth
118
- },
119
- children: items.map((item, index) => {
120
- const {
121
- id,
122
- label,
123
- items: nestedItems
124
- } = item;
125
- const itemId = id ?? label; // Give `firstItemRef` to the first focusable item
126
-
127
- const itemRef = index === 0 && !itemId !== selectedId || index === 1 && items[0].id === selectedId ? firstItemRef : ref => {
128
- itemRefs.current[index] = ref;
129
- return ref;
130
- };
131
- return nestedItems ? /*#__PURE__*/(0, _react.createElement)(_ListboxGroup.default, { ...item,
132
- expandProps: expandProps,
133
- LinkRouter: LinkRouter,
134
- itemRouterProps: itemRouterProps,
135
- prevItemRef: itemRefs.current[index - 1] ?? null,
136
- nextItemRef: itemRefs.current[index + 1] ?? null,
137
- ref: itemRef,
138
- key: itemId
139
- }) : /*#__PURE__*/(0, _react.createElement)(_ListboxItem.default, { ...item,
140
- key: itemId,
141
- id: itemId,
142
- LinkRouter: LinkRouter,
143
- itemRouterProps: itemRouterProps,
144
- prevItemRef: itemRefs.current[index - 1] ?? null,
145
- nextItemRef: itemRefs.current[index + 1] ?? null,
146
- ref: itemRef
147
- });
148
- })
149
- })
150
- })
151
- });
152
- };
153
-
154
- Listbox.propTypes = { ..._componentsBase.withLinkRouter.propTypes,
155
-
156
- /**
157
- * Focus will be moved to the item with this ref once within the menu.
158
- */
159
- firstItemRef: _propTypes.default.object,
160
-
161
- /**
162
- * Focus will be returned to the dropdown control with this ref after leaving
163
- * the last menu item.
164
- */
165
- parentRef: _propTypes.default.object,
166
-
167
- /**
168
- * `Listbox` items
169
- */
170
- items: _propTypes.default.array,
171
-
172
- /**
173
- * To select an item by default
174
- */
175
- selectedId: _propTypes.default.string,
176
-
177
- /**
178
- * onClose event
179
- */
180
- onClose: _propTypes.default.func,
181
- tokens: (0, _componentsBase.getTokensPropType)('Listbox')
182
- };
183
- Listbox.Overlay = _ListboxOverlay.default;
184
- var _default = Listbox;
185
- exports.default = _default;
@@ -1,145 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
- var _componentsBase = require("@telus-uds/components-base");
13
-
14
- var _styledComponents = _interopRequireDefault(require("styled-components"));
15
-
16
- var _ListboxItem = _interopRequireDefault(require("./ListboxItem"));
17
-
18
- var _GroupControl = _interopRequireDefault(require("./GroupControl"));
19
-
20
- var _jsxRuntime = require("react/jsx-runtime");
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
-
26
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
-
28
- /* eslint-disable react/require-default-props */
29
- const StyledGroupWrapper = /*#__PURE__*/_styledComponents.default.li.withConfig({
30
- displayName: "ListboxGroup__StyledGroupWrapper",
31
- componentId: "components-web__sc-3jlyy7-0"
32
- })({
33
- margin: 'none',
34
- padding: 'none',
35
- display: 'block',
36
- overflowY: 'hidden',
37
- // Currently the default expand collapse control does not have a focus state and so the browser default is applied.
38
- // This hides the outline so that it does not clash with the custom control we provide.
39
- '& div[role=button]': {
40
- outline: 'none'
41
- }
42
- });
43
-
44
- const StyledList = /*#__PURE__*/_styledComponents.default.ul.withConfig({
45
- displayName: "ListboxGroup__StyledList",
46
- componentId: "components-web__sc-3jlyy7-1"
47
- })({
48
- margin: 0,
49
- padding: 0,
50
- listStyle: 'none'
51
- });
52
-
53
- const ListboxGroup = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
54
- let {
55
- id,
56
- label,
57
- items,
58
- LinkRouter,
59
- linkRouterProps,
60
- expandProps,
61
- onLastItemBlur,
62
- nextItemRef,
63
- prevItemRef
64
- } = _ref;
65
- const {
66
- selectedId
67
- } = (0, _componentsBase.useListboxContext)(); // TODO: implement keyboard navigation via refs for grouped items separately here
68
-
69
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledGroupWrapper, {
70
- role: "option",
71
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.ExpandCollapse.Panel, {
72
- panelId: id ?? label,
73
- controlTokens: {
74
- icon: null,
75
- paddingLeft: 'none',
76
- paddingRight: 'none',
77
- paddingTop: 'none',
78
- paddingBottom: 'none',
79
- backgroundColor: 'transparent',
80
- borderColor: 'transparent',
81
- textLine: 'none',
82
- borderWidth: 0
83
- } // TODO refactor
84
- // eslint-disable-next-line react/no-unstable-nested-components
85
- ,
86
- control: controlProps => /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupControl.default, {
87
- id: id ?? label,
88
- ...controlProps,
89
- label: label
90
- }),
91
- ...expandProps,
92
- tokens: {
93
- contentPaddingLeft: 'none',
94
- contentPaddingRight: 'none',
95
- contentPaddingTop: 'none',
96
- contentPaddingBottom: 'none',
97
- borderColor: 'transparent',
98
- borderRadius: 0,
99
- borderWidth: 0,
100
- marginBottom: 0
101
- },
102
- controlRef: ref,
103
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledList, {
104
- children: items.map((item, index) => {
105
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListboxItem.default, {
106
- id: item.id ?? item.label,
107
- ...item,
108
- selected: item.id && item.id === selectedId || item.label && item.label === selectedId,
109
- isChild: true,
110
- LinkRouter: LinkRouter,
111
- linkRouterProps: linkRouterProps,
112
- ...(index === 0 && {
113
- prevItemRef
114
- }),
115
- ...(index === items.length - 1 && {
116
- nextItemRef
117
- }),
118
- ...(index === items.length - 1 && {
119
- onBlur: onLastItemBlur
120
- })
121
- }, item.label);
122
- })
123
- })
124
- })
125
- });
126
- });
127
- ListboxGroup.displayName = 'ListboxGroup';
128
- ListboxGroup.propTypes = { ..._componentsBase.withLinkRouter.propTypes,
129
- label: _propTypes.default.string,
130
- items: _propTypes.default.arrayOf(_propTypes.default.shape({
131
- href: _propTypes.default.string,
132
- label: _propTypes.default.string,
133
- current: _propTypes.default.bool
134
- })),
135
- expandProps: _propTypes.default.object,
136
- nextItemRef: _propTypes.default.object,
137
- prevItemRef: _propTypes.default.object,
138
-
139
- /**
140
- * Use this callback to redirect the focus after it leaves the last item of the group.
141
- */
142
- onLastItemBlur: _propTypes.default.func
143
- };
144
- var _default = ListboxGroup;
145
- exports.default = _default;