@telus-uds/components-base 1.3.0 → 1.3.1

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 (342) hide show
  1. package/.turbo/turbo-build.log +5 -2
  2. package/CHANGELOG.json +38 -0
  3. package/CHANGELOG.md +15 -2
  4. package/__tests__/ActivityIndicator/ActivityIndicator.test.jsx +35 -0
  5. package/__tests__/ActivityIndicator/__snapshots__/ActivityIndicator.test.jsx.snap +287 -0
  6. package/babel.config.js +27 -5
  7. package/component-docs.json +88 -424
  8. package/lib/A11yText/index.js +5 -4
  9. package/lib/ActivityIndicator/Spinner.js +46 -37
  10. package/lib/ActivityIndicator/Spinner.native.js +26 -15
  11. package/lib/Box/Box.js +4 -4
  12. package/lib/Button/ButtonBase.js +7 -8
  13. package/lib/Card/Card.js +5 -4
  14. package/lib/Card/PressableCardBase.js +6 -11
  15. package/lib/Checkbox/Checkbox.js +4 -6
  16. package/lib/Divider/Divider.js +12 -11
  17. package/lib/ExpandCollapse/Control.js +7 -7
  18. package/lib/ExpandCollapse/ExpandCollapse.js +6 -2
  19. package/lib/ExpandCollapse/Panel.js +6 -7
  20. package/lib/Feedback/Feedback.js +6 -5
  21. package/lib/Fieldset/Fieldset.js +1 -3
  22. package/lib/HorizontalScroll/HorizontalScroll.js +5 -6
  23. package/lib/IconButton/IconButton.js +6 -6
  24. package/lib/InputLabel/InputLabel.js +7 -2
  25. package/lib/InputSupports/InputSupports.js +2 -2
  26. package/lib/Link/LinkBase.js +5 -6
  27. package/lib/List/List.js +4 -6
  28. package/lib/List/ListItem.js +6 -2
  29. package/lib/Modal/Modal.js +6 -2
  30. package/lib/Notification/Notification.js +7 -2
  31. package/lib/Pagination/Pagination.js +8 -3
  32. package/lib/Progress/Progress.js +5 -4
  33. package/lib/Progress/ProgressBar.js +8 -7
  34. package/lib/Radio/Radio.js +4 -6
  35. package/lib/Radio/RadioButton.js +6 -3
  36. package/lib/Radio/RadioGroup.js +7 -2
  37. package/lib/RadioCard/RadioCard.js +4 -4
  38. package/lib/RadioCard/RadioCardGroup.js +9 -6
  39. package/lib/Search/Search.js +7 -2
  40. package/lib/Select/Select.js +10 -9
  41. package/lib/SideNav/Item.js +7 -7
  42. package/lib/SideNav/SideNav.js +7 -3
  43. package/lib/Skeleton/Skeleton.js +6 -2
  44. package/lib/Spacer/Spacer.js +7 -18
  45. package/lib/StackView/StackView.js +7 -7
  46. package/lib/StackView/StackWrapBox.js +6 -7
  47. package/lib/StackView/StackWrapGap.js +6 -5
  48. package/lib/StepTracker/Step.js +7 -3
  49. package/lib/StepTracker/StepTracker.js +7 -7
  50. package/lib/Tabs/Tabs.js +6 -2
  51. package/lib/Tabs/TabsItem.js +6 -5
  52. package/lib/Tags/Tags.js +5 -6
  53. package/lib/TextInput/TextArea.js +13 -14
  54. package/lib/TextInput/TextInput.js +13 -14
  55. package/lib/TextInput/TextInputBase.js +5 -3
  56. package/lib/ToggleSwitch/ToggleSwitch.js +10 -9
  57. package/lib/ToggleSwitch/ToggleSwitchGroup.js +5 -7
  58. package/lib/Tooltip/Tooltip.js +7 -2
  59. package/lib/TooltipButton/TooltipButton.js +7 -2
  60. package/lib/Typography/Typography.js +8 -6
  61. package/lib/index.js +7 -0
  62. package/lib/utils/children.js +5 -1
  63. package/lib/utils/index.js +14 -0
  64. package/lib/utils/props/index.js +9 -0
  65. package/lib/{InputSupports/propTypes.js → utils/props/inputSupportsProps.js} +2 -3
  66. package/lib/utils/ssr.js +51 -0
  67. package/lib-module/A11yInfoProvider/index.js +62 -0
  68. package/lib-module/A11yText/index.js +55 -0
  69. package/lib-module/ActivityIndicator/Spinner.js +76 -0
  70. package/lib-module/ActivityIndicator/Spinner.native.js +143 -0
  71. package/lib-module/ActivityIndicator/index.js +40 -0
  72. package/lib-module/ActivityIndicator/shared.js +12 -0
  73. package/lib-module/BaseProvider/index.js +26 -0
  74. package/lib-module/Box/Box.js +243 -0
  75. package/lib-module/Box/index.js +2 -0
  76. package/lib-module/Button/Button.js +25 -0
  77. package/lib-module/Button/ButtonBase.js +254 -0
  78. package/lib-module/Button/ButtonGroup.js +164 -0
  79. package/lib-module/Button/ButtonLink.js +39 -0
  80. package/lib-module/Button/index.js +4 -0
  81. package/lib-module/Button/propTypes.js +36 -0
  82. package/lib-module/Card/Card.js +83 -0
  83. package/lib-module/Card/CardBase.js +62 -0
  84. package/lib-module/Card/PressableCardBase.js +113 -0
  85. package/lib-module/Card/index.js +4 -0
  86. package/lib-module/Checkbox/Checkbox.js +321 -0
  87. package/lib-module/Checkbox/CheckboxGroup.js +218 -0
  88. package/lib-module/Checkbox/CheckboxInput.js +58 -0
  89. package/lib-module/Checkbox/CheckboxInput.native.js +6 -0
  90. package/lib-module/Checkbox/index.js +3 -0
  91. package/lib-module/Divider/Divider.js +123 -0
  92. package/lib-module/Divider/index.js +2 -0
  93. package/lib-module/ExpandCollapse/Accordion.js +15 -0
  94. package/lib-module/ExpandCollapse/Control.js +130 -0
  95. package/lib-module/ExpandCollapse/ExpandCollapse.js +94 -0
  96. package/lib-module/ExpandCollapse/Panel.js +158 -0
  97. package/lib-module/ExpandCollapse/index.js +7 -0
  98. package/lib-module/Feedback/Feedback.js +144 -0
  99. package/lib-module/Feedback/index.js +2 -0
  100. package/lib-module/Fieldset/Fieldset.js +145 -0
  101. package/lib-module/Fieldset/FieldsetContainer.js +29 -0
  102. package/lib-module/Fieldset/FieldsetContainer.native.js +20 -0
  103. package/lib-module/Fieldset/Legend.js +21 -0
  104. package/lib-module/Fieldset/Legend.native.js +28 -0
  105. package/lib-module/Fieldset/cssReset.js +14 -0
  106. package/lib-module/Fieldset/index.js +2 -0
  107. package/lib-module/FlexGrid/Col/Col.js +265 -0
  108. package/lib-module/FlexGrid/Col/index.js +2 -0
  109. package/lib-module/FlexGrid/FlexGrid.js +147 -0
  110. package/lib-module/FlexGrid/Row/Row.js +177 -0
  111. package/lib-module/FlexGrid/Row/index.js +2 -0
  112. package/lib-module/FlexGrid/helpers/index.js +18 -0
  113. package/lib-module/FlexGrid/index.js +2 -0
  114. package/lib-module/FlexGrid/providers/GutterContext.js +3 -0
  115. package/lib-module/HorizontalScroll/HorizontalScroll.js +171 -0
  116. package/lib-module/HorizontalScroll/HorizontalScrollButton.js +102 -0
  117. package/lib-module/HorizontalScroll/ScrollViewEnd.js +47 -0
  118. package/lib-module/HorizontalScroll/ScrollViewEnd.native.js +24 -0
  119. package/lib-module/HorizontalScroll/dictionary.js +11 -0
  120. package/lib-module/HorizontalScroll/index.js +11 -0
  121. package/lib-module/HorizontalScroll/itemPositions.js +106 -0
  122. package/lib-module/Icon/Icon.js +61 -0
  123. package/lib-module/Icon/IconText.js +81 -0
  124. package/lib-module/Icon/index.js +4 -0
  125. package/lib-module/IconButton/IconButton.js +115 -0
  126. package/lib-module/IconButton/index.js +2 -0
  127. package/lib-module/InputLabel/InputLabel.js +131 -0
  128. package/lib-module/InputLabel/LabelContent.js +24 -0
  129. package/lib-module/InputLabel/LabelContent.native.js +16 -0
  130. package/lib-module/InputLabel/index.js +2 -0
  131. package/lib-module/InputSupports/InputSupports.js +88 -0
  132. package/lib-module/InputSupports/index.js +2 -0
  133. package/lib-module/InputSupports/useInputSupports.js +31 -0
  134. package/lib-module/Link/ChevronLink.js +51 -0
  135. package/lib-module/Link/InlinePressable.js +37 -0
  136. package/lib-module/Link/InlinePressable.native.js +85 -0
  137. package/lib-module/Link/Link.js +27 -0
  138. package/lib-module/Link/LinkBase.js +210 -0
  139. package/lib-module/Link/TextButton.js +43 -0
  140. package/lib-module/Link/index.js +5 -0
  141. package/lib-module/List/List.js +55 -0
  142. package/lib-module/List/ListItem.js +213 -0
  143. package/lib-module/List/index.js +5 -0
  144. package/lib-module/Modal/Modal.js +208 -0
  145. package/lib-module/Modal/dictionary.js +9 -0
  146. package/lib-module/Modal/index.js +2 -0
  147. package/lib-module/Notification/Notification.js +196 -0
  148. package/lib-module/Notification/dictionary.js +8 -0
  149. package/lib-module/Notification/index.js +2 -0
  150. package/lib-module/Pagination/PageButton.js +65 -0
  151. package/lib-module/Pagination/Pagination.js +140 -0
  152. package/lib-module/Pagination/SideButton.js +103 -0
  153. package/lib-module/Pagination/dictionary.js +18 -0
  154. package/lib-module/Pagination/index.js +2 -0
  155. package/lib-module/Pagination/usePagination.js +72 -0
  156. package/lib-module/Progress/Progress.js +85 -0
  157. package/lib-module/Progress/ProgressBar.js +134 -0
  158. package/lib-module/Progress/ProgressBarBackground.js +41 -0
  159. package/lib-module/Progress/index.js +4 -0
  160. package/lib-module/Radio/Radio.js +263 -0
  161. package/lib-module/Radio/RadioButton.js +128 -0
  162. package/lib-module/Radio/RadioGroup.js +225 -0
  163. package/lib-module/Radio/RadioInput.js +60 -0
  164. package/lib-module/Radio/RadioInput.native.js +6 -0
  165. package/lib-module/Radio/index.js +3 -0
  166. package/lib-module/RadioCard/RadioCard.js +218 -0
  167. package/lib-module/RadioCard/RadioCardGroup.js +232 -0
  168. package/lib-module/RadioCard/index.js +3 -0
  169. package/lib-module/Search/Search.js +233 -0
  170. package/lib-module/Search/dictionary.js +12 -0
  171. package/lib-module/Search/index.js +2 -0
  172. package/lib-module/Select/Group.js +20 -0
  173. package/lib-module/Select/Group.native.js +14 -0
  174. package/lib-module/Select/Item.js +17 -0
  175. package/lib-module/Select/Item.native.js +9 -0
  176. package/lib-module/Select/Picker.js +67 -0
  177. package/lib-module/Select/Picker.native.js +110 -0
  178. package/lib-module/Select/Select.js +317 -0
  179. package/lib-module/Select/index.js +6 -0
  180. package/lib-module/SideNav/Item.js +139 -0
  181. package/lib-module/SideNav/ItemContent.js +45 -0
  182. package/lib-module/SideNav/ItemsGroup.js +115 -0
  183. package/lib-module/SideNav/SideNav.js +133 -0
  184. package/lib-module/SideNav/index.js +1 -0
  185. package/lib-module/Skeleton/Skeleton.js +117 -0
  186. package/lib-module/Skeleton/index.js +2 -0
  187. package/lib-module/Skeleton/skeleton.constant.js +3 -0
  188. package/lib-module/Skeleton/skeletonWebAnimation.js +18 -0
  189. package/lib-module/Skeleton/useSkeletonNativeAnimation.js +24 -0
  190. package/lib-module/Spacer/Spacer.js +97 -0
  191. package/lib-module/Spacer/index.js +2 -0
  192. package/lib-module/StackView/StackView.js +124 -0
  193. package/lib-module/StackView/StackWrap.js +48 -0
  194. package/lib-module/StackView/StackWrap.native.js +3 -0
  195. package/lib-module/StackView/StackWrapBox.js +114 -0
  196. package/lib-module/StackView/StackWrapGap.js +58 -0
  197. package/lib-module/StackView/common.js +32 -0
  198. package/lib-module/StackView/getStackedContent.js +123 -0
  199. package/lib-module/StackView/index.js +5 -0
  200. package/lib-module/StepTracker/Step.js +229 -0
  201. package/lib-module/StepTracker/StepTracker.js +175 -0
  202. package/lib-module/StepTracker/dictionary.js +10 -0
  203. package/lib-module/StepTracker/index.js +2 -0
  204. package/lib-module/Tabs/Tabs.js +113 -0
  205. package/lib-module/Tabs/TabsItem.js +215 -0
  206. package/lib-module/Tabs/index.js +2 -0
  207. package/lib-module/Tags/Tags.js +238 -0
  208. package/lib-module/Tags/index.js +2 -0
  209. package/lib-module/TextInput/TextArea.js +88 -0
  210. package/lib-module/TextInput/TextInput.js +60 -0
  211. package/lib-module/TextInput/TextInputBase.js +233 -0
  212. package/lib-module/TextInput/index.js +3 -0
  213. package/lib-module/TextInput/propTypes.js +31 -0
  214. package/lib-module/ThemeProvider/ThemeProvider.js +35 -0
  215. package/lib-module/ThemeProvider/index.js +6 -0
  216. package/lib-module/ThemeProvider/useSetTheme.js +22 -0
  217. package/lib-module/ThemeProvider/useTheme.js +14 -0
  218. package/lib-module/ThemeProvider/useThemeTokens.js +105 -0
  219. package/lib-module/ThemeProvider/utils/index.js +2 -0
  220. package/lib-module/ThemeProvider/utils/styles.js +174 -0
  221. package/lib-module/ThemeProvider/utils/theme-tokens.js +151 -0
  222. package/lib-module/ToggleSwitch/ToggleSwitch.js +224 -0
  223. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +202 -0
  224. package/lib-module/ToggleSwitch/index.js +3 -0
  225. package/lib-module/Tooltip/Backdrop.js +52 -0
  226. package/lib-module/Tooltip/Backdrop.native.js +43 -0
  227. package/lib-module/Tooltip/Tooltip.js +332 -0
  228. package/lib-module/Tooltip/dictionary.js +8 -0
  229. package/lib-module/Tooltip/getTooltipPosition.js +164 -0
  230. package/lib-module/Tooltip/index.js +2 -0
  231. package/lib-module/TooltipButton/TooltipButton.js +71 -0
  232. package/lib-module/TooltipButton/index.js +2 -0
  233. package/lib-module/Typography/Typography.js +118 -0
  234. package/lib-module/Typography/index.js +2 -0
  235. package/lib-module/ViewportProvider/ViewportProvider.js +28 -0
  236. package/lib-module/ViewportProvider/index.js +3 -0
  237. package/lib-module/ViewportProvider/useViewport.js +3 -0
  238. package/lib-module/ViewportProvider/useViewportListener.js +43 -0
  239. package/lib-module/index.js +48 -0
  240. package/lib-module/utils/a11y/index.js +2 -0
  241. package/lib-module/utils/a11y/semantics.js +154 -0
  242. package/lib-module/utils/a11y/textSize.js +34 -0
  243. package/lib-module/utils/animation/index.js +2 -0
  244. package/lib-module/utils/animation/useVerticalExpandAnimation.js +49 -0
  245. package/lib-module/utils/children.js +118 -0
  246. package/lib-module/utils/index.js +15 -0
  247. package/lib-module/utils/info/index.js +7 -0
  248. package/lib-module/utils/info/platform/index.js +11 -0
  249. package/lib-module/utils/info/platform/platform.android.js +1 -0
  250. package/lib-module/utils/info/platform/platform.ios.js +1 -0
  251. package/lib-module/utils/info/platform/platform.js +1 -0
  252. package/lib-module/utils/info/platform/platform.native.js +4 -0
  253. package/lib-module/utils/info/versions.js +5 -0
  254. package/lib-module/utils/input.js +180 -0
  255. package/lib-module/utils/pressability.js +97 -0
  256. package/lib-module/utils/props/a11yProps.js +140 -0
  257. package/lib-module/utils/props/clickProps.js +25 -0
  258. package/lib-module/utils/props/componentPropType.js +63 -0
  259. package/lib-module/utils/props/copyPropTypes.js +2 -0
  260. package/lib-module/utils/props/getPropSelector.js +6 -0
  261. package/lib-module/utils/props/hrefAttrsProp.js +30 -0
  262. package/lib-module/utils/props/index.js +16 -0
  263. package/lib-module/utils/props/inputSupportsProps.js +54 -0
  264. package/lib-module/utils/props/linkProps.js +47 -0
  265. package/lib-module/utils/props/paddingProp.js +9 -0
  266. package/lib-module/utils/props/pressProps.js +42 -0
  267. package/lib-module/utils/props/rectProp.js +9 -0
  268. package/lib-module/utils/props/responsiveProps.js +30 -0
  269. package/lib-module/utils/props/selectSystemProps.js +24 -0
  270. package/lib-module/utils/props/spacingProps.js +56 -0
  271. package/lib-module/utils/props/tokens.js +120 -0
  272. package/lib-module/utils/props/variantProp.js +18 -0
  273. package/lib-module/utils/props/viewProps.js +22 -0
  274. package/lib-module/utils/ssr.js +35 -0
  275. package/lib-module/utils/useCopy.js +42 -0
  276. package/lib-module/utils/useHash.js +44 -0
  277. package/lib-module/utils/useHash.native.js +7 -0
  278. package/lib-module/utils/useResponsiveProp.js +47 -0
  279. package/lib-module/utils/useSpacingScale.js +123 -0
  280. package/lib-module/utils/useUniqueId.js +12 -0
  281. package/lib-module/utils/withLinkRouter.js +82 -0
  282. package/package.json +9 -5
  283. package/src/A11yText/index.jsx +7 -3
  284. package/src/ActivityIndicator/Spinner.jsx +56 -44
  285. package/src/ActivityIndicator/Spinner.native.jsx +20 -12
  286. package/src/Box/Box.jsx +10 -9
  287. package/src/Button/ButtonBase.jsx +9 -8
  288. package/src/Card/Card.jsx +7 -4
  289. package/src/Card/PressableCardBase.jsx +12 -12
  290. package/src/Checkbox/Checkbox.jsx +12 -5
  291. package/src/Divider/Divider.jsx +17 -10
  292. package/src/ExpandCollapse/Control.jsx +12 -7
  293. package/src/ExpandCollapse/ExpandCollapse.jsx +13 -3
  294. package/src/ExpandCollapse/Panel.jsx +15 -5
  295. package/src/Feedback/Feedback.jsx +13 -3
  296. package/src/Fieldset/Fieldset.jsx +1 -1
  297. package/src/HorizontalScroll/HorizontalScroll.jsx +12 -5
  298. package/src/IconButton/IconButton.jsx +12 -8
  299. package/src/InputLabel/InputLabel.jsx +16 -2
  300. package/src/InputSupports/InputSupports.jsx +1 -1
  301. package/src/Link/LinkBase.jsx +10 -9
  302. package/src/List/List.jsx +12 -5
  303. package/src/List/ListItem.jsx +16 -2
  304. package/src/Modal/Modal.jsx +63 -50
  305. package/src/Notification/Notification.jsx +17 -3
  306. package/src/Pagination/Pagination.jsx +10 -3
  307. package/src/Progress/Progress.jsx +5 -3
  308. package/src/Progress/ProgressBar.jsx +8 -6
  309. package/src/Radio/Radio.jsx +13 -5
  310. package/src/Radio/RadioButton.jsx +13 -3
  311. package/src/Radio/RadioGroup.jsx +14 -2
  312. package/src/RadioCard/RadioCard.jsx +9 -6
  313. package/src/RadioCard/RadioCardGroup.jsx +16 -4
  314. package/src/Search/Search.jsx +15 -3
  315. package/src/Select/Select.jsx +21 -7
  316. package/src/SideNav/Item.jsx +15 -7
  317. package/src/SideNav/SideNav.jsx +13 -2
  318. package/src/Skeleton/Skeleton.jsx +55 -43
  319. package/src/Spacer/Spacer.jsx +8 -16
  320. package/src/StackView/StackView.jsx +13 -12
  321. package/src/StackView/StackWrapBox.jsx +12 -12
  322. package/src/StackView/StackWrapGap.jsx +9 -7
  323. package/src/StepTracker/Step.jsx +7 -4
  324. package/src/StepTracker/StepTracker.jsx +8 -8
  325. package/src/Tabs/Tabs.jsx +16 -3
  326. package/src/Tabs/TabsItem.jsx +13 -9
  327. package/src/Tags/Tags.jsx +20 -5
  328. package/src/TextInput/TextArea.jsx +20 -8
  329. package/src/TextInput/TextInput.jsx +20 -8
  330. package/src/TextInput/TextInputBase.jsx +13 -3
  331. package/src/ToggleSwitch/ToggleSwitch.jsx +16 -5
  332. package/src/ToggleSwitch/ToggleSwitchGroup.jsx +14 -6
  333. package/src/Tooltip/Tooltip.jsx +13 -3
  334. package/src/TooltipButton/TooltipButton.jsx +6 -4
  335. package/src/Typography/Typography.jsx +10 -6
  336. package/src/index.js +1 -1
  337. package/src/utils/children.jsx +2 -1
  338. package/src/utils/index.js +1 -0
  339. package/src/utils/props/index.js +1 -0
  340. package/src/{InputSupports/propTypes.js → utils/props/inputSupportsProps.js} +2 -4
  341. package/src/utils/ssr.js +35 -0
  342. package/release-context.json +0 -7
@@ -0,0 +1,224 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Platform from "react-native-web/dist/exports/Platform";
4
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
5
+ import View from "react-native-web/dist/exports/View";
6
+ import InputLabel from '../InputLabel';
7
+ import ButtonBase from '../Button/ButtonBase';
8
+ import StackView from '../StackView';
9
+ import { useThemeTokensCallback, applyShadowToken } from '../ThemeProvider';
10
+ import { a11yProps, getTokensPropType, selectTokens, pressProps, selectSystemProps, useUniqueId, variantProp, viewProps } from '../utils';
11
+ import { useInputValue } from '../utils/input';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, pressProps, viewProps]);
15
+
16
+ const selectButtonTokens = tokens => selectTokens('Button', { ...tokens,
17
+ // Width tokens are applied to our inner track. Disable Button width token so it wraps our track width.
18
+ width: null
19
+ }); // Map and rename icon-specific tokens to name used within Icon
20
+
21
+
22
+ const selectIconTokens = ({
23
+ iconSize,
24
+ iconColor
25
+ }) => ({
26
+ size: iconSize,
27
+ color: iconColor
28
+ });
29
+
30
+ const selectTrackStyles = ({
31
+ trackBorderWidth,
32
+ trackBorderColor,
33
+ trackBorderRadius,
34
+ width
35
+ }) => ({
36
+ borderWidth: trackBorderWidth,
37
+ borderColor: trackBorderColor,
38
+ borderRadius: trackBorderRadius,
39
+ width
40
+ });
41
+
42
+ const selectSwitchStyles = ({
43
+ switchSize,
44
+ switchColor,
45
+ switchBorderWidth,
46
+ switchBorderColor,
47
+ switchBorderRadius,
48
+ switchShadow
49
+ }) => ({
50
+ width: switchSize,
51
+ height: switchSize,
52
+ backgroundColor: switchColor,
53
+ borderWidth: switchBorderWidth,
54
+ borderColor: switchBorderColor,
55
+ borderRadius: switchBorderRadius,
56
+ ...applyShadowToken(switchShadow),
57
+ ...Platform.select({
58
+ // TODO: https://github.com/telus/universal-design-system/issues/487
59
+ web: {
60
+ transition: 'transform 200ms'
61
+ }
62
+ })
63
+ });
64
+
65
+ const selectLabelStyles = ({
66
+ labelMarginLeft
67
+ }) => ({
68
+ marginLeft: labelMarginLeft
69
+ });
70
+
71
+ const selectLabelTokens = ({
72
+ labelColor,
73
+ labelFontName,
74
+ labelFontSize,
75
+ labelFontWeight,
76
+ labelLineHeight
77
+ }) => ({
78
+ color: labelColor,
79
+ fontName: labelFontName,
80
+ fontWeight: labelFontWeight,
81
+ fontSize: labelFontSize,
82
+ lineHeight: labelLineHeight
83
+ });
84
+
85
+ const ToggleSwitch = /*#__PURE__*/forwardRef(({
86
+ value,
87
+ initialValue,
88
+ onChange,
89
+ id,
90
+ label,
91
+ inactive,
92
+ tokens,
93
+ tooltip,
94
+ variant,
95
+ accessibilityRole = 'switch',
96
+ accessibilityLabel = label,
97
+ ...rest
98
+ }, ref) => {
99
+ const getTokens = useThemeTokensCallback('ToggleSwitch', tokens, variant);
100
+ const themeTokens = getTokens();
101
+ const {
102
+ currentValue,
103
+ setValue
104
+ } = useInputValue({
105
+ value,
106
+ initialValue,
107
+ onChange
108
+ });
109
+
110
+ const handlePress = event => setValue(!currentValue, event);
111
+
112
+ const getButtonTokens = buttonState => selectButtonTokens(getTokens(buttonState));
113
+
114
+ const uniqueId = useUniqueId('toggleSwitch');
115
+ const inputId = id ?? uniqueId;
116
+ return /*#__PURE__*/_jsxs(StackView, {
117
+ space: 2,
118
+ direction: "row",
119
+ children: [Boolean(label) && /*#__PURE__*/_jsx(View, {
120
+ style: selectLabelStyles(themeTokens),
121
+ children: /*#__PURE__*/_jsx(InputLabel, {
122
+ forId: inputId,
123
+ label: label,
124
+ tokens: selectLabelTokens(themeTokens),
125
+ tooltip: tooltip
126
+ })
127
+ }), /*#__PURE__*/_jsx(ButtonBase, {
128
+ id: id,
129
+ ref: ref,
130
+ selected: currentValue,
131
+ inactive: inactive,
132
+ tokens: getButtonTokens,
133
+ accessibilityLabel: accessibilityLabel,
134
+ accessibilityRole: accessibilityRole,
135
+ accessibilityState: {
136
+ checked: currentValue
137
+ },
138
+ onPress: handlePress,
139
+ ...selectProps(rest),
140
+ children: buttonState => {
141
+ const stateTokens = getTokens(buttonState);
142
+ const IconComponent = stateTokens.icon;
143
+ const switchStyles = selectSwitchStyles(stateTokens);
144
+ const trackStyles = selectTrackStyles(stateTokens);
145
+ const iconTokens = selectIconTokens(stateTokens); // If drag-slide support is needed, use a PanResponder and apply these to an Animated value.
146
+ // Use translate transforms for smoothest non-thread-blocking animations and to allow drag.
147
+
148
+ const slideStart = 0;
149
+ const slideEnd = stateTokens.width - stateTokens.switchSize - stateTokens.trackBorderWidth * 2;
150
+ const switchOffset = buttonState.selected ? slideEnd : slideStart;
151
+ const switchPositionStyle = {
152
+ transform: [{
153
+ translateX: switchOffset
154
+ }]
155
+ };
156
+ return /*#__PURE__*/_jsx(View, {
157
+ style: [staticStyles.track, trackStyles],
158
+ children: /*#__PURE__*/_jsx(View, {
159
+ style: [staticStyles.switch, switchStyles, switchPositionStyle],
160
+ children: IconComponent && /*#__PURE__*/_jsx(IconComponent, { ...iconTokens
161
+ })
162
+ })
163
+ });
164
+ }
165
+ })]
166
+ });
167
+ });
168
+ ToggleSwitch.displayName = 'ToggleSwitch';
169
+ ToggleSwitch.propTypes = { ...selectedSystemPropTypes,
170
+ tokens: getTokensPropType('ToggleSwitch'),
171
+ variant: variantProp.propType,
172
+
173
+ /**
174
+ * If this is a "controlled" component and a parent handles its selected state,
175
+ * tells the switch if it is on (true) or off (false).
176
+ */
177
+ value: PropTypes.bool,
178
+
179
+ /**
180
+ * If this is an "uncontrolled" component that handles its own selected state,
181
+ * optionally tells the switch if it should default to on (true) or off (false).
182
+ */
183
+ initialValue: PropTypes.bool,
184
+
185
+ /**
186
+ * Function called when the switch is toggled, with one boolean argument that is the
187
+ * new position of the switch, on (true) or off (false). For "controlled" components,
188
+ * this should always be passed and used to control the state of the switch.
189
+ */
190
+ onChange: PropTypes.func,
191
+
192
+ /**
193
+ * Input ID.
194
+ */
195
+ id: PropTypes.string,
196
+
197
+ /**
198
+ * An optional label.
199
+ */
200
+ label: PropTypes.string,
201
+
202
+ /**
203
+ * If passed, the switch does not respond to user input and may recieve different
204
+ * theme tokens if the theme supports inactive appearance.
205
+ */
206
+ inactive: PropTypes.bool,
207
+
208
+ /**
209
+ * Content of an optional Tooltip. If set, a tooltip button will be shown next to the label.
210
+ */
211
+ tooltip: PropTypes.string
212
+ };
213
+ const staticStyles = StyleSheet.create({
214
+ track: {
215
+ flexGrow: 1,
216
+ alignSelf: 'stretch',
217
+ flexDirection: 'row'
218
+ },
219
+ switch: {
220
+ alignItems: 'center',
221
+ justifyContent: 'center'
222
+ }
223
+ });
224
+ export default ToggleSwitch;
@@ -0,0 +1,202 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ABBPropTypes from 'airbnb-prop-types';
4
+ import Platform from "react-native-web/dist/exports/Platform";
5
+ import ToggleSwitch from './ToggleSwitch';
6
+ import Fieldset from '../Fieldset';
7
+ import { getStackedContent } from '../StackView';
8
+ import { useViewport } from '../ViewportProvider';
9
+ import { useThemeTokens } from '../ThemeProvider';
10
+ import { a11yProps, getTokensPropType, pressProps, selectSystemProps, variantProp, viewProps } from '../utils/props';
11
+ import { useMultipleInputValues } from '../utils/input';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, pressProps, viewProps]);
14
+ const ToggleSwitchGroup = /*#__PURE__*/forwardRef(({
15
+ variant,
16
+ tokens,
17
+ items = [],
18
+ values,
19
+ initialValues,
20
+ maxValues = 1,
21
+ onChange,
22
+ readOnly = false,
23
+ inactive = false,
24
+ feedback,
25
+ hint,
26
+ tooltip,
27
+ legend,
28
+ name: inputGroupName,
29
+ accessibilityRole = maxValues === 1 ? 'radiogroup' // radiogroup is cross-platform; only web aria has generic groups
30
+ : Platform.select({
31
+ web: 'group',
32
+ default: 'none'
33
+ }),
34
+ toggleSwitchTokens,
35
+ validation,
36
+ ...rest
37
+ }, ref) => {
38
+ const viewport = useViewport();
39
+ const {
40
+ space,
41
+ fieldSpace
42
+ } = useThemeTokens('ToggleSwitchGroup', tokens, variant, {
43
+ viewport
44
+ });
45
+ const {
46
+ currentValues,
47
+ toggleOneValue
48
+ } = useMultipleInputValues({
49
+ initialValues,
50
+ values,
51
+ maxValues,
52
+ onChange,
53
+ readOnly
54
+ });
55
+ const selectedProps = selectProps({
56
+ accessibilityRole,
57
+ ...rest
58
+ });
59
+ const itemA11yRole = selectedProps.accessibilityRole === 'radiogroup' ? 'radio' : 'switch';
60
+ const toggleSwitches = items.map(({
61
+ label,
62
+ id = label,
63
+ accessibilityLabel = label,
64
+ onChange: itemOnChange,
65
+ ref: itemRef,
66
+ tooltip: itemTooltip
67
+ }, index) => {
68
+ const isSelected = currentValues.includes(id);
69
+
70
+ const handleChange = (newCheckedState, event) => {
71
+ if (typeof itemOnChange === 'function') itemOnChange(newCheckedState, event);
72
+ toggleOneValue(id, event);
73
+ };
74
+
75
+ const itemA11y = {
76
+ accessibilityState: {
77
+ checked: isSelected
78
+ },
79
+ accessibilityRole: itemA11yRole,
80
+ accessibilityLabel,
81
+ ...a11yProps.getPositionInSet(items.length, index)
82
+ };
83
+ return /*#__PURE__*/_jsx(ToggleSwitch, {
84
+ id: id,
85
+ ref: itemRef,
86
+ onChange: handleChange,
87
+ tokens: toggleSwitchTokens,
88
+ value: isSelected,
89
+ inactive: inactive,
90
+ label: label,
91
+ tooltip: itemTooltip,
92
+ ...itemA11y
93
+ }, id);
94
+ });
95
+ return /*#__PURE__*/_jsx(Fieldset, {
96
+ ref: ref,
97
+ name: inputGroupName,
98
+ legend: legend,
99
+ tooltip: tooltip,
100
+ hint: hint,
101
+ space: fieldSpace,
102
+ feedback: feedback,
103
+ inactive: inactive,
104
+ validation: validation,
105
+ ...selectedProps,
106
+ children: getStackedContent(toggleSwitches, {
107
+ space,
108
+ direction: 'column'
109
+ })
110
+ });
111
+ });
112
+ ToggleSwitchGroup.displayName = 'ToggleSwitchGroup';
113
+ ToggleSwitchGroup.propTypes = { ...selectedSystemPropTypes,
114
+ tokens: getTokensPropType('ToggleSwitchGroup'),
115
+ variant: variantProp.propType,
116
+
117
+ /**
118
+ * The maximum number of items a user may select at once. Defaults to 1 and behaves
119
+ * like radio buttons. To have no limit and allow any number of selections, pass `null`.
120
+ */
121
+ maxValues: PropTypes.number,
122
+
123
+ /**
124
+ * The options a user may select
125
+ */
126
+ items: PropTypes.arrayOf(PropTypes.shape({
127
+ /**
128
+ * The text displayed to the user on the label.
129
+ */
130
+ label: PropTypes.string.isRequired,
131
+
132
+ /**
133
+ * An optional accessibility label may be passed to each ToggleSwitch
134
+ * and will be applied as normal for a React Native accessibilityLabel prop.
135
+ */
136
+ accessibilityLabel: PropTypes.string,
137
+
138
+ /**
139
+ * An optional unique string may be provided to identify this option,
140
+ * which will be used in code and passed to any onChange function.
141
+ * If not provided, the label is used.
142
+ */
143
+ id: PropTypes.string,
144
+
145
+ /**
146
+ * An optional ref for one individual ToggleSwitch in the ToggleSwitchGroup
147
+ */
148
+ ref: ABBPropTypes.ref()
149
+ })),
150
+
151
+ /**
152
+ * If provided, this function is called when the current selection is changed
153
+ * and is passed an array of the `id`s of all currently selected `items`.
154
+ */
155
+ onChange: PropTypes.func,
156
+
157
+ /**
158
+ * If the selected item(s) in the toggle switch group are to be controlled externally by
159
+ * a parent component, pass an array of strings as well as an `onChange` handler.
160
+ * Passing an array for "values" makes the ToggleSwitchGroup a "controlled" component that
161
+ * expects its state to be handled via `onChange` and so doesn't handle it itself.
162
+ */
163
+ values: PropTypes.arrayOf(PropTypes.string),
164
+
165
+ /**
166
+ * If `values` is not passed, making the ToggleSwitchGroup an "uncontrolled" component
167
+ * managing its own selected state, a default set of selections may be provided.
168
+ * Changing the `initialValues` does not change the user's selections.
169
+ */
170
+ initialValues: PropTypes.arrayOf(PropTypes.string),
171
+
172
+ /**
173
+ * Optional additional text giving more detail to help a user make a choice.
174
+ */
175
+ hint: PropTypes.string,
176
+
177
+ /**
178
+ * Optional tooltip text content to include alongside the legend and hint.
179
+ */
180
+ tooltip: PropTypes.string,
181
+
182
+ /**
183
+ * If provided, a Feedback element is rendered containing this text.
184
+ */
185
+ feedback: PropTypes.string,
186
+
187
+ /**
188
+ * Main text used to describe this group, used in Fieldset's Legend element.
189
+ */
190
+ legend: PropTypes.string,
191
+
192
+ /**
193
+ * Toggle switch token overrides.
194
+ */
195
+ toggleSwitchTokens: getTokensPropType('ToggleSwitch'),
196
+
197
+ /**
198
+ * Current validation status of the group, passed to the feedback element if there is one.
199
+ */
200
+ validation: PropTypes.oneOf(['error', 'success'])
201
+ };
202
+ export default ToggleSwitchGroup;
@@ -0,0 +1,3 @@
1
+ import ToggleSwitch from './ToggleSwitch';
2
+ import ToggleSwitchGroup from './ToggleSwitchGroup';
3
+ export { ToggleSwitch, ToggleSwitchGroup };
@@ -0,0 +1,52 @@
1
+ import { useEffect, useState } from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import PropTypes from 'prop-types';
4
+
5
+ function createPortalNode(nodeId) {
6
+ const node = document.createElement('div');
7
+ node.id = nodeId; // we're mimicking React Native's Modal component, except for using an `absolute` position
8
+ // this way the backdrop stays in place when scrolling the window - that's why we need to
9
+ // position it at the scroll position when rendering
10
+
11
+ node.style.cssText = `
12
+ position: absolute;
13
+ top: ${window.scrollY}px;
14
+ left: ${window.scrollX}px;
15
+ right: 0;
16
+ bottom: 0;
17
+ z-index: 9999;
18
+ pointer-events: none;
19
+ `;
20
+ document.body.appendChild(node);
21
+ return node;
22
+ }
23
+
24
+ function removePortalNode(nodeId) {
25
+ const node = document.getElementById(nodeId);
26
+ node.parentElement.removeChild(node);
27
+ }
28
+ /**
29
+ * The Web version of Backdrop utilizes React Portal for overlaying page content, so it is
30
+ * dependent on ReactDOM. Tooltip's closing is handled by the onBlur callback of the control.
31
+ */
32
+
33
+
34
+ function Backdrop({
35
+ children
36
+ }) {
37
+ const [portalNode, setPortalNode] = useState();
38
+ useEffect(() => {
39
+ const nodeId = `tooltip-backdrop-${Date.now()}`;
40
+ const node = createPortalNode(nodeId);
41
+ setPortalNode(node);
42
+ return () => {
43
+ removePortalNode(nodeId);
44
+ };
45
+ }, []);
46
+ return portalNode ? /*#__PURE__*/ReactDOM.createPortal(children, portalNode) : null;
47
+ }
48
+
49
+ Backdrop.propTypes = {
50
+ children: PropTypes.node
51
+ };
52
+ export default Backdrop;
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import TouchableWithoutFeedback from "react-native-web/dist/exports/TouchableWithoutFeedback";
3
+ import Modal from "react-native-web/dist/exports/Modal";
4
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
5
+ import View from "react-native-web/dist/exports/View";
6
+ import PropTypes from 'prop-types';
7
+ /**
8
+ * The Native version of Backdrop utilizes React Native's Modal component for overlaying
9
+ * the app's content, since this is the only reliable to do it. The only drawback of this
10
+ * approach is that a press on the Backdrop will actually stop the press event from propagating,
11
+ * i.e. anything rendered beneath the Backdrop can't be pressed until the Backdrop is closed.
12
+ */
13
+
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+
16
+ function Backdrop({
17
+ onPress,
18
+ children
19
+ }) {
20
+ return /*#__PURE__*/_jsx(Modal, {
21
+ transparent: true,
22
+ children: /*#__PURE__*/_jsx(TouchableWithoutFeedback, {
23
+ onPress: onPress,
24
+ children: /*#__PURE__*/_jsx(View, {
25
+ style: staticStyles.backdrop,
26
+ children: children
27
+ })
28
+ })
29
+ });
30
+ }
31
+
32
+ export default Backdrop;
33
+ Backdrop.propTypes = {
34
+ onPress: PropTypes.func,
35
+ children: PropTypes.node
36
+ };
37
+ const staticStyles = StyleSheet.create({
38
+ backdrop: {
39
+ flexBasis: '100%',
40
+ backgroundColor: 'rgba(255, 255, 255, 0.5)' // to visually mark that the content beneath is not pressable
41
+
42
+ }
43
+ });