@telus-uds/components-base 1.8.3 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/CHANGELOG.md +37 -2
  2. package/component-docs.json +17 -1
  3. package/lib/ActivityIndicator/Spinner.js +7 -7
  4. package/lib/ActivityIndicator/Spinner.native.js +2 -2
  5. package/lib/Button/ButtonBase.js +2 -2
  6. package/lib/Button/ButtonGroup.js +1 -1
  7. package/lib/Card/Card.js +9 -4
  8. package/lib/Checkbox/Checkbox.js +5 -3
  9. package/lib/Checkbox/CheckboxGroup.js +2 -2
  10. package/lib/Divider/Divider.js +2 -2
  11. package/lib/ExpandCollapse/Panel.js +12 -18
  12. package/lib/FlexGrid/Col/Col.js +1 -1
  13. package/lib/Icon/Icon.js +1 -1
  14. package/lib/Link/InlinePressable.js +5 -1
  15. package/lib/Link/LinkBase.js +5 -2
  16. package/lib/List/List.js +8 -2
  17. package/lib/Pagination/PageButton.js +2 -2
  18. package/lib/Pagination/Pagination.js +5 -3
  19. package/lib/Pagination/usePagination.js +2 -2
  20. package/lib/Progress/ProgressBar.js +3 -3
  21. package/lib/Progress/ProgressBarBackground.js +3 -3
  22. package/lib/Radio/Radio.js +2 -2
  23. package/lib/Radio/RadioGroup.js +2 -2
  24. package/lib/RadioCard/RadioCard.js +1 -1
  25. package/lib/RadioCard/RadioCardGroup.js +2 -2
  26. package/lib/Search/Search.js +1 -1
  27. package/lib/SideNav/SideNav.js +2 -2
  28. package/lib/Skeleton/Skeleton.js +1 -1
  29. package/lib/Skeleton/skeletonWebAnimation.js +1 -1
  30. package/lib/StackView/StackWrap.js +3 -1
  31. package/lib/StackView/getStackedContent.js +2 -2
  32. package/lib/Tabs/Tabs.js +28 -3
  33. package/lib/Tabs/TabsItem.js +5 -6
  34. package/lib/Tags/Tags.js +1 -1
  35. package/lib/TextInput/TextInput.js +0 -11
  36. package/lib/TextInput/TextInputBase.js +9 -0
  37. package/lib/TextInput/propTypes.js +3 -8
  38. package/lib/ThemeProvider/utils/styles.js +2 -2
  39. package/lib/ThemeProvider/utils/theme-tokens.js +7 -9
  40. package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
  41. package/lib/ToggleSwitch/ToggleSwitchGroup.js +1 -1
  42. package/lib/Tooltip/Backdrop.js +2 -10
  43. package/lib/utils/animation/useVerticalExpandAnimation.js +40 -14
  44. package/lib/utils/children.js +2 -2
  45. package/lib/utils/input.js +6 -12
  46. package/lib/utils/props/componentPropType.js +3 -3
  47. package/lib/utils/props/selectSystemProps.js +2 -2
  48. package/lib/utils/props/textInputProps.js +8 -1
  49. package/lib/utils/props/tokens.js +2 -2
  50. package/lib/utils/useSpacingScale.js +3 -1
  51. package/lib/utils/useUniqueId.js +1 -1
  52. package/lib-module/A11yInfoProvider/index.js +63 -0
  53. package/lib-module/A11yText/index.js +56 -0
  54. package/lib-module/ActivityIndicator/Spinner.js +77 -0
  55. package/lib-module/ActivityIndicator/Spinner.native.js +144 -0
  56. package/lib-module/ActivityIndicator/index.js +41 -0
  57. package/lib-module/ActivityIndicator/shared.js +12 -0
  58. package/lib-module/BaseProvider/index.js +29 -0
  59. package/lib-module/Box/Box.js +244 -0
  60. package/lib-module/Box/index.js +2 -0
  61. package/lib-module/Button/Button.js +26 -0
  62. package/lib-module/Button/ButtonBase.js +271 -0
  63. package/lib-module/Button/ButtonGroup.js +247 -0
  64. package/lib-module/Button/ButtonLink.js +40 -0
  65. package/lib-module/Button/index.js +4 -0
  66. package/lib-module/Button/propTypes.js +36 -0
  67. package/lib-module/Card/Card.js +85 -0
  68. package/lib-module/Card/CardBase.js +66 -0
  69. package/lib-module/Card/PressableCardBase.js +114 -0
  70. package/lib-module/Card/index.js +4 -0
  71. package/lib-module/Checkbox/Checkbox.js +348 -0
  72. package/lib-module/Checkbox/CheckboxGroup.js +233 -0
  73. package/lib-module/Checkbox/CheckboxInput.js +60 -0
  74. package/lib-module/Checkbox/CheckboxInput.native.js +6 -0
  75. package/lib-module/Checkbox/index.js +3 -0
  76. package/lib-module/Divider/Divider.js +124 -0
  77. package/lib-module/Divider/index.js +2 -0
  78. package/lib-module/ExpandCollapse/Accordion.js +15 -0
  79. package/lib-module/ExpandCollapse/Control.js +136 -0
  80. package/lib-module/ExpandCollapse/ExpandCollapse.js +95 -0
  81. package/lib-module/ExpandCollapse/Panel.js +159 -0
  82. package/lib-module/ExpandCollapse/index.js +7 -0
  83. package/lib-module/Feedback/Feedback.js +157 -0
  84. package/lib-module/Feedback/index.js +2 -0
  85. package/lib-module/Fieldset/Fieldset.js +153 -0
  86. package/lib-module/Fieldset/FieldsetContainer.js +32 -0
  87. package/lib-module/Fieldset/FieldsetContainer.native.js +23 -0
  88. package/lib-module/Fieldset/Legend.js +24 -0
  89. package/lib-module/Fieldset/Legend.native.js +31 -0
  90. package/lib-module/Fieldset/cssReset.js +14 -0
  91. package/lib-module/Fieldset/index.js +2 -0
  92. package/lib-module/FlexGrid/Col/Col.js +276 -0
  93. package/lib-module/FlexGrid/Col/index.js +2 -0
  94. package/lib-module/FlexGrid/FlexGrid.js +148 -0
  95. package/lib-module/FlexGrid/Row/Row.js +184 -0
  96. package/lib-module/FlexGrid/Row/index.js +2 -0
  97. package/lib-module/FlexGrid/helpers/index.js +18 -0
  98. package/lib-module/FlexGrid/index.js +2 -0
  99. package/lib-module/FlexGrid/providers/GutterContext.js +3 -0
  100. package/lib-module/HorizontalScroll/HorizontalScroll.js +175 -0
  101. package/lib-module/HorizontalScroll/HorizontalScrollButton.js +81 -0
  102. package/lib-module/HorizontalScroll/ScrollViewEnd.js +48 -0
  103. package/lib-module/HorizontalScroll/ScrollViewEnd.native.js +27 -0
  104. package/lib-module/HorizontalScroll/dictionary.js +11 -0
  105. package/lib-module/HorizontalScroll/index.js +11 -0
  106. package/lib-module/HorizontalScroll/itemPositions.js +112 -0
  107. package/lib-module/Icon/Icon.js +62 -0
  108. package/lib-module/Icon/IconText.js +83 -0
  109. package/lib-module/Icon/index.js +4 -0
  110. package/lib-module/IconButton/IconButton.js +122 -0
  111. package/lib-module/IconButton/index.js +2 -0
  112. package/lib-module/InputLabel/InputLabel.js +148 -0
  113. package/lib-module/InputLabel/LabelContent.js +27 -0
  114. package/lib-module/InputLabel/LabelContent.native.js +19 -0
  115. package/lib-module/InputLabel/index.js +2 -0
  116. package/lib-module/InputSupports/InputSupports.js +96 -0
  117. package/lib-module/InputSupports/index.js +2 -0
  118. package/lib-module/InputSupports/useInputSupports.js +32 -0
  119. package/lib-module/Link/ChevronLink.js +52 -0
  120. package/lib-module/Link/InlinePressable.js +44 -0
  121. package/lib-module/Link/InlinePressable.native.js +89 -0
  122. package/lib-module/Link/Link.js +28 -0
  123. package/lib-module/Link/LinkBase.js +243 -0
  124. package/lib-module/Link/TextButton.js +35 -0
  125. package/lib-module/Link/index.js +5 -0
  126. package/lib-module/List/List.js +62 -0
  127. package/lib-module/List/ListItem.js +248 -0
  128. package/lib-module/List/index.js +5 -0
  129. package/lib-module/Modal/Modal.js +222 -0
  130. package/lib-module/Modal/dictionary.js +9 -0
  131. package/lib-module/Modal/index.js +2 -0
  132. package/lib-module/Notification/Notification.js +209 -0
  133. package/lib-module/Notification/dictionary.js +8 -0
  134. package/lib-module/Notification/index.js +2 -0
  135. package/lib-module/Pagination/PageButton.js +66 -0
  136. package/lib-module/Pagination/Pagination.js +153 -0
  137. package/lib-module/Pagination/SideButton.js +106 -0
  138. package/lib-module/Pagination/dictionary.js +18 -0
  139. package/lib-module/Pagination/index.js +2 -0
  140. package/lib-module/Pagination/usePagination.js +73 -0
  141. package/lib-module/Progress/Progress.js +89 -0
  142. package/lib-module/Progress/ProgressBar.js +138 -0
  143. package/lib-module/Progress/ProgressBarBackground.js +42 -0
  144. package/lib-module/Progress/index.js +4 -0
  145. package/lib-module/Radio/Radio.js +285 -0
  146. package/lib-module/Radio/RadioButton.js +138 -0
  147. package/lib-module/Radio/RadioGroup.js +243 -0
  148. package/lib-module/Radio/RadioInput.js +62 -0
  149. package/lib-module/Radio/RadioInput.native.js +6 -0
  150. package/lib-module/Radio/index.js +3 -0
  151. package/lib-module/RadioCard/RadioCard.js +219 -0
  152. package/lib-module/RadioCard/RadioCardGroup.js +250 -0
  153. package/lib-module/RadioCard/index.js +3 -0
  154. package/lib-module/Search/Search.js +261 -0
  155. package/lib-module/Search/dictionary.js +12 -0
  156. package/lib-module/Search/index.js +2 -0
  157. package/lib-module/Select/Group.js +21 -0
  158. package/lib-module/Select/Group.native.js +15 -0
  159. package/lib-module/Select/Item.js +20 -0
  160. package/lib-module/Select/Item.native.js +3 -0
  161. package/lib-module/Select/Picker.js +68 -0
  162. package/lib-module/Select/Picker.native.js +120 -0
  163. package/lib-module/Select/Select.js +337 -0
  164. package/lib-module/Select/index.js +6 -0
  165. package/lib-module/SideNav/Item.js +145 -0
  166. package/lib-module/SideNav/ItemContent.js +48 -0
  167. package/lib-module/SideNav/ItemsGroup.js +117 -0
  168. package/lib-module/SideNav/SideNav.js +136 -0
  169. package/lib-module/SideNav/index.js +1 -0
  170. package/lib-module/Skeleton/Skeleton.js +179 -0
  171. package/lib-module/Skeleton/index.js +2 -0
  172. package/lib-module/Skeleton/skeleton.constant.js +3 -0
  173. package/lib-module/Skeleton/skeletonWebAnimation.js +18 -0
  174. package/lib-module/Skeleton/useSkeletonNativeAnimation.js +24 -0
  175. package/lib-module/Spacer/Spacer.js +98 -0
  176. package/lib-module/Spacer/index.js +2 -0
  177. package/lib-module/StackView/StackView.js +125 -0
  178. package/lib-module/StackView/StackWrap.js +50 -0
  179. package/lib-module/StackView/StackWrap.native.js +3 -0
  180. package/lib-module/StackView/StackWrapBox.js +115 -0
  181. package/lib-module/StackView/StackWrapGap.js +59 -0
  182. package/lib-module/StackView/common.js +35 -0
  183. package/lib-module/StackView/getStackedContent.js +124 -0
  184. package/lib-module/StackView/index.js +5 -0
  185. package/lib-module/StepTracker/Step.js +248 -0
  186. package/lib-module/StepTracker/StepTracker.js +185 -0
  187. package/lib-module/StepTracker/dictionary.js +10 -0
  188. package/lib-module/StepTracker/index.js +2 -0
  189. package/lib-module/Tabs/Tabs.js +143 -0
  190. package/lib-module/Tabs/TabsItem.js +224 -0
  191. package/lib-module/Tabs/index.js +2 -0
  192. package/lib-module/Tags/Tags.js +251 -0
  193. package/lib-module/Tags/index.js +2 -0
  194. package/lib-module/TextInput/TextArea.js +94 -0
  195. package/lib-module/TextInput/TextInput.js +64 -0
  196. package/lib-module/TextInput/TextInputBase.js +254 -0
  197. package/lib-module/TextInput/index.js +3 -0
  198. package/lib-module/TextInput/propTypes.js +33 -0
  199. package/lib-module/ThemeProvider/ThemeProvider.js +36 -0
  200. package/lib-module/ThemeProvider/index.js +6 -0
  201. package/lib-module/ThemeProvider/useSetTheme.js +25 -0
  202. package/lib-module/ThemeProvider/useTheme.js +14 -0
  203. package/lib-module/ThemeProvider/useThemeTokens.js +110 -0
  204. package/lib-module/ThemeProvider/utils/index.js +2 -0
  205. package/lib-module/ThemeProvider/utils/styles.js +181 -0
  206. package/lib-module/ThemeProvider/utils/theme-tokens.js +163 -0
  207. package/lib-module/ToggleSwitch/ToggleSwitch.js +250 -0
  208. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +220 -0
  209. package/lib-module/ToggleSwitch/index.js +3 -0
  210. package/lib-module/Tooltip/Backdrop.js +45 -0
  211. package/lib-module/Tooltip/Backdrop.native.js +44 -0
  212. package/lib-module/Tooltip/Tooltip.js +348 -0
  213. package/lib-module/Tooltip/dictionary.js +8 -0
  214. package/lib-module/Tooltip/getTooltipPosition.js +175 -0
  215. package/lib-module/Tooltip/index.js +2 -0
  216. package/lib-module/TooltipButton/TooltipButton.js +78 -0
  217. package/lib-module/TooltipButton/index.js +2 -0
  218. package/lib-module/Typography/Typography.js +124 -0
  219. package/lib-module/Typography/index.js +2 -0
  220. package/lib-module/ViewportProvider/ViewportProvider.js +29 -0
  221. package/lib-module/ViewportProvider/index.js +3 -0
  222. package/lib-module/ViewportProvider/useViewport.js +3 -0
  223. package/lib-module/ViewportProvider/useViewportListener.js +46 -0
  224. package/lib-module/index.js +48 -0
  225. package/lib-module/utils/a11y/index.js +2 -0
  226. package/lib-module/utils/a11y/semantics.js +157 -0
  227. package/lib-module/utils/a11y/textSize.js +36 -0
  228. package/lib-module/utils/animation/index.js +2 -0
  229. package/lib-module/utils/animation/useVerticalExpandAnimation.js +88 -0
  230. package/lib-module/utils/children.js +119 -0
  231. package/lib-module/utils/containUniqueFields.js +26 -0
  232. package/lib-module/utils/index.js +16 -0
  233. package/lib-module/utils/info/index.js +7 -0
  234. package/lib-module/utils/info/platform/index.js +11 -0
  235. package/lib-module/utils/info/platform/platform.android.js +1 -0
  236. package/lib-module/utils/info/platform/platform.ios.js +1 -0
  237. package/lib-module/utils/info/platform/platform.js +1 -0
  238. package/lib-module/utils/info/platform/platform.native.js +4 -0
  239. package/lib-module/utils/info/versions.js +5 -0
  240. package/lib-module/utils/input.js +179 -0
  241. package/lib-module/utils/pressability.js +111 -0
  242. package/lib-module/utils/props/a11yProps.js +140 -0
  243. package/lib-module/utils/props/clickProps.js +26 -0
  244. package/lib-module/utils/props/componentPropType.js +63 -0
  245. package/lib-module/utils/props/copyPropTypes.js +2 -0
  246. package/lib-module/utils/props/getPropSelector.js +9 -0
  247. package/lib-module/utils/props/handlerProps.js +65 -0
  248. package/lib-module/utils/props/hrefAttrsProp.js +33 -0
  249. package/lib-module/utils/props/index.js +19 -0
  250. package/lib-module/utils/props/inputSupportsProps.js +62 -0
  251. package/lib-module/utils/props/linkProps.js +44 -0
  252. package/lib-module/utils/props/paddingProp.js +9 -0
  253. package/lib-module/utils/props/pressProps.js +42 -0
  254. package/lib-module/utils/props/rectProp.js +9 -0
  255. package/lib-module/utils/props/responsiveProps.js +30 -0
  256. package/lib-module/utils/props/selectSystemProps.js +24 -0
  257. package/lib-module/utils/props/spacingProps.js +56 -0
  258. package/lib-module/utils/props/textInputProps.js +201 -0
  259. package/lib-module/utils/props/textProps.js +59 -0
  260. package/lib-module/utils/props/tokens.js +133 -0
  261. package/lib-module/utils/props/variantProp.js +18 -0
  262. package/lib-module/utils/props/viewProps.js +22 -0
  263. package/lib-module/utils/ssr.js +38 -0
  264. package/lib-module/utils/useCopy.js +44 -0
  265. package/lib-module/utils/useHash.js +45 -0
  266. package/lib-module/utils/useHash.native.js +7 -0
  267. package/lib-module/utils/useResponsiveProp.js +47 -0
  268. package/lib-module/utils/useSpacingScale.js +125 -0
  269. package/lib-module/utils/useUniqueId.js +13 -0
  270. package/lib-module/utils/withLinkRouter.js +83 -0
  271. package/package.json +3 -3
  272. package/src/Card/Card.jsx +6 -4
  273. package/src/Checkbox/Checkbox.jsx +3 -1
  274. package/src/ExpandCollapse/Panel.jsx +10 -20
  275. package/src/Link/InlinePressable.jsx +5 -2
  276. package/src/Link/LinkBase.jsx +4 -1
  277. package/src/List/List.jsx +6 -2
  278. package/src/Tabs/Tabs.jsx +24 -2
  279. package/src/Tabs/TabsItem.jsx +6 -5
  280. package/src/TextInput/TextInput.jsx +1 -8
  281. package/src/TextInput/TextInputBase.jsx +11 -1
  282. package/src/TextInput/propTypes.js +3 -7
  283. package/src/utils/animation/useVerticalExpandAnimation.js +47 -13
  284. package/src/utils/props/textInputProps.js +7 -1
@@ -0,0 +1,62 @@
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((_ref, ref) => {
9
+ let {
10
+ checked,
11
+ defaultChecked,
12
+ disabled,
13
+ id,
14
+ isControlled,
15
+ name,
16
+ onChange,
17
+ value
18
+ } = _ref;
19
+
20
+ const handleClick = event => {
21
+ // Cancel the click dispatched via the label tag, since it's already wrapped
22
+ // in <Pressable>
23
+ event.preventDefault();
24
+ event.stopPropagation();
25
+ };
26
+
27
+ return /*#__PURE__*/_jsx("input", {
28
+ checked: isControlled ? checked : undefined,
29
+ defaultChecked: isControlled ? undefined : defaultChecked,
30
+ disabled: disabled,
31
+ hidden: true,
32
+ id: id,
33
+ name: name,
34
+ onChange: onChange,
35
+ onClick: handleClick,
36
+ ref: ref,
37
+ type: "radio",
38
+ value: value
39
+ });
40
+ });
41
+ RadioInput.displayName = 'Radio';
42
+ RadioInput.propTypes = {
43
+ checked: PropTypes.bool,
44
+ defaultChecked: PropTypes.bool,
45
+ disabled: PropTypes.bool,
46
+ id: PropTypes.string,
47
+ isControlled: PropTypes.bool,
48
+ name: PropTypes.string,
49
+ onChange: PropTypes.func,
50
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool])
51
+ };
52
+ RadioInput.defaultProps = {
53
+ checked: undefined,
54
+ defaultChecked: undefined,
55
+ disabled: false,
56
+ id: null,
57
+ isControlled: false,
58
+ name: undefined,
59
+ onChange: () => {},
60
+ value: undefined
61
+ };
62
+ 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';
@@ -0,0 +1,219 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
4
+ import Text from "react-native-web/dist/exports/Text";
5
+ import View from "react-native-web/dist/exports/View";
6
+ import { useThemeTokensCallback, applyTextStyles } from '../ThemeProvider';
7
+ import { a11yProps, focusHandlerProps, getTokensPropType, selectSystemProps, selectTokens, useInputValue, useUniqueId, variantProp, viewProps } from '../utils';
8
+ import { PressableCardBase, selectPressableCardTokens } from '../Card';
9
+ import StackView from '../StackView';
10
+ import RadioButton, { selectRadioButtonTokens } from '../Radio/RadioButton';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsxs as _jsxs } from "react/jsx-runtime";
13
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, viewProps]);
14
+ /**
15
+ * A Card that behaves like a radio button. Use when users select a single choice from mutually exclusive options
16
+ * with need to show additional information for each option. The whole card is interactive as one item.
17
+ *
18
+ * ## Component API
19
+ *
20
+ * Use `title` prop to provide a main description, and `children` for additional content. Avoid including
21
+ * interactive elements within the RadioCard content.
22
+ *
23
+ * For a disabled `RadioCard`, set the `inactive` prop to `true`.
24
+ *
25
+ * ### Controlled version
26
+ *
27
+ * If the radio card is controlled from outside, it needs to receive `checked` and `onChange` props.
28
+ *
29
+ * ### Uncontrolled version
30
+ *
31
+ * In case of uncontrolled radio card you can use `defaultChecked` prop to provide the initial value.
32
+ * Whenever the radio card gets toggled, it calls the `onChange` callback with the new value (boolean).
33
+ *
34
+ * ### Using within forms
35
+ *
36
+ * You can pass `name` and `value` props if you need a particular radio card to be a part of a radio group
37
+ * on a form.
38
+ *
39
+ * ### Validation
40
+ *
41
+ * You can mark a radio card as failing validation by setting the `error` prop to `true`.
42
+ *
43
+ * ## A11y guidelines
44
+ *
45
+ * Radio card accepts all the common accessibility props, but also sets some defaults, including
46
+ * accessibility role `'radio'` and accessibility state that depends on the other props (`checked`, `inactive`)
47
+ * or the internal state in case of uncontrolled radio button.
48
+ */
49
+
50
+ const RadioCard = /*#__PURE__*/forwardRef((_ref, ref) => {
51
+ let {
52
+ tokens,
53
+ variant,
54
+ title,
55
+ children,
56
+ inactive,
57
+ defaultChecked,
58
+ checked,
59
+ name: inputName,
60
+ value,
61
+ id,
62
+ onChange,
63
+ ...rest
64
+ } = _ref;
65
+ const {
66
+ currentValue: isChecked,
67
+ setValue: setIsChecked,
68
+ isControlled
69
+ } = useInputValue({
70
+ value: checked,
71
+ initialValue: defaultChecked,
72
+ onChange
73
+ });
74
+
75
+ const handleChange = event => {
76
+ if (!inactive && !isChecked) {
77
+ setIsChecked(true, event);
78
+ }
79
+ };
80
+
81
+ const uniqueId = useUniqueId('RadioCard');
82
+ const inputId = id !== null && id !== void 0 ? id : uniqueId;
83
+ const getTokens = useThemeTokensCallback('RadioCard', tokens, variant);
84
+
85
+ const getCardTokens = cardState => selectPressableCardTokens(getTokens(cardState));
86
+
87
+ return /*#__PURE__*/_jsx(PressableCardBase, {
88
+ ref: ref,
89
+ inactive: inactive,
90
+ checked: isChecked,
91
+ tokens: getCardTokens,
92
+ onPress: handleChange,
93
+ accessibilityRole: "radio",
94
+ accessibilityState: {
95
+ checked: isChecked,
96
+ disabled: inactive
97
+ },
98
+ ...selectProps(rest),
99
+ children: cardState => {
100
+ const {
101
+ radioSpace,
102
+ contentSpace,
103
+ ...themeTokens
104
+ } = getTokens(cardState);
105
+ const radioTokens = selectRadioButtonTokens(themeTokens, 'radio');
106
+ const titleTokens = selectTokens('Typography', themeTokens);
107
+ const textStyle = applyTextStyles(titleTokens);
108
+ return /*#__PURE__*/_jsxs(StackView, {
109
+ direction: "row",
110
+ space: radioSpace,
111
+ children: [/*#__PURE__*/_jsx(View, {
112
+ style: [staticStyles.alignWithText, {
113
+ height: textStyle.lineHeight
114
+ }],
115
+ children: /*#__PURE__*/_jsx(RadioButton, {
116
+ tokens: radioTokens,
117
+ isControlled: isControlled,
118
+ isChecked: isChecked,
119
+ inactive: inactive,
120
+ defaultChecked: defaultChecked,
121
+ inputId: inputId,
122
+ handleChange: handleChange,
123
+ name: inputName,
124
+ value: value
125
+ })
126
+ }), /*#__PURE__*/_jsxs(StackView, {
127
+ direction: "column",
128
+ space: contentSpace,
129
+ tokens: {
130
+ flexShrink: 1
131
+ },
132
+ children: [title && /*#__PURE__*/_jsx(Text, {
133
+ style: textStyle,
134
+ children: title
135
+ }), typeof children === 'function' ? children(cardState, textStyle) : children]
136
+ })]
137
+ });
138
+ }
139
+ });
140
+ });
141
+ RadioCard.displayName = 'RadioCard';
142
+ RadioCard.propTypes = { ...selectedSystemPropTypes,
143
+
144
+ /**
145
+ * Content to be displayed at the top of the card alongside the radio button
146
+ */
147
+ title: PropTypes.string,
148
+
149
+ /**
150
+ * Additional content to be displayed below the button.
151
+ */
152
+ children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
153
+
154
+ /**
155
+ * Use `checked` for controlled Radio. For uncontrolled Radio, use the `defaultChecked` prop.
156
+ */
157
+ checked: PropTypes.bool,
158
+
159
+ /**
160
+ * Use `defaultChecked` to provide the initial value for an uncontrolled Radio.
161
+ */
162
+ defaultChecked: PropTypes.bool,
163
+
164
+ /**
165
+ * An optional radio button description.
166
+ */
167
+ description: PropTypes.string,
168
+
169
+ /**
170
+ * Radio card button ID.
171
+ */
172
+ id: PropTypes.string,
173
+
174
+ /**
175
+ * Whether the corresponding input is disabled or active.
176
+ */
177
+ inactive: PropTypes.bool,
178
+
179
+ /**
180
+ * The label.
181
+ */
182
+ label: PropTypes.string,
183
+
184
+ /**
185
+ * Associate this radio card with a group (set as the name attribute).
186
+ */
187
+ name: PropTypes.string,
188
+
189
+ /**
190
+ * Whether the underlying input triggered a validation error or not.
191
+ */
192
+ error: PropTypes.bool,
193
+
194
+ /**
195
+ * The value. Must be unique within the group.
196
+ */
197
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
198
+
199
+ /**
200
+ * Callback called when a controlled radio card gets interacted with.
201
+ */
202
+ onChange: PropTypes.func,
203
+
204
+ /**
205
+ * Radio card tokens.
206
+ */
207
+ tokens: getTokensPropType('RadioCard'),
208
+
209
+ /**
210
+ * Radio variant.
211
+ */
212
+ variant: variantProp.propType
213
+ };
214
+ const staticStyles = StyleSheet.create({
215
+ alignWithText: {
216
+ justifyContent: 'center'
217
+ }
218
+ });
219
+ export default RadioCard;
@@ -0,0 +1,250 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { useViewport } from '../ViewportProvider';
4
+ import { useThemeTokens } from '../ThemeProvider';
5
+ import { a11yProps, containUniqueFields, focusHandlerProps, getTokensPropType, selectSystemProps, useInputValue, variantProp, viewProps } from '../utils';
6
+ import StackView, { StackWrap } from '../StackView';
7
+ import RadioCard from './RadioCard';
8
+ import Fieldset from '../Fieldset';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
11
+ const [selectItemProps, selectedItemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, viewProps]);
12
+ /**
13
+ * A group of Cards that behave as a radio button group. Use when users select a single choice from mutually
14
+ * exclusive options with need to show additional information for each option. The whole cards are each
15
+ * interactive as one item.
16
+ *
17
+ * ## Component API
18
+ *
19
+ * Use the `items` prop to pass an array of objects describing each RadioCard in the group:
20
+ *
21
+ * - `title`: main text passed to RadioCard's `title` prop
22
+ * - `content`: React content passed to RadioCard's `children` prop
23
+ * - `id`: identifier used to store which RadioCard is selected (uses `title` if undefinded)
24
+ * - `onChange`: optional function called on selection, in addition to updating the group's selection state
25
+ *
26
+ * ### Controlled version
27
+ *
28
+ * If the selection state is controlled from outside, it needs to receive `checkedId` and `onChange` props.
29
+ *
30
+ * ### Uncontrolled version
31
+ *
32
+ * If the RadioCardGroup manages its own state, you can use `initialCheckedId` prop to provide the initial value.
33
+ * Whenever the radio card gets toggled, it calls the `onChange` callback with the new value (string).
34
+ *
35
+ * ### Use in forms
36
+ *
37
+ * For web forms, the `name` prop may be used to define the name of the group's `fieldset` and input elements.
38
+ *
39
+ * ### Validation
40
+ *
41
+ * Validation state may be set by passing 'error' or 'success' to the `validation` prop.
42
+ *
43
+ * ## A11y guidelines
44
+ *
45
+ * RadioCardGroup accepts all the common accessibility props, but also sets accessibility role `'radiogroup'`
46
+ * and controls the accessibility state of children like RadioCard and Feedback based on current state.
47
+ *
48
+ * @example
49
+ * ```jsx
50
+ * <RadioCardGroup
51
+ * initialCheckedId="card1"
52
+ * items={[
53
+ * { title: 'Card 1', id: 'card1', content: <Typography>More info</Typography> },
54
+ * { title: 'Card 2', id: 'card2', content: <Typography>Extra content</Typography> },
55
+ * { title: 'Card 3', id: 'card3', content: <Typography>More content</Typography> }
56
+ * ]}
57
+ * legend="Cards"
58
+ * hint="Choose a card to select"
59
+ * />
60
+ * ```
61
+ */
62
+
63
+ const RadioCardGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
64
+ let {
65
+ copy = 'en',
66
+ tokens,
67
+ radioCardTokens,
68
+ variant,
69
+ items = [],
70
+ legend,
71
+ tooltip,
72
+ hint,
73
+ validation,
74
+ feedback,
75
+ initialCheckedId,
76
+ checkedId,
77
+ onChange,
78
+ readOnly,
79
+ name: inputGroupName,
80
+ inactive,
81
+ ...rest
82
+ } = _ref;
83
+ const viewport = useViewport();
84
+ const {
85
+ space,
86
+ fieldSpace,
87
+ direction
88
+ } = useThemeTokens('RadioCardGroup', tokens, variant, {
89
+ viewport
90
+ });
91
+ const {
92
+ currentValue,
93
+ setValue
94
+ } = useInputValue({
95
+ value: checkedId,
96
+ initialValue: initialCheckedId,
97
+ onChange,
98
+ readOnly: readOnly || inactive
99
+ });
100
+ const StackContainer = direction === 'row' ? StackWrap : StackView; // Needs 'radiogroup' role on direct parent of radios for MacOS Voiceover's numbering to work,
101
+ // and also needs 'radiogroup' role on fieldset for correct description on focusing the set.
102
+ // TODO: test this on more web screen readers.
103
+
104
+ const uniqueFields = ['id'];
105
+
106
+ if (!containUniqueFields(items, uniqueFields)) {
107
+ throw new Error("RadioCardGroup items must have unique ".concat(uniqueFields.join(', ')));
108
+ }
109
+
110
+ return /*#__PURE__*/_jsx(Fieldset, {
111
+ copy: copy,
112
+ ref: ref,
113
+ name: inputGroupName,
114
+ legend: legend,
115
+ tooltip: tooltip,
116
+ hint: hint,
117
+ space: fieldSpace,
118
+ feedback: feedback,
119
+ inactive: inactive || readOnly,
120
+ validation: validation,
121
+ accessibilityRole: "radiogroup",
122
+ ...selectProps(rest),
123
+ children: props => /*#__PURE__*/_jsx(StackContainer, {
124
+ space: space,
125
+ accessibilityRole: "radiogroup",
126
+ children: items.map((_ref2, index) => {
127
+ let {
128
+ title,
129
+ content,
130
+ id,
131
+ onChange: itemOnChange,
132
+ ...itemRest
133
+ } = _ref2;
134
+ const cardId = id || "RadioCard[".concat(index, "]");
135
+
136
+ const handleChange = (newCheckedState, event) => {
137
+ if (typeof itemOnChange === 'function') itemOnChange(newCheckedState, event);
138
+ if (newCheckedState) setValue(cardId, event);
139
+ };
140
+
141
+ return /*#__PURE__*/_jsx(RadioCard, {
142
+ id: cardId,
143
+ checked: currentValue === cardId,
144
+ onChange: handleChange,
145
+ inactive: inactive,
146
+ title: title,
147
+ name: inputGroupName,
148
+ tokens: radioCardTokens,
149
+ variant: variant,
150
+ readOnly: readOnly,
151
+ ...selectItemProps(itemRest),
152
+ ...props,
153
+ children: content
154
+ }, cardId);
155
+ })
156
+ })
157
+ });
158
+ });
159
+ RadioCardGroup.displayName = 'RadioCardGroup';
160
+ RadioCardGroup.propTypes = { ...selectedSystemPropTypes,
161
+
162
+ /**
163
+ * Whether the English or French copy will be used (e.g. for accessibility labels).
164
+ */
165
+ copy: PropTypes.oneOf(['en', 'fr']),
166
+
167
+ /**
168
+ * Optional theme token overrides for the outer RadioCardGroup component
169
+ */
170
+ tokens: getTokensPropType('RadioCardGroup'),
171
+
172
+ /**
173
+ * Optional theme token overrides for each inner RadioCard component
174
+ */
175
+ radioCardTokens: getTokensPropType('RadioCard'),
176
+
177
+ /**
178
+ * Theme variants, shared between both RadioCardGroup and RadioCard
179
+ */
180
+ variant: variantProp.propType,
181
+
182
+ /**
183
+ * Array of objects containing specifics for each RadioCard to be rendered in the group.
184
+ */
185
+ items: PropTypes.arrayOf(PropTypes.exact({ ...selectedItemPropTypes,
186
+ title: PropTypes.string,
187
+ content: PropTypes.node,
188
+ id: PropTypes.string,
189
+ onChange: PropTypes.func
190
+ })),
191
+
192
+ /**
193
+ * Main text used to describe this group, used in Fieldset's Legend element.
194
+ */
195
+ legend: PropTypes.string,
196
+
197
+ /**
198
+ * Optional additional text giving more detail to help a user make a choice.
199
+ */
200
+ hint: PropTypes.string,
201
+
202
+ /**
203
+ * Optional tooltip text content to include alongside the legend and hint.
204
+ */
205
+ tooltip: PropTypes.string,
206
+
207
+ /**
208
+ * Current validation status of the group, passed to the feedback element if there is one.
209
+ */
210
+ validation: PropTypes.oneOf(['error', 'success']),
211
+
212
+ /**
213
+ * If provided, a Feedback element is rendered containing this text.
214
+ */
215
+ feedback: PropTypes.string,
216
+
217
+ /**
218
+ * If provided, the radio card with this id is selected on first render.
219
+ */
220
+ initialCheckedId: PropTypes.string,
221
+
222
+ /**
223
+ * If not undefined, the radio card with this id is selected (or none is selected if `null`), and the
224
+ * element's selection state will be controlled by its parent using the `onChange` function.
225
+ */
226
+ checkedId: PropTypes.string,
227
+
228
+ /**
229
+ * Function to call on change in selection state. Is required if the selection state is controlled
230
+ * by a parent using checkedId and the input is not readOnly.
231
+ */
232
+ onChange: PropTypes.func,
233
+
234
+ /**
235
+ * If true, the radio cards cannot be selected by the user and simply show their current state.
236
+ */
237
+ readOnly: PropTypes.bool,
238
+
239
+ /**
240
+ * If true, the radio card cannot be interacted with, elements are set as `disabled` and if the
241
+ * theme supports `inactive` appearances rules, these are applied.
242
+ */
243
+ inactive: PropTypes.bool,
244
+
245
+ /**
246
+ * On Web, this is passed to the `name` attribute of the fieldset and each radio input.
247
+ */
248
+ name: PropTypes.string
249
+ };
250
+ export default RadioCardGroup;
@@ -0,0 +1,3 @@
1
+ import RadioCard from './RadioCard';
2
+ export default RadioCard;
3
+ export { default as RadioCardGroup } from './RadioCardGroup';