@telus-uds/components-web 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/.eslintignore +2 -0
  2. package/.vscode/settings.json +7 -0
  3. package/CHANGELOG.md +39 -2
  4. package/lib/Autocomplete/Autocomplete.js +393 -0
  5. package/lib/Autocomplete/Loading.js +51 -0
  6. package/lib/Autocomplete/Suggestions.js +81 -0
  7. package/lib/Autocomplete/constants.js +19 -0
  8. package/lib/Autocomplete/dictionary.js +19 -0
  9. package/lib/Autocomplete/index.js +13 -0
  10. package/lib/BlockQuote/BlockQuote.js +173 -0
  11. package/lib/BlockQuote/index.js +13 -0
  12. package/lib/Callout/Callout.js +3 -0
  13. package/lib/Card/Card.js +180 -0
  14. package/lib/Card/CardContent.js +110 -0
  15. package/lib/Card/CardFooter.js +98 -0
  16. package/lib/Card/index.js +13 -0
  17. package/lib/Countdown/Countdown.js +189 -0
  18. package/lib/Countdown/Segment.js +111 -0
  19. package/lib/Countdown/constants.js +14 -0
  20. package/lib/Countdown/dictionary.js +29 -0
  21. package/lib/Countdown/index.js +13 -0
  22. package/lib/Countdown/types.js +39 -0
  23. package/lib/Countdown/useCountdown.js +40 -0
  24. package/lib/IconButton/IconButton.js +70 -0
  25. package/lib/IconButton/index.js +13 -0
  26. package/lib/Listbox/GroupControl.js +94 -0
  27. package/lib/Listbox/Listbox.js +164 -0
  28. package/lib/Listbox/ListboxGroup.js +129 -0
  29. package/lib/Listbox/ListboxItem.js +137 -0
  30. package/lib/Listbox/ListboxOverlay.js +89 -0
  31. package/lib/Listbox/PressableItem.js +149 -0
  32. package/lib/Listbox/index.js +13 -0
  33. package/lib/Modal/ModalContent.js +11 -4
  34. package/lib/NavigationBar/resolveItemSelection.js +24 -0
  35. package/lib/OptimizeImage/OptimizeImage.js +127 -0
  36. package/lib/OptimizeImage/index.js +13 -0
  37. package/lib/OptimizeImage/utils/getFallbackUrl.js +18 -0
  38. package/lib/OptimizeImage/utils/getOptimizedUrl.js +32 -0
  39. package/lib/OptimizeImage/utils/hasWebpSupport.js +38 -0
  40. package/lib/OptimizeImage/utils/index.js +31 -0
  41. package/lib/OptimizeImage/utils/isSvgUrl.js +10 -0
  42. package/lib/QuantitySelector/QuantitySelector.js +253 -0
  43. package/lib/QuantitySelector/dictionary.js +33 -0
  44. package/lib/QuantitySelector/index.js +13 -0
  45. package/lib/QuantitySelector/styles.js +40 -0
  46. package/lib/StoryCard/StoryCard.js +244 -0
  47. package/lib/StoryCard/index.js +13 -0
  48. package/lib/TermsAndConditions/ExpandCollapse.js +141 -0
  49. package/lib/TermsAndConditions/TermsAndConditions.js +221 -0
  50. package/lib/TermsAndConditions/dictionary.js +19 -0
  51. package/lib/TermsAndConditions/index.js +15 -0
  52. package/lib/Testimonial/Testimonial.js +226 -0
  53. package/lib/Testimonial/index.js +13 -0
  54. package/lib/Video/ControlBar/ControlBar.js +315 -0
  55. package/lib/Video/ControlBar/Controls/VideoButton/VideoButton.js +91 -0
  56. package/lib/Video/ControlBar/Controls/VideoMenu/VideoMenu.js +186 -0
  57. package/lib/Video/ControlBar/Controls/VideoProgressBar/VideoProgressBar.js +221 -0
  58. package/lib/Video/ControlBar/Controls/VolumeSlider/VolumeSlider.js +213 -0
  59. package/lib/Video/MiddleControlButton/MiddleControlButton.js +89 -0
  60. package/lib/Video/Video.js +1072 -0
  61. package/lib/Video/index.js +13 -0
  62. package/lib/Video/videoText.js +62 -0
  63. package/lib/WebVideo/WebVideo.js +170 -0
  64. package/lib/WebVideo/index.js +13 -0
  65. package/lib/baseExports.js +0 -12
  66. package/lib/index.js +118 -1
  67. package/lib/shared/VideoSplash/SplashButton/SplashButton.js +102 -0
  68. package/lib/shared/VideoSplash/SplashButtonWithDetails/SplashButtonWithDetails.js +234 -0
  69. package/lib/shared/VideoSplash/VideoSplash.js +86 -0
  70. package/lib/shared/VideoSplash/helpers.js +38 -0
  71. package/lib/utils/index.js +8 -0
  72. package/lib/utils/useOverlaidPosition.js +246 -0
  73. package/lib-module/Autocomplete/Autocomplete.js +369 -0
  74. package/lib-module/Autocomplete/Loading.js +38 -0
  75. package/lib-module/Autocomplete/Suggestions.js +64 -0
  76. package/lib-module/Autocomplete/constants.js +5 -0
  77. package/lib-module/Autocomplete/dictionary.js +12 -0
  78. package/lib-module/Autocomplete/index.js +2 -0
  79. package/lib-module/BlockQuote/BlockQuote.js +156 -0
  80. package/lib-module/BlockQuote/index.js +2 -0
  81. package/lib-module/Callout/Callout.js +3 -0
  82. package/lib-module/Card/Card.js +158 -0
  83. package/lib-module/Card/CardContent.js +92 -0
  84. package/lib-module/Card/CardFooter.js +80 -0
  85. package/lib-module/Card/index.js +2 -0
  86. package/lib-module/Countdown/Countdown.js +165 -0
  87. package/lib-module/Countdown/Segment.js +94 -0
  88. package/lib-module/Countdown/constants.js +4 -0
  89. package/lib-module/Countdown/dictionary.js +22 -0
  90. package/lib-module/Countdown/index.js +2 -0
  91. package/lib-module/Countdown/types.js +23 -0
  92. package/lib-module/Countdown/useCountdown.js +32 -0
  93. package/lib-module/IconButton/IconButton.js +52 -0
  94. package/lib-module/IconButton/index.js +2 -0
  95. package/lib-module/Listbox/GroupControl.js +80 -0
  96. package/lib-module/Listbox/Listbox.js +142 -0
  97. package/lib-module/Listbox/ListboxGroup.js +106 -0
  98. package/lib-module/Listbox/ListboxItem.js +112 -0
  99. package/lib-module/Listbox/ListboxOverlay.js +68 -0
  100. package/lib-module/Listbox/PressableItem.js +128 -0
  101. package/lib-module/Listbox/index.js +2 -0
  102. package/lib-module/Modal/ModalContent.js +10 -4
  103. package/lib-module/NavigationBar/resolveItemSelection.js +16 -0
  104. package/lib-module/OptimizeImage/OptimizeImage.js +106 -0
  105. package/lib-module/OptimizeImage/index.js +2 -0
  106. package/lib-module/OptimizeImage/utils/getFallbackUrl.js +8 -0
  107. package/lib-module/OptimizeImage/utils/getOptimizedUrl.js +22 -0
  108. package/lib-module/OptimizeImage/utils/hasWebpSupport.js +32 -0
  109. package/lib-module/OptimizeImage/utils/index.js +4 -0
  110. package/lib-module/OptimizeImage/utils/isSvgUrl.js +3 -0
  111. package/lib-module/QuantitySelector/QuantitySelector.js +232 -0
  112. package/lib-module/QuantitySelector/dictionary.js +26 -0
  113. package/lib-module/QuantitySelector/index.js +2 -0
  114. package/lib-module/QuantitySelector/styles.js +21 -0
  115. package/lib-module/StoryCard/StoryCard.js +220 -0
  116. package/lib-module/StoryCard/index.js +2 -0
  117. package/lib-module/TermsAndConditions/ExpandCollapse.js +120 -0
  118. package/lib-module/TermsAndConditions/TermsAndConditions.js +193 -0
  119. package/lib-module/TermsAndConditions/dictionary.js +12 -0
  120. package/lib-module/TermsAndConditions/index.js +1 -0
  121. package/lib-module/Testimonial/Testimonial.js +204 -0
  122. package/lib-module/Testimonial/index.js +2 -0
  123. package/lib-module/Video/ControlBar/ControlBar.js +292 -0
  124. package/lib-module/Video/ControlBar/Controls/VideoButton/VideoButton.js +74 -0
  125. package/lib-module/Video/ControlBar/Controls/VideoMenu/VideoMenu.js +167 -0
  126. package/lib-module/Video/ControlBar/Controls/VideoProgressBar/VideoProgressBar.js +201 -0
  127. package/lib-module/Video/ControlBar/Controls/VolumeSlider/VolumeSlider.js +193 -0
  128. package/lib-module/Video/MiddleControlButton/MiddleControlButton.js +72 -0
  129. package/lib-module/Video/Video.js +1042 -0
  130. package/lib-module/Video/index.js +2 -0
  131. package/lib-module/Video/videoText.js +55 -0
  132. package/lib-module/WebVideo/WebVideo.js +144 -0
  133. package/lib-module/WebVideo/index.js +2 -0
  134. package/lib-module/baseExports.js +1 -1
  135. package/lib-module/index.js +13 -0
  136. package/lib-module/shared/VideoSplash/SplashButton/SplashButton.js +85 -0
  137. package/lib-module/shared/VideoSplash/SplashButtonWithDetails/SplashButtonWithDetails.js +216 -0
  138. package/lib-module/shared/VideoSplash/VideoSplash.js +65 -0
  139. package/lib-module/shared/VideoSplash/helpers.js +23 -0
  140. package/lib-module/utils/index.js +2 -1
  141. package/lib-module/utils/useOverlaidPosition.js +235 -0
  142. package/package.json +7 -5
  143. package/src/Autocomplete/Autocomplete.jsx +354 -0
  144. package/src/Autocomplete/Loading.jsx +18 -0
  145. package/src/Autocomplete/Suggestions.jsx +52 -0
  146. package/src/Autocomplete/constants.js +6 -0
  147. package/src/Autocomplete/dictionary.js +12 -0
  148. package/src/Autocomplete/index.js +3 -0
  149. package/src/BlockQuote/BlockQuote.jsx +130 -0
  150. package/src/BlockQuote/index.js +3 -0
  151. package/src/Callout/Callout.jsx +1 -1
  152. package/src/Card/Card.jsx +170 -0
  153. package/src/Card/CardContent.jsx +88 -0
  154. package/src/Card/CardFooter.jsx +70 -0
  155. package/src/Card/index.js +3 -0
  156. package/src/Countdown/Countdown.jsx +144 -0
  157. package/src/Countdown/Segment.jsx +69 -0
  158. package/src/Countdown/constants.js +4 -0
  159. package/src/Countdown/dictionary.js +22 -0
  160. package/src/Countdown/index.js +3 -0
  161. package/src/Countdown/types.js +23 -0
  162. package/src/Countdown/useCountdown.js +34 -0
  163. package/src/IconButton/IconButton.jsx +46 -0
  164. package/src/IconButton/index.js +3 -0
  165. package/src/Listbox/GroupControl.jsx +65 -0
  166. package/src/Listbox/Listbox.jsx +148 -0
  167. package/src/Listbox/ListboxGroup.jsx +110 -0
  168. package/src/Listbox/ListboxItem.jsx +101 -0
  169. package/src/Listbox/ListboxOverlay.jsx +71 -0
  170. package/src/Listbox/PressableItem.jsx +121 -0
  171. package/src/Listbox/index.js +3 -0
  172. package/src/Modal/ModalContent.jsx +8 -4
  173. package/src/NavigationBar/resolveItemSelection.js +11 -0
  174. package/src/OptimizeImage/OptimizeImage.jsx +131 -0
  175. package/src/OptimizeImage/index.js +3 -0
  176. package/src/OptimizeImage/utils/getFallbackUrl.js +9 -0
  177. package/src/OptimizeImage/utils/getOptimizedUrl.js +30 -0
  178. package/src/OptimizeImage/utils/hasWebpSupport.js +33 -0
  179. package/src/OptimizeImage/utils/index.js +5 -0
  180. package/src/OptimizeImage/utils/isSvgUrl.js +3 -0
  181. package/src/QuantitySelector/QuantitySelector.jsx +245 -0
  182. package/src/QuantitySelector/dictionary.js +27 -0
  183. package/src/QuantitySelector/index.js +3 -0
  184. package/src/QuantitySelector/styles.js +83 -0
  185. package/src/StoryCard/StoryCard.jsx +198 -0
  186. package/src/StoryCard/index.js +3 -0
  187. package/src/TermsAndConditions/ExpandCollapse.jsx +106 -0
  188. package/src/TermsAndConditions/TermsAndConditions.jsx +161 -0
  189. package/src/TermsAndConditions/dictionary.js +12 -0
  190. package/src/TermsAndConditions/index.js +1 -0
  191. package/src/Testimonial/Testimonial.jsx +169 -0
  192. package/src/Testimonial/index.js +3 -0
  193. package/src/Video/ControlBar/ControlBar.jsx +261 -0
  194. package/src/Video/ControlBar/Controls/VideoButton/VideoButton.jsx +61 -0
  195. package/src/Video/ControlBar/Controls/VideoMenu/VideoMenu.jsx +159 -0
  196. package/src/Video/ControlBar/Controls/VideoProgressBar/VideoProgressBar.jsx +185 -0
  197. package/src/Video/ControlBar/Controls/VolumeSlider/VolumeSlider.jsx +184 -0
  198. package/src/Video/MiddleControlButton/MiddleControlButton.jsx +64 -0
  199. package/src/Video/Video.jsx +988 -0
  200. package/src/Video/index.js +3 -0
  201. package/src/Video/videoText.js +58 -0
  202. package/src/WebVideo/WebVideo.jsx +131 -0
  203. package/src/WebVideo/index.js +3 -0
  204. package/src/baseExports.js +0 -2
  205. package/src/index.js +13 -0
  206. package/src/shared/VideoSplash/SplashButton/SplashButton.jsx +64 -0
  207. package/src/shared/VideoSplash/SplashButtonWithDetails/SplashButtonWithDetails.jsx +128 -0
  208. package/src/shared/VideoSplash/VideoSplash.jsx +50 -0
  209. package/src/shared/VideoSplash/helpers.js +27 -0
  210. package/src/utils/index.js +10 -1
  211. package/src/utils/useOverlaidPosition.js +226 -0
  212. package/types/Autocomplete.d.ts +32 -0
  213. package/types/Card.d.ts +45 -0
  214. package/types/ControlBar.d.ts +59 -0
  215. package/types/MiddleControlButton.d.ts +15 -0
  216. package/types/Video.d.ts +39 -0
  217. package/types/VideoButton.d.ts +14 -0
  218. package/types/VideoMenu.d.ts +16 -0
  219. package/types/VideoProgressBar.d.ts +17 -0
  220. package/types/VolumeSlider.d.ts +20 -0
@@ -0,0 +1,52 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { IconButton as IconButtonBase, useThemeTokens } from '@telus-uds/components-base';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const IconButton = /*#__PURE__*/forwardRef((_ref, ref) => {
6
+ let {
7
+ icon,
8
+ action,
9
+ tokens,
10
+ variant = {},
11
+ ...iconButtonProps
12
+ } = _ref;
13
+ const variantWithAction = action && !variant.action ? { ...variant,
14
+ action
15
+ } : variant;
16
+ const {
17
+ icon: themeIcon
18
+ } = useThemeTokens('IconButton', tokens, variantWithAction);
19
+ return (
20
+ /*#__PURE__*/
21
+ // If we want the arrow icons to have directional animation instead of scale, we can pass
22
+ // either appropriate iconTransateX/Y here, or define and pass variants like { direction: 'left' }
23
+ // which have theme rules that set `iconTranslateX` tokens in the theme rules and unset `iconScale`.
24
+ _jsx(IconButtonBase, {
25
+ ref: ref,
26
+ ...iconButtonProps,
27
+ tokens: tokens,
28
+ variant: variant,
29
+ icon: icon ?? themeIcon
30
+ })
31
+ );
32
+ });
33
+ const multiBrandIconNames = ['add', 'subtract', 'close', 'play', 'moveUp', 'moveDown', 'moveLeft', 'moveRight', 'expand'];
34
+ IconButton.displayName = 'IconButton';
35
+
36
+ const propsWithoutIcon = _ref2 => {
37
+ let {
38
+ icon,
39
+ ...props
40
+ } = _ref2;
41
+ return props;
42
+ };
43
+
44
+ IconButton.propTypes = { ...propsWithoutIcon(IconButtonBase.propTypes),
45
+ // eslint-disable-next-line react/require-default-props
46
+ action: PropTypes.oneOf(multiBrandIconNames),
47
+ icon: PropTypes.func
48
+ };
49
+ IconButton.defaultProps = {
50
+ icon: null
51
+ };
52
+ export default IconButton;
@@ -0,0 +1,2 @@
1
+ import IconButton from './IconButton';
2
+ export default IconButton;
@@ -0,0 +1,80 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+ import PropTypes from 'prop-types';
4
+ import { Icon, Spacer, useThemeTokens } from '@telus-uds/components-base';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ import { jsxs as _jsxs } from "react/jsx-runtime";
7
+ const StyledControlWrapper = /*#__PURE__*/styled.div.withConfig({
8
+ displayName: "GroupControl__StyledControlWrapper",
9
+ componentId: "components-web__sc-1r7ts3q-0"
10
+ })(_ref => {
11
+ let {
12
+ focus,
13
+ tokens
14
+ } = _ref;
15
+ return {
16
+ fontFamily: `${tokens.groupFontName}${tokens.groupFontWeight}normal`,
17
+ fontSize: tokens.groupFontSize,
18
+ color: tokens.groupColor,
19
+ textDecoration: tokens.itemTextDecoration,
20
+ backgroundColor: tokens.groupBackgroundColor,
21
+ outline: tokens.itemOutline,
22
+ width: '100%',
23
+ display: 'flex',
24
+ justifyContent: 'space-between',
25
+ ...(focus ? {
26
+ border: `${tokens.groupBorderWidth} solid ${tokens.groupBorderColor}`,
27
+ borderRadius: tokens.groupBorderRadius,
28
+ paddingLeft: `calc(${tokens.groupPaddingLeft}px - ${tokens.groupBorderWidth}px)`,
29
+ paddingRight: `calc(${tokens.groupPaddingRight}px - ${tokens.groupBorderWidth}px)`,
30
+ paddingTop: `calc(${tokens.groupPaddingTop}px - ${tokens.groupBorderWidth}px)`,
31
+ paddingBottom: `calc(${tokens.groupPaddingBottom}px - ${tokens.groupBorderWidth}px)`
32
+ } : {
33
+ paddingLeft: tokens.groupPaddingLeft,
34
+ paddingRight: tokens.groupPaddingRight,
35
+ paddingTop: tokens.groupPaddingTop,
36
+ paddingBottom: tokens.groupPaddingBottom
37
+ })
38
+ };
39
+ });
40
+
41
+ const GroupControl = _ref2 => {
42
+ let {
43
+ expanded,
44
+ pressed,
45
+ hover,
46
+ focus,
47
+ current,
48
+ label
49
+ } = _ref2;
50
+ const tokens = useThemeTokens('ListBox', {}, {}, {
51
+ expanded,
52
+ pressed,
53
+ hover,
54
+ current,
55
+ focus
56
+ });
57
+ return /*#__PURE__*/_jsxs(StyledControlWrapper, {
58
+ focus,
59
+ tokens,
60
+ children: [label, /*#__PURE__*/_jsx(Spacer, {
61
+ space: 1,
62
+ direction: "row"
63
+ }), /*#__PURE__*/_jsx(Icon, {
64
+ icon: tokens.groupIcon,
65
+ variant: {
66
+ size: 'micro'
67
+ }
68
+ })]
69
+ });
70
+ };
71
+
72
+ GroupControl.propTypes = {
73
+ expanded: PropTypes.bool,
74
+ pressed: PropTypes.bool,
75
+ hover: PropTypes.bool,
76
+ focus: PropTypes.bool,
77
+ current: PropTypes.bool,
78
+ label: PropTypes.string
79
+ };
80
+ export default GroupControl;
@@ -0,0 +1,142 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import styled from 'styled-components';
4
+ import { ExpandCollapse, withLinkRouter } from '@telus-uds/components-base';
5
+ import ListboxGroup from './ListboxGroup';
6
+ import ListboxItem from './ListboxItem';
7
+ import DropdownOverlay from './ListboxOverlay';
8
+ import resolveItemSelection from '../NavigationBar/resolveItemSelection';
9
+ import { createElement as _createElement } from "react";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ const StyledList = /*#__PURE__*/styled.ul.withConfig({
12
+ displayName: "Listbox__StyledList",
13
+ componentId: "components-web__sc-1564thh-0"
14
+ })({
15
+ margin: 0,
16
+ padding: 0,
17
+ listStyle: 'none'
18
+ });
19
+
20
+ const getInitialOpen = (items, selectedId) => items.filter(item => item.items && item.items.some(nestedItem => (nestedItem.id ?? nestedItem.label) === selectedId)).map(item => item.id ?? item.label);
21
+
22
+ const Listbox = _ref => {
23
+ let {
24
+ items = [],
25
+ firstItemRef = null,
26
+ // focus will be moved to this one once within the menu
27
+ parentRef = null,
28
+ // to return focus to after leaving the last menu item
29
+ selectedId,
30
+ LinkRouter,
31
+ itemRouterProps,
32
+ onClose
33
+ } = _ref;
34
+ const initialOpen = getInitialOpen(items, selectedId); // We need to keep track of each item's ref in order to be able to
35
+ // focus on a specific item via keyboard navigation
36
+
37
+ const itemRefs = useRef([]);
38
+ if (firstItemRef !== null && firstItemRef !== void 0 && firstItemRef.current) itemRefs.current[0] = firstItemRef.current;
39
+ const [focusedIndex, setFocusedIndex] = useState(0);
40
+ const handleKeydown = useCallback(event => {
41
+ const nextItemRef = itemRefs.current[focusedIndex + 1];
42
+ const prevItemRef = itemRefs.current[focusedIndex - 1];
43
+
44
+ if (event.key === 'ArrowUp' || event.shiftKey && event.key === 'Tab') {
45
+ var _parentRef$current;
46
+
47
+ // Move the focus to the previous item or to the parent one if on the first
48
+ if (prevItemRef) {
49
+ event.preventDefault();
50
+ prevItemRef.focus();
51
+ } else if (parentRef) (_parentRef$current = parentRef.current) === null || _parentRef$current === void 0 ? void 0 : _parentRef$current.focus();
52
+
53
+ setFocusedIndex(focusedIndex - 1);
54
+ } else if ((event.key === 'ArrowDown' || event.key === 'Tab') && nextItemRef) {
55
+ event.preventDefault();
56
+ setFocusedIndex(focusedIndex + 1);
57
+ nextItemRef.focus();
58
+ } else if (event.key === 'Escape') {
59
+ var _parentRef$current2, _parentRef$current3;
60
+
61
+ // Close the dropdown
62
+ 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
63
+
64
+ parentRef === null || parentRef === void 0 ? void 0 : (_parentRef$current3 = parentRef.current) === null || _parentRef$current3 === void 0 ? void 0 : _parentRef$current3.focus();
65
+ if (onClose) onClose(event);
66
+ }
67
+ }, [focusedIndex, onClose, parentRef]); // Add listeners for mouse clicks outside and for key presses
68
+
69
+ useEffect(() => {
70
+ window.addEventListener('click', onClose);
71
+ window.addEventListener('keydown', handleKeydown);
72
+ window.addEventListener('touchstart', onClose);
73
+ return () => {
74
+ window.removeEventListener('click', onClose);
75
+ window.removeEventListener('keydown', handleKeydown);
76
+ window.removeEventListener('touchstart', onClose);
77
+ };
78
+ }, [onClose, handleKeydown]);
79
+ return /*#__PURE__*/_jsx(ExpandCollapse, {
80
+ initialOpen: initialOpen,
81
+ maxOpen: 1,
82
+ children: expandProps => /*#__PURE__*/_jsx(StyledList, {
83
+ role: "listbox",
84
+ children: items.map((item, index) => {
85
+ const {
86
+ id,
87
+ label,
88
+ items: nestedItems
89
+ } = item;
90
+ const {
91
+ itemId,
92
+ selected
93
+ } = resolveItemSelection({
94
+ id,
95
+ label,
96
+ items: nestedItems
97
+ }, selectedId); // Give `firstItemRef` to the first focusable item
98
+
99
+ const itemRef = index === 0 && !itemId !== selectedId || index === 1 && items[0].id === selectedId ? firstItemRef : ref => {
100
+ itemRefs.current[index] = ref;
101
+ return ref;
102
+ };
103
+ return nestedItems ? /*#__PURE__*/_createElement(ListboxGroup, { ...item,
104
+ selectedId: selectedId,
105
+ key: itemId,
106
+ expandProps: expandProps,
107
+ LinkRouter: LinkRouter,
108
+ itemRouterProps: itemRouterProps,
109
+ prevItemRef: itemRefs.current[index - 1] ?? null,
110
+ nextItemRef: itemRefs.current[index + 1] ?? null,
111
+ ref: itemRef
112
+ }) : /*#__PURE__*/_createElement(ListboxItem, { ...item,
113
+ selected: selected,
114
+ key: itemId,
115
+ LinkRouter: LinkRouter,
116
+ itemRouterProps: itemRouterProps,
117
+ prevItemRef: itemRefs.current[index - 1] ?? null,
118
+ nextItemRef: itemRefs.current[index + 1] ?? null,
119
+ ref: itemRef
120
+ });
121
+ })
122
+ })
123
+ });
124
+ };
125
+
126
+ Listbox.propTypes = { ...withLinkRouter.propTypes,
127
+
128
+ /**
129
+ * Focus will be moved to the item with this ref once within the menu.
130
+ */
131
+ firstItemRef: PropTypes.object,
132
+
133
+ /**
134
+ * Focus will be returned to the dropdown control with this ref after leaving
135
+ * the last menu item.
136
+ */
137
+ parentRef: PropTypes.object,
138
+ items: PropTypes.array,
139
+ selectedId: PropTypes.string
140
+ };
141
+ Listbox.Overlay = DropdownOverlay;
142
+ export default Listbox;
@@ -0,0 +1,106 @@
1
+ /* eslint-disable react/require-default-props */
2
+ import React, { forwardRef } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import { ExpandCollapse, withLinkRouter } from '@telus-uds/components-base';
5
+ import styled from 'styled-components';
6
+ import ListboxItem from './ListboxItem';
7
+ import GroupControl from './GroupControl';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const StyledGroupWrapper = /*#__PURE__*/styled.li.withConfig({
10
+ displayName: "ListboxGroup__StyledGroupWrapper",
11
+ componentId: "components-web__sc-3jlyy7-0"
12
+ })({
13
+ margin: 'none',
14
+ padding: 'none',
15
+ display: 'block',
16
+ overflowY: 'hidden',
17
+ // Currently the default expand collapse control does not have a focus state and so the browser default is applied.
18
+ // This hides the outline so that it does not clash with the custom control we provide.
19
+ '& div[role=button]': {
20
+ outline: 'none'
21
+ }
22
+ });
23
+ const StyledList = /*#__PURE__*/styled.ul.withConfig({
24
+ displayName: "ListboxGroup__StyledList",
25
+ componentId: "components-web__sc-3jlyy7-1"
26
+ })({
27
+ margin: 0,
28
+ padding: 0,
29
+ listStyle: 'none'
30
+ });
31
+ const ListboxGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
32
+ let {
33
+ id,
34
+ label,
35
+ items,
36
+ selectedId,
37
+ LinkRouter,
38
+ linkRouterProps,
39
+ expandProps,
40
+ onLastItemBlur,
41
+ nextItemRef,
42
+ prevItemRef
43
+ } = _ref;
44
+ // TODO: implement keyboard navigation via refs for grouped items separately here
45
+ return /*#__PURE__*/_jsx(StyledGroupWrapper, {
46
+ role: "option",
47
+ children: /*#__PURE__*/_jsx(ExpandCollapse.Panel, {
48
+ panelId: id ?? label,
49
+ controlTokens: {
50
+ icon: null,
51
+ paddingLeft: 'none',
52
+ paddingRight: 'none',
53
+ paddingTop: 'none',
54
+ paddingBottom: 'none'
55
+ } // TODO refactor
56
+ // eslint-disable-next-line react/no-unstable-nested-components
57
+ ,
58
+ control: controlProps => /*#__PURE__*/_jsx(GroupControl, { ...controlProps,
59
+ label: label
60
+ }),
61
+ ...expandProps,
62
+ tokens: {
63
+ contentPaddingLeft: 'none',
64
+ contentPaddingRight: 'none',
65
+ contentPaddingTop: 'none',
66
+ contentPaddingBottom: 'none'
67
+ },
68
+ controlRef: ref,
69
+ children: /*#__PURE__*/_jsx(StyledList, {
70
+ children: items.map((item, index) => /*#__PURE__*/_jsx(ListboxItem, { ...item,
71
+ selected: item.id === selectedId,
72
+ isChild: true,
73
+ LinkRouter: LinkRouter,
74
+ linkRouterProps: linkRouterProps,
75
+ ...(index === 0 && {
76
+ prevItemRef
77
+ }),
78
+ ...(index === items.length - 1 && {
79
+ nextItemRef
80
+ }),
81
+ ...(index === items.length - 1 && {
82
+ onBlur: onLastItemBlur
83
+ })
84
+ }, item.label))
85
+ })
86
+ })
87
+ });
88
+ });
89
+ ListboxGroup.displayName = 'ListboxGroup';
90
+ ListboxGroup.propTypes = { ...withLinkRouter.propTypes,
91
+ label: PropTypes.string,
92
+ items: PropTypes.arrayOf(PropTypes.shape({
93
+ href: PropTypes.string,
94
+ label: PropTypes.string,
95
+ current: PropTypes.bool
96
+ })),
97
+ expandProps: PropTypes.object,
98
+ nextItemRef: PropTypes.object,
99
+ prevItemRef: PropTypes.object,
100
+
101
+ /**
102
+ * Use this callback to redirect the focus after it leaves the last item of the group.
103
+ */
104
+ onLastItemBlur: PropTypes.func
105
+ };
106
+ export default ListboxGroup;
@@ -0,0 +1,112 @@
1
+ /* eslint-disable react/require-default-props */
2
+ import React, { forwardRef } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import styled from 'styled-components';
5
+ import { selectSystemProps, withLinkRouter, useThemeTokens } from '@telus-uds/components-base';
6
+ import { htmlAttrs } from '../utils';
7
+ import PressableItem from './PressableItem';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs]);
10
+ const StyledItemContainer = /*#__PURE__*/styled.li.withConfig({
11
+ displayName: "ListboxItem__StyledItemContainer",
12
+ componentId: "components-web__sc-tlroet-0"
13
+ })({
14
+ display: 'flex',
15
+ paddingLeft: _ref => {
16
+ let {
17
+ isChild
18
+ } = _ref;
19
+ return isChild ? '16px' : '0px';
20
+ },
21
+ '&&&': {
22
+ // Docusaurus applies aggressively high-specificity margin on `li`
23
+ margin: 0
24
+ }
25
+ });
26
+
27
+ const getSelectedItemStyles = _ref2 => {
28
+ let {
29
+ tokens
30
+ } = _ref2;
31
+ return {
32
+ display: tokens.itemDisplay,
33
+ fontFamily: `${tokens.itemFontName}${tokens.itemFontWeight}normal`,
34
+ fontSize: tokens.itemFontSize,
35
+ paddingTop: tokens.itemPaddingTop,
36
+ paddingBottom: tokens.itemPaddingBottom,
37
+ paddingLeft: tokens.itemPaddingLeft,
38
+ paddingRight: tokens.itemPaddingRight,
39
+ color: tokens.itemColor,
40
+ textDecoration: tokens.itemTextDecoration,
41
+ backgroundColor: tokens.itemBackgroundColor,
42
+ outline: tokens.itemOutline,
43
+ borderWidth: tokens.itemBorderWidth,
44
+ width: '100%'
45
+ };
46
+ };
47
+
48
+ const SelectedItem = /*#__PURE__*/styled.div.withConfig({
49
+ displayName: "ListboxItem__SelectedItem",
50
+ componentId: "components-web__sc-tlroet-1"
51
+ })(_ref3 => {
52
+ let {
53
+ isChild,
54
+ tokens
55
+ } = _ref3;
56
+ return { ...getSelectedItemStyles({
57
+ tokens
58
+ }),
59
+ borderLeft: isChild ? `${tokens.itemBorderLeftWidth}px solid ${tokens.itemBorderLeftColor}` : 'none'
60
+ };
61
+ });
62
+ const ListboxItem = /*#__PURE__*/forwardRef((_ref4, ref) => {
63
+ let {
64
+ href,
65
+ label,
66
+ onPress,
67
+ selected = false,
68
+ isChild = false,
69
+ onBlur,
70
+ nextItemRef,
71
+ prevItemRef,
72
+ tokens,
73
+ variant = {},
74
+ ...rest
75
+ } = _ref4;
76
+ const selectedProps = selectProps(rest);
77
+ const systemTokens = useThemeTokens('ListBox', tokens, variant, {
78
+ isChild
79
+ });
80
+ return /*#__PURE__*/_jsx(StyledItemContainer, {
81
+ isChild: isChild,
82
+ ...selectedProps,
83
+ role: "option",
84
+ children: selected ? /*#__PURE__*/_jsx(SelectedItem, {
85
+ isChild: isChild,
86
+ tokens: systemTokens,
87
+ children: label
88
+ }) : /*#__PURE__*/_jsx(PressableItem, {
89
+ href: href,
90
+ isChild: isChild,
91
+ onPress: onPress,
92
+ onBlur: onBlur,
93
+ nextItemRef: nextItemRef,
94
+ prevItemRef: prevItemRef,
95
+ ref: ref,
96
+ children: label
97
+ })
98
+ });
99
+ });
100
+ ListboxItem.displayName = 'ListboxItem';
101
+ ListboxItem.propTypes = { ...selectedSystemPropTypes,
102
+ ...withLinkRouter.propTypes,
103
+ href: PropTypes.string,
104
+ isChild: PropTypes.bool,
105
+ label: PropTypes.node.isRequired,
106
+ nextItemRef: PropTypes.object,
107
+ prevItemRef: PropTypes.object,
108
+ onPress: PropTypes.func,
109
+ selected: PropTypes.bool,
110
+ reactRouterLinkComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
111
+ };
112
+ export default withLinkRouter(ListboxItem);
@@ -0,0 +1,68 @@
1
+ /* eslint-disable react/require-default-props */
2
+ import React, { forwardRef } from 'react';
3
+ import { Card, Portal, useThemeTokens } from '@telus-uds/components-base';
4
+ import PropTypes from 'prop-types';
5
+ import View from "react-native-web/dist/exports/View";
6
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const staticStyles = StyleSheet.create({
9
+ positioner: {
10
+ flex: 1,
11
+ // Grow to maxWidth when possible, shrink when not possible
12
+ position: 'absolute',
13
+ zIndex: 10000 // Position on top of all the other overlays, including backdrops and modals
14
+
15
+ },
16
+ hidden: {
17
+ // Use opacity not visibility to hide the dropdown during positioning
18
+ // so on web, children may be focused from the first render
19
+ opacity: 0
20
+ }
21
+ });
22
+ const paddingVertical = 0;
23
+ const paddingHorizontal = 0;
24
+ const DropdownOverlay = /*#__PURE__*/forwardRef((_ref, ref) => {
25
+ let {
26
+ children,
27
+ isReady = false,
28
+ overlaidPosition,
29
+ maxWidth,
30
+ minWidth,
31
+ onLayout
32
+ } = _ref;
33
+ const systemTokens = useThemeTokens('ListBox', {}, {});
34
+ return /*#__PURE__*/_jsx(Portal, {
35
+ children: /*#__PURE__*/_jsx(View, {
36
+ ref: ref,
37
+ onLayout: onLayout,
38
+ style: [overlaidPosition, {
39
+ maxWidth,
40
+ minWidth
41
+ }, staticStyles.positioner, !isReady && staticStyles.hidden],
42
+ children: /*#__PURE__*/_jsx(Card, {
43
+ tokens: {
44
+ shadow: systemTokens.shadow,
45
+ paddingBottom: paddingVertical,
46
+ paddingTop: paddingVertical,
47
+ paddingLeft: paddingHorizontal,
48
+ paddingRight: paddingHorizontal
49
+ },
50
+ children: children
51
+ })
52
+ })
53
+ });
54
+ });
55
+ DropdownOverlay.displayName = 'DropdownOverlay';
56
+ DropdownOverlay.propTypes = {
57
+ children: PropTypes.node.isRequired,
58
+ isReady: PropTypes.bool,
59
+ overlaidPosition: PropTypes.shape({
60
+ top: PropTypes.number,
61
+ left: PropTypes.number,
62
+ width: PropTypes.number
63
+ }),
64
+ maxWidth: PropTypes.number,
65
+ minWidth: PropTypes.number,
66
+ onLayout: PropTypes.func
67
+ };
68
+ export default DropdownOverlay;
@@ -0,0 +1,128 @@
1
+ /* eslint-disable react/require-default-props */
2
+ import React, { forwardRef } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import { selectSystemProps, useThemeTokens } from '@telus-uds/components-base';
5
+ import styled from 'styled-components';
6
+ import { htmlAttrs } from '../utils';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([htmlAttrs]);
9
+
10
+ const getItemStyles = _ref => {
11
+ let {
12
+ tokens
13
+ } = _ref;
14
+ return {
15
+ fontFamily: `${tokens.groupFontName}${tokens.groupFontWeight}normal`,
16
+ fontSize: tokens.itemFontSize,
17
+ paddingTop: tokens.itemPaddingTop,
18
+ paddingBottom: tokens.itemPaddingBottom,
19
+ paddingLeft: tokens.itemPaddingLeft,
20
+ paddingRight: tokens.itemPaddingRight,
21
+ borderWidth: tokens.itemBorderWidth,
22
+ width: '100%',
23
+ backgroundColor: tokens.itemBackgroundColor,
24
+ color: tokens.groupColor,
25
+ display: tokens.itemDisplay,
26
+ outline: tokens.itemOutline,
27
+ textDecoration: tokens.itemTextDecoration
28
+ };
29
+ };
30
+
31
+ const StyledLink = /*#__PURE__*/styled.a.withConfig({
32
+ displayName: "PressableItem__StyledLink",
33
+ componentId: "components-web__sc-1h6cvsc-0"
34
+ })(_ref2 => {
35
+ let {
36
+ isChild,
37
+ tokens
38
+ } = _ref2;
39
+ return { ...getItemStyles({
40
+ isChild,
41
+ tokens
42
+ }),
43
+ borderLeft: isChild ? `${tokens.itemBorderWidth}px solid ${tokens.itemBorderBackgroundColor}` : 'none',
44
+ cursor: 'pointer',
45
+ [`&:hover, &:focus, &:active`]: {
46
+ color: tokens.itemColor
47
+ },
48
+ '&:hover': {
49
+ backgroundColor: tokens.groupBackgroundColor
50
+ },
51
+ // Highlighting for pressable items that are not links per se
52
+ // TODO: find a better way to display and style a pressable link
53
+ '&:hover > div, &:hover > div > span': {
54
+ color: `${tokens.itemColor} !important`
55
+ },
56
+ '&:focus': {
57
+ border: `${tokens.groupBorderWidth}px solid ${tokens.itemBorderLeftColor}`,
58
+ borderLeft: isChild && `${tokens.itemBorderWidth}px solid ${tokens.itemBorderLeftColor}`,
59
+ borderRadius: !isChild && tokens.groupBorderRadius,
60
+ paddingLeft: !isChild && `calc(${tokens.itemPaddingLeft}px - ${tokens.groupBorderWidth}px)`,
61
+ paddingRight: `calc(${tokens.itemPaddingRight}px - ${tokens.groupBorderWidth}px)`,
62
+ paddingTop: `calc(${tokens.itemPaddingTop}px - ${tokens.groupBorderWidth}px)`,
63
+ paddingBottom: `calc(${tokens.itemPaddingBottom}px - ${tokens.groupBorderWidth}px)`,
64
+ backgroundColor: tokens.groupBackgroundColor
65
+ },
66
+ '&:active': {
67
+ backgroundColor: tokens.itemBorderBackgroundColor
68
+ }
69
+ };
70
+ });
71
+ const PressableItem = /*#__PURE__*/forwardRef((_ref3, ref) => {
72
+ let {
73
+ children,
74
+ href,
75
+ isChild = false,
76
+ onBlur,
77
+ onPress,
78
+ tabIndex = 0,
79
+ nextItemRef,
80
+ prevItemRef,
81
+ tokens,
82
+ variant = {},
83
+ ...rest
84
+ } = _ref3;
85
+
86
+ const handleKeyPress = event => {
87
+ if (['Enter', ' '].includes(event === null || event === void 0 ? void 0 : event.key)) {
88
+ onPress === null || onPress === void 0 ? void 0 : onPress(event);
89
+ } else if ((event === null || event === void 0 ? void 0 : event.key) === 'ArrowDown' && nextItemRef !== null && nextItemRef !== void 0 && nextItemRef.current) {
90
+ nextItemRef.current.focus();
91
+ } else if ((event === null || event === void 0 ? void 0 : event.key) === 'ArrowUp' && prevItemRef !== null && prevItemRef !== void 0 && prevItemRef.current) {
92
+ prevItemRef.current.focus();
93
+ }
94
+ };
95
+
96
+ const systemTokens = useThemeTokens('ListBox', tokens, variant, {
97
+ isChild,
98
+ hover: true
99
+ });
100
+ return /*#__PURE__*/_jsx(StyledLink, {
101
+ isChild: isChild,
102
+ tokens: systemTokens,
103
+ onBlur: onBlur,
104
+ onClick: onPress,
105
+ onKeyPress: handleKeyPress,
106
+ ref: ref,
107
+ tabIndex: tabIndex,
108
+ ...(href && {
109
+ href
110
+ }),
111
+ ...(onPress && {
112
+ onClick: onPress
113
+ }),
114
+ ...selectProps(rest),
115
+ children: children
116
+ });
117
+ });
118
+ PressableItem.displayName = 'PressableItem';
119
+ PressableItem.propTypes = { ...selectedSystemPropTypes,
120
+ href: PropTypes.string,
121
+ isChild: PropTypes.bool,
122
+ children: PropTypes.node.isRequired,
123
+ onBlur: PropTypes.func,
124
+ onPress: PropTypes.func,
125
+ nextItemRef: PropTypes.object,
126
+ prevItemRef: PropTypes.object
127
+ };
128
+ export default PressableItem;
@@ -0,0 +1,2 @@
1
+ import Listbox from './Listbox';
2
+ export default Listbox;