@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,101 +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 _utils = require("../utils");
17
-
18
- var _jsxRuntime = require("react/jsx-runtime");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- 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); }
23
-
24
- 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; }
25
-
26
- /* eslint-disable react/require-default-props */
27
- const [selectProps, selectedSystemPropTypes] = (0, _componentsBase.selectSystemProps)([_utils.htmlAttrs]);
28
-
29
- const StyledItemContainer = /*#__PURE__*/_styledComponents.default.li.withConfig({
30
- displayName: "ListboxItem__StyledItemContainer",
31
- componentId: "components-web__sc-tlroet-0"
32
- })({
33
- display: 'flex',
34
- paddingLeft: _ref => {
35
- let {
36
- isChild
37
- } = _ref;
38
- return isChild ? '16px' : '0px';
39
- },
40
- '&&&': {
41
- // Docusaurus applies aggressively high-specificity margin on `li`
42
- margin: 0
43
- }
44
- });
45
-
46
- const ListboxItem = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
47
- let {
48
- href,
49
- label,
50
- isChild = false,
51
- onBlur,
52
- nextItemRef,
53
- prevItemRef,
54
- tokens,
55
- variant = {},
56
- LinkRouter,
57
- linkRouterProps,
58
- id,
59
- onPress = () => {},
60
- ...rest
61
- } = _ref2;
62
- const selectedProps = selectProps({
63
- href,
64
- ...rest
65
- });
66
- const getTokens = (0, _componentsBase.useThemeTokensCallback)('Listbox', tokens, variant, {
67
- isChild
68
- });
69
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledItemContainer, {
70
- isChild: isChild,
71
- ...selectedProps,
72
- role: "option",
73
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.PressableItem, {
74
- href: href,
75
- isChild: isChild,
76
- onPress: onPress,
77
- onBlur: onBlur,
78
- nextItemRef: nextItemRef,
79
- prevItemRef: prevItemRef,
80
- ref: ref,
81
- tokens: getTokens,
82
- selectedProps: selectedProps,
83
- id: id,
84
- children: label
85
- })
86
- });
87
- });
88
- ListboxItem.displayName = 'ListboxItem';
89
- ListboxItem.propTypes = { ...selectedSystemPropTypes,
90
- ..._componentsBase.withLinkRouter.propTypes,
91
- href: _propTypes.default.string,
92
- isChild: _propTypes.default.bool,
93
- label: _propTypes.default.node.isRequired,
94
- nextItemRef: _propTypes.default.object,
95
- prevItemRef: _propTypes.default.object,
96
- onPress: _propTypes.default.func
97
- };
98
-
99
- var _default = (0, _componentsBase.withLinkRouter)(ListboxItem);
100
-
101
- exports.default = _default;
@@ -1,91 +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 _componentsBase = require("@telus-uds/components-base");
11
-
12
- var _propTypes = _interopRequireDefault(require("prop-types"));
13
-
14
- var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
15
-
16
- var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
17
-
18
- var _WebPortal = _interopRequireDefault(require("../WebPortal"));
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 staticStyles = _StyleSheet.default.create({
30
- positioner: {
31
- flex: 1,
32
- // Grow to maxWidth when possible, shrink when not possible
33
- position: 'absolute',
34
- zIndex: 10000 // Position on top of all the other overlays, including backdrops and modals
35
-
36
- },
37
- hidden: {
38
- // Use opacity not visibility to hide the dropdown during positioning
39
- // so on web, children may be focused from the first render
40
- opacity: 0
41
- }
42
- });
43
-
44
- const paddingVertical = 0;
45
- const paddingHorizontal = 0;
46
- const DropdownOverlay = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
47
- let {
48
- children,
49
- isReady = false,
50
- overlaidPosition,
51
- maxWidth,
52
- minWidth,
53
- onLayout
54
- } = _ref;
55
- const systemTokens = (0, _componentsBase.useThemeTokens)('Listbox', {}, {});
56
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_WebPortal.default, {
57
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
58
- ref: ref,
59
- onLayout: onLayout,
60
- style: [overlaidPosition, {
61
- maxWidth,
62
- minWidth
63
- }, staticStyles.positioner, !isReady && staticStyles.hidden],
64
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Card, {
65
- tokens: {
66
- shadow: systemTokens.shadow,
67
- paddingBottom: paddingVertical,
68
- paddingTop: paddingVertical,
69
- paddingLeft: paddingHorizontal,
70
- paddingRight: paddingHorizontal
71
- },
72
- children: children
73
- })
74
- })
75
- });
76
- });
77
- DropdownOverlay.displayName = 'DropdownOverlay';
78
- DropdownOverlay.propTypes = {
79
- children: _propTypes.default.node.isRequired,
80
- isReady: _propTypes.default.bool,
81
- overlaidPosition: _propTypes.default.shape({
82
- top: _propTypes.default.number,
83
- left: _propTypes.default.number,
84
- width: _propTypes.default.number
85
- }),
86
- maxWidth: _propTypes.default.number,
87
- minWidth: _propTypes.default.number,
88
- onLayout: _propTypes.default.func
89
- };
90
- var _default = DropdownOverlay;
91
- 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 _Listbox = _interopRequireDefault(require("./Listbox"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- var _default = _Listbox.default;
13
- exports.default = _default;
@@ -1,406 +0,0 @@
1
- /* eslint-disable react/require-default-props */
2
- import React, { forwardRef, useRef, useState } from 'react';
3
- import PropTypes from 'prop-types';
4
- import { throttle } from 'lodash';
5
- import { InputSupports, inputSupportsProps, selectSystemProps, TextInput, textInputProps, textInputHandlerProps, Typography, useCopy, useSafeLayoutEffect, useThemeTokens } from '@telus-uds/components-base';
6
- import Listbox from '../Listbox';
7
- import { htmlAttrs, useOverlaidPosition } from '../utils';
8
- import Loading from './Loading';
9
- import Suggestions from './Suggestions';
10
- import { DEFAULT_MAX_SUGGESTIONS, DEFAULT_MIN_TO_SUGGESTION, INPUT_LEFT_PADDING, MIN_LISTBOX_WIDTH } from './constants';
11
- import dictionary from './dictionary';
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- import { Fragment as _Fragment } from "react/jsx-runtime";
14
- import { jsxs as _jsxs } from "react/jsx-runtime";
15
- const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs, inputSupportsProps, textInputHandlerProps, textInputProps]); // Returns JSX to display a bold string `str` with unbolded occurrences of the
16
- // `substring` based in the array of `matchIndexes` provided
17
-
18
- const highlightAllMatches = function (str) {
19
- let substring = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
20
- let matchIndexes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
21
- let resultsTextColor = arguments.length > 3 ? arguments[3] : undefined;
22
- return (
23
- /*#__PURE__*/
24
- // Wrapping all in bold
25
- _jsx(Typography, {
26
- variant: {
27
- bold: false
28
- },
29
- tokens: {
30
- color: resultsTextColor
31
- },
32
- children: matchIndexes.reduce((acc, matchIndex, index) => [...acc, // Add a piece of the string up to the first occurrence of the substring
33
- index === 0 && (str.slice(0, matchIndex) ?? ''),
34
- /*#__PURE__*/
35
- // Unbold the occurrence of the substring (while keeping the original casing)
36
- _jsx(Typography, {
37
- variant: {
38
- bold: true
39
- },
40
- tokens: {
41
- color: resultsTextColor
42
- },
43
- children: str.slice(matchIndex, matchIndex + substring.length)
44
- }, matchIndex), // Add the rest of the string until the next occurrence or the end of it
45
- str.slice(matchIndex + substring.length, matchIndexes[index + 1] ?? str.length)], [])
46
- })
47
- );
48
- };
49
-
50
- const highlight = function () {
51
- let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
52
- let text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
53
- let color = arguments.length > 2 ? arguments[2] : undefined;
54
- return items.reduce((acc, item) => {
55
- var _Array$from;
56
-
57
- const matches = (_Array$from = Array.from(item.label.toLowerCase().matchAll(text.toLowerCase()))) === null || _Array$from === void 0 ? void 0 : _Array$from.map(_ref => {
58
- let {
59
- index
60
- } = _ref;
61
- return index;
62
- });
63
-
64
- if (matches !== null && matches !== void 0 && matches.length) {
65
- return [...acc, { ...item,
66
- label: highlightAllMatches(item.label, text, matches, color)
67
- }];
68
- }
69
-
70
- return [...acc, item];
71
- }, []);
72
- };
73
-
74
- const Autocomplete = /*#__PURE__*/forwardRef((_ref2, ref) => {
75
- var _ref3;
76
-
77
- let {
78
- children,
79
- copy = 'en',
80
- fullWidth = true,
81
- initialItems,
82
- initialValue,
83
- isLoading = false,
84
- items,
85
- maxSuggestions = DEFAULT_MAX_SUGGESTIONS,
86
- minToSuggestion = DEFAULT_MIN_TO_SUGGESTION,
87
- noResults,
88
- onChange,
89
- onClear,
90
- onSelect,
91
- readOnly,
92
- validation,
93
- value,
94
- ...rest
95
- } = _ref2;
96
- const {
97
- color: resultsTextColor
98
- } = useThemeTokens('Search', {}, {
99
- focus: true
100
- }); // The wrapped input is mostly responsible for controlled vs uncontrolled handling,
101
- // but we also need to adjust suggestions based on the mode:
102
- // - in controlled mode we rely entirely on the suggestions passed via the `items` prop,
103
- // - in uncontrolled mode we filter the suggestions ourselves based on the `initialItems`
104
- // prop and the text entered
105
-
106
- const isControlled = value !== undefined; // We need to store current items for uncontrolled usage
107
-
108
- const [currentItems, setCurrentItems] = useState(initialItems); // We need to store the current value as well to be able to highlight it
109
-
110
- const [currentValue, setCurrentValue] = useState(value ?? initialValue);
111
- const inputTokens = {
112
- paddingLeft: INPUT_LEFT_PADDING
113
- }; // Setting up the overlay
114
-
115
- const openOverlayRef = useRef();
116
- const [isExpanded, setIsExpanded] = useState(((_ref3 = value ?? initialValue) === null || _ref3 === void 0 ? void 0 : _ref3.length) >= minToSuggestion);
117
- const {
118
- overlaidPosition,
119
- sourceRef: inputRef,
120
- targetRef,
121
- onTargetLayout,
122
- isReady
123
- } = useOverlaidPosition({
124
- isShown: isExpanded,
125
- offsets: {
126
- vertical: 4
127
- }
128
- }); // We limit the number of suggestions displayed to avoid huge lists
129
- // TODO: add a way to make the `Listbox` occupy fixed height and be scrollable
130
- // within that height, which will unlock similar behaviour for `AutoComplete` as well
131
-
132
- const itemsToSuggest = function () {
133
- let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
134
- return maxSuggestions ? data.slice(0, maxSuggestions) : [...data];
135
- };
136
-
137
- const getCopy = useCopy({
138
- dictionary,
139
- copy
140
- }); // Tracking input width changes to resize the listbox overlay accordingly
141
-
142
- const [inputWidth, setInputWidth] = useState();
143
- useSafeLayoutEffect(() => {
144
- const updateInputWidth = () => {
145
- var _inputRef$current;
146
-
147
- setInputWidth((inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.clientWidth) + 4); // adding back all the input borders / outlines
148
-
149
- setIsExpanded(false); // close the suggestions while the input is changing
150
- };
151
-
152
- const throttledUpdateInputWidth = throttle(updateInputWidth, 100, {
153
- leading: false
154
- });
155
- updateInputWidth();
156
- window.addEventListener('load', updateInputWidth);
157
- window.addEventListener('resize', throttledUpdateInputWidth);
158
- return () => {
159
- window.removeEventListener('load', updateInputWidth);
160
- window.removeEventListener('resize', throttledUpdateInputWidth);
161
- };
162
- }, [inputRef]);
163
-
164
- const handleChange = newValue => {
165
- onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
166
- setCurrentValue(newValue);
167
- setIsExpanded((newValue === null || newValue === void 0 ? void 0 : newValue.length) >= minToSuggestion);
168
-
169
- if (!isControlled && initialItems !== undefined) {
170
- setCurrentItems(initialItems.filter(_ref4 => {
171
- var _label$toLowerCase;
172
-
173
- let {
174
- label
175
- } = _ref4;
176
- return label === null || label === void 0 ? void 0 : (_label$toLowerCase = label.toLowerCase()) === null || _label$toLowerCase === void 0 ? void 0 : _label$toLowerCase.includes(newValue === null || newValue === void 0 ? void 0 : newValue.toLowerCase());
177
- }));
178
- }
179
- };
180
-
181
- const handleSelect = selectedId => {
182
- var _ref5;
183
-
184
- onSelect === null || onSelect === void 0 ? void 0 : onSelect(selectedId);
185
- const {
186
- label: newValue
187
- } = (_ref5 = isControlled ? items : currentItems) === null || _ref5 === void 0 ? void 0 : _ref5.find(_ref6 => {
188
- let {
189
- id
190
- } = _ref6;
191
- return id === selectedId;
192
- });
193
- onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
194
- setCurrentValue(newValue);
195
- if (!isControlled && inputRef !== null && inputRef !== void 0 && inputRef.current) inputRef.current.value = newValue;
196
- setIsExpanded(false);
197
- };
198
-
199
- const handleClose = event => {
200
- var _openOverlayRef$curre, _openOverlayRef$curre2;
201
-
202
- if (event.type === 'keydown') {
203
- if (event.key === 'Escape' || event.key === 27) {
204
- setIsExpanded(false);
205
- } else if (event.key === 'ArrowDown' && isExpanded && !isLoading && targetRef !== null && targetRef !== void 0 && targetRef.current) {
206
- targetRef.current.focus();
207
- }
208
- } else if (event.type === 'click' && openOverlayRef !== null && openOverlayRef !== void 0 && openOverlayRef.current && event.target && !(openOverlayRef !== null && openOverlayRef !== void 0 && (_openOverlayRef$curre = openOverlayRef.current) !== null && _openOverlayRef$curre !== void 0 && _openOverlayRef$curre.contains(event.target))) {
209
- setIsExpanded(false);
210
- } else if (event.type === 'touchstart' && openOverlayRef !== null && openOverlayRef !== void 0 && openOverlayRef.current && event.touches[0].target && !(openOverlayRef !== null && openOverlayRef !== void 0 && (_openOverlayRef$curre2 = openOverlayRef.current) !== null && _openOverlayRef$curre2 !== void 0 && _openOverlayRef$curre2.contains(event.touches[0].target))) {
211
- setIsExpanded(false);
212
- }
213
- };
214
-
215
- const {
216
- supportsProps,
217
- ...selectedProps
218
- } = selectProps(rest);
219
- return /*#__PURE__*/_jsxs(_Fragment, {
220
- children: [/*#__PURE__*/_jsx(InputSupports, { ...supportsProps,
221
- accessibilityAutoComplete: "list",
222
- accessibilityControls: "autocomplete",
223
- accessibilityExpanded: isExpanded,
224
- accessibilityRole: "combobox",
225
- ...selectedProps,
226
- validation: validation,
227
- ref: ref,
228
- children: _ref7 => {
229
- let {
230
- inputId,
231
- ...props
232
- } = _ref7;
233
- if (typeof children === 'function') return children({
234
- inputId,
235
- inputRef,
236
- onChange: handleChange,
237
- onKeyPress: handleClose,
238
- readOnly,
239
- tokens: inputTokens,
240
- ...selectedProps,
241
- ...props,
242
- ...(isControlled ? {
243
- value
244
- } : {
245
- initialValue
246
- })
247
- });
248
- return /*#__PURE__*/_jsx(TextInput, {
249
- onChange: handleChange,
250
- onClear: onClear,
251
- onKeyPress: handleClose,
252
- readOnly: readOnly,
253
- ref: inputRef,
254
- tokens: inputTokens,
255
- validation: validation,
256
- ...selectedProps,
257
- ...props,
258
- ...(isControlled ? {
259
- value
260
- } : {
261
- initialValue
262
- })
263
- });
264
- }
265
- }), isExpanded && /*#__PURE__*/_jsxs(_Fragment, {
266
- children: [/*#__PURE__*/_jsx(Listbox.Overlay, {
267
- overlaidPosition: overlaidPosition,
268
- isReady: isReady,
269
- minWidth: fullWidth ? inputWidth : MIN_LISTBOX_WIDTH,
270
- maxWidth: inputWidth,
271
- onLayout: onTargetLayout,
272
- ref: openOverlayRef,
273
- children: isLoading ? /*#__PURE__*/_jsx(Loading, {
274
- label: getCopy('loading')
275
- }) : /*#__PURE__*/_jsx(Suggestions, {
276
- hasResults: getCopy('hasResults'),
277
- id: "autocomplete",
278
- items: itemsToSuggest(highlight(isControlled ? items : currentItems, currentValue, resultsTextColor)),
279
- noResults: noResults ?? getCopy('noResults'),
280
- onClose: handleClose,
281
- onSelect: handleSelect,
282
- parentRef: inputRef,
283
- ref: targetRef
284
- })
285
- }), (targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) && /*#__PURE__*/_jsx("div", {
286
- // This catches and shifts focus to other interactive elements.
287
- onFocus: () => {
288
- var _targetRef$current;
289
-
290
- return targetRef === null || targetRef === void 0 ? void 0 : (_targetRef$current = targetRef.current) === null || _targetRef$current === void 0 ? void 0 : _targetRef$current.focus();
291
- } // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
292
- ,
293
- tabIndex: 0
294
- })]
295
- })]
296
- });
297
- });
298
- Autocomplete.displayName = 'Autocomplete'; // If a language dictionary entry is provided, it must contain every key
299
-
300
- const dictionaryContentShape = PropTypes.shape({
301
- hasResults: PropTypes.string.isRequired,
302
- loading: PropTypes.string.isRequired,
303
- noResults: PropTypes.string.isRequired
304
- });
305
- Autocomplete.propTypes = { ...selectedSystemPropTypes,
306
-
307
- /**
308
- * Can be used to provide a function that renders a custom input:
309
- * <Autocomplete items={items} value={currentValue}>
310
- * {({ inputId, inputRef, onChange, onKeyPress, readOnly, tokens, value }) => (
311
- * <Search
312
- * nativeID={inputId}
313
- * ref={inputRef}
314
- * onChange={onChange}
315
- * onKeyPress={onKeyPress}
316
- * readOnly={readOnly}
317
- * tokens={tokens}
318
- * value={value}
319
- * />
320
- * )}
321
- * </Autocomplete>
322
- */
323
- children: PropTypes.func,
324
-
325
- /**
326
- * Copy language identifier
327
- */
328
- copy: PropTypes.oneOfType([PropTypes.oneOf(['en', 'fr']), dictionaryContentShape]),
329
-
330
- /**
331
- * Set to true in order to display the loading indicator instead of results
332
- */
333
- isLoading: PropTypes.bool,
334
-
335
- /**
336
- * List of items to display as suggestions
337
- */
338
- items: PropTypes.arrayOf(PropTypes.shape({
339
- id: PropTypes.string,
340
- label: PropTypes.string
341
- })),
342
-
343
- /**
344
- * Label to display alongside the spinner when in a loading state
345
- */
346
- loadingLabel: PropTypes.string,
347
-
348
- /**
349
- * Minimum number of characters typed for a list of suggestions to appear
350
- */
351
- minToSuggestion: PropTypes.number,
352
-
353
- /**
354
- * Maximum number of suggestions provided at the same time
355
- */
356
- maxSuggestions: PropTypes.number,
357
-
358
- /**
359
- * Text or JSX to render when no results are available
360
- */
361
- noResults: PropTypes.node,
362
-
363
- /**
364
- * Handler function to be called when the input value changes
365
- */
366
- onChange: PropTypes.func,
367
-
368
- /**
369
- * Handler function to be called when the clear button (appears if the handler is passed) is pressed
370
- */
371
- onClear: PropTypes.func,
372
-
373
- /**
374
- * Callback function to be called when an item is selected from the list
375
- */
376
- onSelect: PropTypes.func,
377
-
378
- /**
379
- * Input value for controlled usage
380
- */
381
- value: PropTypes.string,
382
-
383
- /**
384
- * Can be used to set the initial items of the component
385
- */
386
- initialItems: PropTypes.arrayOf(PropTypes.shape({
387
- id: PropTypes.string,
388
- label: PropTypes.string
389
- })),
390
-
391
- /**
392
- * Initial value for the component
393
- */
394
- initialValue: PropTypes.string,
395
-
396
- /**
397
- * Boolean to set if it's readonly or not
398
- */
399
- readOnly: PropTypes.bool,
400
-
401
- /**
402
- * Use to visually mark an input as valid or invalid.
403
- */
404
- validation: PropTypes.oneOf(['error', 'success'])
405
- };
406
- export default Autocomplete;
@@ -1,32 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { Box, StackView } from '@telus-uds/components-base';
4
- import Spinner from '../Spinner';
5
- import { jsx as _jsx } from "react/jsx-runtime";
6
-
7
- const Loading = _ref => {
8
- let {
9
- label
10
- } = _ref;
11
- return /*#__PURE__*/_jsx(Box, {
12
- space: 3,
13
- children: /*#__PURE__*/_jsx(StackView, {
14
- direction: "row",
15
- space: 2,
16
- tokens: {
17
- alignItems: 'center'
18
- },
19
- children: /*#__PURE__*/_jsx(Spinner, {
20
- inline: true,
21
- show: true,
22
- label: label,
23
- labelPosition: "right"
24
- })
25
- })
26
- });
27
- };
28
-
29
- Loading.propTypes = {
30
- label: PropTypes.string
31
- };
32
- export default Loading;