@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.
- package/CHANGELOG.md +10 -2
- package/component-docs.json +281 -70
- 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/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/TextInput/TextInputBase.js +2 -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/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/TextInput/TextInputBase.js +2 -0
- package/lib-module/index.js +2 -1
- package/lib-module/utils/useOverlaidPosition.js +5 -4
- package/package.json +4 -2
- 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/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/TextInput/TextInputBase.jsx +2 -0
- package/src/index.js +2 -1
- package/src/utils/useOverlaidPosition.js +6 -5
|
@@ -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;
|
|
@@ -0,0 +1,106 @@
|
|
|
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 _portal = require("@gorhom/portal");
|
|
19
|
+
|
|
20
|
+
var _ThemeProvider = require("../ThemeProvider");
|
|
21
|
+
|
|
22
|
+
var _Card = _interopRequireDefault(require("../Card"));
|
|
23
|
+
|
|
24
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
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); }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
/* eslint-disable react/require-default-props */
|
|
33
|
+
const staticStyles = _StyleSheet.default.create({
|
|
34
|
+
positioner: {
|
|
35
|
+
flex: 1,
|
|
36
|
+
// Grow to maxWidth when possible, shrink when not possible
|
|
37
|
+
position: 'absolute',
|
|
38
|
+
zIndex: 1000000000000000 // Position on top of all the other overlays, including backdrops and modals
|
|
39
|
+
|
|
40
|
+
},
|
|
41
|
+
hidden: {
|
|
42
|
+
// Use opacity not visibility to hide the dropdown during positioning
|
|
43
|
+
// so on web, children may be focused from the first render
|
|
44
|
+
opacity: 0
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const paddingVertical = 0;
|
|
49
|
+
const paddingHorizontal = 0;
|
|
50
|
+
const DropdownOverlay = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
51
|
+
let {
|
|
52
|
+
children,
|
|
53
|
+
isReady = false,
|
|
54
|
+
overlaidPosition,
|
|
55
|
+
maxWidth,
|
|
56
|
+
minWidth,
|
|
57
|
+
onLayout
|
|
58
|
+
} = _ref;
|
|
59
|
+
const systemTokens = (0, _ThemeProvider.useThemeTokens)('Listbox', {}, {});
|
|
60
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
61
|
+
ref: ref,
|
|
62
|
+
onLayout: onLayout,
|
|
63
|
+
style: [overlaidPosition, {
|
|
64
|
+
maxWidth,
|
|
65
|
+
minWidth
|
|
66
|
+
}, staticStyles.positioner, !isReady && staticStyles.hidden],
|
|
67
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Card.default, {
|
|
68
|
+
tokens: {
|
|
69
|
+
shadow: systemTokens.shadow,
|
|
70
|
+
paddingBottom: paddingVertical,
|
|
71
|
+
paddingTop: paddingVertical,
|
|
72
|
+
paddingLeft: paddingHorizontal,
|
|
73
|
+
paddingRight: paddingHorizontal
|
|
74
|
+
},
|
|
75
|
+
children: children
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const withPortal = Overlay => {
|
|
81
|
+
// eslint-disable-next-line react/display-name, react/no-multi-comp
|
|
82
|
+
return props => {
|
|
83
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_portal.Portal, {
|
|
84
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Overlay, { ...props
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
DropdownOverlay.displayName = 'DropdownOverlay';
|
|
91
|
+
DropdownOverlay.propTypes = {
|
|
92
|
+
children: _propTypes.default.node.isRequired,
|
|
93
|
+
isReady: _propTypes.default.bool,
|
|
94
|
+
overlaidPosition: _propTypes.default.shape({
|
|
95
|
+
top: _propTypes.default.number,
|
|
96
|
+
left: _propTypes.default.number,
|
|
97
|
+
width: _propTypes.default.number
|
|
98
|
+
}),
|
|
99
|
+
maxWidth: _propTypes.default.number,
|
|
100
|
+
minWidth: _propTypes.default.number,
|
|
101
|
+
onLayout: _propTypes.default.func
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
var _default = _Platform.default.OS === 'web' ? withPortal(DropdownOverlay) : DropdownOverlay;
|
|
105
|
+
|
|
106
|
+
exports.default = _default;
|
|
@@ -40,7 +40,6 @@ const getItemStyles = _ref => {
|
|
|
40
40
|
itemPaddingRight,
|
|
41
41
|
itemBackgroundColor,
|
|
42
42
|
itemColor,
|
|
43
|
-
itemDisplay,
|
|
44
43
|
itemOutline,
|
|
45
44
|
itemTextDecoration,
|
|
46
45
|
itemBorderLeftColor,
|
|
@@ -62,7 +61,6 @@ const getItemStyles = _ref => {
|
|
|
62
61
|
width: '100%',
|
|
63
62
|
backgroundColor: itemBackgroundColor,
|
|
64
63
|
color: itemColor,
|
|
65
|
-
display: itemDisplay,
|
|
66
64
|
outline: itemOutline,
|
|
67
65
|
textDecoration: itemTextDecoration,
|
|
68
66
|
borderLeft: `${itemBorderLeftWidth}px solid ${itemBorderLeftColor}`,
|