@telus-uds/components-base 1.8.2 → 1.8.5

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 (278) hide show
  1. package/CHANGELOG.md +33 -2
  2. package/component-docs.json +36 -1
  3. package/lib/ActivityIndicator/Spinner.js +7 -7
  4. package/lib/ActivityIndicator/Spinner.native.js +2 -2
  5. package/lib/Button/ButtonBase.js +2 -2
  6. package/lib/Button/ButtonGroup.js +1 -1
  7. package/lib/Checkbox/Checkbox.js +5 -3
  8. package/lib/Checkbox/CheckboxGroup.js +2 -2
  9. package/lib/Divider/Divider.js +2 -2
  10. package/lib/ExpandCollapse/Panel.js +2 -17
  11. package/lib/FlexGrid/Col/Col.js +1 -1
  12. package/lib/Icon/Icon.js +1 -1
  13. package/lib/Link/InlinePressable.js +5 -1
  14. package/lib/Link/LinkBase.js +5 -2
  15. package/lib/List/List.js +12 -7
  16. package/lib/List/ListItem.js +4 -5
  17. package/lib/Modal/Modal.js +2 -1
  18. package/lib/Pagination/PageButton.js +2 -2
  19. package/lib/Pagination/Pagination.js +5 -3
  20. package/lib/Pagination/usePagination.js +2 -2
  21. package/lib/Progress/ProgressBar.js +3 -3
  22. package/lib/Progress/ProgressBarBackground.js +3 -3
  23. package/lib/Radio/Radio.js +2 -2
  24. package/lib/Radio/RadioGroup.js +2 -2
  25. package/lib/RadioCard/RadioCard.js +1 -1
  26. package/lib/RadioCard/RadioCardGroup.js +2 -2
  27. package/lib/Search/Search.js +1 -1
  28. package/lib/SideNav/SideNav.js +2 -2
  29. package/lib/Skeleton/Skeleton.js +1 -1
  30. package/lib/Skeleton/skeletonWebAnimation.js +1 -1
  31. package/lib/StackView/StackWrap.js +3 -1
  32. package/lib/StackView/getStackedContent.js +2 -2
  33. package/lib/Tabs/Tabs.js +28 -3
  34. package/lib/Tabs/TabsItem.js +5 -6
  35. package/lib/Tags/Tags.js +1 -1
  36. package/lib/ThemeProvider/utils/styles.js +2 -2
  37. package/lib/ThemeProvider/utils/theme-tokens.js +7 -9
  38. package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
  39. package/lib/ToggleSwitch/ToggleSwitchGroup.js +1 -1
  40. package/lib/Tooltip/Backdrop.js +2 -10
  41. package/lib/utils/animation/useVerticalExpandAnimation.js +40 -14
  42. package/lib/utils/children.js +2 -2
  43. package/lib/utils/input.js +6 -12
  44. package/lib/utils/props/componentPropType.js +3 -3
  45. package/lib/utils/props/selectSystemProps.js +2 -2
  46. package/lib/utils/props/tokens.js +2 -2
  47. package/lib/utils/useSpacingScale.js +3 -1
  48. package/lib/utils/useUniqueId.js +1 -1
  49. package/lib-module/A11yInfoProvider/index.js +63 -0
  50. package/lib-module/A11yText/index.js +56 -0
  51. package/lib-module/ActivityIndicator/Spinner.js +77 -0
  52. package/lib-module/ActivityIndicator/Spinner.native.js +144 -0
  53. package/lib-module/ActivityIndicator/index.js +41 -0
  54. package/lib-module/ActivityIndicator/shared.js +12 -0
  55. package/lib-module/BaseProvider/index.js +29 -0
  56. package/lib-module/Box/Box.js +244 -0
  57. package/lib-module/Box/index.js +2 -0
  58. package/lib-module/Button/Button.js +26 -0
  59. package/lib-module/Button/ButtonBase.js +271 -0
  60. package/lib-module/Button/ButtonGroup.js +247 -0
  61. package/lib-module/Button/ButtonLink.js +40 -0
  62. package/lib-module/Button/index.js +4 -0
  63. package/lib-module/Button/propTypes.js +36 -0
  64. package/lib-module/Card/Card.js +84 -0
  65. package/lib-module/Card/CardBase.js +66 -0
  66. package/lib-module/Card/PressableCardBase.js +114 -0
  67. package/lib-module/Card/index.js +4 -0
  68. package/lib-module/Checkbox/Checkbox.js +348 -0
  69. package/lib-module/Checkbox/CheckboxGroup.js +233 -0
  70. package/lib-module/Checkbox/CheckboxInput.js +60 -0
  71. package/lib-module/Checkbox/CheckboxInput.native.js +6 -0
  72. package/lib-module/Checkbox/index.js +3 -0
  73. package/lib-module/Divider/Divider.js +124 -0
  74. package/lib-module/Divider/index.js +2 -0
  75. package/lib-module/ExpandCollapse/Accordion.js +15 -0
  76. package/lib-module/ExpandCollapse/Control.js +136 -0
  77. package/lib-module/ExpandCollapse/ExpandCollapse.js +95 -0
  78. package/lib-module/ExpandCollapse/Panel.js +151 -0
  79. package/lib-module/ExpandCollapse/index.js +7 -0
  80. package/lib-module/Feedback/Feedback.js +157 -0
  81. package/lib-module/Feedback/index.js +2 -0
  82. package/lib-module/Fieldset/Fieldset.js +153 -0
  83. package/lib-module/Fieldset/FieldsetContainer.js +32 -0
  84. package/lib-module/Fieldset/FieldsetContainer.native.js +23 -0
  85. package/lib-module/Fieldset/Legend.js +24 -0
  86. package/lib-module/Fieldset/Legend.native.js +31 -0
  87. package/lib-module/Fieldset/cssReset.js +14 -0
  88. package/lib-module/Fieldset/index.js +2 -0
  89. package/lib-module/FlexGrid/Col/Col.js +276 -0
  90. package/lib-module/FlexGrid/Col/index.js +2 -0
  91. package/lib-module/FlexGrid/FlexGrid.js +148 -0
  92. package/lib-module/FlexGrid/Row/Row.js +184 -0
  93. package/lib-module/FlexGrid/Row/index.js +2 -0
  94. package/lib-module/FlexGrid/helpers/index.js +18 -0
  95. package/lib-module/FlexGrid/index.js +2 -0
  96. package/lib-module/FlexGrid/providers/GutterContext.js +3 -0
  97. package/lib-module/HorizontalScroll/HorizontalScroll.js +175 -0
  98. package/lib-module/HorizontalScroll/HorizontalScrollButton.js +81 -0
  99. package/lib-module/HorizontalScroll/ScrollViewEnd.js +48 -0
  100. package/lib-module/HorizontalScroll/ScrollViewEnd.native.js +27 -0
  101. package/lib-module/HorizontalScroll/dictionary.js +11 -0
  102. package/lib-module/HorizontalScroll/index.js +11 -0
  103. package/lib-module/HorizontalScroll/itemPositions.js +112 -0
  104. package/lib-module/Icon/Icon.js +62 -0
  105. package/lib-module/Icon/IconText.js +83 -0
  106. package/lib-module/Icon/index.js +4 -0
  107. package/lib-module/IconButton/IconButton.js +122 -0
  108. package/lib-module/IconButton/index.js +2 -0
  109. package/lib-module/InputLabel/InputLabel.js +148 -0
  110. package/lib-module/InputLabel/LabelContent.js +27 -0
  111. package/lib-module/InputLabel/LabelContent.native.js +19 -0
  112. package/lib-module/InputLabel/index.js +2 -0
  113. package/lib-module/InputSupports/InputSupports.js +96 -0
  114. package/lib-module/InputSupports/index.js +2 -0
  115. package/lib-module/InputSupports/useInputSupports.js +32 -0
  116. package/lib-module/Link/ChevronLink.js +52 -0
  117. package/lib-module/Link/InlinePressable.js +44 -0
  118. package/lib-module/Link/InlinePressable.native.js +89 -0
  119. package/lib-module/Link/Link.js +28 -0
  120. package/lib-module/Link/LinkBase.js +243 -0
  121. package/lib-module/Link/TextButton.js +35 -0
  122. package/lib-module/Link/index.js +5 -0
  123. package/lib-module/List/List.js +62 -0
  124. package/lib-module/List/ListItem.js +248 -0
  125. package/lib-module/List/index.js +5 -0
  126. package/lib-module/Modal/Modal.js +222 -0
  127. package/lib-module/Modal/dictionary.js +9 -0
  128. package/lib-module/Modal/index.js +2 -0
  129. package/lib-module/Notification/Notification.js +209 -0
  130. package/lib-module/Notification/dictionary.js +8 -0
  131. package/lib-module/Notification/index.js +2 -0
  132. package/lib-module/Pagination/PageButton.js +66 -0
  133. package/lib-module/Pagination/Pagination.js +153 -0
  134. package/lib-module/Pagination/SideButton.js +106 -0
  135. package/lib-module/Pagination/dictionary.js +18 -0
  136. package/lib-module/Pagination/index.js +2 -0
  137. package/lib-module/Pagination/usePagination.js +73 -0
  138. package/lib-module/Progress/Progress.js +89 -0
  139. package/lib-module/Progress/ProgressBar.js +138 -0
  140. package/lib-module/Progress/ProgressBarBackground.js +42 -0
  141. package/lib-module/Progress/index.js +4 -0
  142. package/lib-module/Radio/Radio.js +285 -0
  143. package/lib-module/Radio/RadioButton.js +138 -0
  144. package/lib-module/Radio/RadioGroup.js +243 -0
  145. package/lib-module/Radio/RadioInput.js +62 -0
  146. package/lib-module/Radio/RadioInput.native.js +6 -0
  147. package/lib-module/Radio/index.js +3 -0
  148. package/lib-module/RadioCard/RadioCard.js +219 -0
  149. package/lib-module/RadioCard/RadioCardGroup.js +250 -0
  150. package/lib-module/RadioCard/index.js +3 -0
  151. package/lib-module/Search/Search.js +261 -0
  152. package/lib-module/Search/dictionary.js +12 -0
  153. package/lib-module/Search/index.js +2 -0
  154. package/lib-module/Select/Group.js +21 -0
  155. package/lib-module/Select/Group.native.js +15 -0
  156. package/lib-module/Select/Item.js +20 -0
  157. package/lib-module/Select/Item.native.js +3 -0
  158. package/lib-module/Select/Picker.js +68 -0
  159. package/lib-module/Select/Picker.native.js +120 -0
  160. package/lib-module/Select/Select.js +337 -0
  161. package/lib-module/Select/index.js +6 -0
  162. package/lib-module/SideNav/Item.js +145 -0
  163. package/lib-module/SideNav/ItemContent.js +48 -0
  164. package/lib-module/SideNav/ItemsGroup.js +117 -0
  165. package/lib-module/SideNav/SideNav.js +136 -0
  166. package/lib-module/SideNav/index.js +1 -0
  167. package/lib-module/Skeleton/Skeleton.js +179 -0
  168. package/lib-module/Skeleton/index.js +2 -0
  169. package/lib-module/Skeleton/skeleton.constant.js +3 -0
  170. package/lib-module/Skeleton/skeletonWebAnimation.js +18 -0
  171. package/lib-module/Skeleton/useSkeletonNativeAnimation.js +24 -0
  172. package/lib-module/Spacer/Spacer.js +98 -0
  173. package/lib-module/Spacer/index.js +2 -0
  174. package/lib-module/StackView/StackView.js +125 -0
  175. package/lib-module/StackView/StackWrap.js +50 -0
  176. package/lib-module/StackView/StackWrap.native.js +3 -0
  177. package/lib-module/StackView/StackWrapBox.js +115 -0
  178. package/lib-module/StackView/StackWrapGap.js +59 -0
  179. package/lib-module/StackView/common.js +35 -0
  180. package/lib-module/StackView/getStackedContent.js +124 -0
  181. package/lib-module/StackView/index.js +5 -0
  182. package/lib-module/StepTracker/Step.js +248 -0
  183. package/lib-module/StepTracker/StepTracker.js +185 -0
  184. package/lib-module/StepTracker/dictionary.js +10 -0
  185. package/lib-module/StepTracker/index.js +2 -0
  186. package/lib-module/Tabs/Tabs.js +143 -0
  187. package/lib-module/Tabs/TabsItem.js +224 -0
  188. package/lib-module/Tabs/index.js +2 -0
  189. package/lib-module/Tags/Tags.js +251 -0
  190. package/lib-module/Tags/index.js +2 -0
  191. package/lib-module/TextInput/TextArea.js +94 -0
  192. package/lib-module/TextInput/TextInput.js +72 -0
  193. package/lib-module/TextInput/TextInputBase.js +245 -0
  194. package/lib-module/TextInput/index.js +3 -0
  195. package/lib-module/TextInput/propTypes.js +37 -0
  196. package/lib-module/ThemeProvider/ThemeProvider.js +36 -0
  197. package/lib-module/ThemeProvider/index.js +6 -0
  198. package/lib-module/ThemeProvider/useSetTheme.js +25 -0
  199. package/lib-module/ThemeProvider/useTheme.js +14 -0
  200. package/lib-module/ThemeProvider/useThemeTokens.js +110 -0
  201. package/lib-module/ThemeProvider/utils/index.js +2 -0
  202. package/lib-module/ThemeProvider/utils/styles.js +181 -0
  203. package/lib-module/ThemeProvider/utils/theme-tokens.js +163 -0
  204. package/lib-module/ToggleSwitch/ToggleSwitch.js +250 -0
  205. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +220 -0
  206. package/lib-module/ToggleSwitch/index.js +3 -0
  207. package/lib-module/Tooltip/Backdrop.js +45 -0
  208. package/lib-module/Tooltip/Backdrop.native.js +44 -0
  209. package/lib-module/Tooltip/Tooltip.js +348 -0
  210. package/lib-module/Tooltip/dictionary.js +8 -0
  211. package/lib-module/Tooltip/getTooltipPosition.js +175 -0
  212. package/lib-module/Tooltip/index.js +2 -0
  213. package/lib-module/TooltipButton/TooltipButton.js +78 -0
  214. package/lib-module/TooltipButton/index.js +2 -0
  215. package/lib-module/Typography/Typography.js +124 -0
  216. package/lib-module/Typography/index.js +2 -0
  217. package/lib-module/ViewportProvider/ViewportProvider.js +29 -0
  218. package/lib-module/ViewportProvider/index.js +3 -0
  219. package/lib-module/ViewportProvider/useViewport.js +3 -0
  220. package/lib-module/ViewportProvider/useViewportListener.js +46 -0
  221. package/lib-module/index.js +48 -0
  222. package/lib-module/utils/a11y/index.js +2 -0
  223. package/lib-module/utils/a11y/semantics.js +157 -0
  224. package/lib-module/utils/a11y/textSize.js +36 -0
  225. package/lib-module/utils/animation/index.js +2 -0
  226. package/lib-module/utils/animation/useVerticalExpandAnimation.js +88 -0
  227. package/lib-module/utils/children.js +119 -0
  228. package/lib-module/utils/containUniqueFields.js +26 -0
  229. package/lib-module/utils/index.js +16 -0
  230. package/lib-module/utils/info/index.js +7 -0
  231. package/lib-module/utils/info/platform/index.js +11 -0
  232. package/lib-module/utils/info/platform/platform.android.js +1 -0
  233. package/lib-module/utils/info/platform/platform.ios.js +1 -0
  234. package/lib-module/utils/info/platform/platform.js +1 -0
  235. package/lib-module/utils/info/platform/platform.native.js +4 -0
  236. package/lib-module/utils/info/versions.js +5 -0
  237. package/lib-module/utils/input.js +179 -0
  238. package/lib-module/utils/pressability.js +111 -0
  239. package/lib-module/utils/props/a11yProps.js +140 -0
  240. package/lib-module/utils/props/clickProps.js +26 -0
  241. package/lib-module/utils/props/componentPropType.js +63 -0
  242. package/lib-module/utils/props/copyPropTypes.js +2 -0
  243. package/lib-module/utils/props/getPropSelector.js +9 -0
  244. package/lib-module/utils/props/handlerProps.js +65 -0
  245. package/lib-module/utils/props/hrefAttrsProp.js +33 -0
  246. package/lib-module/utils/props/index.js +19 -0
  247. package/lib-module/utils/props/inputSupportsProps.js +62 -0
  248. package/lib-module/utils/props/linkProps.js +44 -0
  249. package/lib-module/utils/props/paddingProp.js +9 -0
  250. package/lib-module/utils/props/pressProps.js +42 -0
  251. package/lib-module/utils/props/rectProp.js +9 -0
  252. package/lib-module/utils/props/responsiveProps.js +30 -0
  253. package/lib-module/utils/props/selectSystemProps.js +24 -0
  254. package/lib-module/utils/props/spacingProps.js +56 -0
  255. package/lib-module/utils/props/textInputProps.js +194 -0
  256. package/lib-module/utils/props/textProps.js +59 -0
  257. package/lib-module/utils/props/tokens.js +133 -0
  258. package/lib-module/utils/props/variantProp.js +18 -0
  259. package/lib-module/utils/props/viewProps.js +22 -0
  260. package/lib-module/utils/ssr.js +38 -0
  261. package/lib-module/utils/useCopy.js +44 -0
  262. package/lib-module/utils/useHash.js +45 -0
  263. package/lib-module/utils/useHash.native.js +7 -0
  264. package/lib-module/utils/useResponsiveProp.js +47 -0
  265. package/lib-module/utils/useSpacingScale.js +125 -0
  266. package/lib-module/utils/useUniqueId.js +13 -0
  267. package/lib-module/utils/withLinkRouter.js +83 -0
  268. package/package.json +3 -2
  269. package/src/Checkbox/Checkbox.jsx +3 -1
  270. package/src/ExpandCollapse/Panel.jsx +2 -19
  271. package/src/Link/InlinePressable.jsx +5 -2
  272. package/src/Link/LinkBase.jsx +4 -1
  273. package/src/List/List.jsx +34 -19
  274. package/src/List/ListItem.jsx +12 -2
  275. package/src/Modal/Modal.jsx +2 -1
  276. package/src/Tabs/Tabs.jsx +24 -2
  277. package/src/Tabs/TabsItem.jsx +6 -5
  278. package/src/utils/animation/useVerticalExpandAnimation.js +47 -13
@@ -0,0 +1,133 @@
1
+ import PropTypes from 'prop-types';
2
+ import { components as tokenKeys } from '@telus-uds/system-theme-tokens'; // Tokens can be primitive values (e.g. `'rgba(0,0,0,0'`, `12`), or objects of such values,
3
+ // such as tokens that describe shadow (e.g. shadow: { inset: true, color: 'rgba(...)' ... }),
4
+ // or components (e.g. Icon tokens)
5
+
6
+ const tokenValue = PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool, PropTypes.elementType]);
7
+ const tokenValueType = PropTypes.oneOfType([tokenValue, PropTypes.objectOf(tokenValue)]);
8
+ export const getTokenNames = componentName => {
9
+ const componentTokenSchema = tokenKeys[componentName];
10
+
11
+ if (!componentTokenSchema) {
12
+ throw new Error("No \"".concat(componentName, "\" tokenKeys in @telus-uds/system-theme-tokens"));
13
+ }
14
+
15
+ return Object.keys(componentTokenSchema);
16
+ };
17
+ /**
18
+ * Returns the subset of a set of tokens that may be accepted by the `tokens` prop of a named component
19
+ * or by a provided array of tokens. A prefix may be provided, for example:
20
+ *
21
+ * @example
22
+ * ```jsx
23
+ * // returns tokens from `themeTokens` that exist in the theme schema for `Button`.
24
+ * selectTokens('Button', themeTokens)
25
+ * ```
26
+ *
27
+ * @example
28
+ * ```jsx
29
+ * // returns `{ backgroundColor, width }` where the values of those keys come from
30
+ * // the source object's `{ containerBackgroundColor, containerWidth }` properties.
31
+ * selectTokens(['backgroundColor', 'width'], themeTokens, 'container')
32
+ * ```
33
+ *
34
+ * @example
35
+ * ```jsx
36
+ * // returns tokens that are defined in the `Button` theme schema, from tokens with
37
+ * // a prefix `'button'` e.g. a token `buttonBorderWidth` outputs as `borderWidth`.
38
+ * selectTokens('Button', themeTokens, 'button')
39
+ * ```
40
+ *
41
+ * @param {string[]|string} specifier - a name of a component in the theme schema, or an array of token names
42
+ * @param {object} tokens - a source object of theme tokens
43
+ * @param {string} [prefix] - if provided, matches keys in the source object with this as the first camelCase item
44
+ * @returns {object} - subset of theme tokens
45
+ */
46
+
47
+ export const selectTokens = (specifier, tokens, prefix) => {
48
+ const tokenNames = typeof specifier === 'string' ? getTokenNames(specifier) : specifier;
49
+ const filteredTokens = tokenNames.reduce((validTokens, key) => {
50
+ const prefixedKey = prefix ? "".concat(prefix).concat(key[0].toUpperCase()).concat(key.slice(1)) : key;
51
+ const token = tokens[prefixedKey];
52
+ return token !== undefined ? { ...validTokens,
53
+ [key]: token
54
+ } : validTokens;
55
+ }, {});
56
+ return filteredTokens;
57
+ };
58
+ /**
59
+ * @typedef {string|number|boolean|{[key: string]:string|number|boolean}} TokenValue
60
+ * @typedef {{[key: string]: TokenValue}} TokensSet
61
+ * @typedef {(AppearanceSet) => TokensSet} TokensGetter
62
+ * @typedef {TokensSet|TokensGetter} TokensProp
63
+ */
64
+
65
+ /**
66
+ * 'tokens' is an optional object prop on all themable components. Its keys must match the
67
+ * token keys in the component's theme schema.
68
+ *
69
+ * This prop is intended to be used as an 'escape hatch' for difficult or exceptional cases
70
+ * where the main theming system doesn't apply. It is intentionally permissive about values.
71
+ *
72
+ * @param {...string} componentsNames - one or more ComponentName, which tokens keys are accepted
73
+ * @return {function} - a custom PropTypes validator
74
+ *
75
+ * @example
76
+ * Component.propTypes = {
77
+ * // accepts all tokens keys defined in Component schema
78
+ * tokens: getTokensPropType('Component')
79
+ * }
80
+ *
81
+ * Component.propTypes = {
82
+ * // accepts all tokens keys defined in schemas for Component1 and Component2
83
+ * tokens: getTokensPropType('Component1', 'Component2')
84
+ * }
85
+ */
86
+
87
+ export const getTokensPropType = function () {
88
+ for (var _len = arguments.length, componentsNames = new Array(_len), _key = 0; _key < _len; _key++) {
89
+ componentsNames[_key] = arguments[_key];
90
+ }
91
+
92
+ return (props, propName, componentName) => {
93
+ PropTypes.checkPropTypes({
94
+ [propName]: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
95
+ }, props, propName, componentName);
96
+
97
+ if (typeof props[propName] !== 'function') {
98
+ PropTypes.checkPropTypes({
99
+ [propName]: PropTypes.exact(Object.fromEntries(componentsNames.flatMap(component => getTokenNames(component).map(key => [key, tokenValueType]))))
100
+ }, props, propName, componentName);
101
+ }
102
+ };
103
+ };
104
+ /**
105
+ * Get a proptypes validator for a set of tokens that is not based on a component in the theme schema.
106
+ *
107
+ * For example, for a set of tokens used in a common style, or for a set of tokens required by
108
+ * a themeless component whose tokens are set by a parent but requires tokens of a certain shape.
109
+ *
110
+ * By default, requires an object with a complete set of tokens (allowing `null`, but not `undefined`).
111
+ *
112
+ * @param {string[]} componentTokenKeys - array of strings of token names
113
+ * @param {object} [options]
114
+ * @param {boolean} [options.partial] - if true, allows tokens to be undefined
115
+ * @param {boolean} [options.allowFunction] - if true, allows functions as well as tokens objects
116
+ * @returns
117
+ */
118
+
119
+ export const getTokensSetPropType = function (componentTokenKeys) {
120
+ let {
121
+ partial = false,
122
+ allowFunction = false
123
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
124
+ const tokensObjectValidator = PropTypes.exact(Object.fromEntries(componentTokenKeys.map(key => [key, partial ? tokenValueType : // Some theme tokens can validly resolve to `null`, but .isRequired treats null as undefined
125
+ function (props, propName) {
126
+ for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
127
+ args[_key2 - 2] = arguments[_key2];
128
+ }
129
+
130
+ return props[propName] !== null && tokenValueType.isRequired(props, propName, ...args);
131
+ }])));
132
+ return allowFunction ? PropTypes.oneOfType([tokensObjectValidator, PropTypes.func]) : tokensObjectValidator;
133
+ };
@@ -0,0 +1,18 @@
1
+ import PropTypes from 'prop-types';
2
+ /**
3
+ * @typedef {{[key: string]: string|number|boolean}} AppearanceSet
4
+ * @typedef {AppearanceSet} VariantProp
5
+ */
6
+
7
+ export default {
8
+ /**
9
+ * 'variant' is an optional object prop on all themable components.
10
+ *
11
+ * Contains an object with keys that correspond to the current component theme's allowed
12
+ * appearances and values that correspond to the allowed values of that component.
13
+ *
14
+ * Since the particular keys and values depend on which theme is currently active,
15
+ * the exact shape of variant props is not enforced using PropTypes.
16
+ */
17
+ propType: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]))
18
+ };
@@ -0,0 +1,22 @@
1
+ import PropTypes from 'prop-types';
2
+ import getPropSelector from './getPropSelector';
3
+ const viewPropTypes = {
4
+ pointerEvents: PropTypes.oneOf(['all', 'none', 'box-only', 'box-none']),
5
+ onLayout: PropTypes.func,
6
+ nativeID: PropTypes.string,
7
+ testID: PropTypes.string,
8
+ dataSet: PropTypes.object
9
+ };
10
+ export default {
11
+ /**
12
+ * Subset of `View` proptypes that could conceivably be needed on any component
13
+ * that renders a single View.
14
+ */
15
+ types: viewPropTypes,
16
+
17
+ /**
18
+ * Filters a props object, returning only cross-platform View props that are potentially
19
+ * relevant to any basic layout component that renders one View.
20
+ */
21
+ select: getPropSelector(viewPropTypes)
22
+ };
@@ -0,0 +1,38 @@
1
+ import AppRegistry from "react-native-web/dist/exports/AppRegistry";
2
+ /** @typedef {import('react').ComponentType} ReactComponent */
3
+
4
+ /** @typedef {import('react').ReactElement} ReactElement */
5
+
6
+ /**
7
+ * Registers the app's root component with React Native Web and generates
8
+ * the main <style> tag containing React Native Web stylesheet styles.
9
+ *
10
+ * @param {ReactComponent} AppRoot
11
+ * @param {string} [appName]
12
+ * @returns {ReactElement[]}
13
+ */
14
+
15
+ export const getReactNativeWebSSRStyles = function (AppRoot) {
16
+ let appName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'app';
17
+ AppRegistry.registerComponent(appName, () => AppRoot);
18
+ const {
19
+ getStyleElement
20
+ } = AppRegistry.getApplication(appName);
21
+ return [getStyleElement()];
22
+ };
23
+ /**
24
+ * Gets style tags for each currently supported CSS-in-JS library and returns
25
+ * them alongside any existing style tags.
26
+ *
27
+ * @param {ReactComponent} AppRoot
28
+ * @param {string} [appName]
29
+ * @param {ReactElement[]} [existingStyles]
30
+ * @returns {ReactElement[]}
31
+ */
32
+
33
+ export const getSSRStyles = function (AppRoot) {
34
+ let appName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'app';
35
+ let existingStyles = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
36
+ return [...existingStyles, ...getReactNativeWebSSRStyles(AppRoot, appName) // if any other CSS-in-JS is added e.g. styled-components generate and add its styles here
37
+ ];
38
+ };
@@ -0,0 +1,44 @@
1
+ export const DEFAULT_COPY = 'en';
2
+ /**
3
+ * Extract translations from a keyed dictionary for a given language.
4
+ * Returns a getter.
5
+ *
6
+ * @example
7
+ * const getCopy = useCopy({
8
+ * copy: 'en',
9
+ * dictionary: {
10
+ * en: { label: 'english label' },
11
+ * fr: { label: 'french label' }
12
+ * }
13
+ * })
14
+ *
15
+ * getCopy('label') => 'english label'
16
+ *
17
+ * @description The entire dictionary may be overridden by simply passing a single language object as `copy`:
18
+ * @example
19
+ * const getCopy = useCopy({
20
+ * copy: { label: 'custom label' }
21
+ * })
22
+ *
23
+ * getCopy('label') => 'custom label'
24
+ *
25
+ * @param {object} [dictionary]
26
+ * @param {'en'|'fr'|object} copy - language
27
+ * @return {function(string): string}
28
+ */
29
+
30
+ function useCopy(_ref) {
31
+ let {
32
+ dictionary,
33
+ copy = DEFAULT_COPY
34
+ } = _ref;
35
+
36
+ if (typeof copy === 'string') {
37
+ return key => key ? dictionary[copy][key] : dictionary[copy];
38
+ } // support overriding the entire copy dictionary with an object for a single language
39
+
40
+
41
+ return key => copy[key];
42
+ }
43
+
44
+ export default useCopy;
@@ -0,0 +1,45 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ const doAction = (action, event) => {
4
+ var _window, _window$location;
5
+
6
+ return typeof action === 'function' && action((_window = window) === null || _window === void 0 ? void 0 : (_window$location = _window.location) === null || _window$location === void 0 ? void 0 : _window$location.hash, event);
7
+ };
8
+ /**
9
+ * @typedef {import('react').SyntheticEvent} SyntheticEvent
10
+ */
11
+
12
+ /**
13
+ * Calls a function (passing it the current hash) based on the current hash state on mount,
14
+ * and binds it to call it again any time the hash changes.
15
+ *
16
+ * Consider using `useCallback` on the function to minimise adding and removing of event listeners.
17
+ *
18
+ * On Native, this is replaced with a harmless no-op function as there is no direct equivalent.
19
+ *
20
+ * @param {(hash: string, event?: SyntheticEvent) => void} action - a function to act on the current hash on load and when it changes
21
+ * @returns
22
+ */
23
+
24
+
25
+ const useHash = function (action) {
26
+ let isReady = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
27
+ const [isDone, setIsDone] = useState(false); // Do the action just once when ready after component mount, from hash on page load
28
+
29
+ const isToDo = isReady && !isDone;
30
+ useEffect(() => {
31
+ if (isToDo) {
32
+ setIsDone(true);
33
+ doAction(action);
34
+ }
35
+ }, [isToDo, action]); // Bind the action for each hash change; do re-bind if the function changes.
36
+
37
+ useEffect(() => {
38
+ const handleChange = event => doAction(action, event);
39
+
40
+ window.addEventListener('hashchange', handleChange);
41
+ return () => window.removeEventListener('hashchange', handleChange);
42
+ }, [action]);
43
+ };
44
+
45
+ export default useHash;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * No URL hashes on Native, so do a no-op. Remembering scenes for reloads
3
+ * is handled at OS level and deep links have completely different usage.
4
+ */
5
+ const useHash = () => {};
6
+
7
+ export default useHash;
@@ -0,0 +1,47 @@
1
+ import { viewports } from '@telus-uds/system-constants';
2
+ import { useViewport } from '../ViewportProvider';
3
+
4
+ const hasOwn = (objectProp, key) => Object.prototype.hasOwnProperty.call(objectProp, key);
5
+
6
+ const hasResponsiveProperties = objectProp => viewports.keys.some(key => hasOwn(objectProp, key));
7
+ /**
8
+ * Resolves a prop which may be a responsive object with keys for viewports.
9
+ *
10
+ * Used internally in useResponsiveProp - see that for more details.
11
+ *
12
+ * @param {*} prop
13
+ * @param {"xs"|"sm"|"md"|"lg"|"xl"} viewport
14
+ * @param {*} [defaultValue]
15
+ * @returns {*}
16
+ */
17
+
18
+
19
+ export const resolveResponsiveProp = (prop, viewport, defaultValue) => {
20
+ if (prop === undefined) return defaultValue;
21
+ if (!prop || typeof prop !== 'object' || !hasResponsiveProperties(prop)) return prop;
22
+ const value = viewports.keys.includes(viewport) ? // If there's a current viewport, return the closest match at or below it
23
+ viewports.inherit(prop)[viewport] : // If no current viewport is available, default to smallest viewport
24
+ prop[viewports.keys.find(key => hasOwn(prop, key))];
25
+ return value === undefined ? defaultValue : value;
26
+ };
27
+ /**
28
+ * Takes any value and, if that value is a responsive prop (an object with one or more
29
+ * keys matching system viewport names), returns the value corresponding to the largest
30
+ * viewport key smaller than the current screen's viewport.
31
+ *
32
+ * For example, if passed `{ sm: 4, lg: 8 }`, it will return 8 on `xl` and `lg` viewports,
33
+ * 4 on `md` and `sm` viewports, and `undefined` (or a provided `defaultValue`) on `xs` viewports.
34
+ *
35
+ * To generate propTypes for responsive props, see `responsiveProps` in `./utils/props/responsiveProps.js`.
36
+ *
37
+ * @param {*} prop - any value which may be an object with viewport keys
38
+ * @param {*} [defaultValue] - default value to provide if no matches found for the current viewport
39
+ * @returns {*}
40
+ */
41
+
42
+ const useResponsiveProp = (prop, defaultValue) => {
43
+ const viewport = useViewport();
44
+ return resolveResponsiveProp(prop, viewport, defaultValue);
45
+ };
46
+
47
+ export default useResponsiveProp;
@@ -0,0 +1,125 @@
1
+ import { useViewport } from '../ViewportProvider';
2
+ import { useThemeTokens } from '../ThemeProvider';
3
+ import { resolveResponsiveProp } from './useResponsiveProp';
4
+ /**
5
+ * @typedef {import('@telus-uds/system-constants/viewports').Viewport} Viewport
6
+ * @typedef {import('./props/spacingProps.js').SpacingValue} SpacingValue
7
+ * @typedef {import('./props/spacingProps.js').SpacingIndex} SpacingIndex
8
+ * @typedef {import('./props/spacingProps.js').SpacingObject} SpacingObject
9
+ * @typedef {import('./props/spacingProps.js').SpacingOptions} SpacingOptions
10
+ */
11
+
12
+ const resolveSpacingOptions = space => {
13
+ if (!(space !== null && space !== void 0 && space.options)) return {};
14
+ const {
15
+ size,
16
+ variant,
17
+ subtract = 0
18
+ } = space.options;
19
+ const overridden = typeof size === 'number'; // Might need an option that adapts the size value by current user's system font scale, so that
20
+ // meaningful spacing between items doesn't disappear on the highest a11y font scale settings.
21
+ // https://github.com/telus/universal-design-system/issues/583
22
+
23
+ return {
24
+ tokens: {
25
+ size
26
+ },
27
+ variant,
28
+ overridden,
29
+ subtract
30
+ };
31
+ };
32
+ /**
33
+ * Pass a {@link SpacingValue}, which is one of:
34
+ *
35
+ * - A number 0-11 ({@link SpacingIndex}) pointing to an index on the theme's spacing scale
36
+ * - Or, an object ({@link SpacingObject}), with optional properties:
37
+ * - `xs`, `sm`, `md`, `lg`, `xl`: {@link SpacingIndex} to apply at or above these specified {@link Viewport}
38
+ * - `options`: an optional {@link SpacingOptions} object, see below
39
+ * - `space`: a {@link SpacingIndex} to apply to all viewports (can be used alongside `options`)
40
+ *
41
+ * ## Example
42
+ *
43
+ * If the theme's spacing scale is `[0, 4, 8, 12, 16, 24, 48]` with no theme rules:
44
+ *
45
+ * - `useSpacingScale(0)` returns `0`
46
+ * - `useSpacingScale(2)` returns `8`
47
+ * - `useSpacingScale({ xs: 3, lg: 4 })` returns `12` at 'xs', 'sm' or 'md' viewports, and `16` at 'lg' or 'xl'.
48
+ *
49
+ * These viewport properties are intended to support case-specific responsive layout changes, for example, where a
50
+ * grid item drops or adds spacing on a particular side at viewports where the parent changes the layout shape.
51
+ *
52
+ * ## Theming
53
+ *
54
+ * A theme's `'spacingScale'` has theme rules and appearances same as components, and may support `viewport`.
55
+ * For example, a theme with the following rule would change index [2] above from `8` to `12` on large viewports:
56
+ *
57
+ * ```json
58
+ * { if: { space: 2, viewport: ['lg', 'xl'] }, tokens: { size: 12 }}
59
+ * ```
60
+ *
61
+ * Setting responsive spacing in the theme is the preferred way to adapt the aesthetic tightness or looseness of
62
+ * a theme to the available space without changing the shape of the layout itself.
63
+ *
64
+ * ## Options
65
+ *
66
+ * Space values passed as objects may have an `options` key, with the following optional properties:
67
+ *
68
+ * - `variant`: Themes may choose to have spacing scale variants, same as variants in component themes.
69
+ * For example, if a theme rule contains `{ if: { space: 2, compact: true }, tokens: { size: 6 }}`,
70
+ * this tighter spacing can be accessed with:
71
+ *
72
+ * ```jsx
73
+ * const compactSize = useSpacingScale({ space: 2, options: { variant: { compact: true }}})`
74
+ * ```
75
+ *
76
+ * - `subtract`: Sometimes on-brand spacing needs to be reduced by another value to achieve an on-brand result.
77
+ * For example, a component with a variable border may want to subtract its border width from its padding so
78
+ * the total distance from content edge to bounding box is a valid theme value, regardless of border width:
79
+ *
80
+ * ```jsx
81
+ * const padding = useSpacingScale({ space: 2, options: { subtract: themeTokens.borderWidth }})
82
+ * ```
83
+ *
84
+ * - `size`: In exceptional cases, the theme's spacing scale may be bypassed by passing a `size` option.
85
+ * This can result in layouts that may be rejected for being off-brand so should only be used as a
86
+ * last resort for fixing layout problems (e.g. when working around non-branded embedded content).
87
+ * Where possible, fixing layout issues using a spacing scale value and the `subtract` option is preferred.
88
+ *
89
+ * ```jsx
90
+ * // Comments should be included when `size` is used, stating why this off-brand size is needed
91
+ * const iframeOffset = useSpacingScale({ options: { size: 13 }})`
92
+ * ```
93
+ *
94
+ * ## References
95
+ *
96
+ * `/ADRs/inter-component-spacing/README.md` - ADR on this structure
97
+ *
98
+ * @param {SpacingValue} [spaceValue] - a {@link SpacingIndex} number, or a {@link SpacingObject}
99
+ * @returns {number}
100
+ */
101
+
102
+
103
+ const useSpacingScale = spaceValue => {
104
+ var _spaceValue$space;
105
+
106
+ // In future, may need to consider window height as well as width, particularly for native apps,
107
+ // e.g. to ensure designs don't look lost on large, tall, not-so-wide portrait screens.
108
+ const viewport = useViewport();
109
+ const {
110
+ tokens,
111
+ variant,
112
+ overridden,
113
+ subtract = 0
114
+ } = resolveSpacingOptions(spaceValue);
115
+ const space = !overridden && ((_spaceValue$space = spaceValue === null || spaceValue === void 0 ? void 0 : spaceValue.space) !== null && _spaceValue$space !== void 0 ? _spaceValue$space : resolveResponsiveProp(spaceValue, viewport, 0));
116
+ const {
117
+ size
118
+ } = useThemeTokens('spacingScale', tokens, variant, {
119
+ space: typeof space === 'number' ? space : 0,
120
+ viewport
121
+ });
122
+ return Math.max(size - subtract, 0);
123
+ };
124
+
125
+ export default useSpacingScale;
@@ -0,0 +1,13 @@
1
+ import { useState } from 'react';
2
+ let id = 0;
3
+
4
+ function useUniqueId() {
5
+ let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
6
+ const [uniqueId] = useState(() => {
7
+ id += 1;
8
+ return "".concat(prefix, "-").concat(id);
9
+ });
10
+ return uniqueId;
11
+ }
12
+
13
+ export default useUniqueId;
@@ -0,0 +1,83 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types'; // Prototype-safe alternative to (linter-forbidden) someObject.hasOwnProperty()
3
+
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+
6
+ const hasOwnProperty = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
7
+ /**
8
+ * Higher-order component that has no effect unless an additional prop `LinkRouter` is passed.
9
+ * This may be used to provide custom wrappers for integrations with third party libraries.
10
+ *
11
+ * If LinkRouter is passed, LinkRouter is rendered in place of the main component and is passed:
12
+ *
13
+ * - `linkRouterProps`: an optional object passed alongside LinkRouter, for props needed by the wrapper
14
+ * that are not valid props for the wrapped component.
15
+ * - `Component`: automatically provided, the original component to render inside the wrapper.
16
+ * - `ref`: forwarded `ref` passed down to `Component`
17
+ * - All other props passed to the outer component
18
+ *
19
+ * @example A LinkRouter component to be used with link-like components might look like:
20
+ *
21
+ * ```jsx
22
+ * const LinkLinkRouter = forwardRef(({ Component, linkRouterProps: { to, options }, href, ...rest }, ref) => {
23
+ * const { href: resolvedHref, onClick } = useSomeRouterHook({ to, href, options })
24
+ * return <Component href={resolvedHref} onPress={onClick} {...rest} />
25
+ * })
26
+ * ```
27
+ *
28
+ * Any component that takes href and onPress props may then use this wrapper:
29
+ *
30
+ * ```jsx
31
+ * <Link href={href} LinkRouter={LinkLinkRouter} linkRouterProps={{ to, options }}>Some link</Link>
32
+ * <IconButton icon={SomeIcon} LinkRouter={LinkLinkRouter} linkRouterProps={{ to, options }} ref={iconRef} />
33
+ * ```
34
+ */
35
+
36
+
37
+ const withLinkRouter = Component => {
38
+ const wrappedComponent = /*#__PURE__*/forwardRef((_ref, ref) => {
39
+ let {
40
+ LinkRouter,
41
+ linkRouterProps,
42
+ ...props
43
+ } = _ref;
44
+ if (!LinkRouter) return /*#__PURE__*/_jsx(Component, { ...props,
45
+ ref: ref
46
+ });
47
+ return /*#__PURE__*/_jsx(LinkRouter, {
48
+ linkRouterProps: linkRouterProps,
49
+ Component: Component,
50
+ ref: ref,
51
+ ...props
52
+ });
53
+ }); // Ensure the returned component has appropriate outer properties set:
54
+
55
+ /* eslint-disable-next-line react/forbid-foreign-prop-types */
56
+
57
+ const {
58
+ displayName,
59
+ name,
60
+ propTypes,
61
+ ...otherProperties
62
+ } = Component; // Apply unique component name as a displayName
63
+
64
+ wrappedComponent.displayName = Component.displayName || Component.name; // Apply proptypes including wrapper props - is safely { ...undefined, ...undefined } in prod
65
+
66
+ wrappedComponent.propTypes = { ...Component.propTypes,
67
+ ...withLinkRouter.propTypes
68
+ }; // Forward any other properties explicitly set e.g. Component.SubComponent
69
+
70
+ Object.keys(otherProperties).forEach(key => {
71
+ // Skip internal React properties from wrappedComponent's forwardRef (render, $$typeof, etc)
72
+ if (hasOwnProperty(Component, key) && !hasOwnProperty(wrappedComponent, key)) {
73
+ wrappedComponent[key] = Component[key];
74
+ }
75
+ });
76
+ return wrappedComponent;
77
+ };
78
+
79
+ withLinkRouter.propTypes = {
80
+ LinkRouter: PropTypes.elementType,
81
+ linkRouterProps: PropTypes.object
82
+ };
83
+ export default withLinkRouter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telus-uds/components-base",
3
- "version": "1.8.2",
3
+ "version": "1.8.5",
4
4
  "description": "Base components",
5
5
  "keywords": [
6
6
  "base"
@@ -31,6 +31,7 @@
31
31
  "build:code": "npm run build:main && npm run build:module",
32
32
  "build:docs": "babel-node --plugins=@nearform/babel-plugin-react-docgen generate-component-docs.js",
33
33
  "storybook": "start-storybook",
34
+ "build-storybook": "build-storybook",
34
35
  "dev": "npm run build:code --watch"
35
36
  },
36
37
  "bugs": {
@@ -55,7 +56,7 @@
55
56
  "@storybook/react": "^6.5.6",
56
57
  "@storybook/builder-webpack5": "^6.5.6",
57
58
  "@storybook/manager-webpack5": "^6.5.6",
58
- "@telus-uds/browserslist-config": "^1.0.2",
59
+ "@telus-uds/browserslist-config": "^1.0.4",
59
60
  "@testing-library/jest-native": "^4.0.1",
60
61
  "@testing-library/react-hooks": "^7.0.1",
61
62
  "@testing-library/react-native": "^7.2.0",
@@ -213,7 +213,9 @@ const Checkbox = forwardRef(
213
213
  value={value}
214
214
  />
215
215
  {isChecked && IconComponent && (
216
- <IconComponent {...iconTokens} testID="Checkbox-Icon" />
216
+ <View testID="Checkbox-Icon">
217
+ <IconComponent {...iconTokens} />
218
+ </View>
217
219
  )}
218
220
  </View>
219
221
  </View>
@@ -1,5 +1,5 @@
1
1
  import React, { forwardRef, useState } from 'react'
2
- import { Animated, Platform, StyleSheet, View } from 'react-native'
2
+ import { Animated, Platform, View } from 'react-native'
3
3
  import PropTypes from 'prop-types'
4
4
 
5
5
  import ExpandCollapseControl from './Control'
@@ -86,13 +86,6 @@ const ExpandCollapsePanel = forwardRef(
86
86
  tokens: themeTokens
87
87
  })
88
88
 
89
- // on web we can hide the contents until we have the container measured and avoid occasional jitter
90
- // this won't work on native platforms
91
- const overflowContainerStyles =
92
- containerHeight === null && Platform.OS === 'web'
93
- ? { height: 0, visibility: 'hidden' }
94
- : undefined
95
-
96
89
  const focusabilityProps = isExpanded ? {} : a11yProps.nonFocusableProps
97
90
 
98
91
  return (
@@ -105,11 +98,7 @@ const ExpandCollapsePanel = forwardRef(
105
98
  >
106
99
  {control}
107
100
  </ExpandCollapseControl>
108
- <Animated.View
109
- ref={animatedRef}
110
- style={[overflowContainerStyles, animatedStyles, staticStyles.itemsContainer]}
111
- {...focusabilityProps}
112
- >
101
+ <Animated.View ref={animatedRef} style={animatedStyles} {...focusabilityProps}>
113
102
  <View onLayout={onContainerLayout}>
114
103
  <View style={selectContainerStyles(themeTokens)}>{children}</View>
115
104
  </View>
@@ -156,10 +145,4 @@ ExpandCollapsePanel.propTypes = {
156
145
  controlTokens: getTokensPropType('ExpandCollapseControl')
157
146
  }
158
147
 
159
- const staticStyles = StyleSheet.create({
160
- itemsContainer: {
161
- overflow: 'hidden'
162
- }
163
- })
164
-
165
148
  export default ExpandCollapsePanel