@telus-uds/components-base 1.60.0 → 1.61.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 +10 -2
  2. package/component-docs.json +281 -70
  3. package/lib/Autocomplete/Autocomplete.js +483 -0
  4. package/lib/Autocomplete/Loading.js +51 -0
  5. package/lib/Autocomplete/Suggestions.js +85 -0
  6. package/lib/Autocomplete/constants.js +14 -0
  7. package/lib/Autocomplete/dictionary.js +19 -0
  8. package/lib/Autocomplete/index.js +13 -0
  9. package/lib/Listbox/GroupControl.js +121 -0
  10. package/lib/Listbox/Listbox.js +198 -0
  11. package/lib/Listbox/ListboxGroup.js +142 -0
  12. package/lib/Listbox/ListboxItem.js +97 -0
  13. package/lib/Listbox/ListboxOverlay.js +106 -0
  14. package/lib/Listbox/PressableItem.js +0 -2
  15. package/lib/Listbox/index.js +5 -24
  16. package/lib/TextInput/TextInputBase.js +2 -0
  17. package/lib/index.js +17 -13
  18. package/lib/utils/useOverlaidPosition.js +6 -4
  19. package/lib-module/Autocomplete/Autocomplete.js +448 -0
  20. package/lib-module/Autocomplete/Loading.js +36 -0
  21. package/lib-module/Autocomplete/Suggestions.js +66 -0
  22. package/lib-module/Autocomplete/constants.js +4 -0
  23. package/lib-module/Autocomplete/dictionary.js +12 -0
  24. package/lib-module/Autocomplete/index.js +2 -0
  25. package/lib-module/Listbox/GroupControl.js +102 -0
  26. package/lib-module/Listbox/Listbox.js +172 -0
  27. package/lib-module/Listbox/ListboxGroup.js +117 -0
  28. package/lib-module/Listbox/ListboxItem.js +71 -0
  29. package/lib-module/Listbox/ListboxOverlay.js +80 -0
  30. package/lib-module/Listbox/PressableItem.js +0 -2
  31. package/lib-module/Listbox/index.js +2 -2
  32. package/lib-module/TextInput/TextInputBase.js +2 -0
  33. package/lib-module/index.js +2 -1
  34. package/lib-module/utils/useOverlaidPosition.js +5 -4
  35. package/package.json +4 -2
  36. package/src/Autocomplete/Autocomplete.jsx +411 -0
  37. package/src/Autocomplete/Loading.jsx +18 -0
  38. package/src/Autocomplete/Suggestions.jsx +54 -0
  39. package/src/Autocomplete/constants.js +4 -0
  40. package/src/Autocomplete/dictionary.js +12 -0
  41. package/src/Autocomplete/index.js +3 -0
  42. package/src/Listbox/GroupControl.jsx +93 -0
  43. package/src/Listbox/Listbox.jsx +165 -0
  44. package/src/Listbox/ListboxGroup.jsx +120 -0
  45. package/src/Listbox/ListboxItem.jsx +76 -0
  46. package/src/Listbox/ListboxOverlay.jsx +82 -0
  47. package/src/Listbox/PressableItem.jsx +0 -2
  48. package/src/Listbox/index.js +3 -2
  49. package/src/TextInput/TextInputBase.jsx +2 -0
  50. package/src/index.js +2 -1
  51. package/src/utils/useOverlaidPosition.js +6 -5
@@ -0,0 +1,483 @@
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 _Dimensions = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Dimensions"));
13
+
14
+ var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
15
+
16
+ var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
17
+
18
+ var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
19
+
20
+ var _lodash = _interopRequireDefault(require("lodash.throttle"));
21
+
22
+ var _stringPrototype = _interopRequireDefault(require("string.prototype.matchall"));
23
+
24
+ var _utils = require("../utils");
25
+
26
+ var _ThemeProvider = require("../ThemeProvider");
27
+
28
+ var _Listbox = _interopRequireDefault(require("../Listbox"));
29
+
30
+ var _Typography = _interopRequireDefault(require("../Typography"));
31
+
32
+ var _TextInput = require("../TextInput");
33
+
34
+ var _InputSupports = _interopRequireDefault(require("../InputSupports"));
35
+
36
+ var _Loading = _interopRequireDefault(require("./Loading"));
37
+
38
+ var _Suggestions = _interopRequireDefault(require("./Suggestions"));
39
+
40
+ var _constants = require("./constants");
41
+
42
+ var _dictionary = _interopRequireDefault(require("./dictionary"));
43
+
44
+ var _jsxRuntime = require("react/jsx-runtime");
45
+
46
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
+
48
+ 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); }
49
+
50
+ 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; }
51
+
52
+ /* eslint-disable react/require-default-props */
53
+ const staticStyles = _StyleSheet.default.create({
54
+ container: {
55
+ zIndex: 100,
56
+ flexDirection: 'column',
57
+ justifyContent: 'flex-start',
58
+ flexGrow: 0,
59
+ flexShrink: 0
60
+ }
61
+ });
62
+
63
+ const [selectProps, selectedSystemPropTypes] = (0, _utils.selectSystemProps)([_utils.htmlAttrs, _utils.inputSupportsProps, _utils.textInputHandlerProps, _utils.textInputProps]); // Returns JSX to display a bold string `str` with unbolded occurrences of the
64
+ // `substring` based in the array of `matchIndexes` provided
65
+
66
+ const highlightAllMatches = function (str) {
67
+ let substring = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
68
+ let matchIndexes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
69
+ let resultsTextColor = arguments.length > 3 ? arguments[3] : undefined;
70
+ return (
71
+ /*#__PURE__*/
72
+ // Wrapping all in bold
73
+ (0, _jsxRuntime.jsx)(_Typography.default, {
74
+ variant: {
75
+ bold: false
76
+ },
77
+ tokens: {
78
+ color: resultsTextColor
79
+ },
80
+ children: matchIndexes.reduce((acc, matchIndex, index) => [...acc, // Add a piece of the string up to the first occurrence of the substring
81
+ index === 0 && (str.slice(0, matchIndex) ?? ''),
82
+ /*#__PURE__*/
83
+ // Unbold the occurrence of the substring (while keeping the original casing)
84
+ (0, _jsxRuntime.jsx)(_Typography.default, {
85
+ variant: {
86
+ bold: true
87
+ },
88
+ tokens: {
89
+ color: resultsTextColor
90
+ },
91
+ children: str.slice(matchIndex, matchIndex + substring.length)
92
+ }, matchIndex), // Add the rest of the string until the next occurrence or the end of it
93
+ str.slice(matchIndex + substring.length, matchIndexes[index + 1] ?? str.length)], [])
94
+ })
95
+ );
96
+ };
97
+
98
+ const highlight = function () {
99
+ let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
100
+ let text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
101
+ let color = arguments.length > 2 ? arguments[2] : undefined;
102
+ return items.reduce((acc, item) => {
103
+ var _Array$from;
104
+
105
+ const matches = (_Array$from = Array.from((0, _stringPrototype.default)(item.label.toLowerCase(), text.toLowerCase().replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')))) === null || _Array$from === void 0 ? void 0 : _Array$from.map(_ref => {
106
+ let {
107
+ index
108
+ } = _ref;
109
+ return index;
110
+ });
111
+
112
+ if (matches !== null && matches !== void 0 && matches.length) {
113
+ return [...acc, { ...item,
114
+ label: highlightAllMatches(item.label, text, matches, color)
115
+ }];
116
+ }
117
+
118
+ return [...acc, item];
119
+ }, []);
120
+ };
121
+
122
+ const Autocomplete = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
123
+ var _ref3;
124
+
125
+ let {
126
+ children,
127
+ copy = 'en',
128
+ fullWidth = true,
129
+ initialItems,
130
+ initialValue,
131
+ isLoading = false,
132
+ items,
133
+ maxSuggestions = _constants.DEFAULT_MAX_SUGGESTIONS,
134
+ minToSuggestion = _constants.DEFAULT_MIN_TO_SUGGESTION,
135
+ noResults,
136
+ onChange,
137
+ onClear,
138
+ onSelect,
139
+ readOnly,
140
+ validation,
141
+ value,
142
+ helpText = '',
143
+ ...rest
144
+ } = _ref2;
145
+ const {
146
+ color: resultsTextColor
147
+ } = (0, _ThemeProvider.useThemeTokens)('Search', {}, {
148
+ focus: true
149
+ }); // The wrapped input is mostly responsible for controlled vs uncontrolled handling,
150
+ // but we also need to adjust suggestions based on the mode:
151
+ // - in controlled mode we rely entirely on the suggestions passed via the `items` prop,
152
+ // - in uncontrolled mode we filter the suggestions ourselves based on the `initialItems`
153
+ // prop and the text entered
154
+
155
+ const isControlled = value !== undefined; // We need to store current items for uncontrolled usage
156
+
157
+ const [currentItems, setCurrentItems] = (0, _react.useState)(initialItems); // We need to store the current value as well to be able to highlight it
158
+
159
+ const [currentValue, setCurrentValue] = (0, _react.useState)(value ?? initialValue);
160
+ const inputTokens = {
161
+ paddingLeft: _constants.INPUT_LEFT_PADDING
162
+ }; // Setting up the overlay
163
+
164
+ const openOverlayRef = (0, _react.useRef)();
165
+ const [isExpanded, setIsExpanded] = (0, _react.useState)(((_ref3 = value ?? initialValue) === null || _ref3 === void 0 ? void 0 : _ref3.length) >= minToSuggestion);
166
+ const [isFocused, setisFocused] = (0, _react.useState)(false);
167
+ const [sourceLayout, setSourceLayout] = (0, _react.useState)(null);
168
+ const {
169
+ supportsProps,
170
+ ...selectedProps
171
+ } = selectProps(rest);
172
+ const {
173
+ hint,
174
+ label: inputLabel
175
+ } = supportsProps;
176
+ const hintExpansionEnabled = isFocused && helpText && !currentValue;
177
+ const {
178
+ overlaidPosition,
179
+ sourceRef: inputRef,
180
+ // targetRef,
181
+ onTargetLayout,
182
+ isReady
183
+ } = (0, _utils.useOverlaidPosition)({
184
+ isShown: isExpanded || hintExpansionEnabled,
185
+ offsets: {
186
+ vertical: _Platform.default.OS !== 'web' && (hint || inputLabel) ? 28 : 4
187
+ }
188
+ });
189
+ const targetRef = (0, _react.useRef)(null); // We limit the number of suggestions displayed to avoid huge lists
190
+ // TODO: add a way to make the `Listbox` occupy fixed height and be scrollable
191
+ // within that height, which will unlock similar behaviour for `AutoComplete` as well
192
+
193
+ const itemsToSuggest = function () {
194
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
195
+ return maxSuggestions ? data.slice(0, maxSuggestions) : [...data];
196
+ };
197
+
198
+ const getCopy = (0, _utils.useCopy)({
199
+ dictionary: _dictionary.default,
200
+ copy
201
+ }); // Tracking input width changes to resize the listbox overlay accordingly
202
+
203
+ const [inputWidth, setInputWidth] = (0, _react.useState)();
204
+ (0, _utils.useSafeLayoutEffect)(() => {
205
+ if (_Platform.default.OS === 'web') {
206
+ const updateInputWidth = () => {
207
+ var _inputRef$current;
208
+
209
+ 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
210
+
211
+ setIsExpanded(false); // close the suggestions while the input is changing
212
+ };
213
+
214
+ const throttledUpdateInputWidth = (0, _lodash.default)(updateInputWidth, 100, {
215
+ leading: false
216
+ });
217
+ updateInputWidth();
218
+
219
+ _Dimensions.default.addEventListener('change', throttledUpdateInputWidth);
220
+
221
+ return () => {
222
+ _Dimensions.default.removeEventListener('change', throttledUpdateInputWidth);
223
+ };
224
+ }
225
+
226
+ setInputWidth(sourceLayout === null || sourceLayout === void 0 ? void 0 : sourceLayout.width);
227
+ return () => {};
228
+ }, [inputRef, sourceLayout]);
229
+
230
+ const handleMeasure = event => {
231
+ onTargetLayout(event);
232
+
233
+ if (_Platform.default.OS !== 'web') {
234
+ var _inputRef$current2;
235
+
236
+ inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.measureInWindow((x, y, width) => {
237
+ setInputWidth(width);
238
+ });
239
+ }
240
+ };
241
+
242
+ const handleChange = newValue => {
243
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue || '');
244
+ setCurrentValue(newValue);
245
+ setIsExpanded((newValue === null || newValue === void 0 ? void 0 : newValue.length) >= minToSuggestion);
246
+
247
+ if (!isControlled && initialItems !== undefined) {
248
+ setCurrentItems(initialItems.filter(_ref4 => {
249
+ var _label$toLowerCase;
250
+
251
+ let {
252
+ label
253
+ } = _ref4;
254
+ 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());
255
+ }));
256
+ }
257
+ };
258
+
259
+ const handleSelect = selectedId => {
260
+ var _ref5;
261
+
262
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect(selectedId);
263
+ const {
264
+ label: newValue,
265
+ nested
266
+ } = (_ref5 = isControlled ? items : currentItems) === null || _ref5 === void 0 ? void 0 : _ref5.find(_ref6 => {
267
+ let {
268
+ id
269
+ } = _ref6;
270
+ return id === selectedId;
271
+ });
272
+
273
+ if (!nested) {
274
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
275
+ setIsExpanded(false);
276
+ }
277
+
278
+ setCurrentValue(newValue);
279
+ if (!isControlled && inputRef !== null && inputRef !== void 0 && inputRef.current) inputRef.current.value = newValue;
280
+ };
281
+
282
+ const handleClose = event => {
283
+ var _openOverlayRef$curre, _openOverlayRef$curre2;
284
+
285
+ if (event.type === 'keydown') {
286
+ if (event.key === 'Escape' || event.key === 27) {
287
+ setIsExpanded(false);
288
+ } else if (event.key === 'ArrowDown' && isExpanded && !isLoading && targetRef !== null && targetRef !== void 0 && targetRef.current) {
289
+ targetRef.current.focus();
290
+ }
291
+ } 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))) {
292
+ setIsExpanded(false);
293
+ } 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))) {
294
+ setIsExpanded(false);
295
+ } else if (_Platform.default.OS === 'web') {
296
+ // needed for dropdown to be collapsed when clicking outside on web
297
+ setIsExpanded(false);
298
+ }
299
+ };
300
+
301
+ const itemsToShow = currentValue ? itemsToSuggest(highlight(isControlled ? items : currentItems, currentValue, resultsTextColor)) : [];
302
+ const helpTextToShow = isFocused && !currentValue ? helpText : noResults ?? getCopy('noResults');
303
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_View.default, {
304
+ style: staticStyles.container,
305
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_InputSupports.default, { ...supportsProps,
306
+ accessibilityAutoComplete: "list",
307
+ accessibilityControls: "autocomplete",
308
+ accessibilityExpanded: isExpanded,
309
+ accessibilityRole: "combobox",
310
+ ...selectedProps,
311
+ validation: validation,
312
+ ref: ref,
313
+ children: _ref7 => {
314
+ let {
315
+ inputId,
316
+ ...props
317
+ } = _ref7;
318
+ if (typeof children === 'function') return children({
319
+ inputId,
320
+ inputRef,
321
+ onChange: handleChange,
322
+ onKeyPress: handleClose,
323
+ readOnly,
324
+ tokens: inputTokens,
325
+ ...selectedProps,
326
+ ...props,
327
+ ...(isControlled ? {
328
+ value
329
+ } : {
330
+ initialValue
331
+ })
332
+ });
333
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_TextInput.TextInput, {
334
+ onChange: handleChange,
335
+ onFocus: () => {
336
+ setisFocused(true);
337
+ },
338
+ onBlur: () => {
339
+ setisFocused(false);
340
+ },
341
+ onClear: onClear,
342
+ onKeyPress: handleClose,
343
+ readOnly: readOnly,
344
+ ref: inputRef,
345
+ ...(_Platform.default.OS !== 'web' ? {
346
+ onLayout: event => setSourceLayout(event.nativeEvent.layout)
347
+ } : {}),
348
+ tokens: inputTokens,
349
+ validation: validation,
350
+ ...selectedProps,
351
+ ...props,
352
+ ...(isControlled ? {
353
+ value
354
+ } : {
355
+ initialValue
356
+ })
357
+ });
358
+ }
359
+ }), (isExpanded || hintExpansionEnabled) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
360
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Listbox.default.Overlay, {
361
+ overlaidPosition: overlaidPosition,
362
+ isReady: isReady,
363
+ minWidth: fullWidth ? inputWidth : _constants.MIN_LISTBOX_WIDTH,
364
+ maxWidth: inputWidth,
365
+ onLayout: handleMeasure,
366
+ ref: openOverlayRef,
367
+ children: isLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Loading.default, {
368
+ label: getCopy('loading')
369
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Suggestions.default, {
370
+ hasResults: getCopy('hasResults'),
371
+ id: "autocomplete",
372
+ items: itemsToShow,
373
+ noResults: helpTextToShow,
374
+ onClose: handleClose,
375
+ onSelect: handleSelect,
376
+ parentRef: inputRef,
377
+ ref: targetRef
378
+ })
379
+ }), (targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default // This catches and shifts focus to other interactive elements.
380
+ , {
381
+ onFocus: () => {
382
+ var _targetRef$current;
383
+
384
+ return targetRef === null || targetRef === void 0 ? void 0 : (_targetRef$current = targetRef.current) === null || _targetRef$current === void 0 ? void 0 : _targetRef$current.focus();
385
+ },
386
+ tabIndex: 0
387
+ })]
388
+ })]
389
+ });
390
+ });
391
+ Autocomplete.displayName = 'Autocomplete'; // If a language dictionary entry is provided, it must contain every key
392
+
393
+ const dictionaryContentShape = _propTypes.default.shape({
394
+ hasResults: _propTypes.default.string.isRequired,
395
+ loading: _propTypes.default.string.isRequired,
396
+ noResults: _propTypes.default.string.isRequired
397
+ });
398
+
399
+ Autocomplete.propTypes = { ...selectedSystemPropTypes,
400
+
401
+ /**
402
+ * Can be used to provide a function that renders a custom input:
403
+ * <Autocomplete items={items} value={currentValue}>
404
+ * {({ inputId, inputRef, onChange, onKeyPress, readOnly, tokens, value }) => (
405
+ * <Search
406
+ * nativeID={inputId}
407
+ * ref={inputRef}
408
+ * onChange={onChange}
409
+ * onKeyPress={onKeyPress}
410
+ * readOnly={readOnly}
411
+ * tokens={tokens}
412
+ * value={value}
413
+ * />
414
+ * )}
415
+ * </Autocomplete>
416
+ */
417
+ children: _propTypes.default.func,
418
+
419
+ /**
420
+ * Copy language identifier
421
+ */
422
+ copy: _propTypes.default.oneOfType([_propTypes.default.oneOf(['en', 'fr']), dictionaryContentShape]),
423
+
424
+ /**
425
+ * Set to true in order to display the loading indicator instead of results
426
+ */
427
+ isLoading: _propTypes.default.bool,
428
+
429
+ /**
430
+ * List of items to display as suggestions
431
+ */
432
+ items: _propTypes.default.arrayOf(_propTypes.default.shape({
433
+ id: _propTypes.default.string,
434
+ label: _propTypes.default.string
435
+ })),
436
+
437
+ /**
438
+ * Label to display alongside the spinner when in a loading state
439
+ */
440
+ loadingLabel: _propTypes.default.string,
441
+
442
+ /**
443
+ * Minimum number of characters typed for a list of suggestions to appear
444
+ */
445
+ minToSuggestion: _propTypes.default.number,
446
+
447
+ /**
448
+ * Maximum number of suggestions provided at the same time
449
+ */
450
+ maxSuggestions: _propTypes.default.number,
451
+
452
+ /**
453
+ * Text or JSX to render when no results are available
454
+ */
455
+ noResults: _propTypes.default.node,
456
+
457
+ /**
458
+ * Help text to display when the input is focused and empty
459
+ */
460
+ helpText: _propTypes.default.string,
461
+
462
+ /**
463
+ * Handler function to be called when the input value changes
464
+ */
465
+ onChange: _propTypes.default.func,
466
+
467
+ /**
468
+ * Handler function to be called when the clear button (appears if the handler is passed) is pressed
469
+ */
470
+ onClear: _propTypes.default.func,
471
+
472
+ /**
473
+ * Callback function to be called when an item is selected from the list
474
+ */
475
+ onSelect: _propTypes.default.func,
476
+
477
+ /**
478
+ * Input value for controlled usage
479
+ */
480
+ value: _propTypes.default.string
481
+ };
482
+ var _default = Autocomplete;
483
+ exports.default = _default;
@@ -0,0 +1,51 @@
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 _ActivityIndicator = _interopRequireDefault(require("../ActivityIndicator"));
13
+
14
+ var _Typography = _interopRequireDefault(require("../Typography"));
15
+
16
+ var _Box = _interopRequireDefault(require("../Box"));
17
+
18
+ var _StackView = _interopRequireDefault(require("../StackView"));
19
+
20
+ var _jsxRuntime = require("react/jsx-runtime");
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
24
+ const Loading = _ref => {
25
+ let {
26
+ label
27
+ } = _ref;
28
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
29
+ space: 3,
30
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StackView.default, {
31
+ direction: "row",
32
+ space: 2,
33
+ tokens: {
34
+ alignItems: 'center'
35
+ },
36
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ActivityIndicator.default, {
37
+ variant: {
38
+ size: 'large'
39
+ }
40
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
41
+ children: label
42
+ })]
43
+ })
44
+ });
45
+ };
46
+
47
+ Loading.propTypes = {
48
+ label: _propTypes.default.string
49
+ };
50
+ var _default = Loading;
51
+ exports.default = _default;
@@ -0,0 +1,85 @@
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 _A11yText = _interopRequireDefault(require("../A11yText"));
13
+
14
+ var _Typography = _interopRequireDefault(require("../Typography"));
15
+
16
+ var _Box = _interopRequireDefault(require("../Box"));
17
+
18
+ var _Listbox = _interopRequireDefault(require("../Listbox"));
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
+ const Suggestions = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
29
+ let {
30
+ hasResults,
31
+ items = [],
32
+ noResults,
33
+ onClose,
34
+ onSelect,
35
+ parentRef
36
+ } = _ref;
37
+ const pressableItems = items.map(_ref2 => {
38
+ let {
39
+ id,
40
+ ...rest
41
+ } = _ref2;
42
+ return {
43
+ id,
44
+ onPress: () => onSelect(id),
45
+ ...rest
46
+ };
47
+ });
48
+ if (items !== null && items !== void 0 && items.length) return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
49
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_A11yText.default, {
50
+ accessibilityLiveRegion: "polite",
51
+ text: hasResults
52
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Listbox.default, {
53
+ items: pressableItems,
54
+ firstItemRef: ref,
55
+ parentRef: parentRef,
56
+ onClose: onClose
57
+ })]
58
+ });
59
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
60
+ space: 3,
61
+ children: typeof noResults === 'string' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
62
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Typography.default, {
63
+ accessibilityLiveRegion: "polite",
64
+ variant: {
65
+ size: 'small'
66
+ },
67
+ children: noResults
68
+ })
69
+ }) : noResults
70
+ });
71
+ });
72
+ Suggestions.displayName = 'Suggestions';
73
+ Suggestions.propTypes = {
74
+ hasResults: _propTypes.default.string.isRequired,
75
+ items: _propTypes.default.arrayOf(_propTypes.default.shape({
76
+ id: _propTypes.default.string,
77
+ label: _propTypes.default.node
78
+ })).isRequired,
79
+ noResults: _propTypes.default.node.isRequired,
80
+ onClose: _propTypes.default.func.isRequired,
81
+ onSelect: _propTypes.default.func.isRequired,
82
+ parentRef: _propTypes.default.object.isRequired
83
+ };
84
+ var _default = Suggestions;
85
+ exports.default = _default;
@@ -0,0 +1,14 @@
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
+ const DEFAULT_MIN_TO_SUGGESTION = 1;
8
+ exports.DEFAULT_MIN_TO_SUGGESTION = DEFAULT_MIN_TO_SUGGESTION;
9
+ const DEFAULT_MAX_SUGGESTIONS = 5;
10
+ exports.DEFAULT_MAX_SUGGESTIONS = DEFAULT_MAX_SUGGESTIONS;
11
+ const INPUT_LEFT_PADDING = 16;
12
+ exports.INPUT_LEFT_PADDING = INPUT_LEFT_PADDING;
13
+ const MIN_LISTBOX_WIDTH = 288;
14
+ exports.MIN_LISTBOX_WIDTH = MIN_LISTBOX_WIDTH;
@@ -0,0 +1,19 @@
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;
@@ -0,0 +1,13 @@
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;