@telus-uds/components-web 1.6.1 → 1.8.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/.eslintignore +2 -0
- package/.vscode/settings.json +7 -0
- package/CHANGELOG.md +26 -2
- package/lib/BlockQuote/BlockQuote.js +173 -0
- package/lib/BlockQuote/index.js +13 -0
- package/lib/IconButton/IconButton.js +70 -0
- package/lib/IconButton/index.js +13 -0
- package/lib/Listbox/GroupControl.js +94 -0
- package/lib/Listbox/Listbox.js +164 -0
- package/lib/Listbox/ListboxGroup.js +129 -0
- package/lib/Listbox/ListboxItem.js +137 -0
- package/lib/Listbox/ListboxOverlay.js +89 -0
- package/lib/Listbox/PressableItem.js +149 -0
- package/lib/Listbox/index.js +13 -0
- package/lib/Modal/Modal.js +5 -1
- package/lib/Modal/ModalContent.js +3 -1
- package/lib/NavigationBar/resolveItemSelection.js +24 -0
- package/lib/Spinner/Spinner.js +234 -0
- package/lib/Spinner/SpinnerContent.js +107 -0
- package/lib/Spinner/constants.js +14 -0
- package/lib/Spinner/index.js +13 -0
- package/lib/baseExports.js +0 -6
- package/lib/index.js +37 -1
- package/lib/utils/useOverlaidPosition.js +246 -0
- package/lib-module/BlockQuote/BlockQuote.js +156 -0
- package/lib-module/BlockQuote/index.js +2 -0
- package/lib-module/IconButton/IconButton.js +52 -0
- package/lib-module/IconButton/index.js +2 -0
- package/lib-module/Listbox/GroupControl.js +80 -0
- package/lib-module/Listbox/Listbox.js +142 -0
- package/lib-module/Listbox/ListboxGroup.js +106 -0
- package/lib-module/Listbox/ListboxItem.js +112 -0
- package/lib-module/Listbox/ListboxOverlay.js +68 -0
- package/lib-module/Listbox/PressableItem.js +128 -0
- package/lib-module/Listbox/index.js +2 -0
- package/lib-module/Modal/Modal.js +5 -1
- package/lib-module/Modal/ModalContent.js +3 -1
- package/lib-module/NavigationBar/resolveItemSelection.js +16 -0
- package/lib-module/Spinner/Spinner.js +213 -0
- package/lib-module/Spinner/SpinnerContent.js +90 -0
- package/lib-module/Spinner/constants.js +4 -0
- package/lib-module/Spinner/index.js +2 -0
- package/lib-module/baseExports.js +1 -1
- package/lib-module/index.js +4 -0
- package/lib-module/utils/useOverlaidPosition.js +235 -0
- package/package.json +3 -3
- package/src/BlockQuote/BlockQuote.jsx +130 -0
- package/src/BlockQuote/index.js +3 -0
- package/src/IconButton/IconButton.jsx +46 -0
- package/src/IconButton/index.js +3 -0
- package/src/Listbox/GroupControl.jsx +65 -0
- package/src/Listbox/Listbox.jsx +148 -0
- package/src/Listbox/ListboxGroup.jsx +110 -0
- package/src/Listbox/ListboxItem.jsx +101 -0
- package/src/Listbox/ListboxOverlay.jsx +71 -0
- package/src/Listbox/PressableItem.jsx +121 -0
- package/src/Listbox/index.js +3 -0
- package/src/Modal/Modal.jsx +12 -2
- package/src/Modal/ModalContent.jsx +3 -0
- package/src/NavigationBar/resolveItemSelection.js +11 -0
- package/src/Spinner/Spinner.jsx +186 -0
- package/src/Spinner/SpinnerContent.jsx +76 -0
- package/src/Spinner/constants.js +4 -0
- package/src/Spinner/index.js +3 -0
- package/src/baseExports.js +0 -1
- package/src/index.js +4 -0
- package/src/utils/useOverlaidPosition.js +226 -0
- package/types/Spinner.d.ts +16 -0
package/.eslintignore
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,36 @@
|
|
|
1
1
|
# Change Log - @telus-uds/components-web
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 24 Apr 2023 21:33:59 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.8.0
|
|
8
|
+
|
|
9
|
+
Mon, 24 Apr 2023 21:33:59 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- move 'IconButton' to components-web (kyle.king2@telus.com)
|
|
14
|
+
- makes listbox component to multibrand (mauricio.batresmontejo@telus.com)
|
|
15
|
+
- move blockquote to components web (evander.owusu@telus.com)
|
|
16
|
+
- Bump @telus-uds/components-base to v1.37.0
|
|
17
|
+
- Bump @telus-uds/system-theme-tokens to v2.22.0
|
|
18
|
+
|
|
19
|
+
## 1.7.0
|
|
20
|
+
|
|
21
|
+
Thu, 20 Apr 2023 19:13:33 GMT
|
|
22
|
+
|
|
23
|
+
### Minor changes
|
|
24
|
+
|
|
25
|
+
- web modal to accept children (srikanthkhari@gmail.com)
|
|
26
|
+
- Added Spinner (wlsdud194@hotmail.com)
|
|
27
|
+
- update snapshots (kyle.king2@telus.com)
|
|
28
|
+
- Bump @telus-uds/components-base to v1.36.0
|
|
29
|
+
- Bump @telus-uds/system-theme-tokens to v2.21.0
|
|
30
|
+
|
|
7
31
|
## 1.6.1
|
|
8
32
|
|
|
9
|
-
Wed, 19 Apr 2023 18:
|
|
33
|
+
Wed, 19 Apr 2023 18:49:51 GMT
|
|
10
34
|
|
|
11
35
|
### Patches
|
|
12
36
|
|
|
@@ -0,0 +1,173 @@
|
|
|
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 _componentsBase = require("@telus-uds/components-base");
|
|
13
|
+
|
|
14
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
15
|
+
|
|
16
|
+
var _utils = require("../utils");
|
|
17
|
+
|
|
18
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
const [selectProps, selectedSystemPropTypes] = (0, _componentsBase.selectSystemProps)([_utils.htmlAttrs]);
|
|
23
|
+
|
|
24
|
+
const BlockQuoteContainer = /*#__PURE__*/_styledComponents.default.blockquote.withConfig({
|
|
25
|
+
displayName: "BlockQuote__BlockQuoteContainer",
|
|
26
|
+
componentId: "components-web__sc-vals3u-0"
|
|
27
|
+
})(["margin:0;position:relative;padding-left:", ";padding-right:", ";padding-bottom:", ";padding-top:", ";&::before{content:'';left:0;top:0;position:absolute;height:100%;width:", ";background:", ";}"], _ref => {
|
|
28
|
+
let {
|
|
29
|
+
paddingLeft
|
|
30
|
+
} = _ref;
|
|
31
|
+
return `${paddingLeft}px`;
|
|
32
|
+
}, _ref2 => {
|
|
33
|
+
let {
|
|
34
|
+
paddingRight
|
|
35
|
+
} = _ref2;
|
|
36
|
+
return `${paddingRight}px`;
|
|
37
|
+
}, _ref3 => {
|
|
38
|
+
let {
|
|
39
|
+
paddingBottom
|
|
40
|
+
} = _ref3;
|
|
41
|
+
return `${paddingBottom}px`;
|
|
42
|
+
}, _ref4 => {
|
|
43
|
+
let {
|
|
44
|
+
paddingTop
|
|
45
|
+
} = _ref4;
|
|
46
|
+
return `${paddingTop}px`;
|
|
47
|
+
}, _ref5 => {
|
|
48
|
+
let {
|
|
49
|
+
width
|
|
50
|
+
} = _ref5;
|
|
51
|
+
return `${width}px`;
|
|
52
|
+
}, _ref6 => {
|
|
53
|
+
let {
|
|
54
|
+
backgroundGradient
|
|
55
|
+
} = _ref6;
|
|
56
|
+
return backgroundGradient && (0, _utils.transformGradient)(backgroundGradient);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const QuoteContainer = /*#__PURE__*/_styledComponents.default.div.withConfig({
|
|
60
|
+
displayName: "BlockQuote__QuoteContainer",
|
|
61
|
+
componentId: "components-web__sc-vals3u-1"
|
|
62
|
+
})(["margin-bottom:", ";"], _ref7 => {
|
|
63
|
+
let {
|
|
64
|
+
marginBottom
|
|
65
|
+
} = _ref7;
|
|
66
|
+
return `${marginBottom}px`;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const BlockQuote = _ref8 => {
|
|
70
|
+
let {
|
|
71
|
+
children,
|
|
72
|
+
link,
|
|
73
|
+
additionalInfo,
|
|
74
|
+
linkHref,
|
|
75
|
+
textStyle = 'large',
|
|
76
|
+
LinkRouter,
|
|
77
|
+
linkRouterProps,
|
|
78
|
+
tokens,
|
|
79
|
+
variant,
|
|
80
|
+
...rest
|
|
81
|
+
} = _ref8;
|
|
82
|
+
const {
|
|
83
|
+
color,
|
|
84
|
+
paddingTop,
|
|
85
|
+
paddingBottom,
|
|
86
|
+
paddingLeft,
|
|
87
|
+
paddingRight,
|
|
88
|
+
marginBottom,
|
|
89
|
+
width,
|
|
90
|
+
backgroundGradient
|
|
91
|
+
} = (0, _componentsBase.useThemeTokens)('BlockQuote', tokens, variant);
|
|
92
|
+
const mappedTextSize = textStyle === 'heading' ? 'h3' : textStyle;
|
|
93
|
+
|
|
94
|
+
const renderLink = () => {
|
|
95
|
+
if (linkHref) {
|
|
96
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Link, {
|
|
97
|
+
href: linkHref,
|
|
98
|
+
tokens: {
|
|
99
|
+
blockFontWeight: '500',
|
|
100
|
+
color
|
|
101
|
+
},
|
|
102
|
+
variant: {
|
|
103
|
+
alternative: true
|
|
104
|
+
},
|
|
105
|
+
LinkRouter: LinkRouter,
|
|
106
|
+
linkRouterProps: linkRouterProps,
|
|
107
|
+
children: link
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Typography, {
|
|
112
|
+
tokens: {
|
|
113
|
+
color,
|
|
114
|
+
fontWeight: '500'
|
|
115
|
+
},
|
|
116
|
+
children: link
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const renderQuote = () => {
|
|
121
|
+
const quote = /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Typography, {
|
|
122
|
+
tokens: {
|
|
123
|
+
color,
|
|
124
|
+
fontWeight: '400'
|
|
125
|
+
},
|
|
126
|
+
variant: {
|
|
127
|
+
size: mappedTextSize
|
|
128
|
+
},
|
|
129
|
+
children: children
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (additionalInfo || link) {
|
|
133
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(QuoteContainer, {
|
|
134
|
+
marginBottom: marginBottom,
|
|
135
|
+
children: quote
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return quote;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(BlockQuoteContainer, { ...selectProps(rest),
|
|
143
|
+
paddingTop: paddingTop,
|
|
144
|
+
paddingBottom: paddingBottom,
|
|
145
|
+
paddingLeft: paddingLeft,
|
|
146
|
+
paddingRight: paddingRight,
|
|
147
|
+
width: width,
|
|
148
|
+
backgroundGradient: backgroundGradient,
|
|
149
|
+
children: [renderQuote(), (additionalInfo || link) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_componentsBase.StackView, {
|
|
150
|
+
space: 0,
|
|
151
|
+
children: [link && renderLink(), additionalInfo && /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Typography, {
|
|
152
|
+
tokens: {
|
|
153
|
+
color
|
|
154
|
+
},
|
|
155
|
+
variant: {
|
|
156
|
+
size: 'small'
|
|
157
|
+
},
|
|
158
|
+
children: additionalInfo
|
|
159
|
+
})]
|
|
160
|
+
})]
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
BlockQuote.propTypes = { ...selectedSystemPropTypes,
|
|
165
|
+
..._componentsBase.withLinkRouter.propTypes,
|
|
166
|
+
children: _propTypes.default.node.isRequired,
|
|
167
|
+
link: _propTypes.default.string,
|
|
168
|
+
linkHref: _propTypes.default.string,
|
|
169
|
+
additionalInfo: _propTypes.default.string,
|
|
170
|
+
textStyle: _propTypes.default.oneOf(['large', 'heading'])
|
|
171
|
+
};
|
|
172
|
+
var _default = BlockQuote;
|
|
173
|
+
exports.default = _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _BlockQuote = _interopRequireDefault(require("./BlockQuote"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var _default = _BlockQuote.default;
|
|
13
|
+
exports.default = _default;
|
|
@@ -0,0 +1,70 @@
|
|
|
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 _componentsBase = require("@telus-uds/components-base");
|
|
13
|
+
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
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); }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
const IconButton = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
23
|
+
let {
|
|
24
|
+
icon,
|
|
25
|
+
action,
|
|
26
|
+
tokens,
|
|
27
|
+
variant = {},
|
|
28
|
+
...iconButtonProps
|
|
29
|
+
} = _ref;
|
|
30
|
+
const variantWithAction = action && !variant.action ? { ...variant,
|
|
31
|
+
action
|
|
32
|
+
} : variant;
|
|
33
|
+
const {
|
|
34
|
+
icon: themeIcon
|
|
35
|
+
} = (0, _componentsBase.useThemeTokens)('IconButton', tokens, variantWithAction);
|
|
36
|
+
return (
|
|
37
|
+
/*#__PURE__*/
|
|
38
|
+
// If we want the arrow icons to have directional animation instead of scale, we can pass
|
|
39
|
+
// either appropriate iconTransateX/Y here, or define and pass variants like { direction: 'left' }
|
|
40
|
+
// which have theme rules that set `iconTranslateX` tokens in the theme rules and unset `iconScale`.
|
|
41
|
+
(0, _jsxRuntime.jsx)(_componentsBase.IconButton, {
|
|
42
|
+
ref: ref,
|
|
43
|
+
...iconButtonProps,
|
|
44
|
+
tokens: tokens,
|
|
45
|
+
variant: variant,
|
|
46
|
+
icon: icon ?? themeIcon
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
const multiBrandIconNames = ['add', 'subtract', 'close', 'play', 'moveUp', 'moveDown', 'moveLeft', 'moveRight', 'expand'];
|
|
51
|
+
IconButton.displayName = 'IconButton';
|
|
52
|
+
|
|
53
|
+
const propsWithoutIcon = _ref2 => {
|
|
54
|
+
let {
|
|
55
|
+
icon,
|
|
56
|
+
...props
|
|
57
|
+
} = _ref2;
|
|
58
|
+
return props;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
IconButton.propTypes = { ...propsWithoutIcon(_componentsBase.IconButton.propTypes),
|
|
62
|
+
// eslint-disable-next-line react/require-default-props
|
|
63
|
+
action: _propTypes.default.oneOf(multiBrandIconNames),
|
|
64
|
+
icon: _propTypes.default.func
|
|
65
|
+
};
|
|
66
|
+
IconButton.defaultProps = {
|
|
67
|
+
icon: null
|
|
68
|
+
};
|
|
69
|
+
var _default = IconButton;
|
|
70
|
+
exports.default = _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _IconButton = _interopRequireDefault(require("./IconButton"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var _default = _IconButton.default;
|
|
13
|
+
exports.default = _default;
|
|
@@ -0,0 +1,94 @@
|
|
|
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 _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
14
|
+
var _componentsBase = require("@telus-uds/components-base");
|
|
15
|
+
|
|
16
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
const StyledControlWrapper = /*#__PURE__*/_styledComponents.default.div.withConfig({
|
|
21
|
+
displayName: "GroupControl__StyledControlWrapper",
|
|
22
|
+
componentId: "components-web__sc-1r7ts3q-0"
|
|
23
|
+
})(_ref => {
|
|
24
|
+
let {
|
|
25
|
+
focus,
|
|
26
|
+
tokens
|
|
27
|
+
} = _ref;
|
|
28
|
+
return {
|
|
29
|
+
fontFamily: `${tokens.groupFontName}${tokens.groupFontWeight}normal`,
|
|
30
|
+
fontSize: tokens.groupFontSize,
|
|
31
|
+
color: tokens.groupColor,
|
|
32
|
+
textDecoration: tokens.itemTextDecoration,
|
|
33
|
+
backgroundColor: tokens.groupBackgroundColor,
|
|
34
|
+
outline: tokens.itemOutline,
|
|
35
|
+
width: '100%',
|
|
36
|
+
display: 'flex',
|
|
37
|
+
justifyContent: 'space-between',
|
|
38
|
+
...(focus ? {
|
|
39
|
+
border: `${tokens.groupBorderWidth} solid ${tokens.groupBorderColor}`,
|
|
40
|
+
borderRadius: tokens.groupBorderRadius,
|
|
41
|
+
paddingLeft: `calc(${tokens.groupPaddingLeft}px - ${tokens.groupBorderWidth}px)`,
|
|
42
|
+
paddingRight: `calc(${tokens.groupPaddingRight}px - ${tokens.groupBorderWidth}px)`,
|
|
43
|
+
paddingTop: `calc(${tokens.groupPaddingTop}px - ${tokens.groupBorderWidth}px)`,
|
|
44
|
+
paddingBottom: `calc(${tokens.groupPaddingBottom}px - ${tokens.groupBorderWidth}px)`
|
|
45
|
+
} : {
|
|
46
|
+
paddingLeft: tokens.groupPaddingLeft,
|
|
47
|
+
paddingRight: tokens.groupPaddingRight,
|
|
48
|
+
paddingTop: tokens.groupPaddingTop,
|
|
49
|
+
paddingBottom: tokens.groupPaddingBottom
|
|
50
|
+
})
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const GroupControl = _ref2 => {
|
|
55
|
+
let {
|
|
56
|
+
expanded,
|
|
57
|
+
pressed,
|
|
58
|
+
hover,
|
|
59
|
+
focus,
|
|
60
|
+
current,
|
|
61
|
+
label
|
|
62
|
+
} = _ref2;
|
|
63
|
+
const tokens = (0, _componentsBase.useThemeTokens)('ListBox', {}, {}, {
|
|
64
|
+
expanded,
|
|
65
|
+
pressed,
|
|
66
|
+
hover,
|
|
67
|
+
current,
|
|
68
|
+
focus
|
|
69
|
+
});
|
|
70
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(StyledControlWrapper, {
|
|
71
|
+
focus,
|
|
72
|
+
tokens,
|
|
73
|
+
children: [label, /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Spacer, {
|
|
74
|
+
space: 1,
|
|
75
|
+
direction: "row"
|
|
76
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.Icon, {
|
|
77
|
+
icon: tokens.groupIcon,
|
|
78
|
+
variant: {
|
|
79
|
+
size: 'micro'
|
|
80
|
+
}
|
|
81
|
+
})]
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
GroupControl.propTypes = {
|
|
86
|
+
expanded: _propTypes.default.bool,
|
|
87
|
+
pressed: _propTypes.default.bool,
|
|
88
|
+
hover: _propTypes.default.bool,
|
|
89
|
+
focus: _propTypes.default.bool,
|
|
90
|
+
current: _propTypes.default.bool,
|
|
91
|
+
label: _propTypes.default.string
|
|
92
|
+
};
|
|
93
|
+
var _default = GroupControl;
|
|
94
|
+
exports.default = _default;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
13
|
+
|
|
14
|
+
var _componentsBase = require("@telus-uds/components-base");
|
|
15
|
+
|
|
16
|
+
var _ListboxGroup = _interopRequireDefault(require("./ListboxGroup"));
|
|
17
|
+
|
|
18
|
+
var _ListboxItem = _interopRequireDefault(require("./ListboxItem"));
|
|
19
|
+
|
|
20
|
+
var _ListboxOverlay = _interopRequireDefault(require("./ListboxOverlay"));
|
|
21
|
+
|
|
22
|
+
var _resolveItemSelection = _interopRequireDefault(require("../NavigationBar/resolveItemSelection"));
|
|
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
|
+
const StyledList = /*#__PURE__*/_styledComponents.default.ul.withConfig({
|
|
33
|
+
displayName: "Listbox__StyledList",
|
|
34
|
+
componentId: "components-web__sc-1564thh-0"
|
|
35
|
+
})({
|
|
36
|
+
margin: 0,
|
|
37
|
+
padding: 0,
|
|
38
|
+
listStyle: 'none'
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const getInitialOpen = (items, selectedId) => items.filter(item => item.items && item.items.some(nestedItem => (nestedItem.id ?? nestedItem.label) === selectedId)).map(item => item.id ?? item.label);
|
|
42
|
+
|
|
43
|
+
const Listbox = _ref => {
|
|
44
|
+
let {
|
|
45
|
+
items = [],
|
|
46
|
+
firstItemRef = null,
|
|
47
|
+
// focus will be moved to this one once within the menu
|
|
48
|
+
parentRef = null,
|
|
49
|
+
// to return focus to after leaving the last menu item
|
|
50
|
+
selectedId,
|
|
51
|
+
LinkRouter,
|
|
52
|
+
itemRouterProps,
|
|
53
|
+
onClose
|
|
54
|
+
} = _ref;
|
|
55
|
+
const initialOpen = getInitialOpen(items, selectedId); // We need to keep track of each item's ref in order to be able to
|
|
56
|
+
// focus on a specific item via keyboard navigation
|
|
57
|
+
|
|
58
|
+
const itemRefs = (0, _react.useRef)([]);
|
|
59
|
+
if (firstItemRef !== null && firstItemRef !== void 0 && firstItemRef.current) itemRefs.current[0] = firstItemRef.current;
|
|
60
|
+
const [focusedIndex, setFocusedIndex] = (0, _react.useState)(0);
|
|
61
|
+
const handleKeydown = (0, _react.useCallback)(event => {
|
|
62
|
+
const nextItemRef = itemRefs.current[focusedIndex + 1];
|
|
63
|
+
const prevItemRef = itemRefs.current[focusedIndex - 1];
|
|
64
|
+
|
|
65
|
+
if (event.key === 'ArrowUp' || event.shiftKey && event.key === 'Tab') {
|
|
66
|
+
var _parentRef$current;
|
|
67
|
+
|
|
68
|
+
// Move the focus to the previous item or to the parent one if on the first
|
|
69
|
+
if (prevItemRef) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
prevItemRef.focus();
|
|
72
|
+
} else if (parentRef) (_parentRef$current = parentRef.current) === null || _parentRef$current === void 0 ? void 0 : _parentRef$current.focus();
|
|
73
|
+
|
|
74
|
+
setFocusedIndex(focusedIndex - 1);
|
|
75
|
+
} else if ((event.key === 'ArrowDown' || event.key === 'Tab') && nextItemRef) {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
setFocusedIndex(focusedIndex + 1);
|
|
78
|
+
nextItemRef.focus();
|
|
79
|
+
} else if (event.key === 'Escape') {
|
|
80
|
+
var _parentRef$current2, _parentRef$current3;
|
|
81
|
+
|
|
82
|
+
// Close the dropdown
|
|
83
|
+
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
|
|
84
|
+
|
|
85
|
+
parentRef === null || parentRef === void 0 ? void 0 : (_parentRef$current3 = parentRef.current) === null || _parentRef$current3 === void 0 ? void 0 : _parentRef$current3.focus();
|
|
86
|
+
if (onClose) onClose(event);
|
|
87
|
+
}
|
|
88
|
+
}, [focusedIndex, onClose, parentRef]); // Add listeners for mouse clicks outside and for key presses
|
|
89
|
+
|
|
90
|
+
(0, _react.useEffect)(() => {
|
|
91
|
+
window.addEventListener('click', onClose);
|
|
92
|
+
window.addEventListener('keydown', handleKeydown);
|
|
93
|
+
window.addEventListener('touchstart', onClose);
|
|
94
|
+
return () => {
|
|
95
|
+
window.removeEventListener('click', onClose);
|
|
96
|
+
window.removeEventListener('keydown', handleKeydown);
|
|
97
|
+
window.removeEventListener('touchstart', onClose);
|
|
98
|
+
};
|
|
99
|
+
}, [onClose, handleKeydown]);
|
|
100
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_componentsBase.ExpandCollapse, {
|
|
101
|
+
initialOpen: initialOpen,
|
|
102
|
+
maxOpen: 1,
|
|
103
|
+
children: expandProps => /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledList, {
|
|
104
|
+
role: "listbox",
|
|
105
|
+
children: items.map((item, index) => {
|
|
106
|
+
const {
|
|
107
|
+
id,
|
|
108
|
+
label,
|
|
109
|
+
items: nestedItems
|
|
110
|
+
} = item;
|
|
111
|
+
const {
|
|
112
|
+
itemId,
|
|
113
|
+
selected
|
|
114
|
+
} = (0, _resolveItemSelection.default)({
|
|
115
|
+
id,
|
|
116
|
+
label,
|
|
117
|
+
items: nestedItems
|
|
118
|
+
}, selectedId); // Give `firstItemRef` to the first focusable item
|
|
119
|
+
|
|
120
|
+
const itemRef = index === 0 && !itemId !== selectedId || index === 1 && items[0].id === selectedId ? firstItemRef : ref => {
|
|
121
|
+
itemRefs.current[index] = ref;
|
|
122
|
+
return ref;
|
|
123
|
+
};
|
|
124
|
+
return nestedItems ? /*#__PURE__*/(0, _react.createElement)(_ListboxGroup.default, { ...item,
|
|
125
|
+
selectedId: selectedId,
|
|
126
|
+
key: itemId,
|
|
127
|
+
expandProps: expandProps,
|
|
128
|
+
LinkRouter: LinkRouter,
|
|
129
|
+
itemRouterProps: itemRouterProps,
|
|
130
|
+
prevItemRef: itemRefs.current[index - 1] ?? null,
|
|
131
|
+
nextItemRef: itemRefs.current[index + 1] ?? null,
|
|
132
|
+
ref: itemRef
|
|
133
|
+
}) : /*#__PURE__*/(0, _react.createElement)(_ListboxItem.default, { ...item,
|
|
134
|
+
selected: selected,
|
|
135
|
+
key: itemId,
|
|
136
|
+
LinkRouter: LinkRouter,
|
|
137
|
+
itemRouterProps: itemRouterProps,
|
|
138
|
+
prevItemRef: itemRefs.current[index - 1] ?? null,
|
|
139
|
+
nextItemRef: itemRefs.current[index + 1] ?? null,
|
|
140
|
+
ref: itemRef
|
|
141
|
+
});
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
Listbox.propTypes = { ..._componentsBase.withLinkRouter.propTypes,
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Focus will be moved to the item with this ref once within the menu.
|
|
151
|
+
*/
|
|
152
|
+
firstItemRef: _propTypes.default.object,
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Focus will be returned to the dropdown control with this ref after leaving
|
|
156
|
+
* the last menu item.
|
|
157
|
+
*/
|
|
158
|
+
parentRef: _propTypes.default.object,
|
|
159
|
+
items: _propTypes.default.array,
|
|
160
|
+
selectedId: _propTypes.default.string
|
|
161
|
+
};
|
|
162
|
+
Listbox.Overlay = _ListboxOverlay.default;
|
|
163
|
+
var _default = Listbox;
|
|
164
|
+
exports.default = _default;
|