@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.
- package/CHANGELOG.md +11 -2
- package/component-docs.json +381 -471
- package/lib/NavigationBar/NavigationSubMenu.js +2 -4
- package/lib/baseExports.js +12 -0
- package/lib/index.js +0 -18
- package/lib/utils/useOverlaidPosition.js +2 -2
- package/lib-module/NavigationBar/NavigationSubMenu.js +1 -2
- package/lib-module/baseExports.js +1 -1
- package/lib-module/index.js +0 -2
- package/lib-module/utils/useOverlaidPosition.js +2 -2
- package/package.json +2 -2
- package/src/NavigationBar/NavigationSubMenu.jsx +1 -2
- package/src/baseExports.js +2 -0
- package/src/index.js +0 -2
- package/src/utils/useOverlaidPosition.js +2 -2
- package/lib/Autocomplete/Autocomplete.js +0 -430
- package/lib/Autocomplete/Loading.js +0 -46
- package/lib/Autocomplete/Suggestions.js +0 -81
- package/lib/Autocomplete/constants.js +0 -19
- package/lib/Autocomplete/dictionary.js +0 -19
- package/lib/Autocomplete/index.js +0 -13
- package/lib/Listbox/GroupControl.js +0 -110
- package/lib/Listbox/Listbox.js +0 -185
- package/lib/Listbox/ListboxGroup.js +0 -145
- package/lib/Listbox/ListboxItem.js +0 -101
- package/lib/Listbox/ListboxOverlay.js +0 -91
- package/lib/Listbox/index.js +0 -13
- package/lib-module/Autocomplete/Autocomplete.js +0 -406
- package/lib-module/Autocomplete/Loading.js +0 -32
- package/lib-module/Autocomplete/Suggestions.js +0 -64
- package/lib-module/Autocomplete/constants.js +0 -5
- package/lib-module/Autocomplete/dictionary.js +0 -12
- package/lib-module/Autocomplete/index.js +0 -2
- package/lib-module/Listbox/GroupControl.js +0 -96
- package/lib-module/Listbox/Listbox.js +0 -164
- package/lib-module/Listbox/ListboxGroup.js +0 -122
- package/lib-module/Listbox/ListboxItem.js +0 -77
- package/lib-module/Listbox/ListboxOverlay.js +0 -69
- package/lib-module/Listbox/index.js +0 -2
- package/src/Autocomplete/Autocomplete.jsx +0 -375
- package/src/Autocomplete/Loading.jsx +0 -15
- package/src/Autocomplete/Suggestions.jsx +0 -52
- package/src/Autocomplete/constants.js +0 -6
- package/src/Autocomplete/dictionary.js +0 -12
- package/src/Autocomplete/index.js +0 -3
- package/src/Listbox/GroupControl.jsx +0 -82
- package/src/Listbox/Listbox.jsx +0 -169
- package/src/Listbox/ListboxGroup.jsx +0 -125
- package/src/Listbox/ListboxItem.jsx +0 -80
- package/src/Listbox/ListboxOverlay.jsx +0 -72
- package/src/Listbox/index.js +0 -3
|
@@ -13,8 +13,6 @@ var _componentsBase = require("@telus-uds/components-base");
|
|
|
13
13
|
|
|
14
14
|
var _NavigationItem = _interopRequireDefault(require("./NavigationItem"));
|
|
15
15
|
|
|
16
|
-
var _Listbox = _interopRequireDefault(require("../Listbox"));
|
|
17
|
-
|
|
18
16
|
var _useOverlaidPosition = _interopRequireDefault(require("../utils/useOverlaidPosition"));
|
|
19
17
|
|
|
20
18
|
var _resolveItemSelection = _interopRequireDefault(require("./resolveItemSelection"));
|
|
@@ -131,14 +129,14 @@ const NavigationSubMenu = _ref => {
|
|
|
131
129
|
}, `${id}_icon`)];
|
|
132
130
|
}
|
|
133
131
|
}), isOpen && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
134
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
132
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Listbox.Overlay, {
|
|
135
133
|
overlaidPosition: overlaidPosition,
|
|
136
134
|
maxWidth: maxWidth,
|
|
137
135
|
minWidth: minWidth,
|
|
138
136
|
isReady: isReady,
|
|
139
137
|
onLayout: onTargetLayout,
|
|
140
138
|
ref: openOverlayRef,
|
|
141
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(
|
|
139
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Listbox, {
|
|
142
140
|
items: items,
|
|
143
141
|
firstItemRef: targetRef,
|
|
144
142
|
parentRef: sourceRef,
|
package/lib/baseExports.js
CHANGED
|
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "ActivityIndicator", {
|
|
|
21
21
|
return _componentsBase.ActivityIndicator;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "Autocomplete", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _componentsBase.Autocomplete;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "BaseProvider", {
|
|
25
31
|
enumerable: true,
|
|
26
32
|
get: function () {
|
|
@@ -135,6 +141,12 @@ Object.defineProperty(exports, "Link", {
|
|
|
135
141
|
return _componentsBase.Link;
|
|
136
142
|
}
|
|
137
143
|
});
|
|
144
|
+
Object.defineProperty(exports, "Listbox", {
|
|
145
|
+
enumerable: true,
|
|
146
|
+
get: function () {
|
|
147
|
+
return _componentsBase.Listbox;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
138
150
|
Object.defineProperty(exports, "MultiSelectFilter", {
|
|
139
151
|
enumerable: true,
|
|
140
152
|
get: function () {
|
package/lib/index.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
-
Autocomplete: true,
|
|
8
7
|
Badge: true,
|
|
9
8
|
Modal: true,
|
|
10
9
|
OrderedList: true,
|
|
@@ -33,7 +32,6 @@ var _exportNames = {
|
|
|
33
32
|
WebVideo: true,
|
|
34
33
|
WaffleGrid: true,
|
|
35
34
|
Spinner: true,
|
|
36
|
-
Listbox: true,
|
|
37
35
|
VideoPicker: true,
|
|
38
36
|
Video: true,
|
|
39
37
|
StoryCard: true,
|
|
@@ -46,12 +44,6 @@ var _exportNames = {
|
|
|
46
44
|
SkeletonProvider: true,
|
|
47
45
|
WebPortal: true
|
|
48
46
|
};
|
|
49
|
-
Object.defineProperty(exports, "Autocomplete", {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
get: function () {
|
|
52
|
-
return _Autocomplete.default;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
47
|
Object.defineProperty(exports, "Badge", {
|
|
56
48
|
enumerable: true,
|
|
57
49
|
get: function () {
|
|
@@ -130,12 +122,6 @@ Object.defineProperty(exports, "List", {
|
|
|
130
122
|
return _List.default;
|
|
131
123
|
}
|
|
132
124
|
});
|
|
133
|
-
Object.defineProperty(exports, "Listbox", {
|
|
134
|
-
enumerable: true,
|
|
135
|
-
get: function () {
|
|
136
|
-
return _Listbox.default;
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
125
|
Object.defineProperty(exports, "Modal", {
|
|
140
126
|
enumerable: true,
|
|
141
127
|
get: function () {
|
|
@@ -293,8 +279,6 @@ Object.defineProperty(exports, "transformGradient", {
|
|
|
293
279
|
}
|
|
294
280
|
});
|
|
295
281
|
|
|
296
|
-
var _Autocomplete = _interopRequireDefault(require("./Autocomplete"));
|
|
297
|
-
|
|
298
282
|
var _Badge = _interopRequireDefault(require("./Badge"));
|
|
299
283
|
|
|
300
284
|
var _Modal = _interopRequireDefault(require("./Modal"));
|
|
@@ -349,8 +333,6 @@ var _WaffleGrid = _interopRequireDefault(require("./WaffleGrid"));
|
|
|
349
333
|
|
|
350
334
|
var _Spinner = _interopRequireDefault(require("./Spinner"));
|
|
351
335
|
|
|
352
|
-
var _Listbox = _interopRequireDefault(require("./Listbox"));
|
|
353
|
-
|
|
354
336
|
var _VideoPicker = _interopRequireDefault(require("./VideoPicker"));
|
|
355
337
|
|
|
356
338
|
var _Video = _interopRequireDefault(require("./Video"));
|
|
@@ -205,9 +205,9 @@ const useOverlaidPosition = _ref3 => {
|
|
|
205
205
|
if (typeof ((_subscription = subscription) === null || _subscription === void 0 ? void 0 : _subscription.remove) === 'function') {
|
|
206
206
|
// React Native >=0.65.0
|
|
207
207
|
subscription.remove();
|
|
208
|
-
} else if (typeof _Dimensions.default.
|
|
208
|
+
} else if (typeof _Dimensions.default.remove === 'function') {
|
|
209
209
|
// React Native <0.65.0
|
|
210
|
-
_Dimensions.default.
|
|
210
|
+
_Dimensions.default.remove('change', handleDimensionsChange);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
setSourceLayout(null);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React, { useRef } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
|
-
import { Icon, useResponsiveProp, useThemeTokens } from '@telus-uds/components-base';
|
|
3
|
+
import { Icon, useResponsiveProp, useThemeTokens, Listbox } from '@telus-uds/components-base';
|
|
4
4
|
import NavigationItem from './NavigationItem';
|
|
5
|
-
import Listbox from '../Listbox';
|
|
6
5
|
import useOverlaidPosition from '../utils/useOverlaidPosition';
|
|
7
6
|
import resolveItemSelection from './resolveItemSelection';
|
|
8
7
|
/**
|
|
@@ -5,7 +5,7 @@ export {
|
|
|
5
5
|
/**
|
|
6
6
|
* Most base components should be re-exported as-is.
|
|
7
7
|
*/
|
|
8
|
-
A11yText, ActivityIndicator, Box, Button, BaseProvider, A11yInfoProvider, ViewportProvider, ThemeProvider, ButtonDropdown, ButtonGroup, ButtonLink, Carousel, CarouselTabs, Checkbox, CheckboxGroup, ChevronLink, Divider, ExpandCollapse, Feedback, FlexGrid, Icon, InputLabel, InputSupports, Link, MultiSelectFilter, Notification, Pagination, QuickLinks, QuickLinksFeature, Radio, RadioGroup, RadioCard, RadioCardGroup, Responsive, Search, Select, SideNav, Skeleton, SkipLink, Spacer, StackView, StackWrap, StepTracker, Tabs, Tags, TextButton, TextArea, TextInput, Timeline, ToggleSwitch, ToggleSwitchGroup, TooltipButton, Tooltip, Typography, Validator,
|
|
8
|
+
A11yText, ActivityIndicator, Autocomplete, Box, Button, BaseProvider, A11yInfoProvider, ViewportProvider, ThemeProvider, ButtonDropdown, ButtonGroup, ButtonLink, Carousel, CarouselTabs, Checkbox, CheckboxGroup, ChevronLink, Divider, ExpandCollapse, Feedback, FlexGrid, Icon, InputLabel, InputSupports, Link, Listbox, MultiSelectFilter, Notification, Pagination, QuickLinks, QuickLinksFeature, Radio, RadioGroup, RadioCard, RadioCardGroup, Responsive, Search, Select, SideNav, Skeleton, SkipLink, Spacer, StackView, StackWrap, StepTracker, Tabs, Tags, TextButton, TextArea, TextInput, Timeline, ToggleSwitch, ToggleSwitchGroup, TooltipButton, Tooltip, Typography, Validator,
|
|
9
9
|
/*
|
|
10
10
|
* Most utilities exported from @telus-uds/components-base are for building systems, not apps.
|
|
11
11
|
* Re-export only those utilities with a stable API and known use cases within apps / pages.
|
package/lib-module/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { default as Autocomplete } from './Autocomplete';
|
|
2
1
|
export { default as Badge } from './Badge';
|
|
3
2
|
export { default as Modal } from './Modal';
|
|
4
3
|
export { default as OrderedList } from './OrderedList';
|
|
@@ -26,7 +25,6 @@ export { default as Image } from './Image';
|
|
|
26
25
|
export { default as WebVideo } from './WebVideo';
|
|
27
26
|
export { default as WaffleGrid } from './WaffleGrid';
|
|
28
27
|
export { default as Spinner } from './Spinner';
|
|
29
|
-
export { default as Listbox } from './Listbox';
|
|
30
28
|
export { default as VideoPicker } from './VideoPicker';
|
|
31
29
|
export { default as Video } from './Video';
|
|
32
30
|
export { default as StoryCard } from './StoryCard';
|
|
@@ -195,9 +195,9 @@ const useOverlaidPosition = _ref3 => {
|
|
|
195
195
|
if (typeof ((_subscription = subscription) === null || _subscription === void 0 ? void 0 : _subscription.remove) === 'function') {
|
|
196
196
|
// React Native >=0.65.0
|
|
197
197
|
subscription.remove();
|
|
198
|
-
} else if (typeof Dimensions.
|
|
198
|
+
} else if (typeof Dimensions.remove === 'function') {
|
|
199
199
|
// React Native <0.65.0
|
|
200
|
-
Dimensions.
|
|
200
|
+
Dimensions.remove('change', handleDimensionsChange);
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
setSourceLayout(null);
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
],
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@gorhom/portal": "^1.0.14",
|
|
8
|
-
"@telus-uds/components-base": "1.
|
|
8
|
+
"@telus-uds/components-base": "1.61.0",
|
|
9
9
|
"@telus-uds/system-constants": "^1.3.0",
|
|
10
10
|
"fscreen": "^1.2.0",
|
|
11
11
|
"lodash.omit": "^4.5.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"skip": true
|
|
64
64
|
},
|
|
65
65
|
"types": "types/index.d.ts",
|
|
66
|
-
"version": "2.
|
|
66
|
+
"version": "2.19.0"
|
|
67
67
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React, { useRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
-
import { Icon, useResponsiveProp, useThemeTokens } from '@telus-uds/components-base'
|
|
3
|
+
import { Icon, useResponsiveProp, useThemeTokens, Listbox } from '@telus-uds/components-base'
|
|
4
4
|
import NavigationItem from './NavigationItem'
|
|
5
|
-
import Listbox from '../Listbox'
|
|
6
5
|
import useOverlaidPosition from '../utils/useOverlaidPosition'
|
|
7
6
|
import resolveItemSelection from './resolveItemSelection'
|
|
8
7
|
|
package/src/baseExports.js
CHANGED
package/src/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { default as Autocomplete } from './Autocomplete'
|
|
2
1
|
export { default as Badge } from './Badge'
|
|
3
2
|
export { default as Modal } from './Modal'
|
|
4
3
|
export { default as OrderedList } from './OrderedList'
|
|
@@ -26,7 +25,6 @@ export { default as Image } from './Image'
|
|
|
26
25
|
export { default as WebVideo } from './WebVideo'
|
|
27
26
|
export { default as WaffleGrid } from './WaffleGrid'
|
|
28
27
|
export { default as Spinner } from './Spinner'
|
|
29
|
-
export { default as Listbox } from './Listbox'
|
|
30
28
|
export { default as VideoPicker } from './VideoPicker'
|
|
31
29
|
export { default as Video } from './Video'
|
|
32
30
|
export { default as StoryCard } from './StoryCard'
|
|
@@ -184,9 +184,9 @@ const useOverlaidPosition = ({
|
|
|
184
184
|
if (typeof subscription?.remove === 'function') {
|
|
185
185
|
// React Native >=0.65.0
|
|
186
186
|
subscription.remove()
|
|
187
|
-
} else if (typeof Dimensions.
|
|
187
|
+
} else if (typeof Dimensions.remove === 'function') {
|
|
188
188
|
// React Native <0.65.0
|
|
189
|
-
Dimensions.
|
|
189
|
+
Dimensions.remove('change', handleDimensionsChange)
|
|
190
190
|
}
|
|
191
191
|
setSourceLayout(null)
|
|
192
192
|
setTargetDimensions(null)
|
|
@@ -1,430 +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 _lodash = require("lodash");
|
|
13
|
-
|
|
14
|
-
var _componentsBase = require("@telus-uds/components-base");
|
|
15
|
-
|
|
16
|
-
var _Listbox = _interopRequireDefault(require("../Listbox"));
|
|
17
|
-
|
|
18
|
-
var _utils = require("../utils");
|
|
19
|
-
|
|
20
|
-
var _Loading = _interopRequireDefault(require("./Loading"));
|
|
21
|
-
|
|
22
|
-
var _Suggestions = _interopRequireDefault(require("./Suggestions"));
|
|
23
|
-
|
|
24
|
-
var _constants = require("./constants");
|
|
25
|
-
|
|
26
|
-
var _dictionary = _interopRequireDefault(require("./dictionary"));
|
|
27
|
-
|
|
28
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
32
|
-
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); }
|
|
33
|
-
|
|
34
|
-
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; }
|
|
35
|
-
|
|
36
|
-
/* eslint-disable react/require-default-props */
|
|
37
|
-
const [selectProps, selectedSystemPropTypes] = (0, _componentsBase.selectSystemProps)([_utils.htmlAttrs, _componentsBase.inputSupportsProps, _componentsBase.textInputHandlerProps, _componentsBase.textInputProps]); // Returns JSX to display a bold string `str` with unbolded occurrences of the
|
|
38
|
-
// `substring` based in the array of `matchIndexes` provided
|
|
39
|
-
|
|
40
|
-
const highlightAllMatches = function (str) {
|
|
41
|
-
let substring = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
42
|
-
let matchIndexes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
43
|
-
let resultsTextColor = arguments.length > 3 ? arguments[3] : undefined;
|
|
44
|
-
return (
|
|
45
|
-
/*#__PURE__*/
|
|
46
|
-
// Wrapping all in bold
|
|
47
|
-
(0, _jsxRuntime.jsx)(_componentsBase.Typography, {
|
|
48
|
-
variant: {
|
|
49
|
-
bold: false
|
|
50
|
-
},
|
|
51
|
-
tokens: {
|
|
52
|
-
color: resultsTextColor
|
|
53
|
-
},
|
|
54
|
-
children: matchIndexes.reduce((acc, matchIndex, index) => [...acc, // Add a piece of the string up to the first occurrence of the substring
|
|
55
|
-
index === 0 && (str.slice(0, matchIndex) ?? ''),
|
|
56
|
-
/*#__PURE__*/
|
|
57
|
-
// Unbold the occurrence of the substring (while keeping the original casing)
|
|
58
|
-
(0, _jsxRuntime.jsx)(_componentsBase.Typography, {
|
|
59
|
-
variant: {
|
|
60
|
-
bold: true
|
|
61
|
-
},
|
|
62
|
-
tokens: {
|
|
63
|
-
color: resultsTextColor
|
|
64
|
-
},
|
|
65
|
-
children: str.slice(matchIndex, matchIndex + substring.length)
|
|
66
|
-
}, matchIndex), // Add the rest of the string until the next occurrence or the end of it
|
|
67
|
-
str.slice(matchIndex + substring.length, matchIndexes[index + 1] ?? str.length)], [])
|
|
68
|
-
})
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const highlight = function () {
|
|
73
|
-
let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
74
|
-
let text = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
75
|
-
let color = arguments.length > 2 ? arguments[2] : undefined;
|
|
76
|
-
return items.reduce((acc, item) => {
|
|
77
|
-
var _Array$from;
|
|
78
|
-
|
|
79
|
-
const matches = (_Array$from = Array.from(item.label.toLowerCase().matchAll(text.toLowerCase()))) === null || _Array$from === void 0 ? void 0 : _Array$from.map(_ref => {
|
|
80
|
-
let {
|
|
81
|
-
index
|
|
82
|
-
} = _ref;
|
|
83
|
-
return index;
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
if (matches !== null && matches !== void 0 && matches.length) {
|
|
87
|
-
return [...acc, { ...item,
|
|
88
|
-
label: highlightAllMatches(item.label, text, matches, color)
|
|
89
|
-
}];
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return [...acc, item];
|
|
93
|
-
}, []);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const Autocomplete = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
|
|
97
|
-
var _ref3;
|
|
98
|
-
|
|
99
|
-
let {
|
|
100
|
-
children,
|
|
101
|
-
copy = 'en',
|
|
102
|
-
fullWidth = true,
|
|
103
|
-
initialItems,
|
|
104
|
-
initialValue,
|
|
105
|
-
isLoading = false,
|
|
106
|
-
items,
|
|
107
|
-
maxSuggestions = _constants.DEFAULT_MAX_SUGGESTIONS,
|
|
108
|
-
minToSuggestion = _constants.DEFAULT_MIN_TO_SUGGESTION,
|
|
109
|
-
noResults,
|
|
110
|
-
onChange,
|
|
111
|
-
onClear,
|
|
112
|
-
onSelect,
|
|
113
|
-
readOnly,
|
|
114
|
-
validation,
|
|
115
|
-
value,
|
|
116
|
-
...rest
|
|
117
|
-
} = _ref2;
|
|
118
|
-
const {
|
|
119
|
-
color: resultsTextColor
|
|
120
|
-
} = (0, _componentsBase.useThemeTokens)('Search', {}, {
|
|
121
|
-
focus: true
|
|
122
|
-
}); // The wrapped input is mostly responsible for controlled vs uncontrolled handling,
|
|
123
|
-
// but we also need to adjust suggestions based on the mode:
|
|
124
|
-
// - in controlled mode we rely entirely on the suggestions passed via the `items` prop,
|
|
125
|
-
// - in uncontrolled mode we filter the suggestions ourselves based on the `initialItems`
|
|
126
|
-
// prop and the text entered
|
|
127
|
-
|
|
128
|
-
const isControlled = value !== undefined; // We need to store current items for uncontrolled usage
|
|
129
|
-
|
|
130
|
-
const [currentItems, setCurrentItems] = (0, _react.useState)(initialItems); // We need to store the current value as well to be able to highlight it
|
|
131
|
-
|
|
132
|
-
const [currentValue, setCurrentValue] = (0, _react.useState)(value ?? initialValue);
|
|
133
|
-
const inputTokens = {
|
|
134
|
-
paddingLeft: _constants.INPUT_LEFT_PADDING
|
|
135
|
-
}; // Setting up the overlay
|
|
136
|
-
|
|
137
|
-
const openOverlayRef = (0, _react.useRef)();
|
|
138
|
-
const [isExpanded, setIsExpanded] = (0, _react.useState)(((_ref3 = value ?? initialValue) === null || _ref3 === void 0 ? void 0 : _ref3.length) >= minToSuggestion);
|
|
139
|
-
const {
|
|
140
|
-
overlaidPosition,
|
|
141
|
-
sourceRef: inputRef,
|
|
142
|
-
targetRef,
|
|
143
|
-
onTargetLayout,
|
|
144
|
-
isReady
|
|
145
|
-
} = (0, _utils.useOverlaidPosition)({
|
|
146
|
-
isShown: isExpanded,
|
|
147
|
-
offsets: {
|
|
148
|
-
vertical: 4
|
|
149
|
-
}
|
|
150
|
-
}); // We limit the number of suggestions displayed to avoid huge lists
|
|
151
|
-
// TODO: add a way to make the `Listbox` occupy fixed height and be scrollable
|
|
152
|
-
// within that height, which will unlock similar behaviour for `AutoComplete` as well
|
|
153
|
-
|
|
154
|
-
const itemsToSuggest = function () {
|
|
155
|
-
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
156
|
-
return maxSuggestions ? data.slice(0, maxSuggestions) : [...data];
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const getCopy = (0, _componentsBase.useCopy)({
|
|
160
|
-
dictionary: _dictionary.default,
|
|
161
|
-
copy
|
|
162
|
-
}); // Tracking input width changes to resize the listbox overlay accordingly
|
|
163
|
-
|
|
164
|
-
const [inputWidth, setInputWidth] = (0, _react.useState)();
|
|
165
|
-
(0, _componentsBase.useSafeLayoutEffect)(() => {
|
|
166
|
-
const updateInputWidth = () => {
|
|
167
|
-
var _inputRef$current;
|
|
168
|
-
|
|
169
|
-
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
|
|
170
|
-
|
|
171
|
-
setIsExpanded(false); // close the suggestions while the input is changing
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const throttledUpdateInputWidth = (0, _lodash.throttle)(updateInputWidth, 100, {
|
|
175
|
-
leading: false
|
|
176
|
-
});
|
|
177
|
-
updateInputWidth();
|
|
178
|
-
window.addEventListener('load', updateInputWidth);
|
|
179
|
-
window.addEventListener('resize', throttledUpdateInputWidth);
|
|
180
|
-
return () => {
|
|
181
|
-
window.removeEventListener('load', updateInputWidth);
|
|
182
|
-
window.removeEventListener('resize', throttledUpdateInputWidth);
|
|
183
|
-
};
|
|
184
|
-
}, [inputRef]);
|
|
185
|
-
|
|
186
|
-
const handleChange = newValue => {
|
|
187
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
188
|
-
setCurrentValue(newValue);
|
|
189
|
-
setIsExpanded((newValue === null || newValue === void 0 ? void 0 : newValue.length) >= minToSuggestion);
|
|
190
|
-
|
|
191
|
-
if (!isControlled && initialItems !== undefined) {
|
|
192
|
-
setCurrentItems(initialItems.filter(_ref4 => {
|
|
193
|
-
var _label$toLowerCase;
|
|
194
|
-
|
|
195
|
-
let {
|
|
196
|
-
label
|
|
197
|
-
} = _ref4;
|
|
198
|
-
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());
|
|
199
|
-
}));
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const handleSelect = selectedId => {
|
|
204
|
-
var _ref5;
|
|
205
|
-
|
|
206
|
-
onSelect === null || onSelect === void 0 ? void 0 : onSelect(selectedId);
|
|
207
|
-
const {
|
|
208
|
-
label: newValue
|
|
209
|
-
} = (_ref5 = isControlled ? items : currentItems) === null || _ref5 === void 0 ? void 0 : _ref5.find(_ref6 => {
|
|
210
|
-
let {
|
|
211
|
-
id
|
|
212
|
-
} = _ref6;
|
|
213
|
-
return id === selectedId;
|
|
214
|
-
});
|
|
215
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
216
|
-
setCurrentValue(newValue);
|
|
217
|
-
if (!isControlled && inputRef !== null && inputRef !== void 0 && inputRef.current) inputRef.current.value = newValue;
|
|
218
|
-
setIsExpanded(false);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const handleClose = event => {
|
|
222
|
-
var _openOverlayRef$curre, _openOverlayRef$curre2;
|
|
223
|
-
|
|
224
|
-
if (event.type === 'keydown') {
|
|
225
|
-
if (event.key === 'Escape' || event.key === 27) {
|
|
226
|
-
setIsExpanded(false);
|
|
227
|
-
} else if (event.key === 'ArrowDown' && isExpanded && !isLoading && targetRef !== null && targetRef !== void 0 && targetRef.current) {
|
|
228
|
-
targetRef.current.focus();
|
|
229
|
-
}
|
|
230
|
-
} 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))) {
|
|
231
|
-
setIsExpanded(false);
|
|
232
|
-
} 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))) {
|
|
233
|
-
setIsExpanded(false);
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
const {
|
|
238
|
-
supportsProps,
|
|
239
|
-
...selectedProps
|
|
240
|
-
} = selectProps(rest);
|
|
241
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
242
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.InputSupports, { ...supportsProps,
|
|
243
|
-
accessibilityAutoComplete: "list",
|
|
244
|
-
accessibilityControls: "autocomplete",
|
|
245
|
-
accessibilityExpanded: isExpanded,
|
|
246
|
-
accessibilityRole: "combobox",
|
|
247
|
-
...selectedProps,
|
|
248
|
-
validation: validation,
|
|
249
|
-
ref: ref,
|
|
250
|
-
children: _ref7 => {
|
|
251
|
-
let {
|
|
252
|
-
inputId,
|
|
253
|
-
...props
|
|
254
|
-
} = _ref7;
|
|
255
|
-
if (typeof children === 'function') return children({
|
|
256
|
-
inputId,
|
|
257
|
-
inputRef,
|
|
258
|
-
onChange: handleChange,
|
|
259
|
-
onKeyPress: handleClose,
|
|
260
|
-
readOnly,
|
|
261
|
-
tokens: inputTokens,
|
|
262
|
-
...selectedProps,
|
|
263
|
-
...props,
|
|
264
|
-
...(isControlled ? {
|
|
265
|
-
value
|
|
266
|
-
} : {
|
|
267
|
-
initialValue
|
|
268
|
-
})
|
|
269
|
-
});
|
|
270
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.TextInput, {
|
|
271
|
-
onChange: handleChange,
|
|
272
|
-
onClear: onClear,
|
|
273
|
-
onKeyPress: handleClose,
|
|
274
|
-
readOnly: readOnly,
|
|
275
|
-
ref: inputRef,
|
|
276
|
-
tokens: inputTokens,
|
|
277
|
-
validation: validation,
|
|
278
|
-
...selectedProps,
|
|
279
|
-
...props,
|
|
280
|
-
...(isControlled ? {
|
|
281
|
-
value
|
|
282
|
-
} : {
|
|
283
|
-
initialValue
|
|
284
|
-
})
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
}), isExpanded && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
288
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Listbox.default.Overlay, {
|
|
289
|
-
overlaidPosition: overlaidPosition,
|
|
290
|
-
isReady: isReady,
|
|
291
|
-
minWidth: fullWidth ? inputWidth : _constants.MIN_LISTBOX_WIDTH,
|
|
292
|
-
maxWidth: inputWidth,
|
|
293
|
-
onLayout: onTargetLayout,
|
|
294
|
-
ref: openOverlayRef,
|
|
295
|
-
children: isLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Loading.default, {
|
|
296
|
-
label: getCopy('loading')
|
|
297
|
-
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Suggestions.default, {
|
|
298
|
-
hasResults: getCopy('hasResults'),
|
|
299
|
-
id: "autocomplete",
|
|
300
|
-
items: itemsToSuggest(highlight(isControlled ? items : currentItems, currentValue, resultsTextColor)),
|
|
301
|
-
noResults: noResults ?? getCopy('noResults'),
|
|
302
|
-
onClose: handleClose,
|
|
303
|
-
onSelect: handleSelect,
|
|
304
|
-
parentRef: inputRef,
|
|
305
|
-
ref: targetRef
|
|
306
|
-
})
|
|
307
|
-
}), (targetRef === null || targetRef === void 0 ? void 0 : targetRef.current) && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
308
|
-
// This catches and shifts focus to other interactive elements.
|
|
309
|
-
onFocus: () => {
|
|
310
|
-
var _targetRef$current;
|
|
311
|
-
|
|
312
|
-
return targetRef === null || targetRef === void 0 ? void 0 : (_targetRef$current = targetRef.current) === null || _targetRef$current === void 0 ? void 0 : _targetRef$current.focus();
|
|
313
|
-
} // eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
314
|
-
,
|
|
315
|
-
tabIndex: 0
|
|
316
|
-
})]
|
|
317
|
-
})]
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
Autocomplete.displayName = 'Autocomplete'; // If a language dictionary entry is provided, it must contain every key
|
|
321
|
-
|
|
322
|
-
const dictionaryContentShape = _propTypes.default.shape({
|
|
323
|
-
hasResults: _propTypes.default.string.isRequired,
|
|
324
|
-
loading: _propTypes.default.string.isRequired,
|
|
325
|
-
noResults: _propTypes.default.string.isRequired
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
Autocomplete.propTypes = { ...selectedSystemPropTypes,
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Can be used to provide a function that renders a custom input:
|
|
332
|
-
* <Autocomplete items={items} value={currentValue}>
|
|
333
|
-
* {({ inputId, inputRef, onChange, onKeyPress, readOnly, tokens, value }) => (
|
|
334
|
-
* <Search
|
|
335
|
-
* nativeID={inputId}
|
|
336
|
-
* ref={inputRef}
|
|
337
|
-
* onChange={onChange}
|
|
338
|
-
* onKeyPress={onKeyPress}
|
|
339
|
-
* readOnly={readOnly}
|
|
340
|
-
* tokens={tokens}
|
|
341
|
-
* value={value}
|
|
342
|
-
* />
|
|
343
|
-
* )}
|
|
344
|
-
* </Autocomplete>
|
|
345
|
-
*/
|
|
346
|
-
children: _propTypes.default.func,
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Copy language identifier
|
|
350
|
-
*/
|
|
351
|
-
copy: _propTypes.default.oneOfType([_propTypes.default.oneOf(['en', 'fr']), dictionaryContentShape]),
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* Set to true in order to display the loading indicator instead of results
|
|
355
|
-
*/
|
|
356
|
-
isLoading: _propTypes.default.bool,
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* List of items to display as suggestions
|
|
360
|
-
*/
|
|
361
|
-
items: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
362
|
-
id: _propTypes.default.string,
|
|
363
|
-
label: _propTypes.default.string
|
|
364
|
-
})),
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Label to display alongside the spinner when in a loading state
|
|
368
|
-
*/
|
|
369
|
-
loadingLabel: _propTypes.default.string,
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Minimum number of characters typed for a list of suggestions to appear
|
|
373
|
-
*/
|
|
374
|
-
minToSuggestion: _propTypes.default.number,
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Maximum number of suggestions provided at the same time
|
|
378
|
-
*/
|
|
379
|
-
maxSuggestions: _propTypes.default.number,
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Text or JSX to render when no results are available
|
|
383
|
-
*/
|
|
384
|
-
noResults: _propTypes.default.node,
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Handler function to be called when the input value changes
|
|
388
|
-
*/
|
|
389
|
-
onChange: _propTypes.default.func,
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Handler function to be called when the clear button (appears if the handler is passed) is pressed
|
|
393
|
-
*/
|
|
394
|
-
onClear: _propTypes.default.func,
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Callback function to be called when an item is selected from the list
|
|
398
|
-
*/
|
|
399
|
-
onSelect: _propTypes.default.func,
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Input value for controlled usage
|
|
403
|
-
*/
|
|
404
|
-
value: _propTypes.default.string,
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* Can be used to set the initial items of the component
|
|
408
|
-
*/
|
|
409
|
-
initialItems: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
410
|
-
id: _propTypes.default.string,
|
|
411
|
-
label: _propTypes.default.string
|
|
412
|
-
})),
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Initial value for the component
|
|
416
|
-
*/
|
|
417
|
-
initialValue: _propTypes.default.string,
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Boolean to set if it's readonly or not
|
|
421
|
-
*/
|
|
422
|
-
readOnly: _propTypes.default.bool,
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* Use to visually mark an input as valid or invalid.
|
|
426
|
-
*/
|
|
427
|
-
validation: _propTypes.default.oneOf(['error', 'success'])
|
|
428
|
-
};
|
|
429
|
-
var _default = Autocomplete;
|
|
430
|
-
exports.default = _default;
|