@telus-uds/components-base 1.8.2 → 1.8.5

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