@telus-uds/components-base 1.3.0 → 1.5.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 (344) hide show
  1. package/.turbo/turbo-build.log +5 -2
  2. package/CHANGELOG.json +82 -0
  3. package/CHANGELOG.md +42 -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 +121 -438
  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 -7
  23. package/lib/HorizontalScroll/HorizontalScrollButton.js +23 -49
  24. package/lib/IconButton/IconButton.js +6 -6
  25. package/lib/InputLabel/InputLabel.js +7 -2
  26. package/lib/InputSupports/InputSupports.js +2 -2
  27. package/lib/Link/LinkBase.js +5 -6
  28. package/lib/List/List.js +4 -6
  29. package/lib/List/ListItem.js +6 -2
  30. package/lib/Modal/Modal.js +6 -2
  31. package/lib/Notification/Notification.js +12 -8
  32. package/lib/Pagination/Pagination.js +8 -3
  33. package/lib/Progress/Progress.js +5 -4
  34. package/lib/Progress/ProgressBar.js +8 -7
  35. package/lib/Radio/Radio.js +4 -6
  36. package/lib/Radio/RadioButton.js +6 -3
  37. package/lib/Radio/RadioGroup.js +7 -2
  38. package/lib/RadioCard/RadioCard.js +4 -4
  39. package/lib/RadioCard/RadioCardGroup.js +9 -6
  40. package/lib/Search/Search.js +7 -2
  41. package/lib/Select/Select.js +10 -9
  42. package/lib/SideNav/Item.js +7 -7
  43. package/lib/SideNav/SideNav.js +7 -3
  44. package/lib/Skeleton/Skeleton.js +6 -2
  45. package/lib/Spacer/Spacer.js +7 -18
  46. package/lib/StackView/StackView.js +7 -7
  47. package/lib/StackView/StackWrapBox.js +6 -7
  48. package/lib/StackView/StackWrapGap.js +6 -5
  49. package/lib/StepTracker/Step.js +7 -3
  50. package/lib/StepTracker/StepTracker.js +7 -7
  51. package/lib/Tabs/Tabs.js +6 -2
  52. package/lib/Tabs/TabsItem.js +6 -5
  53. package/lib/Tags/Tags.js +5 -6
  54. package/lib/TextInput/TextArea.js +13 -14
  55. package/lib/TextInput/TextInput.js +13 -14
  56. package/lib/TextInput/TextInputBase.js +5 -3
  57. package/lib/ToggleSwitch/ToggleSwitch.js +10 -9
  58. package/lib/ToggleSwitch/ToggleSwitchGroup.js +5 -7
  59. package/lib/Tooltip/Tooltip.js +7 -2
  60. package/lib/TooltipButton/TooltipButton.js +7 -2
  61. package/lib/Typography/Typography.js +8 -6
  62. package/lib/index.js +7 -0
  63. package/lib/utils/children.js +5 -1
  64. package/lib/utils/index.js +14 -0
  65. package/lib/utils/props/index.js +9 -0
  66. package/lib/{InputSupports/propTypes.js → utils/props/inputSupportsProps.js} +2 -3
  67. package/lib/utils/ssr.js +51 -0
  68. package/lib-module/A11yInfoProvider/index.js +62 -0
  69. package/lib-module/A11yText/index.js +55 -0
  70. package/lib-module/ActivityIndicator/Spinner.js +76 -0
  71. package/lib-module/ActivityIndicator/Spinner.native.js +143 -0
  72. package/lib-module/ActivityIndicator/index.js +40 -0
  73. package/lib-module/ActivityIndicator/shared.js +12 -0
  74. package/lib-module/BaseProvider/index.js +26 -0
  75. package/lib-module/Box/Box.js +243 -0
  76. package/lib-module/Box/index.js +2 -0
  77. package/lib-module/Button/Button.js +25 -0
  78. package/lib-module/Button/ButtonBase.js +254 -0
  79. package/lib-module/Button/ButtonGroup.js +164 -0
  80. package/lib-module/Button/ButtonLink.js +39 -0
  81. package/lib-module/Button/index.js +4 -0
  82. package/lib-module/Button/propTypes.js +36 -0
  83. package/lib-module/Card/Card.js +83 -0
  84. package/lib-module/Card/CardBase.js +62 -0
  85. package/lib-module/Card/PressableCardBase.js +113 -0
  86. package/lib-module/Card/index.js +4 -0
  87. package/lib-module/Checkbox/Checkbox.js +321 -0
  88. package/lib-module/Checkbox/CheckboxGroup.js +218 -0
  89. package/lib-module/Checkbox/CheckboxInput.js +58 -0
  90. package/lib-module/Checkbox/CheckboxInput.native.js +6 -0
  91. package/lib-module/Checkbox/index.js +3 -0
  92. package/lib-module/Divider/Divider.js +123 -0
  93. package/lib-module/Divider/index.js +2 -0
  94. package/lib-module/ExpandCollapse/Accordion.js +15 -0
  95. package/lib-module/ExpandCollapse/Control.js +130 -0
  96. package/lib-module/ExpandCollapse/ExpandCollapse.js +94 -0
  97. package/lib-module/ExpandCollapse/Panel.js +158 -0
  98. package/lib-module/ExpandCollapse/index.js +7 -0
  99. package/lib-module/Feedback/Feedback.js +144 -0
  100. package/lib-module/Feedback/index.js +2 -0
  101. package/lib-module/Fieldset/Fieldset.js +145 -0
  102. package/lib-module/Fieldset/FieldsetContainer.js +29 -0
  103. package/lib-module/Fieldset/FieldsetContainer.native.js +20 -0
  104. package/lib-module/Fieldset/Legend.js +21 -0
  105. package/lib-module/Fieldset/Legend.native.js +28 -0
  106. package/lib-module/Fieldset/cssReset.js +14 -0
  107. package/lib-module/Fieldset/index.js +2 -0
  108. package/lib-module/FlexGrid/Col/Col.js +265 -0
  109. package/lib-module/FlexGrid/Col/index.js +2 -0
  110. package/lib-module/FlexGrid/FlexGrid.js +147 -0
  111. package/lib-module/FlexGrid/Row/Row.js +177 -0
  112. package/lib-module/FlexGrid/Row/index.js +2 -0
  113. package/lib-module/FlexGrid/helpers/index.js +18 -0
  114. package/lib-module/FlexGrid/index.js +2 -0
  115. package/lib-module/FlexGrid/providers/GutterContext.js +3 -0
  116. package/lib-module/HorizontalScroll/HorizontalScroll.js +170 -0
  117. package/lib-module/HorizontalScroll/HorizontalScrollButton.js +77 -0
  118. package/lib-module/HorizontalScroll/ScrollViewEnd.js +47 -0
  119. package/lib-module/HorizontalScroll/ScrollViewEnd.native.js +24 -0
  120. package/lib-module/HorizontalScroll/dictionary.js +11 -0
  121. package/lib-module/HorizontalScroll/index.js +11 -0
  122. package/lib-module/HorizontalScroll/itemPositions.js +106 -0
  123. package/lib-module/Icon/Icon.js +61 -0
  124. package/lib-module/Icon/IconText.js +81 -0
  125. package/lib-module/Icon/index.js +4 -0
  126. package/lib-module/IconButton/IconButton.js +115 -0
  127. package/lib-module/IconButton/index.js +2 -0
  128. package/lib-module/InputLabel/InputLabel.js +131 -0
  129. package/lib-module/InputLabel/LabelContent.js +24 -0
  130. package/lib-module/InputLabel/LabelContent.native.js +16 -0
  131. package/lib-module/InputLabel/index.js +2 -0
  132. package/lib-module/InputSupports/InputSupports.js +88 -0
  133. package/lib-module/InputSupports/index.js +2 -0
  134. package/lib-module/InputSupports/useInputSupports.js +31 -0
  135. package/lib-module/Link/ChevronLink.js +51 -0
  136. package/lib-module/Link/InlinePressable.js +37 -0
  137. package/lib-module/Link/InlinePressable.native.js +85 -0
  138. package/lib-module/Link/Link.js +27 -0
  139. package/lib-module/Link/LinkBase.js +210 -0
  140. package/lib-module/Link/TextButton.js +43 -0
  141. package/lib-module/Link/index.js +5 -0
  142. package/lib-module/List/List.js +55 -0
  143. package/lib-module/List/ListItem.js +213 -0
  144. package/lib-module/List/index.js +5 -0
  145. package/lib-module/Modal/Modal.js +208 -0
  146. package/lib-module/Modal/dictionary.js +9 -0
  147. package/lib-module/Modal/index.js +2 -0
  148. package/lib-module/Notification/Notification.js +196 -0
  149. package/lib-module/Notification/dictionary.js +8 -0
  150. package/lib-module/Notification/index.js +2 -0
  151. package/lib-module/Pagination/PageButton.js +65 -0
  152. package/lib-module/Pagination/Pagination.js +140 -0
  153. package/lib-module/Pagination/SideButton.js +103 -0
  154. package/lib-module/Pagination/dictionary.js +18 -0
  155. package/lib-module/Pagination/index.js +2 -0
  156. package/lib-module/Pagination/usePagination.js +72 -0
  157. package/lib-module/Progress/Progress.js +85 -0
  158. package/lib-module/Progress/ProgressBar.js +134 -0
  159. package/lib-module/Progress/ProgressBarBackground.js +41 -0
  160. package/lib-module/Progress/index.js +4 -0
  161. package/lib-module/Radio/Radio.js +263 -0
  162. package/lib-module/Radio/RadioButton.js +128 -0
  163. package/lib-module/Radio/RadioGroup.js +225 -0
  164. package/lib-module/Radio/RadioInput.js +60 -0
  165. package/lib-module/Radio/RadioInput.native.js +6 -0
  166. package/lib-module/Radio/index.js +3 -0
  167. package/lib-module/RadioCard/RadioCard.js +218 -0
  168. package/lib-module/RadioCard/RadioCardGroup.js +232 -0
  169. package/lib-module/RadioCard/index.js +3 -0
  170. package/lib-module/Search/Search.js +233 -0
  171. package/lib-module/Search/dictionary.js +12 -0
  172. package/lib-module/Search/index.js +2 -0
  173. package/lib-module/Select/Group.js +20 -0
  174. package/lib-module/Select/Group.native.js +14 -0
  175. package/lib-module/Select/Item.js +17 -0
  176. package/lib-module/Select/Item.native.js +9 -0
  177. package/lib-module/Select/Picker.js +67 -0
  178. package/lib-module/Select/Picker.native.js +110 -0
  179. package/lib-module/Select/Select.js +317 -0
  180. package/lib-module/Select/index.js +6 -0
  181. package/lib-module/SideNav/Item.js +139 -0
  182. package/lib-module/SideNav/ItemContent.js +45 -0
  183. package/lib-module/SideNav/ItemsGroup.js +115 -0
  184. package/lib-module/SideNav/SideNav.js +133 -0
  185. package/lib-module/SideNav/index.js +1 -0
  186. package/lib-module/Skeleton/Skeleton.js +117 -0
  187. package/lib-module/Skeleton/index.js +2 -0
  188. package/lib-module/Skeleton/skeleton.constant.js +3 -0
  189. package/lib-module/Skeleton/skeletonWebAnimation.js +18 -0
  190. package/lib-module/Skeleton/useSkeletonNativeAnimation.js +24 -0
  191. package/lib-module/Spacer/Spacer.js +97 -0
  192. package/lib-module/Spacer/index.js +2 -0
  193. package/lib-module/StackView/StackView.js +124 -0
  194. package/lib-module/StackView/StackWrap.js +48 -0
  195. package/lib-module/StackView/StackWrap.native.js +3 -0
  196. package/lib-module/StackView/StackWrapBox.js +114 -0
  197. package/lib-module/StackView/StackWrapGap.js +58 -0
  198. package/lib-module/StackView/common.js +32 -0
  199. package/lib-module/StackView/getStackedContent.js +123 -0
  200. package/lib-module/StackView/index.js +5 -0
  201. package/lib-module/StepTracker/Step.js +229 -0
  202. package/lib-module/StepTracker/StepTracker.js +175 -0
  203. package/lib-module/StepTracker/dictionary.js +10 -0
  204. package/lib-module/StepTracker/index.js +2 -0
  205. package/lib-module/Tabs/Tabs.js +113 -0
  206. package/lib-module/Tabs/TabsItem.js +215 -0
  207. package/lib-module/Tabs/index.js +2 -0
  208. package/lib-module/Tags/Tags.js +238 -0
  209. package/lib-module/Tags/index.js +2 -0
  210. package/lib-module/TextInput/TextArea.js +88 -0
  211. package/lib-module/TextInput/TextInput.js +60 -0
  212. package/lib-module/TextInput/TextInputBase.js +233 -0
  213. package/lib-module/TextInput/index.js +3 -0
  214. package/lib-module/TextInput/propTypes.js +31 -0
  215. package/lib-module/ThemeProvider/ThemeProvider.js +35 -0
  216. package/lib-module/ThemeProvider/index.js +6 -0
  217. package/lib-module/ThemeProvider/useSetTheme.js +22 -0
  218. package/lib-module/ThemeProvider/useTheme.js +14 -0
  219. package/lib-module/ThemeProvider/useThemeTokens.js +105 -0
  220. package/lib-module/ThemeProvider/utils/index.js +2 -0
  221. package/lib-module/ThemeProvider/utils/styles.js +174 -0
  222. package/lib-module/ThemeProvider/utils/theme-tokens.js +151 -0
  223. package/lib-module/ToggleSwitch/ToggleSwitch.js +224 -0
  224. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +202 -0
  225. package/lib-module/ToggleSwitch/index.js +3 -0
  226. package/lib-module/Tooltip/Backdrop.js +52 -0
  227. package/lib-module/Tooltip/Backdrop.native.js +43 -0
  228. package/lib-module/Tooltip/Tooltip.js +332 -0
  229. package/lib-module/Tooltip/dictionary.js +8 -0
  230. package/lib-module/Tooltip/getTooltipPosition.js +164 -0
  231. package/lib-module/Tooltip/index.js +2 -0
  232. package/lib-module/TooltipButton/TooltipButton.js +71 -0
  233. package/lib-module/TooltipButton/index.js +2 -0
  234. package/lib-module/Typography/Typography.js +118 -0
  235. package/lib-module/Typography/index.js +2 -0
  236. package/lib-module/ViewportProvider/ViewportProvider.js +28 -0
  237. package/lib-module/ViewportProvider/index.js +3 -0
  238. package/lib-module/ViewportProvider/useViewport.js +3 -0
  239. package/lib-module/ViewportProvider/useViewportListener.js +43 -0
  240. package/lib-module/index.js +48 -0
  241. package/lib-module/utils/a11y/index.js +2 -0
  242. package/lib-module/utils/a11y/semantics.js +154 -0
  243. package/lib-module/utils/a11y/textSize.js +34 -0
  244. package/lib-module/utils/animation/index.js +2 -0
  245. package/lib-module/utils/animation/useVerticalExpandAnimation.js +49 -0
  246. package/lib-module/utils/children.js +118 -0
  247. package/lib-module/utils/index.js +15 -0
  248. package/lib-module/utils/info/index.js +7 -0
  249. package/lib-module/utils/info/platform/index.js +11 -0
  250. package/lib-module/utils/info/platform/platform.android.js +1 -0
  251. package/lib-module/utils/info/platform/platform.ios.js +1 -0
  252. package/lib-module/utils/info/platform/platform.js +1 -0
  253. package/lib-module/utils/info/platform/platform.native.js +4 -0
  254. package/lib-module/utils/info/versions.js +5 -0
  255. package/lib-module/utils/input.js +180 -0
  256. package/lib-module/utils/pressability.js +97 -0
  257. package/lib-module/utils/props/a11yProps.js +140 -0
  258. package/lib-module/utils/props/clickProps.js +25 -0
  259. package/lib-module/utils/props/componentPropType.js +63 -0
  260. package/lib-module/utils/props/copyPropTypes.js +2 -0
  261. package/lib-module/utils/props/getPropSelector.js +6 -0
  262. package/lib-module/utils/props/hrefAttrsProp.js +30 -0
  263. package/lib-module/utils/props/index.js +16 -0
  264. package/lib-module/utils/props/inputSupportsProps.js +54 -0
  265. package/lib-module/utils/props/linkProps.js +47 -0
  266. package/lib-module/utils/props/paddingProp.js +9 -0
  267. package/lib-module/utils/props/pressProps.js +42 -0
  268. package/lib-module/utils/props/rectProp.js +9 -0
  269. package/lib-module/utils/props/responsiveProps.js +30 -0
  270. package/lib-module/utils/props/selectSystemProps.js +24 -0
  271. package/lib-module/utils/props/spacingProps.js +56 -0
  272. package/lib-module/utils/props/tokens.js +120 -0
  273. package/lib-module/utils/props/variantProp.js +18 -0
  274. package/lib-module/utils/props/viewProps.js +22 -0
  275. package/lib-module/utils/ssr.js +35 -0
  276. package/lib-module/utils/useCopy.js +42 -0
  277. package/lib-module/utils/useHash.js +44 -0
  278. package/lib-module/utils/useHash.native.js +7 -0
  279. package/lib-module/utils/useResponsiveProp.js +47 -0
  280. package/lib-module/utils/useSpacingScale.js +123 -0
  281. package/lib-module/utils/useUniqueId.js +12 -0
  282. package/lib-module/utils/withLinkRouter.js +82 -0
  283. package/package.json +9 -5
  284. package/src/A11yText/index.jsx +7 -3
  285. package/src/ActivityIndicator/Spinner.jsx +56 -44
  286. package/src/ActivityIndicator/Spinner.native.jsx +20 -12
  287. package/src/Box/Box.jsx +10 -9
  288. package/src/Button/ButtonBase.jsx +9 -8
  289. package/src/Card/Card.jsx +7 -4
  290. package/src/Card/PressableCardBase.jsx +12 -12
  291. package/src/Checkbox/Checkbox.jsx +12 -5
  292. package/src/Divider/Divider.jsx +17 -10
  293. package/src/ExpandCollapse/Control.jsx +12 -7
  294. package/src/ExpandCollapse/ExpandCollapse.jsx +13 -3
  295. package/src/ExpandCollapse/Panel.jsx +15 -5
  296. package/src/Feedback/Feedback.jsx +13 -3
  297. package/src/Fieldset/Fieldset.jsx +1 -1
  298. package/src/HorizontalScroll/HorizontalScroll.jsx +13 -6
  299. package/src/HorizontalScroll/HorizontalScrollButton.jsx +21 -58
  300. package/src/IconButton/IconButton.jsx +12 -8
  301. package/src/InputLabel/InputLabel.jsx +16 -2
  302. package/src/InputSupports/InputSupports.jsx +1 -1
  303. package/src/Link/LinkBase.jsx +10 -9
  304. package/src/List/List.jsx +12 -5
  305. package/src/List/ListItem.jsx +16 -2
  306. package/src/Modal/Modal.jsx +63 -50
  307. package/src/Notification/Notification.jsx +23 -6
  308. package/src/Pagination/Pagination.jsx +10 -3
  309. package/src/Progress/Progress.jsx +5 -3
  310. package/src/Progress/ProgressBar.jsx +8 -6
  311. package/src/Radio/Radio.jsx +13 -5
  312. package/src/Radio/RadioButton.jsx +13 -3
  313. package/src/Radio/RadioGroup.jsx +14 -2
  314. package/src/RadioCard/RadioCard.jsx +9 -6
  315. package/src/RadioCard/RadioCardGroup.jsx +16 -4
  316. package/src/Search/Search.jsx +15 -3
  317. package/src/Select/Select.jsx +21 -7
  318. package/src/SideNav/Item.jsx +15 -7
  319. package/src/SideNav/SideNav.jsx +13 -2
  320. package/src/Skeleton/Skeleton.jsx +55 -43
  321. package/src/Spacer/Spacer.jsx +8 -16
  322. package/src/StackView/StackView.jsx +13 -12
  323. package/src/StackView/StackWrapBox.jsx +12 -12
  324. package/src/StackView/StackWrapGap.jsx +9 -7
  325. package/src/StepTracker/Step.jsx +7 -4
  326. package/src/StepTracker/StepTracker.jsx +8 -8
  327. package/src/Tabs/Tabs.jsx +16 -3
  328. package/src/Tabs/TabsItem.jsx +13 -9
  329. package/src/Tags/Tags.jsx +20 -5
  330. package/src/TextInput/TextArea.jsx +20 -8
  331. package/src/TextInput/TextInput.jsx +20 -8
  332. package/src/TextInput/TextInputBase.jsx +13 -3
  333. package/src/ToggleSwitch/ToggleSwitch.jsx +16 -5
  334. package/src/ToggleSwitch/ToggleSwitchGroup.jsx +14 -6
  335. package/src/Tooltip/Tooltip.jsx +13 -3
  336. package/src/TooltipButton/TooltipButton.jsx +6 -4
  337. package/src/Typography/Typography.jsx +10 -6
  338. package/src/index.js +1 -1
  339. package/src/utils/children.jsx +2 -1
  340. package/src/utils/index.js +1 -0
  341. package/src/utils/props/index.js +1 -0
  342. package/src/{InputSupports/propTypes.js → utils/props/inputSupportsProps.js} +2 -4
  343. package/src/utils/ssr.js +35 -0
  344. package/release-context.json +0 -7
@@ -0,0 +1,263 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Pressable from "react-native-web/dist/exports/Pressable";
4
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
5
+ import Text from "react-native-web/dist/exports/Text";
6
+ import View from "react-native-web/dist/exports/View";
7
+ import RadioLabel from '../InputLabel/LabelContent';
8
+ import RadioButton, { selectRadioButtonTokens } from './RadioButton';
9
+ import { applyShadowToken, applyTextStyles, useThemeTokensCallback } from '../ThemeProvider';
10
+ import { a11yProps, getTokensPropType, selectSystemProps, useInputValue, useUniqueId, variantProp, viewProps } from '../utils';
11
+ import StackView from '../StackView';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
15
+
16
+ const selectContainerStyles = ({
17
+ containerBackgroundColor,
18
+ containerBorderRadius,
19
+ containerOpacity,
20
+ containerPaddingBottom,
21
+ containerPaddingLeft,
22
+ containerPaddingRight,
23
+ containerPaddingTop,
24
+ containerShadow
25
+ }) => ({
26
+ backgroundColor: containerBackgroundColor,
27
+ borderRadius: containerBorderRadius,
28
+ opacity: containerOpacity,
29
+ paddingBottom: containerPaddingBottom,
30
+ paddingLeft: containerPaddingLeft,
31
+ paddingRight: containerPaddingRight,
32
+ paddingTop: containerPaddingTop,
33
+ ...applyShadowToken(containerShadow)
34
+ });
35
+
36
+ const selectDescriptionStyles = ({
37
+ containerPaddingLeft = 0,
38
+ descriptionFontSize,
39
+ descriptionLineHeight,
40
+ descriptionMarginLeft,
41
+ inputSize,
42
+ labelMarginLeft = 0
43
+ }) => ({
44
+ marginLeft: descriptionMarginLeft ?? containerPaddingLeft + inputSize + labelMarginLeft,
45
+ ...applyTextStyles({
46
+ fontSize: descriptionFontSize,
47
+ lineHeight: descriptionLineHeight
48
+ })
49
+ });
50
+
51
+ const selectLabelStyles = ({
52
+ labelColor,
53
+ labelFontName,
54
+ labelFontSize,
55
+ labelFontWeight,
56
+ labelMarginLeft,
57
+ labelLineHeight
58
+ }) => applyTextStyles({
59
+ color: labelColor,
60
+ fontName: labelFontName,
61
+ fontWeight: labelFontWeight,
62
+ fontSize: labelFontSize,
63
+ lineHeight: labelLineHeight,
64
+ marginLeft: labelMarginLeft
65
+ });
66
+ /**
67
+ * Basic Radio component.
68
+ *
69
+ * ## Component API
70
+ *
71
+ * Use `label` prop to provide a label for the radio button. For a disabled `Radio` set the `inactive` prop to `true`.
72
+ *
73
+ * ### Controlled version
74
+ *
75
+ * If the radio button is controlled from outside, it needs to receive `checked` and `onChange` props.
76
+ *
77
+ * ### Uncontrolled version
78
+ *
79
+ * In case of uncontrolled radio button you can use `defaultChecked` prop to provide the initial value.
80
+ * Whenever the radio button gets toggled, it calls the `onChange` callback with the new value (boolean).
81
+ *
82
+ * ### Using within forms
83
+ *
84
+ * You can pass `name` and `value` props if you need a particular radio button to be a part of a radio group
85
+ * on a form.
86
+ *
87
+ * ### Validation
88
+ *
89
+ * You can mark a radio button as failing validation by setting the `error` prop to `true`.
90
+ *
91
+ * ## A11y guidelines
92
+ *
93
+ * Radio component accepts all the common accessibility props, but also sets some defaults, including
94
+ * accessibility role `'radio'` and accessibility state that depends on the other props (`checked`, `inactive`)
95
+ * or the internal state in case of uncontrolled radio button.
96
+ *
97
+ */
98
+
99
+
100
+ const Radio = /*#__PURE__*/forwardRef(({
101
+ checked,
102
+ defaultChecked,
103
+ description,
104
+ error = false,
105
+ id,
106
+ inactive,
107
+ label,
108
+ name: inputName,
109
+ onChange,
110
+ tokens,
111
+ value,
112
+ variant,
113
+ ...rest
114
+ }, ref) => {
115
+ const {
116
+ currentValue: isChecked,
117
+ setValue: setIsChecked,
118
+ isControlled
119
+ } = useInputValue({
120
+ value: checked,
121
+ initialValue: defaultChecked,
122
+ onChange
123
+ }, 'useRadioValue');
124
+ const getTokens = useThemeTokensCallback('Radio', tokens, {
125
+ checked: isChecked,
126
+ inactive,
127
+ error,
128
+ ...variant
129
+ });
130
+
131
+ const handleChange = event => {
132
+ if (!inactive && !isChecked) {
133
+ setIsChecked(true, event);
134
+ }
135
+ };
136
+
137
+ const handleKeyDown = event => {
138
+ // The expected keyboard shortcut for activating a radio is the Space key
139
+ if ((event === null || event === void 0 ? void 0 : event.key) === ' ') handleChange(event);
140
+ };
141
+
142
+ const uniqueId = useUniqueId('radio');
143
+ const inputId = id ?? uniqueId;
144
+ return /*#__PURE__*/_jsx(Pressable, {
145
+ ref: ref,
146
+ disabled: inactive,
147
+ onKeyDown: handleKeyDown,
148
+ onPress: handleChange,
149
+ accessibilityRole: "radio",
150
+ accessibilityState: {
151
+ checked: isChecked,
152
+ disabled: inactive
153
+ },
154
+ ...selectProps(rest),
155
+ children: ({
156
+ focused: focus,
157
+ hovered: hover,
158
+ pressed
159
+ }) => {
160
+ const stateTokens = getTokens({
161
+ focus,
162
+ hover,
163
+ pressed
164
+ });
165
+ return /*#__PURE__*/_jsxs(StackView, {
166
+ space: 0,
167
+ children: [/*#__PURE__*/_jsxs(View, {
168
+ style: [staticStyles.container, selectContainerStyles(stateTokens)],
169
+ children: [/*#__PURE__*/_jsx(RadioButton, {
170
+ tokens: selectRadioButtonTokens(stateTokens),
171
+ isControlled: isControlled,
172
+ isChecked: isChecked,
173
+ inactive: inactive,
174
+ defaultChecked: defaultChecked,
175
+ inputId: inputId,
176
+ handleChange: handleChange,
177
+ name: inputName,
178
+ value: value
179
+ }), Boolean(label) && /*#__PURE__*/_jsx(Text, {
180
+ style: selectLabelStyles(stateTokens),
181
+ children: /*#__PURE__*/_jsx(RadioLabel, {
182
+ forId: inputId,
183
+ children: label
184
+ })
185
+ })]
186
+ }), Boolean(description) && /*#__PURE__*/_jsx(Text, {
187
+ style: selectDescriptionStyles(getTokens()),
188
+ children: description
189
+ })]
190
+ });
191
+ }
192
+ });
193
+ });
194
+ Radio.displayName = 'Radio';
195
+ Radio.propTypes = { ...selectedSystemPropTypes,
196
+
197
+ /**
198
+ * Use `checked` for controlled Radio. For uncontrolled Radio, use the `defaultChecked` prop.
199
+ */
200
+ checked: PropTypes.bool,
201
+
202
+ /**
203
+ * Use `defaultChecked` to provide the initial value for an uncontrolled Radio.
204
+ */
205
+ defaultChecked: PropTypes.bool,
206
+
207
+ /**
208
+ * An optional radio button description.
209
+ */
210
+ description: PropTypes.string,
211
+
212
+ /**
213
+ * Radio button ID.
214
+ */
215
+ id: PropTypes.string,
216
+
217
+ /**
218
+ * Whether the corresponding input is disabled or active.
219
+ */
220
+ inactive: PropTypes.bool,
221
+
222
+ /**
223
+ * The label.
224
+ */
225
+ label: PropTypes.string,
226
+
227
+ /**
228
+ * Associate this radio button with a group (set as the name attribute).
229
+ */
230
+ name: PropTypes.string,
231
+
232
+ /**
233
+ * Whether the underlying input triggered a validation error or not.
234
+ */
235
+ error: PropTypes.bool,
236
+
237
+ /**
238
+ * The value. Must be unique within the group.
239
+ */
240
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
241
+
242
+ /**
243
+ * Callback called when a controlled radio button gets interacted with.
244
+ */
245
+ onChange: PropTypes.func,
246
+
247
+ /**
248
+ * Radio tokens.
249
+ */
250
+ tokens: getTokensPropType('Radio'),
251
+
252
+ /**
253
+ * Radio variant.
254
+ */
255
+ variant: variantProp.propType
256
+ };
257
+ export default Radio;
258
+ const staticStyles = StyleSheet.create({
259
+ container: {
260
+ flexDirection: 'row',
261
+ alignItems: 'center'
262
+ }
263
+ });
@@ -0,0 +1,128 @@
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 RadioInput from './RadioInput';
7
+ import { applyOuterBorder, resolveThemeTokens, validateThemeTokens } from '../ThemeProvider';
8
+ import { a11yProps, getTokensSetPropType, selectSystemProps, selectTokens, viewProps } from '../utils';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]); // TODO: roll out a standard approach to token sets
12
+ // https://github.com/telus/universal-design-system/issues/782
13
+
14
+ const tokenKeys = ['checkedBackgroundColor', 'checkedSize', 'inputBackgroundColor', 'inputBorderColor', 'inputBorderWidth', 'inputOutlineColor', 'inputOutlineWidth', 'inputSize', 'outerBorderColor', 'outerBorderWidth', 'outerBorderGap', 'inputSize'];
15
+ export const selectRadioButtonTokens = (themeTokens, prefix) => selectTokens(tokenKeys, themeTokens, prefix);
16
+
17
+ const getBorderRadius = inputSize => inputSize / 2;
18
+
19
+ const selectCheckedStyles = ({
20
+ checkedBackgroundColor,
21
+ checkedSize
22
+ }) => ({
23
+ backgroundColor: checkedBackgroundColor,
24
+ borderRadius: checkedSize / 2,
25
+ height: checkedSize,
26
+ width: checkedSize
27
+ });
28
+
29
+ const selectInputStyles = ({
30
+ inputBackgroundColor,
31
+ inputBorderColor,
32
+ inputBorderWidth,
33
+ inputOutlineColor,
34
+ inputOutlineWidth,
35
+ inputSize
36
+ }) => ({
37
+ borderColor: inputBorderColor,
38
+ borderRadius: getBorderRadius(inputSize),
39
+ borderWidth: inputBorderWidth,
40
+ backgroundColor: inputBackgroundColor,
41
+ height: inputSize,
42
+ width: inputSize,
43
+ ...Platform.select({
44
+ web: {
45
+ outlineStyle: 'solid',
46
+ outlineColor: inputOutlineColor,
47
+ outlineWidth: inputOutlineWidth
48
+ }
49
+ })
50
+ });
51
+
52
+ const selectOuterBorderStyles = ({
53
+ outerBorderColor,
54
+ outerBorderWidth,
55
+ outerBorderGap,
56
+ inputSize
57
+ }) => ({ ...applyOuterBorder({
58
+ outerBorderColor,
59
+ outerBorderWidth,
60
+ outerBorderGap,
61
+ borderRadius: getBorderRadius(inputSize)
62
+ })
63
+ });
64
+ /**
65
+ * The visual toggle of a radio input. Is not interactive on its own, should be used inside
66
+ * an interactive parent that passes down props when interacted with.
67
+ */
68
+
69
+
70
+ const RadioButton = /*#__PURE__*/forwardRef(({
71
+ isChecked,
72
+ tokens,
73
+ inactive,
74
+ defaultChecked,
75
+ inputId,
76
+ isControlled,
77
+ handleChange,
78
+ name: inputName,
79
+ value,
80
+ ...rest
81
+ }, ref) => {
82
+ const themeTokens = validateThemeTokens(resolveThemeTokens(tokens, {
83
+ checked: isChecked
84
+ }), getTokensSetPropType(tokenKeys), 'RadioButton');
85
+ return /*#__PURE__*/_jsx(View, {
86
+ style: selectOuterBorderStyles(themeTokens),
87
+ ...selectProps(rest),
88
+ children: /*#__PURE__*/_jsxs(View, {
89
+ style: [staticStyles.defaultInputStyles, selectInputStyles(themeTokens, isChecked)],
90
+ testID: "Radio-Input",
91
+ children: [/*#__PURE__*/_jsx(RadioInput, {
92
+ ref: ref,
93
+ checked: isChecked,
94
+ defaultChecked: defaultChecked,
95
+ disabled: inactive,
96
+ id: inputId,
97
+ isControlled: isControlled,
98
+ onChange: handleChange,
99
+ name: inputName,
100
+ value: value
101
+ }), isChecked && /*#__PURE__*/_jsx(View, {
102
+ style: selectCheckedStyles(themeTokens),
103
+ testID: "Radio-Checked"
104
+ })]
105
+ })
106
+ });
107
+ });
108
+ RadioButton.displayName = 'RadioButton';
109
+ RadioButton.propTypes = { ...selectedSystemPropTypes,
110
+ isChecked: PropTypes.bool,
111
+ tokens: getTokensSetPropType(tokenKeys, {
112
+ allowFunction: true
113
+ }),
114
+ inactive: PropTypes.bool,
115
+ defaultChecked: PropTypes.bool,
116
+ inputId: PropTypes.string,
117
+ isControlled: PropTypes.bool,
118
+ handleChange: PropTypes.func,
119
+ name: PropTypes.string,
120
+ value: PropTypes.bool
121
+ };
122
+ const staticStyles = StyleSheet.create({
123
+ defaultInputStyles: {
124
+ alignItems: 'center',
125
+ justifyContent: 'center'
126
+ }
127
+ });
128
+ export default RadioButton;
@@ -0,0 +1,225 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ABBPropTypes from 'airbnb-prop-types';
4
+ import { useViewport } from '../ViewportProvider';
5
+ import { useThemeTokens } from '../ThemeProvider';
6
+ import { a11yProps, getTokensPropType, selectSystemProps, useInputValue, variantProp, viewProps } from '../utils';
7
+ import { getStackedContent } from '../StackView';
8
+ import Radio from './Radio';
9
+ import Fieldset from '../Fieldset';
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
12
+ /**
13
+ * A group of Radios that behave as a radio group. Use when users select a single choice from mutually
14
+ * exclusive options.
15
+ *
16
+ * ## Component API
17
+ *
18
+ * Use the `items` prop to pass an array of objects describing each Radio in the group:
19
+ *
20
+ * - `label`: main text passed to Radio's `label` prop
21
+ * - `id`: identifier used to store which Radio is selected (uses `label` if undefinded)
22
+ * - `onChange`: optional function called on selection, in addition to updating the group's selection state
23
+ *
24
+ * ### Controlled version
25
+ *
26
+ * If the selection state is controlled from outside, it needs to receive `checkedId` and `onChange` props.
27
+ *
28
+ * ### Uncontrolled version
29
+ *
30
+ * If the RadioGroup manages its own state, you can use `initialCheckedId` prop to provide the initial value.
31
+ * Whenever the radio card gets toggled, it calls the `onChange` callback with the new value (string).
32
+ *
33
+ * ### Use in forms
34
+ *
35
+ * For web forms, the `name` prop may be used to define the name of the group's `fieldset` and input elements.
36
+ *
37
+ * ### Validation
38
+ *
39
+ * Validation state may be set by passing 'error' or 'success' to the `validation` prop.
40
+ *
41
+ * ## A11y guidelines
42
+ *
43
+ * RadioGroup accepts all the common accessibility props, but also sets accessibility role `'radiogroup'`
44
+ * and controls the accessibility state of children like Radio and Feedback based on current state.
45
+ *
46
+ * @example
47
+ * ```jsx
48
+ * <RadioGroup
49
+ * initialCheckedId="radio1"
50
+ * items={[
51
+ * { label: 'Radio 1', id: 'radio1' },
52
+ * { label: 'Radio 2', id: 'radio2' },
53
+ * { label: 'Radio 3', id: 'radio3' }
54
+ * ]}
55
+ * legend="Radios"
56
+ * hint="Choose one option"
57
+ * />
58
+ * ```
59
+ */
60
+
61
+ const RadioGroup = /*#__PURE__*/forwardRef(({
62
+ tokens,
63
+ radioTokens,
64
+ variant,
65
+ items = [],
66
+ legend,
67
+ tooltip,
68
+ hint,
69
+ validation,
70
+ feedback,
71
+ initialCheckedId,
72
+ checkedId,
73
+ onChange,
74
+ readOnly,
75
+ name: inputGroupName,
76
+ inactive,
77
+ ...rest
78
+ }, ref) => {
79
+ const viewport = useViewport();
80
+ const {
81
+ space,
82
+ fieldSpace
83
+ } = useThemeTokens('RadioGroup', tokens, variant, {
84
+ viewport
85
+ });
86
+ const {
87
+ currentValue,
88
+ setValue
89
+ } = useInputValue({
90
+ value: checkedId,
91
+ initialValue: initialCheckedId,
92
+ onChange,
93
+ readOnly: readOnly || inactive
94
+ });
95
+ const radios = items.map(({
96
+ label,
97
+ id,
98
+ onChange: itemOnChange,
99
+ ref: itemRef
100
+ }, index) => {
101
+ const radioId = id || `Radio[${index}]`;
102
+ const isChecked = currentValue === radioId;
103
+
104
+ const handleChange = (newCheckedState, event) => {
105
+ if (typeof itemOnChange === 'function') itemOnChange(newCheckedState, event);
106
+ if (newCheckedState) setValue(radioId, event);
107
+ };
108
+
109
+ return /*#__PURE__*/_jsx(Radio, {
110
+ ref: itemRef,
111
+ id: radioId,
112
+ checked: isChecked,
113
+ onChange: handleChange,
114
+ inactive: inactive,
115
+ label: label,
116
+ name: inputGroupName,
117
+ tokens: radioTokens,
118
+ variant: variant
119
+ }, radioId);
120
+ });
121
+ return /*#__PURE__*/_jsx(Fieldset, {
122
+ ref: ref,
123
+ name: inputGroupName,
124
+ legend: legend,
125
+ tooltip: tooltip,
126
+ hint: hint,
127
+ space: fieldSpace,
128
+ feedback: feedback,
129
+ inactive: inactive,
130
+ validation: validation,
131
+ accessibilityRole: "radiogroup",
132
+ ...selectProps(rest),
133
+ children: getStackedContent(radios, {
134
+ space,
135
+ direction: 'column'
136
+ })
137
+ });
138
+ });
139
+ RadioGroup.displayName = 'RadioGroup';
140
+ RadioGroup.propTypes = { ...selectedSystemPropTypes,
141
+
142
+ /**
143
+ * Optional theme token overrides for the outer RadioGroup component
144
+ */
145
+ tokens: getTokensPropType('RadioGroup'),
146
+
147
+ /**
148
+ * Optional theme token overrides for each inner Radio component
149
+ */
150
+ radioTokens: getTokensPropType('Radio'),
151
+
152
+ /**
153
+ * Theme variants, shared between both RadioGroup and Radio
154
+ */
155
+ variant: variantProp.propType,
156
+
157
+ /**
158
+ * Array of objects containing specifics for each Radio to be rendered in the group.
159
+ */
160
+ items: PropTypes.arrayOf(PropTypes.exact({
161
+ label: PropTypes.string,
162
+ id: PropTypes.string,
163
+ onChange: PropTypes.func,
164
+ ref: ABBPropTypes.ref()
165
+ })),
166
+
167
+ /**
168
+ * Main text used to describe this group, used in Fieldset's Legend element.
169
+ */
170
+ legend: 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
+ * Current validation status of the group, passed to the feedback element if there is one.
184
+ */
185
+ validation: PropTypes.oneOf(['error', 'success']),
186
+
187
+ /**
188
+ * If provided, a Feedback element is rendered containing this text.
189
+ */
190
+ feedback: PropTypes.string,
191
+
192
+ /**
193
+ * If provided, the radio card with this id is selected on first render.
194
+ */
195
+ initialCheckedId: PropTypes.string,
196
+
197
+ /**
198
+ * If not undefined, the radio card with this id is selected (or none is selected if `null`), and the
199
+ * element's selection state will be controlled by its parent using the `onChange` function.
200
+ */
201
+ checkedId: PropTypes.string,
202
+
203
+ /**
204
+ * Function to call on change in selection state. Is required if the selection state is controlled
205
+ * by a parent using checkedId and the input is not readOnly.
206
+ */
207
+ onChange: PropTypes.func,
208
+
209
+ /**
210
+ * If true, the radio cards cannot be selected by the user and simply show their current state.
211
+ */
212
+ readOnly: PropTypes.bool,
213
+
214
+ /**
215
+ * If true, the radio card cannot be interacted with, elements are set as `disabled` and if the
216
+ * theme supports `inactive` appearances rules, these are applied.
217
+ */
218
+ inactive: PropTypes.bool,
219
+
220
+ /**
221
+ * On Web, this is passed to the `name` attribute of the fieldset and each radio input.
222
+ */
223
+ name: PropTypes.string
224
+ };
225
+ export default RadioGroup;
@@ -0,0 +1,60 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ /**
4
+ * On Web we need to include an actual input but hide it.
5
+ */
6
+
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const RadioInput = /*#__PURE__*/forwardRef(({
9
+ checked,
10
+ defaultChecked,
11
+ disabled,
12
+ id,
13
+ isControlled,
14
+ name,
15
+ onChange,
16
+ value
17
+ }, ref) => {
18
+ const handleClick = event => {
19
+ // Cancel the click dispatched via the label tag, since it's already wrapped
20
+ // in <Pressable>
21
+ event.preventDefault();
22
+ event.stopPropagation();
23
+ };
24
+
25
+ return /*#__PURE__*/_jsx("input", {
26
+ checked: isControlled ? checked : undefined,
27
+ defaultChecked: isControlled ? undefined : defaultChecked,
28
+ disabled: disabled,
29
+ hidden: true,
30
+ id: id,
31
+ name: name,
32
+ onChange: onChange,
33
+ onClick: handleClick,
34
+ ref: ref,
35
+ type: "radio",
36
+ value: value
37
+ });
38
+ });
39
+ RadioInput.displayName = 'Radio';
40
+ RadioInput.propTypes = {
41
+ checked: PropTypes.bool,
42
+ defaultChecked: PropTypes.bool,
43
+ disabled: PropTypes.bool,
44
+ id: PropTypes.string,
45
+ isControlled: PropTypes.bool,
46
+ name: PropTypes.string,
47
+ onChange: PropTypes.func,
48
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool])
49
+ };
50
+ RadioInput.defaultProps = {
51
+ checked: undefined,
52
+ defaultChecked: undefined,
53
+ disabled: false,
54
+ id: null,
55
+ isControlled: false,
56
+ name: undefined,
57
+ onChange: () => {},
58
+ value: undefined
59
+ };
60
+ export default RadioInput;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * There's no radio button input on native platforms, so this is a noop.
3
+ */
4
+ const RadioInput = () => null;
5
+
6
+ export default RadioInput;
@@ -0,0 +1,3 @@
1
+ import Radio from './Radio';
2
+ export default Radio;
3
+ export { default as RadioGroup } from './RadioGroup';