@telus-uds/components-base 1.59.2 → 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.
- package/CHANGELOG.md +26 -2
- package/component-docs.json +526 -76
- package/lib/Autocomplete/Autocomplete.js +483 -0
- package/lib/Autocomplete/Loading.js +51 -0
- package/lib/Autocomplete/Suggestions.js +85 -0
- package/lib/Autocomplete/constants.js +14 -0
- package/lib/Autocomplete/dictionary.js +19 -0
- package/lib/Autocomplete/index.js +13 -0
- package/lib/Button/ButtonLink.js +7 -3
- package/lib/ExpandCollapse/Panel.js +7 -0
- package/lib/IconButton/IconButton.js +8 -0
- package/lib/Link/ChevronLink.js +9 -2
- package/lib/Link/LinkBase.js +14 -0
- package/lib/Link/TextButton.js +12 -1
- package/lib/Listbox/GroupControl.js +121 -0
- package/lib/Listbox/Listbox.js +198 -0
- package/lib/Listbox/ListboxGroup.js +142 -0
- package/lib/Listbox/ListboxItem.js +97 -0
- package/lib/Listbox/ListboxOverlay.js +106 -0
- package/lib/Listbox/PressableItem.js +0 -2
- package/lib/Listbox/index.js +5 -24
- package/lib/Pagination/dictionary.js +3 -3
- package/lib/Progress/ProgressBarBackground.js +2 -2
- package/lib/SideNav/Item.js +15 -5
- package/lib/Tags/Tags.js +6 -1
- package/lib/TextInput/TextInputBase.js +2 -0
- package/lib/Tooltip/Tooltip.js +6 -1
- package/lib/Tooltip/Tooltip.native.js +6 -1
- package/lib/Tooltip/shared.js +5 -0
- package/lib/index.js +17 -13
- package/lib/utils/useOverlaidPosition.js +6 -4
- package/lib-module/Autocomplete/Autocomplete.js +448 -0
- package/lib-module/Autocomplete/Loading.js +36 -0
- package/lib-module/Autocomplete/Suggestions.js +66 -0
- package/lib-module/Autocomplete/constants.js +4 -0
- package/lib-module/Autocomplete/dictionary.js +12 -0
- package/lib-module/Autocomplete/index.js +2 -0
- package/lib-module/Button/ButtonLink.js +4 -1
- package/lib-module/ExpandCollapse/Panel.js +7 -0
- package/lib-module/IconButton/IconButton.js +8 -0
- package/lib-module/Link/ChevronLink.js +10 -3
- package/lib-module/Link/LinkBase.js +14 -0
- package/lib-module/Link/TextButton.js +11 -1
- package/lib-module/Listbox/GroupControl.js +102 -0
- package/lib-module/Listbox/Listbox.js +172 -0
- package/lib-module/Listbox/ListboxGroup.js +117 -0
- package/lib-module/Listbox/ListboxItem.js +71 -0
- package/lib-module/Listbox/ListboxOverlay.js +80 -0
- package/lib-module/Listbox/PressableItem.js +0 -2
- package/lib-module/Listbox/index.js +2 -2
- package/lib-module/Pagination/dictionary.js +3 -3
- package/lib-module/Progress/ProgressBarBackground.js +2 -2
- package/lib-module/SideNav/Item.js +15 -5
- package/lib-module/Tags/Tags.js +6 -1
- package/lib-module/TextInput/TextInputBase.js +2 -0
- package/lib-module/Tooltip/Tooltip.js +6 -1
- package/lib-module/Tooltip/Tooltip.native.js +6 -1
- package/lib-module/Tooltip/shared.js +5 -0
- package/lib-module/index.js +2 -1
- package/lib-module/utils/useOverlaidPosition.js +5 -4
- package/package.json +5 -3
- package/src/Autocomplete/Autocomplete.jsx +411 -0
- package/src/Autocomplete/Loading.jsx +18 -0
- package/src/Autocomplete/Suggestions.jsx +54 -0
- package/src/Autocomplete/constants.js +4 -0
- package/src/Autocomplete/dictionary.js +12 -0
- package/src/Autocomplete/index.js +3 -0
- package/src/Button/ButtonLink.jsx +4 -1
- package/src/ExpandCollapse/Panel.jsx +11 -1
- package/src/IconButton/IconButton.jsx +7 -0
- package/src/Link/ChevronLink.jsx +10 -3
- package/src/Link/LinkBase.jsx +11 -0
- package/src/Link/TextButton.jsx +8 -2
- package/src/Listbox/GroupControl.jsx +93 -0
- package/src/Listbox/Listbox.jsx +165 -0
- package/src/Listbox/ListboxGroup.jsx +120 -0
- package/src/Listbox/ListboxItem.jsx +76 -0
- package/src/Listbox/ListboxOverlay.jsx +82 -0
- package/src/Listbox/PressableItem.jsx +0 -2
- package/src/Listbox/index.js +3 -2
- package/src/Pagination/dictionary.js +3 -3
- package/src/Progress/ProgressBarBackground.jsx +2 -2
- package/src/SideNav/Item.jsx +13 -5
- package/src/Tags/Tags.jsx +5 -1
- package/src/TextInput/TextInputBase.jsx +2 -0
- package/src/Tooltip/Tooltip.jsx +16 -2
- package/src/Tooltip/Tooltip.native.jsx +15 -2
- package/src/Tooltip/shared.js +4 -0
- package/src/index.js +2 -1
- package/src/utils/useOverlaidPosition.js +6 -5
|
@@ -182,6 +182,13 @@ const ExpandCollapsePanel = /*#__PURE__*/(0, _react.forwardRef)((_ref4, ref) =>
|
|
|
182
182
|
...focusabilityProps,
|
|
183
183
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
184
184
|
onLayout: onContainerLayout,
|
|
185
|
+
style: { ..._Platform.default.select({
|
|
186
|
+
default: {
|
|
187
|
+
flex: 1
|
|
188
|
+
},
|
|
189
|
+
web: {}
|
|
190
|
+
})
|
|
191
|
+
},
|
|
185
192
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
186
193
|
style: selectContainerStyles(themeTokens),
|
|
187
194
|
children: children
|
|
@@ -129,6 +129,7 @@ const IconButton = /*#__PURE__*/(0, _react.forwardRef)((_ref3, ref) => {
|
|
|
129
129
|
icon: IconComponent,
|
|
130
130
|
href,
|
|
131
131
|
hrefAttrs,
|
|
132
|
+
testID,
|
|
132
133
|
accessibilityRole = href ? 'link' : 'button',
|
|
133
134
|
...rawRest
|
|
134
135
|
} = _ref3;
|
|
@@ -166,6 +167,7 @@ const IconButton = /*#__PURE__*/(0, _react.forwardRef)((_ref3, ref) => {
|
|
|
166
167
|
hrefAttrs: hrefAttrs,
|
|
167
168
|
style: getOuterStyle,
|
|
168
169
|
...selectedProps,
|
|
170
|
+
testID: testID,
|
|
169
171
|
children: pressableState => {
|
|
170
172
|
const themeTokens = getTokens((0, _utils.resolvePressableState)(pressableState));
|
|
171
173
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
@@ -185,6 +187,12 @@ IconButton.propTypes = { ...selectedSystemPropTypes,
|
|
|
185
187
|
variant: _utils.variantProp.propType,
|
|
186
188
|
tokens: (0, _utils.getTokensPropType)('IconButton'),
|
|
187
189
|
|
|
190
|
+
/**
|
|
191
|
+
* A unique identifier for testing purposes.
|
|
192
|
+
* Will be added as a `data-testid` attribute.
|
|
193
|
+
*/
|
|
194
|
+
testID: _propTypes.default.string,
|
|
195
|
+
|
|
188
196
|
/**
|
|
189
197
|
* Defines the icon to be rendered
|
|
190
198
|
*/
|
package/lib/Link/ChevronLink.js
CHANGED
|
@@ -36,7 +36,7 @@ const ChevronLink = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
36
36
|
tokens = {},
|
|
37
37
|
variant,
|
|
38
38
|
dataSet,
|
|
39
|
-
...
|
|
39
|
+
...otherlinkProps
|
|
40
40
|
} = _ref;
|
|
41
41
|
const getChevronTokens = (0, _ThemeProvider.useThemeTokensCallback)('ChevronLink', tokens, variant);
|
|
42
42
|
|
|
@@ -59,7 +59,7 @@ const ChevronLink = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
const getTokens = (0, _ThemeProvider.useThemeTokensCallback)('Link', applyChevronTokens, variant);
|
|
62
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LinkBase.default, { ...
|
|
62
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LinkBase.default, { ...otherlinkProps,
|
|
63
63
|
iconPosition: direction,
|
|
64
64
|
tokens: getTokens,
|
|
65
65
|
dataSet: dataSet,
|
|
@@ -69,6 +69,13 @@ const ChevronLink = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
69
69
|
});
|
|
70
70
|
ChevronLink.displayName = 'ChevronLink';
|
|
71
71
|
ChevronLink.propTypes = { ..._LinkBase.default.propTypes,
|
|
72
|
+
children: _propTypes.default.node,
|
|
73
|
+
variant: _propTypes.default.exact({
|
|
74
|
+
size: _propTypes.default.oneOf(['large', 'small', 'micro']),
|
|
75
|
+
alternative: _propTypes.default.bool,
|
|
76
|
+
inverse: _propTypes.default.bool
|
|
77
|
+
}),
|
|
78
|
+
..._utils.linkProps.types,
|
|
72
79
|
tokens: (0, _utils.getTokensPropType)('ChevronLink', 'Link'),
|
|
73
80
|
|
|
74
81
|
/**
|
package/lib/Link/LinkBase.js
CHANGED
|
@@ -238,6 +238,20 @@ const LinkBase = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
238
238
|
LinkBase.displayName = 'LinkBase';
|
|
239
239
|
LinkBase.propTypes = { ...selectedSystemPropTypes,
|
|
240
240
|
tokens: (0, _props.getTokensPropType)('Link'),
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* href for the Link
|
|
244
|
+
*/
|
|
245
|
+
href: _propTypes.default.string,
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* AccesibilityRole for the link base
|
|
249
|
+
*/
|
|
250
|
+
accessibilityrole: _propTypes.default.string,
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Children nodes that can be added
|
|
254
|
+
*/
|
|
241
255
|
variant: _props.variantProp.propType,
|
|
242
256
|
|
|
243
257
|
/**
|
package/lib/Link/TextButton.js
CHANGED
|
@@ -13,6 +13,8 @@ var _ThemeProvider = require("../ThemeProvider");
|
|
|
13
13
|
|
|
14
14
|
var _LinkBase = _interopRequireDefault(require("./LinkBase"));
|
|
15
15
|
|
|
16
|
+
var _utils = require("../utils");
|
|
17
|
+
|
|
16
18
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
19
|
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -47,7 +49,16 @@ const TextButton = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
47
49
|
});
|
|
48
50
|
TextButton.displayName = 'TextButton';
|
|
49
51
|
TextButton.propTypes = { ..._LinkBase.default.propTypes,
|
|
50
|
-
|
|
52
|
+
|
|
53
|
+
/** onPress function */
|
|
54
|
+
onPress: _propTypes.default.func.isRequired,
|
|
55
|
+
|
|
56
|
+
/** Children node that can be added */
|
|
57
|
+
children: _propTypes.default.node.isRequired,
|
|
58
|
+
variant: _utils.variantProp.propType,
|
|
59
|
+
|
|
60
|
+
/** Accesibility role for TextButton */
|
|
61
|
+
accessibilityRole: _propTypes.default.string
|
|
51
62
|
};
|
|
52
63
|
var _default = TextButton;
|
|
53
64
|
exports.default = _default;
|
|
@@ -0,0 +1,121 @@
|
|
|
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 _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
|
|
13
|
+
|
|
14
|
+
var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
|
|
15
|
+
|
|
16
|
+
var _Text = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Text"));
|
|
17
|
+
|
|
18
|
+
var _ThemeProvider = require("../ThemeProvider");
|
|
19
|
+
|
|
20
|
+
var _Icon = _interopRequireDefault(require("../Icon"));
|
|
21
|
+
|
|
22
|
+
var _Spacer = _interopRequireDefault(require("../Spacer"));
|
|
23
|
+
|
|
24
|
+
var _ListboxContext = require("./ListboxContext");
|
|
25
|
+
|
|
26
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
const styles = _StyleSheet.default.create({
|
|
31
|
+
controlWrapper: {
|
|
32
|
+
width: '100%',
|
|
33
|
+
flex: 1,
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
flexDirection: 'row',
|
|
36
|
+
justifyContent: 'space-between',
|
|
37
|
+
boxSizing: 'border-box'
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const GroupControl = _ref => {
|
|
42
|
+
let {
|
|
43
|
+
expanded,
|
|
44
|
+
pressed,
|
|
45
|
+
hover,
|
|
46
|
+
focus,
|
|
47
|
+
label,
|
|
48
|
+
id
|
|
49
|
+
} = _ref;
|
|
50
|
+
const {
|
|
51
|
+
selectedId,
|
|
52
|
+
setSelectedId
|
|
53
|
+
} = (0, _ListboxContext.useListboxContext)();
|
|
54
|
+
const tokens = (0, _ThemeProvider.useThemeTokens)('Listbox', {}, {}, {
|
|
55
|
+
expanded,
|
|
56
|
+
pressed,
|
|
57
|
+
hover,
|
|
58
|
+
current: selectedId === id && id !== undefined,
|
|
59
|
+
focus
|
|
60
|
+
});
|
|
61
|
+
const {
|
|
62
|
+
groupFontName,
|
|
63
|
+
groupFontWeight,
|
|
64
|
+
groupFontSize,
|
|
65
|
+
groupColor,
|
|
66
|
+
groupBackgroundColor,
|
|
67
|
+
groupBorderColor,
|
|
68
|
+
groupBorderWidth,
|
|
69
|
+
groupBorderRadius,
|
|
70
|
+
groupPaddingLeft,
|
|
71
|
+
groupPaddingRight,
|
|
72
|
+
groupPaddingTop,
|
|
73
|
+
groupPaddingBottom,
|
|
74
|
+
itemTextDecoration,
|
|
75
|
+
itemOutline,
|
|
76
|
+
groupHeight
|
|
77
|
+
} = tokens;
|
|
78
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_View.default, {
|
|
79
|
+
onPress: () => setSelectedId(id),
|
|
80
|
+
style: [styles.controlWrapper, {
|
|
81
|
+
fontFamily: `${groupFontName}${groupFontWeight}normal`,
|
|
82
|
+
fontSize: groupFontSize,
|
|
83
|
+
color: groupColor,
|
|
84
|
+
textDecoration: itemTextDecoration,
|
|
85
|
+
backgroundColor: groupBackgroundColor,
|
|
86
|
+
outline: itemOutline,
|
|
87
|
+
height: groupHeight,
|
|
88
|
+
border: `${groupBorderWidth}px solid ${groupBorderColor}`,
|
|
89
|
+
borderRadius: groupBorderRadius,
|
|
90
|
+
paddingLeft: groupPaddingLeft - groupBorderWidth,
|
|
91
|
+
paddingRight: groupPaddingRight - groupBorderWidth,
|
|
92
|
+
paddingTop: groupPaddingTop - groupBorderWidth,
|
|
93
|
+
paddingBottom: groupPaddingBottom - groupBorderWidth
|
|
94
|
+
}],
|
|
95
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, {
|
|
96
|
+
children: label
|
|
97
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spacer.default, {
|
|
98
|
+
space: 1,
|
|
99
|
+
direction: "row"
|
|
100
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
|
|
101
|
+
icon: tokens.groupIcon,
|
|
102
|
+
tokens: {
|
|
103
|
+
color: tokens.groupColor
|
|
104
|
+
},
|
|
105
|
+
variant: {
|
|
106
|
+
size: 'micro'
|
|
107
|
+
}
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
GroupControl.propTypes = {
|
|
113
|
+
id: _propTypes.default.string,
|
|
114
|
+
expanded: _propTypes.default.bool,
|
|
115
|
+
pressed: _propTypes.default.bool,
|
|
116
|
+
hover: _propTypes.default.bool,
|
|
117
|
+
focus: _propTypes.default.bool,
|
|
118
|
+
label: _propTypes.default.string
|
|
119
|
+
};
|
|
120
|
+
var _default = GroupControl;
|
|
121
|
+
exports.default = _default;
|
|
@@ -0,0 +1,198 @@
|
|
|
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 _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
|
|
13
|
+
|
|
14
|
+
var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
|
|
15
|
+
|
|
16
|
+
var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
|
|
17
|
+
|
|
18
|
+
var _ThemeProvider = require("../ThemeProvider");
|
|
19
|
+
|
|
20
|
+
var _utils = require("../utils");
|
|
21
|
+
|
|
22
|
+
var _ExpandCollapse = _interopRequireDefault(require("../ExpandCollapse"));
|
|
23
|
+
|
|
24
|
+
var _ListboxGroup = _interopRequireDefault(require("./ListboxGroup"));
|
|
25
|
+
|
|
26
|
+
var _ListboxItem = _interopRequireDefault(require("./ListboxItem"));
|
|
27
|
+
|
|
28
|
+
var _ListboxContext = require("./ListboxContext");
|
|
29
|
+
|
|
30
|
+
var _ListboxOverlay = _interopRequireDefault(require("./ListboxOverlay"));
|
|
31
|
+
|
|
32
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
33
|
+
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
|
+
|
|
36
|
+
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); }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
40
|
+
const styles = _StyleSheet.default.create({
|
|
41
|
+
list: {
|
|
42
|
+
padding: 0,
|
|
43
|
+
margin: 0
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const getInitialOpen = (items, selectedId) => items.filter(item => item.items && item.items.some(nestedItem => (nestedItem.id ?? nestedItem.label) === selectedId)).map(item => item.id ?? item.label);
|
|
48
|
+
|
|
49
|
+
const Listbox = _ref => {
|
|
50
|
+
let {
|
|
51
|
+
items = [],
|
|
52
|
+
firstItemRef = null,
|
|
53
|
+
// focus will be moved to this one once within the menu
|
|
54
|
+
parentRef = null,
|
|
55
|
+
// to return focus to after leaving the last menu item
|
|
56
|
+
selectedId: defaultSelectedId,
|
|
57
|
+
LinkRouter,
|
|
58
|
+
itemRouterProps,
|
|
59
|
+
onClose,
|
|
60
|
+
variant,
|
|
61
|
+
tokens
|
|
62
|
+
} = _ref;
|
|
63
|
+
const initialOpen = getInitialOpen(items, defaultSelectedId);
|
|
64
|
+
const [selectedId, setSelectedId] = (0, _react.useState)(defaultSelectedId);
|
|
65
|
+
const {
|
|
66
|
+
minHeight,
|
|
67
|
+
minWidth
|
|
68
|
+
} = (0, _ThemeProvider.useThemeTokens)('Listbox', variant, tokens); // We need to keep track of each item's ref in order to be able to
|
|
69
|
+
// focus on a specific item via keyboard navigation
|
|
70
|
+
|
|
71
|
+
const itemRefs = (0, _react.useRef)([]);
|
|
72
|
+
if (firstItemRef !== null && firstItemRef !== void 0 && firstItemRef.current) itemRefs.current[0] = firstItemRef.current;
|
|
73
|
+
const [focusedIndex, setFocusedIndex] = (0, _react.useState)(0);
|
|
74
|
+
const handleKeydown = (0, _react.useCallback)(event => {
|
|
75
|
+
const nextItemRef = itemRefs.current[focusedIndex + 1];
|
|
76
|
+
const prevItemRef = itemRefs.current[focusedIndex - 1];
|
|
77
|
+
|
|
78
|
+
if (event.key === 'ArrowUp' || event.shiftKey && event.key === 'Tab') {
|
|
79
|
+
var _parentRef$current;
|
|
80
|
+
|
|
81
|
+
// Move the focus to the previous item or to the parent one if on the first
|
|
82
|
+
if (prevItemRef) {
|
|
83
|
+
event.preventDefault();
|
|
84
|
+
prevItemRef.focus();
|
|
85
|
+
} else if (parentRef) (_parentRef$current = parentRef.current) === null || _parentRef$current === void 0 ? void 0 : _parentRef$current.focus();
|
|
86
|
+
|
|
87
|
+
setFocusedIndex(focusedIndex - 1);
|
|
88
|
+
} else if ((event.key === 'ArrowDown' || event.key === 'Tab') && nextItemRef) {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
setFocusedIndex(focusedIndex + 1);
|
|
91
|
+
nextItemRef.focus();
|
|
92
|
+
} else if (event.key === 'Escape') {
|
|
93
|
+
var _parentRef$current2, _parentRef$current3;
|
|
94
|
+
|
|
95
|
+
// Close the dropdown
|
|
96
|
+
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
|
|
97
|
+
|
|
98
|
+
parentRef === null || parentRef === void 0 ? void 0 : (_parentRef$current3 = parentRef.current) === null || _parentRef$current3 === void 0 ? void 0 : _parentRef$current3.focus();
|
|
99
|
+
if (onClose) onClose(event);
|
|
100
|
+
}
|
|
101
|
+
}, [focusedIndex, onClose, parentRef]); // Add listeners for mouse clicks outside and for key presses
|
|
102
|
+
|
|
103
|
+
(0, _react.useEffect)(() => {
|
|
104
|
+
if (_Platform.default.OS === 'web') {
|
|
105
|
+
window.addEventListener('click', onClose);
|
|
106
|
+
window.addEventListener('keydown', handleKeydown);
|
|
107
|
+
window.addEventListener('touchstart', onClose);
|
|
108
|
+
return () => {
|
|
109
|
+
window.removeEventListener('click', onClose);
|
|
110
|
+
window.removeEventListener('keydown', handleKeydown);
|
|
111
|
+
window.removeEventListener('touchstart', onClose);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return () => {};
|
|
116
|
+
}, [onClose, handleKeydown]);
|
|
117
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListboxContext.ListboxContext.Provider, {
|
|
118
|
+
value: {
|
|
119
|
+
selectedId,
|
|
120
|
+
setSelectedId
|
|
121
|
+
},
|
|
122
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ExpandCollapse.default, {
|
|
123
|
+
initialOpen: initialOpen,
|
|
124
|
+
maxOpen: 1,
|
|
125
|
+
children: expandProps => /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
126
|
+
style: [styles.list, {
|
|
127
|
+
minHeight,
|
|
128
|
+
minWidth
|
|
129
|
+
}],
|
|
130
|
+
role: "listbox",
|
|
131
|
+
children: items.map((item, index) => {
|
|
132
|
+
const {
|
|
133
|
+
id,
|
|
134
|
+
label,
|
|
135
|
+
items: nestedItems
|
|
136
|
+
} = item;
|
|
137
|
+
const itemId = id ?? label; // Give the list of refs.
|
|
138
|
+
|
|
139
|
+
const itemRef = ref => {
|
|
140
|
+
itemRefs.current[index] = ref;
|
|
141
|
+
return ref;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return nestedItems ? /*#__PURE__*/(0, _react.createElement)(_ListboxGroup.default, { ...item,
|
|
145
|
+
expandProps: expandProps,
|
|
146
|
+
LinkRouter: LinkRouter,
|
|
147
|
+
itemRouterProps: itemRouterProps,
|
|
148
|
+
prevItemRef: itemRefs.current[index - 1] ?? null,
|
|
149
|
+
nextItemRef: itemRefs.current[index + 1] ?? null,
|
|
150
|
+
ref: index === 0 ? firstItemRef : itemRef,
|
|
151
|
+
key: itemId
|
|
152
|
+
}) : /*#__PURE__*/(0, _react.createElement)(_ListboxItem.default, { ...item,
|
|
153
|
+
key: itemId,
|
|
154
|
+
id: itemId,
|
|
155
|
+
LinkRouter: LinkRouter,
|
|
156
|
+
itemRouterProps: itemRouterProps,
|
|
157
|
+
prevItemRef: itemRefs.current[index - 1] ?? null,
|
|
158
|
+
nextItemRef: itemRefs.current[index + 1] ?? null,
|
|
159
|
+
ref: index === 0 ? firstItemRef : itemRef
|
|
160
|
+
});
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
})
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
Listbox.propTypes = { ..._utils.withLinkRouter.propTypes,
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Focus will be moved to the item with this ref once within the menu.
|
|
171
|
+
*/
|
|
172
|
+
firstItemRef: _propTypes.default.object,
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Focus will be returned to the dropdown control with this ref after leaving
|
|
176
|
+
* the last menu item.
|
|
177
|
+
*/
|
|
178
|
+
parentRef: _propTypes.default.object,
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* `Listbox` items
|
|
182
|
+
*/
|
|
183
|
+
items: _propTypes.default.array,
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* To select an item by default
|
|
187
|
+
*/
|
|
188
|
+
selectedId: _propTypes.default.string,
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* onClose event
|
|
192
|
+
*/
|
|
193
|
+
onClose: _propTypes.default.func,
|
|
194
|
+
tokens: (0, _utils.getTokensPropType)('Listbox')
|
|
195
|
+
};
|
|
196
|
+
Listbox.Overlay = _ListboxOverlay.default;
|
|
197
|
+
var _default = Listbox;
|
|
198
|
+
exports.default = _default;
|
|
@@ -0,0 +1,142 @@
|
|
|
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 _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
|
|
13
|
+
|
|
14
|
+
var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
|
|
15
|
+
|
|
16
|
+
var _utils = require("../utils");
|
|
17
|
+
|
|
18
|
+
var _ExpandCollapse = _interopRequireDefault(require("../ExpandCollapse"));
|
|
19
|
+
|
|
20
|
+
var _ListboxItem = _interopRequireDefault(require("./ListboxItem"));
|
|
21
|
+
|
|
22
|
+
var _ListboxContext = require("./ListboxContext");
|
|
23
|
+
|
|
24
|
+
var _GroupControl = _interopRequireDefault(require("./GroupControl"));
|
|
25
|
+
|
|
26
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
27
|
+
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
|
|
30
|
+
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); }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
/* eslint-disable react-native-a11y/has-valid-accessibility-role */
|
|
35
|
+
const styles = _StyleSheet.default.create({
|
|
36
|
+
groupWrapper: {
|
|
37
|
+
margin: 0,
|
|
38
|
+
padding: 0,
|
|
39
|
+
overflow: 'hidden'
|
|
40
|
+
},
|
|
41
|
+
list: {
|
|
42
|
+
margin: 0,
|
|
43
|
+
padding: 0
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const ListboxGroup = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
48
|
+
let {
|
|
49
|
+
id,
|
|
50
|
+
label,
|
|
51
|
+
items,
|
|
52
|
+
LinkRouter,
|
|
53
|
+
linkRouterProps,
|
|
54
|
+
expandProps,
|
|
55
|
+
onLastItemBlur,
|
|
56
|
+
nextItemRef,
|
|
57
|
+
prevItemRef
|
|
58
|
+
} = _ref;
|
|
59
|
+
const {
|
|
60
|
+
selectedId
|
|
61
|
+
} = (0, _ListboxContext.useListboxContext)(); // TODO: implement keyboard navigation via refs for grouped items separately here
|
|
62
|
+
|
|
63
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
64
|
+
id: "test",
|
|
65
|
+
style: styles.groupWrapper,
|
|
66
|
+
accessibilityRole: "listitem",
|
|
67
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ExpandCollapse.default.Panel, {
|
|
68
|
+
panelId: id ?? label,
|
|
69
|
+
controlTokens: {
|
|
70
|
+
icon: null,
|
|
71
|
+
paddingLeft: 0,
|
|
72
|
+
paddingRight: 0,
|
|
73
|
+
paddingTop: 0,
|
|
74
|
+
paddingBottom: 0,
|
|
75
|
+
backgroundColor: 'transparent',
|
|
76
|
+
borderColor: 'transparent',
|
|
77
|
+
textLine: 'none',
|
|
78
|
+
borderWidth: 0
|
|
79
|
+
} // TODO refactor
|
|
80
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
81
|
+
,
|
|
82
|
+
control: controlProps => /*#__PURE__*/(0, _jsxRuntime.jsx)(_GroupControl.default, {
|
|
83
|
+
id: id ?? label,
|
|
84
|
+
...controlProps,
|
|
85
|
+
label: label
|
|
86
|
+
}),
|
|
87
|
+
...expandProps,
|
|
88
|
+
tokens: {
|
|
89
|
+
contentPaddingLeft: 0,
|
|
90
|
+
contentPaddingRight: 0,
|
|
91
|
+
contentPaddingTop: 0,
|
|
92
|
+
contentPaddingBottom: 0,
|
|
93
|
+
borderColor: 'transparent',
|
|
94
|
+
borderRadius: 0,
|
|
95
|
+
borderWidth: 0,
|
|
96
|
+
marginBottom: 0
|
|
97
|
+
},
|
|
98
|
+
controlRef: ref,
|
|
99
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
100
|
+
style: styles.list,
|
|
101
|
+
children: items.map((item, index) => {
|
|
102
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ListboxItem.default, {
|
|
103
|
+
id: item.id ?? item.label,
|
|
104
|
+
...item,
|
|
105
|
+
selected: item.id && item.id === selectedId || item.label && item.label === selectedId,
|
|
106
|
+
isChild: true,
|
|
107
|
+
LinkRouter: LinkRouter,
|
|
108
|
+
linkRouterProps: linkRouterProps,
|
|
109
|
+
...(index === 0 && {
|
|
110
|
+
prevItemRef
|
|
111
|
+
}),
|
|
112
|
+
...(index === items.length - 1 && {
|
|
113
|
+
nextItemRef
|
|
114
|
+
}),
|
|
115
|
+
...(index === items.length - 1 && {
|
|
116
|
+
onBlur: onLastItemBlur
|
|
117
|
+
})
|
|
118
|
+
}, item.label);
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
ListboxGroup.displayName = 'ListboxGroup';
|
|
125
|
+
ListboxGroup.propTypes = { ..._utils.withLinkRouter.propTypes,
|
|
126
|
+
label: _propTypes.default.string,
|
|
127
|
+
items: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
128
|
+
href: _propTypes.default.string,
|
|
129
|
+
label: _propTypes.default.string,
|
|
130
|
+
current: _propTypes.default.bool
|
|
131
|
+
})),
|
|
132
|
+
expandProps: _propTypes.default.object,
|
|
133
|
+
nextItemRef: _propTypes.default.object,
|
|
134
|
+
prevItemRef: _propTypes.default.object,
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Use this callback to redirect the focus after it leaves the last item of the group.
|
|
138
|
+
*/
|
|
139
|
+
onLastItemBlur: _propTypes.default.func
|
|
140
|
+
};
|
|
141
|
+
var _default = ListboxGroup;
|
|
142
|
+
exports.default = _default;
|
|
@@ -0,0 +1,97 @@
|
|
|
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 _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
|
|
13
|
+
|
|
14
|
+
var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
|
|
15
|
+
|
|
16
|
+
var _utils = require("../utils");
|
|
17
|
+
|
|
18
|
+
var _PressableItem = _interopRequireDefault(require("./PressableItem"));
|
|
19
|
+
|
|
20
|
+
var _ThemeProvider = require("../ThemeProvider");
|
|
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
|
+
/* eslint-disable react/require-default-props */
|
|
31
|
+
const [selectProps, selectedSystemPropTypes] = (0, _utils.selectSystemProps)([_utils.htmlAttrs]);
|
|
32
|
+
|
|
33
|
+
const styles = _StyleSheet.default.create({
|
|
34
|
+
itemContainer: {
|
|
35
|
+
display: 'flex',
|
|
36
|
+
margin: 0
|
|
37
|
+
},
|
|
38
|
+
childContainer: {
|
|
39
|
+
paddingLeft: 16
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const ListboxItem = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
44
|
+
let {
|
|
45
|
+
href,
|
|
46
|
+
label,
|
|
47
|
+
isChild = false,
|
|
48
|
+
onBlur,
|
|
49
|
+
nextItemRef,
|
|
50
|
+
prevItemRef,
|
|
51
|
+
tokens,
|
|
52
|
+
variant = {},
|
|
53
|
+
LinkRouter,
|
|
54
|
+
linkRouterProps,
|
|
55
|
+
id,
|
|
56
|
+
onPress = () => {},
|
|
57
|
+
...rest
|
|
58
|
+
} = _ref;
|
|
59
|
+
const selectedProps = selectProps({
|
|
60
|
+
href,
|
|
61
|
+
...rest
|
|
62
|
+
});
|
|
63
|
+
const getTokens = (0, _ThemeProvider.useThemeTokensCallback)('Listbox', tokens, variant, {
|
|
64
|
+
isChild
|
|
65
|
+
});
|
|
66
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
67
|
+
style: [styles.itemContainer, isChild && styles.childContainer],
|
|
68
|
+
role: "option",
|
|
69
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PressableItem.default, {
|
|
70
|
+
href: href,
|
|
71
|
+
isChild: isChild,
|
|
72
|
+
onPress: onPress,
|
|
73
|
+
onBlur: onBlur,
|
|
74
|
+
nextItemRef: nextItemRef,
|
|
75
|
+
prevItemRef: prevItemRef,
|
|
76
|
+
ref: ref,
|
|
77
|
+
tokens: getTokens,
|
|
78
|
+
selectedProps: selectedProps,
|
|
79
|
+
id: id,
|
|
80
|
+
children: label
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
ListboxItem.displayName = 'ListboxItem';
|
|
85
|
+
ListboxItem.propTypes = { ...selectedSystemPropTypes,
|
|
86
|
+
..._utils.withLinkRouter.propTypes,
|
|
87
|
+
href: _propTypes.default.string,
|
|
88
|
+
isChild: _propTypes.default.bool,
|
|
89
|
+
label: _propTypes.default.node.isRequired,
|
|
90
|
+
nextItemRef: _propTypes.default.object,
|
|
91
|
+
prevItemRef: _propTypes.default.object,
|
|
92
|
+
onPress: _propTypes.default.func
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
var _default = (0, _utils.withLinkRouter)(ListboxItem);
|
|
96
|
+
|
|
97
|
+
exports.default = _default;
|