@telus-uds/components-base 0.0.2-prerelease.9 → 1.0.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 (282) hide show
  1. package/.eslintrc.js +9 -0
  2. package/.ultra.cache.json +1 -1
  3. package/CHANGELOG.md +32 -0
  4. package/README.md +4 -2
  5. package/__fixtures__/test-utils.js +25 -0
  6. package/__fixtures__/testTheme.js +4 -2
  7. package/__tests__/Button/ButtonGroup.test.jsx +4 -5
  8. package/__tests__/Checkbox/Checkbox.test.jsx +2 -2
  9. package/__tests__/Checkbox/CheckboxGroup.test.jsx +4 -5
  10. package/__tests__/ExpandCollapse/ExpandCollapse.test.jsx +2 -2
  11. package/__tests__/HorizontalScroll/HorizontalScroll.test.jsx +164 -0
  12. package/__tests__/Link/LinkBase.test.jsx +0 -14
  13. package/__tests__/Radio/Radio.test.jsx +2 -2
  14. package/__tests__/Radio/RadioGroup.test.jsx +4 -5
  15. package/__tests__/RadioCard/RadioCard.test.jsx +2 -2
  16. package/__tests__/RadioCard/RadioCardGroup.test.jsx +4 -5
  17. package/__tests__/Search/Search.test.jsx +9 -8
  18. package/__tests__/Select/Select.test.jsx +3 -2
  19. package/__tests__/Tabs/Tabs.test.jsx +1 -161
  20. package/__tests__/Tags/Tags.test.jsx +4 -5
  21. package/__tests__/TextInput/TextArea.test.jsx +3 -2
  22. package/__tests__/TextInput/TextInputBase.test.jsx +10 -5
  23. package/__tests__/ThemeProvider/ThemeProvider.test.jsx +77 -0
  24. package/__tests__/ThemeProvider/useThemeTokens.test.jsx +9 -5
  25. package/__tests__/ThemeProvider/utils/theme-tokens.test.js +41 -0
  26. package/__tests__/ToggleSwitch/ToggleSwitch.test.jsx +3 -2
  27. package/__tests__/utils/children.test.jsx +128 -0
  28. package/__tests__/utils/input.test.js +1 -1
  29. package/__tests__/utils/semantics.test.jsx +43 -0
  30. package/lib/A11yText/index.js +10 -5
  31. package/lib/ActivityIndicator/Spinner.js +16 -13
  32. package/lib/ActivityIndicator/Spinner.native.js +12 -8
  33. package/lib/Box/Box.js +102 -8
  34. package/lib/Button/Button.js +9 -8
  35. package/lib/Button/ButtonBase.js +14 -7
  36. package/lib/Button/ButtonGroup.js +25 -10
  37. package/lib/Button/ButtonLink.js +10 -7
  38. package/lib/Card/Card.js +2 -0
  39. package/lib/Card/CardBase.js +12 -5
  40. package/lib/Card/PressableCardBase.js +12 -8
  41. package/lib/Checkbox/Checkbox.js +25 -14
  42. package/lib/Checkbox/CheckboxGroup.js +22 -12
  43. package/lib/Divider/Divider.js +12 -7
  44. package/lib/ExpandCollapse/Accordion.js +10 -4
  45. package/lib/ExpandCollapse/Control.js +12 -6
  46. package/lib/ExpandCollapse/ExpandCollapse.js +10 -5
  47. package/lib/ExpandCollapse/Panel.js +8 -7
  48. package/lib/Feedback/Feedback.js +10 -5
  49. package/lib/Fieldset/Fieldset.js +10 -5
  50. package/lib/Fieldset/FieldsetContainer.js +10 -5
  51. package/lib/Fieldset/FieldsetContainer.native.js +10 -5
  52. package/lib/Fieldset/Legend.js +10 -5
  53. package/lib/Fieldset/Legend.native.js +10 -5
  54. package/lib/FlexGrid/Col/Col.js +8 -5
  55. package/lib/FlexGrid/FlexGrid.js +31 -6
  56. package/lib/FlexGrid/Row/Row.js +12 -5
  57. package/lib/{Tabs → HorizontalScroll}/HorizontalScroll.js +5 -4
  58. package/lib/{Tabs/TabsScrollButton.js → HorizontalScroll/HorizontalScrollButton.js} +14 -8
  59. package/lib/{Tabs → HorizontalScroll}/ScrollViewEnd.js +0 -0
  60. package/lib/{Tabs → HorizontalScroll}/ScrollViewEnd.native.js +0 -0
  61. package/lib/{Tabs → HorizontalScroll}/dictionary.js +0 -0
  62. package/lib/HorizontalScroll/index.js +35 -0
  63. package/lib/{Tabs → HorizontalScroll}/itemPositions.js +0 -0
  64. package/lib/Icon/Icon.js +16 -9
  65. package/lib/Icon/IconText.js +8 -7
  66. package/lib/IconButton/IconButton.js +10 -5
  67. package/lib/InputLabel/InputLabel.js +33 -5
  68. package/lib/InputLabel/LabelContent.js +22 -12
  69. package/lib/InputLabel/LabelContent.native.js +23 -5
  70. package/lib/InputSupports/InputSupports.js +10 -5
  71. package/lib/Link/ChevronLink.js +12 -5
  72. package/lib/Link/InlinePressable.js +10 -4
  73. package/lib/Link/InlinePressable.native.js +5 -4
  74. package/lib/Link/Link.js +12 -5
  75. package/lib/Link/LinkBase.js +12 -5
  76. package/lib/Link/TextButton.js +10 -5
  77. package/lib/List/List.js +5 -4
  78. package/lib/List/ListItem.js +16 -8
  79. package/lib/Modal/Modal.js +10 -5
  80. package/lib/Notification/Notification.js +21 -5
  81. package/lib/Pagination/PageButton.js +21 -10
  82. package/lib/Pagination/Pagination.js +12 -7
  83. package/lib/Pagination/SideButton.js +12 -7
  84. package/lib/Pagination/usePagination.js +2 -2
  85. package/lib/Progress/Progress.js +10 -5
  86. package/lib/Progress/ProgressBar.js +21 -10
  87. package/lib/Progress/ProgressBarBackground.js +12 -8
  88. package/lib/Radio/Radio.js +14 -13
  89. package/lib/Radio/RadioButton.js +20 -9
  90. package/lib/Radio/RadioGroup.js +24 -13
  91. package/lib/RadioCard/RadioCard.js +14 -10
  92. package/lib/RadioCard/RadioCardGroup.js +13 -12
  93. package/lib/Search/Search.js +29 -18
  94. package/lib/Select/Picker.js +11 -6
  95. package/lib/Select/Picker.native.js +21 -6
  96. package/lib/Select/Select.js +46 -4
  97. package/lib/SideNav/Item.js +10 -5
  98. package/lib/SideNav/ItemsGroup.js +10 -5
  99. package/lib/SideNav/SideNav.js +11 -7
  100. package/lib/Skeleton/Skeleton.js +15 -15
  101. package/lib/Skeleton/skeletonWebAnimation.js +1 -1
  102. package/lib/Spacer/Spacer.js +19 -7
  103. package/lib/StackView/StackView.js +25 -7
  104. package/lib/StackView/StackWrap.js +16 -9
  105. package/lib/StackView/StackWrapBox.js +33 -8
  106. package/lib/StackView/StackWrapGap.js +16 -7
  107. package/lib/StackView/common.js +4 -2
  108. package/lib/StackView/getStackedContent.js +2 -2
  109. package/lib/StepTracker/StepTracker.js +10 -5
  110. package/lib/Tabs/Tabs.js +26 -19
  111. package/lib/Tabs/TabsItem.js +16 -12
  112. package/lib/Tags/Tags.js +27 -11
  113. package/lib/TextInput/TextArea.js +7 -5
  114. package/lib/TextInput/TextInput.js +12 -6
  115. package/lib/TextInput/TextInputBase.js +12 -8
  116. package/lib/ThemeProvider/ThemeProvider.js +14 -10
  117. package/lib/ThemeProvider/useSetTheme.js +6 -1
  118. package/lib/ThemeProvider/utils/styles.js +2 -2
  119. package/lib/ThemeProvider/utils/theme-tokens.js +39 -8
  120. package/lib/ToggleSwitch/ToggleSwitch.js +11 -6
  121. package/lib/Tooltip/Backdrop.js +10 -2
  122. package/lib/Tooltip/Tooltip.js +5 -4
  123. package/lib/Typography/Typography.js +40 -24
  124. package/lib/index.js +21 -0
  125. package/lib/utils/a11y/index.js +13 -0
  126. package/lib/utils/a11y/semantics.js +173 -0
  127. package/lib/utils/animation/useVerticalExpandAnimation.js +1 -1
  128. package/lib/utils/children.js +55 -8
  129. package/lib/utils/input.js +27 -17
  130. package/lib/utils/propTypes.js +82 -29
  131. package/lib/utils/useCopy.js +1 -1
  132. package/lib/utils/useHash.js +8 -4
  133. package/lib/utils/useSpacingScale.js +1 -3
  134. package/lib/utils/useUniqueId.js +1 -1
  135. package/package.json +9 -5
  136. package/release-context.json +4 -4
  137. package/src/A11yText/index.jsx +6 -4
  138. package/src/ActivityIndicator/Spinner.jsx +5 -3
  139. package/src/ActivityIndicator/Spinner.native.jsx +5 -3
  140. package/src/Box/Box.jsx +124 -39
  141. package/src/Button/Button.jsx +7 -4
  142. package/src/Button/ButtonBase.jsx +86 -77
  143. package/src/Button/ButtonGroup.jsx +81 -69
  144. package/src/Button/ButtonLink.jsx +18 -13
  145. package/src/Card/Card.jsx +2 -2
  146. package/src/Card/CardBase.jsx +5 -4
  147. package/src/Card/PressableCardBase.jsx +71 -64
  148. package/src/Checkbox/Checkbox.jsx +118 -108
  149. package/src/Checkbox/CheckboxGroup.jsx +72 -62
  150. package/src/Divider/Divider.jsx +7 -4
  151. package/src/ExpandCollapse/Accordion.jsx +3 -2
  152. package/src/ExpandCollapse/Control.jsx +40 -43
  153. package/src/ExpandCollapse/ExpandCollapse.jsx +26 -23
  154. package/src/ExpandCollapse/Panel.jsx +69 -63
  155. package/src/Feedback/Feedback.jsx +36 -33
  156. package/src/Fieldset/Fieldset.jsx +63 -56
  157. package/src/Fieldset/FieldsetContainer.jsx +14 -5
  158. package/src/Fieldset/FieldsetContainer.native.jsx +7 -4
  159. package/src/Fieldset/Legend.jsx +7 -2
  160. package/src/Fieldset/Legend.native.jsx +7 -2
  161. package/src/FlexGrid/Col/Col.jsx +139 -132
  162. package/src/FlexGrid/FlexGrid.jsx +79 -51
  163. package/src/FlexGrid/Row/Row.jsx +55 -48
  164. package/src/HorizontalScroll/HorizontalScroll.jsx +168 -0
  165. package/src/HorizontalScroll/HorizontalScrollButton.jsx +105 -0
  166. package/src/{Tabs → HorizontalScroll}/ScrollViewEnd.jsx +0 -0
  167. package/src/{Tabs → HorizontalScroll}/ScrollViewEnd.native.jsx +0 -0
  168. package/src/{Tabs → HorizontalScroll}/dictionary.js +0 -0
  169. package/src/HorizontalScroll/index.js +17 -0
  170. package/src/{Tabs → HorizontalScroll}/itemPositions.js +0 -0
  171. package/src/Icon/Icon.jsx +37 -35
  172. package/src/Icon/IconText.jsx +22 -17
  173. package/src/IconButton/IconButton.jsx +49 -42
  174. package/src/InputLabel/InputLabel.jsx +53 -38
  175. package/src/InputLabel/LabelContent.jsx +14 -6
  176. package/src/InputLabel/LabelContent.native.jsx +11 -2
  177. package/src/InputSupports/InputSupports.jsx +29 -34
  178. package/src/Link/ChevronLink.jsx +26 -16
  179. package/src/Link/InlinePressable.jsx +5 -3
  180. package/src/Link/InlinePressable.native.jsx +5 -3
  181. package/src/Link/Link.jsx +22 -16
  182. package/src/Link/LinkBase.jsx +67 -58
  183. package/src/Link/TextButton.jsx +30 -23
  184. package/src/List/List.jsx +5 -4
  185. package/src/List/ListItem.jsx +77 -82
  186. package/src/Modal/Modal.jsx +9 -4
  187. package/src/Notification/Notification.jsx +58 -43
  188. package/src/Pagination/PageButton.jsx +42 -35
  189. package/src/Pagination/Pagination.jsx +88 -92
  190. package/src/Pagination/SideButton.jsx +44 -41
  191. package/src/Progress/Progress.jsx +5 -4
  192. package/src/Progress/ProgressBar.jsx +42 -29
  193. package/src/Progress/ProgressBarBackground.jsx +5 -3
  194. package/src/Radio/Radio.jsx +85 -78
  195. package/src/Radio/RadioButton.jsx +54 -43
  196. package/src/Radio/RadioGroup.jsx +74 -63
  197. package/src/RadioCard/RadioCard.jsx +75 -68
  198. package/src/RadioCard/RadioCardGroup.jsx +82 -75
  199. package/src/Search/Search.jsx +127 -106
  200. package/src/Select/Picker.jsx +49 -42
  201. package/src/Select/Picker.native.jsx +56 -49
  202. package/src/Select/Select.jsx +115 -72
  203. package/src/SideNav/Item.jsx +53 -46
  204. package/src/SideNav/ItemsGroup.jsx +50 -43
  205. package/src/SideNav/SideNav.jsx +68 -60
  206. package/src/Skeleton/Skeleton.jsx +9 -13
  207. package/src/Spacer/Spacer.jsx +11 -4
  208. package/src/StackView/StackView.jsx +46 -23
  209. package/src/StackView/StackWrap.jsx +7 -6
  210. package/src/StackView/StackWrapBox.jsx +61 -28
  211. package/src/StackView/StackWrapGap.jsx +46 -24
  212. package/src/StackView/common.jsx +3 -2
  213. package/src/StepTracker/StepTracker.jsx +73 -62
  214. package/src/Tabs/Tabs.jsx +70 -62
  215. package/src/Tabs/TabsItem.jsx +111 -103
  216. package/src/Tags/Tags.jsx +114 -102
  217. package/src/TextInput/TextArea.jsx +5 -4
  218. package/src/TextInput/TextInput.jsx +5 -4
  219. package/src/TextInput/TextInputBase.jsx +84 -77
  220. package/src/ThemeProvider/ThemeProvider.jsx +11 -7
  221. package/src/ThemeProvider/useSetTheme.js +4 -0
  222. package/src/ThemeProvider/utils/theme-tokens.js +28 -0
  223. package/src/ToggleSwitch/ToggleSwitch.jsx +49 -50
  224. package/src/Tooltip/Tooltip.jsx +134 -130
  225. package/src/Typography/Typography.jsx +67 -44
  226. package/src/index.js +2 -0
  227. package/src/utils/a11y/index.js +1 -0
  228. package/src/utils/a11y/semantics.js +162 -0
  229. package/src/utils/children.jsx +60 -7
  230. package/src/utils/input.js +20 -17
  231. package/src/utils/propTypes.js +101 -39
  232. package/src/utils/useCopy.js +1 -1
  233. package/src/utils/useHash.js +8 -3
  234. package/stories/A11yText/A11yText.stories.jsx +2 -2
  235. package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +1 -1
  236. package/stories/Box/Box.stories.jsx +1 -1
  237. package/stories/Button/Button.stories.jsx +2 -2
  238. package/stories/Button/ButtonGroup.stories.jsx +1 -1
  239. package/stories/Button/ButtonLink.stories.jsx +1 -1
  240. package/stories/Card/Card.stories.jsx +1 -1
  241. package/stories/Checkbox/Checkbox.stories.jsx +1 -1
  242. package/stories/Divider/Divider.stories.jsx +1 -1
  243. package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +2 -2
  244. package/stories/Feedback/Feedback.stories.jsx +1 -1
  245. package/stories/FlexGrid/01 FlexGrid.stories.jsx +1 -1
  246. package/stories/FlexGrid/02 Row.stories.jsx +1 -1
  247. package/stories/FlexGrid/03 Col.stories.jsx +1 -1
  248. package/stories/Icon/Icon.stories.jsx +1 -1
  249. package/stories/IconButton/IconButton.stories.jsx +1 -1
  250. package/stories/InputLabel/InputLabel.stories.jsx +1 -1
  251. package/stories/Link/ChevronLink.stories.jsx +1 -1
  252. package/stories/Link/Link.stories.jsx +1 -1
  253. package/stories/Link/TextButton.stories.jsx +1 -1
  254. package/stories/List/List.stories.jsx +1 -1
  255. package/stories/Modal/Modal.stories.jsx +1 -1
  256. package/stories/Notification/Notification.stories.jsx +1 -1
  257. package/stories/Pagination/Pagination.stories.jsx +1 -1
  258. package/stories/Progress/Progress.stories.jsx +1 -1
  259. package/stories/Radio/Radio.stories.jsx +1 -1
  260. package/stories/RadioCard/RadioCard.stories.jsx +1 -1
  261. package/stories/Search/Search.stories.jsx +1 -1
  262. package/stories/Select/Select.stories.jsx +1 -1
  263. package/stories/SideNav/SideNav.stories.jsx +1 -1
  264. package/stories/SideNav/SideNavItem.stories.jsx +1 -1
  265. package/stories/SideNav/SideNavItemsGroup.stories.jsx +1 -1
  266. package/stories/Skeleton/Skeleton.stories.jsx +2 -2
  267. package/stories/Spacer/Spacer.stories.jsx +1 -1
  268. package/stories/StackView/StackView.stories.jsx +1 -1
  269. package/stories/StackView/StackWrap.stories.jsx +1 -1
  270. package/stories/StepTracker/StepTracker.stories.jsx +1 -1
  271. package/stories/Tabs/Tabs.stories.jsx +1 -1
  272. package/stories/Tags/Tags.stories.jsx +1 -1
  273. package/stories/TextInput/TextArea.stories.jsx +1 -1
  274. package/stories/TextInput/TextInput.stories.jsx +1 -1
  275. package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +1 -1
  276. package/stories/Tooltip/Tooltip.stories.jsx +1 -1
  277. package/stories/TooltipButton/TooltipButton.stories.jsx +1 -1
  278. package/stories/Typography/Typography.stories.jsx +1 -1
  279. package/stories/platform-supports.jsx +1 -1
  280. package/stories/supports.jsx +2 -2
  281. package/src/Tabs/HorizontalScroll.jsx +0 -165
  282. package/src/Tabs/TabsScrollButton.jsx +0 -100
@@ -130,7 +130,7 @@ const selectIconContainerStyles = ({
130
130
  paddingBottom
131
131
  });
132
132
 
133
- function TextInputBase({
133
+ const TextInputBase = /*#__PURE__*/(0, _react.forwardRef)(({
134
134
  value,
135
135
  height,
136
136
  initialValue,
@@ -145,7 +145,7 @@ function TextInputBase({
145
145
  tokens,
146
146
  variant = {},
147
147
  ...remainingProps
148
- }) {
148
+ }, ref) => {
149
149
  const [isFocused, setIsFocused] = (0, _react.useState)(false);
150
150
 
151
151
  const handleFocus = event => {
@@ -181,9 +181,12 @@ function TextInputBase({
181
181
  readOnly
182
182
  });
183
183
 
184
- const handleChangeText = text => {
185
- setValue(text);
186
- if (typeof onChangeText === 'function') onChangeText(text);
184
+ const handleChangeText = event => {
185
+ var _event$nativeEvent, _event$target;
186
+
187
+ const text = ((_event$nativeEvent = event.nativeEvent) === null || _event$nativeEvent === void 0 ? void 0 : _event$nativeEvent.text) || ((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value);
188
+ setValue(text, event);
189
+ if (typeof onChangeText === 'function') onChangeText(text, event);
187
190
  };
188
191
 
189
192
  const states = {
@@ -201,7 +204,7 @@ function TextInputBase({
201
204
  onBlur: handleBlur,
202
205
  onMouseOver: handleMouseOver,
203
206
  onMouseOut: handleMouseOut,
204
- onChangeText: handleChangeText,
207
+ onChange: handleChangeText,
205
208
  defaultValue: initialValue,
206
209
  // currentValue is being updated even if the input is not controlled, passing it down to the
207
210
  // Input could lead to changing its state from uncontrolled to controlled
@@ -213,6 +216,7 @@ function TextInputBase({
213
216
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_View.default, {
214
217
  style: selectOuterBorderStyles(themeTokens),
215
218
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_TextInput.default, {
219
+ ref: ref,
216
220
  style: nativeInputStyle,
217
221
  ...inputProps
218
222
  }), IconComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
@@ -223,8 +227,8 @@ function TextInputBase({
223
227
  })
224
228
  })]
225
229
  });
226
- }
227
-
230
+ });
231
+ TextInputBase.displayName = 'TextInputBase';
228
232
  TextInputBase.propTypes = {
229
233
  value: _propTypes.default.string,
230
234
  height: _propTypes.default.number,
@@ -3,12 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.themeType = exports.ThemeSetterContext = exports.ThemeContext = exports.uninitialisedError = void 0;
6
+ exports.default = exports.ThemeSetterContext = exports.ThemeContext = exports.uninitialisedError = void 0;
7
7
 
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
+ var _utils = require("./utils");
13
+
12
14
  var _jsxRuntime = require("react/jsx-runtime");
13
15
 
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -21,18 +23,18 @@ const uninitialisedError = new Error('Theme context used outside of ThemeProvide
21
23
  exports.uninitialisedError = uninitialisedError;
22
24
  const ThemeContext = /*#__PURE__*/(0, _react.createContext)(uninitialisedError);
23
25
  exports.ThemeContext = ThemeContext;
24
- const ThemeSetterContext = /*#__PURE__*/(0, _react.createContext)(uninitialisedError); // TODO: develop this as theme metadata is added
25
- // https://github.com/telus/universal-design-system/issues/92
26
-
26
+ const ThemeSetterContext = /*#__PURE__*/(0, _react.createContext)(uninitialisedError);
27
27
  exports.ThemeSetterContext = ThemeSetterContext;
28
- const themeType = _propTypes.default.object;
29
- exports.themeType = themeType;
30
28
 
31
29
  const ThemeProvider = ({
32
30
  children,
33
31
  defaultTheme
34
32
  }) => {
35
- const [theme, setTheme] = (0, _react.useState)(defaultTheme);
33
+ const [theme, setTheme] = (0, _react.useState)(defaultTheme); // Validate the theme tokens version on every render.
34
+ // This will intentionally break the application when attempting to use an invalid theme.
35
+ // This will surface an incompatibility quickly rather than allowing the potential for strange bugs due to missing or incompatible tokens.
36
+
37
+ (0, _utils.validateThemeTokensVersion)(theme);
36
38
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeSetterContext.Provider, {
37
39
  value: setTheme,
38
40
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeContext.Provider, {
@@ -43,10 +45,12 @@ const ThemeProvider = ({
43
45
  };
44
46
 
45
47
  ThemeProvider.propTypes = {
46
- // TODO: implement a custom propType that validates schema version
47
- // https://github.com/telus/universal-design-system/issues/92
48
48
  children: _propTypes.default.node.isRequired,
49
- defaultTheme: themeType.isRequired
49
+ defaultTheme: _propTypes.default.shape({
50
+ metadata: _propTypes.default.shape({
51
+ themeTokensVersion: _propTypes.default.string.isRequired
52
+ }).isRequired
53
+ }).isRequired
50
54
  };
51
55
  var _default = ThemeProvider;
52
56
  exports.default = _default;
@@ -11,7 +11,12 @@ var _ThemeProvider = require("./ThemeProvider");
11
11
 
12
12
  const useSetTheme = () => {
13
13
  // Replace current theme with provided object
14
- const setTheme = (0, _react.useContext)(_ThemeProvider.ThemeSetterContext); // Merge provided object into current theme
14
+ const setTheme = (0, _react.useContext)(_ThemeProvider.ThemeSetterContext); // Fail fast if dev uses useSetTheme outside of ThemeProvider
15
+
16
+ if (setTheme instanceof Error) {
17
+ throw setTheme;
18
+ } // Merge provided object into current theme
19
+
15
20
 
16
21
  const editTheme = (0, _react.useCallback)(newTheme => setTheme((oldTheme = {}) => ({ ...oldTheme,
17
22
  ...newTheme
@@ -50,7 +50,7 @@ function applyTextStyles({
50
50
  if (fontName) {
51
51
  // Don't set undefined font families. May need some validation here that the font is available.
52
52
  // Android doesn't recognise font weights natively so apply custom font weights via `fontFamily`.
53
- styles.fontFamily = "".concat(fontName).concat(fontWeight).concat(fontStyle);
53
+ styles.fontFamily = `${fontName}${fontWeight}${fontStyle}`;
54
54
  } else if (fontWeight) {
55
55
  // If using system default font, apply the font weight directly.
56
56
  // Font weight support in Android is limited to 'bold' or anything else === 'normal'.
@@ -99,7 +99,7 @@ function applyWebShadow({
99
99
  }) {
100
100
  const insetString = inset ? 'inset ' : '';
101
101
  const boxShadow = {
102
- boxShadow: "".concat(insetString).concat(offsetX, "px ").concat(offsetY, "px ").concat(blur, "px ").concat(spread, "px ").concat(color)
102
+ boxShadow: `${insetString}${offsetX}px ${offsetY}px ${blur}px ${spread}px ${color}`
103
103
  };
104
104
  return boxShadow;
105
105
  }
@@ -3,10 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.toArray = exports.getThemeTokens = exports.mergeAppearances = exports.validateThemeTokens = exports.resolveThemeTokens = exports.doesThemeRuleApply = exports.doesThemeConditionApply = exports.getComponentTheme = void 0;
6
+ exports.validateThemeTokensVersion = exports.toArray = exports.getThemeTokens = exports.mergeAppearances = exports.validateThemeTokens = exports.resolveThemeTokens = exports.doesThemeRuleApply = exports.doesThemeConditionApply = exports.getComponentTheme = void 0;
7
7
 
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
 
10
+ var _satisfies = _interopRequireDefault(require("semver/functions/satisfies"));
11
+
12
+ var _package = _interopRequireDefault(require("../../../package.json"));
13
+
10
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
15
 
12
16
  /**
@@ -24,19 +28,19 @@ const getComponentTheme = (theme, componentName) => {
24
28
  // Give clear and understandable error messages for common dev errors, for example,
25
29
  // typo in component name, missing export or accessing old version of theme
26
30
  if (!theme) {
27
- throw new Error("Called useTheme's getStyle on \"".concat(componentName, "\" with no theme provided"));
31
+ throw new Error(`Called useTheme's getStyle on "${componentName}" with no theme provided`);
28
32
  }
29
33
 
30
34
  const themeName = ((_theme$metadata = theme.metadata) === null || _theme$metadata === void 0 ? void 0 : _theme$metadata.name) || '';
31
35
 
32
36
  if (!theme.components) {
33
- throw new Error("Theme \"".concat(themeName, "\" has no components defined (looking for \"").concat(componentName, "\")"));
37
+ throw new Error(`Theme "${themeName}" has no components defined (looking for "${componentName}")`);
34
38
  }
35
39
 
36
40
  const componentTheme = theme.components[componentName];
37
41
 
38
42
  if (!componentTheme) {
39
- throw new Error("Theme \"".concat(themeName, "\" does not have styles for component \"").concat(componentName, "\""));
43
+ throw new Error(`Theme "${themeName}" does not have styles for component "${componentName}"`);
40
44
  }
41
45
 
42
46
  return componentTheme;
@@ -45,10 +49,8 @@ const getComponentTheme = (theme, componentName) => {
45
49
  exports.getComponentTheme = getComponentTheme;
46
50
 
47
51
  const doesThemeConditionApply = ([key, value], appearances) => {
48
- var _appearances$key;
49
-
50
52
  // use null rather than undefined so we can serialise the value in themes
51
- const appearanceValue = (_appearances$key = appearances[key]) !== null && _appearances$key !== void 0 ? _appearances$key : null;
53
+ const appearanceValue = appearances[key] ?? null;
52
54
  return Array.isArray(value) ? value.includes(appearanceValue) : value === appearanceValue;
53
55
  };
54
56
 
@@ -154,5 +156,34 @@ const getThemeTokens = ({
154
156
  exports.getThemeTokens = getThemeTokens;
155
157
 
156
158
  const toArray = strOrArr => Array.isArray(strOrArr) ? strOrArr : [strOrArr];
159
+ /**
160
+ * Throws an error if the theme was built with an incompatible version of @telus-uds/system-theme-tokens
161
+ *
162
+ * This is used internally by the ThemeProvider to force a fast failure when an incompatible version is detected.
163
+ *
164
+ * Version compatibility is calculated with semver.satisfies.
165
+ * Refer to https://github.com/npm/node-semver and https://semver.npmjs.com/ for details about how
166
+ * semver compatibility.
167
+ *
168
+ * @param {object} theme - UDS theme built for react-native
169
+ */
170
+
171
+
172
+ exports.toArray = toArray;
173
+
174
+ const validateThemeTokensVersion = theme => {
175
+ var _theme$metadata2;
176
+
177
+ const expectedThemeTokensVersion = _package.default.dependencies['@telus-uds/system-theme-tokens'];
178
+ const actualThemeTokensVersion = theme === null || theme === void 0 ? void 0 : (_theme$metadata2 = theme.metadata) === null || _theme$metadata2 === void 0 ? void 0 : _theme$metadata2.themeTokensVersion;
179
+
180
+ if (!(0, _satisfies.default)(actualThemeTokensVersion, expectedThemeTokensVersion)) {
181
+ throw new Error(`Invalid UDS token schema version detected.
182
+
183
+ The UDS base components ${_package.default.name} v${_package.default.version} are only compatible with UDS themes that are built with @telus-uds/system-theme-tokens version that is semver compatible with ${expectedThemeTokensVersion}. The current theme was built with @telus-uds/system-theme-tokens v${actualThemeTokensVersion}.
184
+
185
+ If you see this error than most likely you have attempted to install ${_package.default.name} and a UDS theme manually because you are building a multi-brand application. If you are building a single brand application, consider installing the brand specific design system package such as @telus-uds/ds-allium. For more information, see https://github.com/telus/universal-design-system/blob/main/packages/docs-uds/docs/multi-brand-usage.md`);
186
+ }
187
+ };
157
188
 
158
- exports.toArray = toArray;
189
+ exports.validateThemeTokensVersion = validateThemeTokensVersion;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
@@ -27,6 +27,10 @@ var _jsxRuntime = require("react/jsx-runtime");
27
27
 
28
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
29
 
30
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
31
+
32
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
33
+
30
34
  const selectButtonTokens = tokens => (0, _propTypes2.selectTokens)('Button', { ...tokens,
31
35
  // Width tokens are applied to our inner track. Disable Button width token so it wraps our track width.
32
36
  width: null
@@ -76,7 +80,7 @@ const selectSwitchStyles = ({
76
80
  })
77
81
  });
78
82
 
79
- const ToggleSwitch = ({
83
+ const ToggleSwitch = /*#__PURE__*/(0, _react.forwardRef)(({
80
84
  value,
81
85
  initialValue,
82
86
  onChange,
@@ -84,7 +88,7 @@ const ToggleSwitch = ({
84
88
  tokens,
85
89
  variant,
86
90
  accessibilityRole = 'switch'
87
- }) => {
91
+ }, ref) => {
88
92
  const getTokens = (0, _ThemeProvider.useThemeTokensCallback)('ToggleSwitch', tokens, variant);
89
93
  const {
90
94
  currentValue,
@@ -95,11 +99,12 @@ const ToggleSwitch = ({
95
99
  onChange
96
100
  });
97
101
 
98
- const handlePress = () => setValue(!currentValue);
102
+ const handlePress = event => setValue(!currentValue, event);
99
103
 
100
104
  const getButtonTokens = buttonState => selectButtonTokens(getTokens(buttonState));
101
105
 
102
106
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonBase.default, {
107
+ ref: ref,
103
108
  selected: currentValue,
104
109
  inactive: inactive,
105
110
  tokens: getButtonTokens,
@@ -134,8 +139,8 @@ const ToggleSwitch = ({
134
139
  });
135
140
  }
136
141
  });
137
- };
138
-
142
+ });
143
+ ToggleSwitch.displayName = 'ToggleSwitch';
139
144
  ToggleSwitch.propTypes = { ..._propTypes2.a11yProps.propTypes,
140
145
  ..._propTypes2.pressProps.propTypes,
141
146
  tokens: (0, _propTypes2.getTokensPropType)('ToggleSwitch'),
@@ -19,7 +19,15 @@ function createPortalNode(nodeId) {
19
19
  // this way the backdrop stays in place when scrolling the window - that's why we need to
20
20
  // position it at the scroll position when rendering
21
21
 
22
- node.style.cssText = "\n position: absolute; \n top: ".concat(window.scrollY, "px;\n left: ").concat(window.scrollX, "px; \n right: 0; \n bottom: 0; \n z-index: 9999; \n pointer-events: none;\n ");
22
+ node.style.cssText = `
23
+ position: absolute;
24
+ top: ${window.scrollY}px;
25
+ left: ${window.scrollX}px;
26
+ right: 0;
27
+ bottom: 0;
28
+ z-index: 9999;
29
+ pointer-events: none;
30
+ `;
23
31
  document.body.appendChild(node);
24
32
  return node;
25
33
  }
@@ -39,7 +47,7 @@ function Backdrop({
39
47
  }) {
40
48
  const [portalNode, setPortalNode] = (0, _react.useState)();
41
49
  (0, _react.useEffect)(() => {
42
- const nodeId = "tooltip-backdrop-".concat(Date.now());
50
+ const nodeId = `tooltip-backdrop-${Date.now()}`;
43
51
  const node = createPortalNode(nodeId);
44
52
  setPortalNode(node);
45
53
  return () => {
@@ -161,14 +161,14 @@ const defaultControl = (pressableState, variant) => /*#__PURE__*/(0, _jsxRuntime
161
161
  */
162
162
 
163
163
 
164
- const Tooltip = ({
164
+ const Tooltip = /*#__PURE__*/(0, _react.forwardRef)(({
165
165
  children,
166
166
  content,
167
167
  position = 'auto',
168
168
  copy = 'en',
169
169
  tokens,
170
170
  variant
171
- }) => {
171
+ }, ref) => {
172
172
  const [isOpen, setIsOpen] = (0, _react.useState)(false);
173
173
  const controlRef = (0, _react.useRef)();
174
174
  const [controlLayout, setControlLayout] = (0, _react.useState)(null);
@@ -292,6 +292,7 @@ const Tooltip = ({
292
292
  }), isOpen && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Backdrop.default, {
293
293
  onPress: close,
294
294
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_View.default, {
295
+ ref: ref,
295
296
  style: [staticStyles.tooltip, selectTooltipShadowStyles(themeTokens), // applied separately so that it doesn't cover the arrow
296
297
  tooltipPosition && selectTooltipPositionStyles(tooltipPosition), (tooltipPosition === null || (tooltipPosition === null || tooltipPosition === void 0 ? void 0 : tooltipPosition.isNormalized)) && staticStyles.tooltipHidden // visually hide the tooltip until we have a final measurement
297
298
  ],
@@ -309,8 +310,8 @@ const Tooltip = ({
309
310
  })
310
311
  })]
311
312
  });
312
- };
313
-
313
+ });
314
+ Tooltip.displayName = 'Tooltip';
314
315
  Tooltip.propTypes = {
315
316
  /**
316
317
  * Used to render the control (i.e. tooltip trigger). If a render function is used it will receive the
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
8
+ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
@@ -25,15 +25,13 @@ var _jsxRuntime = require("react/jsx-runtime");
25
25
 
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
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
+
28
32
  /**
29
- * If passed a string like 'h1', 'h2' etc, returns the heading number as a string,
30
- * else returns false
33
+ * @typedef {import('../utils/a11y/semantics').TextTag} TextTag
31
34
  */
32
- function getHeadingLevel(heading) {
33
- const match = typeof heading === 'string' && heading.match(/^h(\d)$/);
34
- return match && match[1];
35
- }
36
-
37
35
  const selectTextStyles = ({
38
36
  fontWeight,
39
37
  fontSize,
@@ -55,16 +53,18 @@ const selectTextStyles = ({
55
53
  }); // General-purpose flexible theme-neutral base component for text
56
54
 
57
55
 
58
- const Typography = ({
56
+ const Typography = /*#__PURE__*/(0, _react.forwardRef)(({
59
57
  children,
60
58
  variant,
61
59
  heading,
60
+ tag = typeof heading === 'string' ? heading : undefined,
61
+ accessibilityRole = heading === true ? 'header' : undefined,
62
62
  block = false,
63
63
  align = undefined,
64
- accessibilityRole = heading ? 'header' : 'text',
65
64
  tokens,
65
+ dataSet,
66
66
  ...rest
67
- }) => {
67
+ }, ref) => {
68
68
  const viewport = (0, _ViewportProvider.useViewport)();
69
69
  const themeTokens = (0, _ThemeProvider.useThemeTokens)('Typography', tokens, variant, {
70
70
  viewport
@@ -73,34 +73,50 @@ const Typography = ({
73
73
  style: selectTextStyles(align ? { ...themeTokens,
74
74
  textAlign: align
75
75
  } : themeTokens),
76
+ dataSet,
76
77
  maxFontSizeMultiplier: (0, _utils2.getMaxFontMultiplier)(themeTokens)
77
78
  };
78
- const headingLevel = getHeadingLevel(heading);
79
- const a11y = { ..._utils2.a11yProps.select(rest),
80
- accessibilityRole,
81
- // On React Native Web, `accessibilityLevel` controls which heading tag (h1, h2 etc) is used.
82
- ...(headingLevel && {
83
- accessibilityLevel: headingLevel
84
- })
79
+ const a11y = { ...(0, _utils2.getA11yPropsFromHtmlTag)(tag, accessibilityRole),
80
+ ..._utils2.a11yProps.select(rest)
85
81
  };
86
- return block ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, { ...a11y,
82
+ return block ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
83
+ ref: ref,
84
+ ...a11y,
87
85
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, { ...textProps,
88
86
  children: children
89
87
  })
90
- }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, { ...textProps,
88
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, {
89
+ ref: ref,
90
+ ...textProps,
91
91
  ...a11y,
92
92
  children: children
93
93
  });
94
- };
95
-
94
+ });
95
+ Typography.displayName = 'Typography';
96
96
  Typography.propTypes = { ..._utils2.a11yProps.types,
97
97
  tokens: (0, _utils2.getTokensPropType)('Typography'),
98
98
  variant: _utils2.variantProp.propType,
99
99
 
100
100
  /**
101
- * If truthy, will render a heading; if a html heading tag is provided, uses that tag on Web
101
+ * Renders the text as a semantic heading. If a html heading tag is provided, uses that tag on Web.
102
+ *
103
+ * Does not affect styling: <Typography heading="h2"> will render a <h2> that looks like plain text.
104
+ * Use both `heading` and `variant` props to render semantic headings that look like headings.
105
+ *
106
+ * In native apps, if this is `true` or any html heading tag string and accessibilityRole prop
107
+ * is not defined, the accessibilityRole will default to "heading".
108
+ */
109
+ heading: _propTypes.default.oneOf([..._utils2.headingTags, true]),
110
+
111
+ /**
112
+ * Optional semantic HTML tag, to apply to the text on web. Does not change styling.
113
+ *
114
+ * `tag` and `heading` props set the same thing, so shouldn't be used together (`tag` overrides `heading`).
115
+ *
116
+ * In native apps, if a header tag is provided ("h1", "h2" etc) and accessibilityRole prop
117
+ * is not defined, the accessibilityRole will default to "heading".
102
118
  */
103
- heading: _propTypes.default.oneOf([true, 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']),
119
+ tag: _propTypes.default.oneOf(_utils2.textTags),
104
120
 
105
121
  /**
106
122
  * If true, forces the element to behave as a View block even if nested in other text
package/lib/index.js CHANGED
@@ -16,6 +16,7 @@ var _exportNames = {
16
16
  Feedback: true,
17
17
  Fieldset: true,
18
18
  FlexGrid: true,
19
+ HorizontalScroll: true,
19
20
  Icon: true,
20
21
  IconButton: true,
21
22
  InputLabel: true,
@@ -122,6 +123,12 @@ Object.defineProperty(exports, "FlexGrid", {
122
123
  return _FlexGrid.default;
123
124
  }
124
125
  });
126
+ Object.defineProperty(exports, "HorizontalScroll", {
127
+ enumerable: true,
128
+ get: function () {
129
+ return _HorizontalScroll.default;
130
+ }
131
+ });
125
132
  Object.defineProperty(exports, "Icon", {
126
133
  enumerable: true,
127
134
  get: function () {
@@ -367,6 +374,20 @@ var _Fieldset = _interopRequireDefault(require("./Fieldset"));
367
374
 
368
375
  var _FlexGrid = _interopRequireDefault(require("./FlexGrid"));
369
376
 
377
+ var _HorizontalScroll = _interopRequireWildcard(require("./HorizontalScroll"));
378
+
379
+ Object.keys(_HorizontalScroll).forEach(function (key) {
380
+ if (key === "default" || key === "__esModule") return;
381
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
382
+ if (key in exports && exports[key] === _HorizontalScroll[key]) return;
383
+ Object.defineProperty(exports, key, {
384
+ enumerable: true,
385
+ get: function () {
386
+ return _HorizontalScroll[key];
387
+ }
388
+ });
389
+ });
390
+
370
391
  var _Icon = _interopRequireWildcard(require("./Icon"));
371
392
 
372
393
  Object.keys(_Icon).forEach(function (key) {
@@ -15,4 +15,17 @@ Object.keys(_textSize).forEach(function (key) {
15
15
  return _textSize[key];
16
16
  }
17
17
  });
18
+ });
19
+
20
+ var _semantics = require("./semantics");
21
+
22
+ Object.keys(_semantics).forEach(function (key) {
23
+ if (key === "default" || key === "__esModule") return;
24
+ if (key in exports && exports[key] === _semantics[key]) return;
25
+ Object.defineProperty(exports, key, {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _semantics[key];
29
+ }
30
+ });
18
31
  });