@telus-uds/components-base 1.8.3 → 1.8.4

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 (269) hide show
  1. package/CHANGELOG.md +14 -2
  2. package/component-docs.json +1 -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 +1 -1
  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/List/List.js +8 -2
  14. package/lib/Pagination/PageButton.js +2 -2
  15. package/lib/Pagination/Pagination.js +5 -3
  16. package/lib/Pagination/usePagination.js +2 -2
  17. package/lib/Progress/ProgressBar.js +3 -3
  18. package/lib/Progress/ProgressBarBackground.js +3 -3
  19. package/lib/Radio/Radio.js +2 -2
  20. package/lib/Radio/RadioGroup.js +2 -2
  21. package/lib/RadioCard/RadioCard.js +1 -1
  22. package/lib/RadioCard/RadioCardGroup.js +2 -2
  23. package/lib/Search/Search.js +1 -1
  24. package/lib/SideNav/SideNav.js +2 -2
  25. package/lib/Skeleton/Skeleton.js +1 -1
  26. package/lib/Skeleton/skeletonWebAnimation.js +1 -1
  27. package/lib/StackView/StackWrap.js +3 -1
  28. package/lib/StackView/getStackedContent.js +2 -2
  29. package/lib/Tabs/Tabs.js +28 -3
  30. package/lib/Tabs/TabsItem.js +5 -6
  31. package/lib/Tags/Tags.js +1 -1
  32. package/lib/ThemeProvider/utils/styles.js +2 -2
  33. package/lib/ThemeProvider/utils/theme-tokens.js +7 -9
  34. package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
  35. package/lib/ToggleSwitch/ToggleSwitchGroup.js +1 -1
  36. package/lib/Tooltip/Backdrop.js +2 -10
  37. package/lib/utils/animation/useVerticalExpandAnimation.js +40 -14
  38. package/lib/utils/children.js +2 -2
  39. package/lib/utils/input.js +6 -12
  40. package/lib/utils/props/componentPropType.js +3 -3
  41. package/lib/utils/props/selectSystemProps.js +2 -2
  42. package/lib/utils/props/tokens.js +2 -2
  43. package/lib/utils/useSpacingScale.js +3 -1
  44. package/lib/utils/useUniqueId.js +1 -1
  45. package/lib-module/A11yInfoProvider/index.js +63 -0
  46. package/lib-module/A11yText/index.js +56 -0
  47. package/lib-module/ActivityIndicator/Spinner.js +77 -0
  48. package/lib-module/ActivityIndicator/Spinner.native.js +144 -0
  49. package/lib-module/ActivityIndicator/index.js +41 -0
  50. package/lib-module/ActivityIndicator/shared.js +12 -0
  51. package/lib-module/BaseProvider/index.js +29 -0
  52. package/lib-module/Box/Box.js +244 -0
  53. package/lib-module/Box/index.js +2 -0
  54. package/lib-module/Button/Button.js +26 -0
  55. package/lib-module/Button/ButtonBase.js +271 -0
  56. package/lib-module/Button/ButtonGroup.js +247 -0
  57. package/lib-module/Button/ButtonLink.js +40 -0
  58. package/lib-module/Button/index.js +4 -0
  59. package/lib-module/Button/propTypes.js +36 -0
  60. package/lib-module/Card/Card.js +84 -0
  61. package/lib-module/Card/CardBase.js +66 -0
  62. package/lib-module/Card/PressableCardBase.js +114 -0
  63. package/lib-module/Card/index.js +4 -0
  64. package/lib-module/Checkbox/Checkbox.js +346 -0
  65. package/lib-module/Checkbox/CheckboxGroup.js +233 -0
  66. package/lib-module/Checkbox/CheckboxInput.js +60 -0
  67. package/lib-module/Checkbox/CheckboxInput.native.js +6 -0
  68. package/lib-module/Checkbox/index.js +3 -0
  69. package/lib-module/Divider/Divider.js +124 -0
  70. package/lib-module/Divider/index.js +2 -0
  71. package/lib-module/ExpandCollapse/Accordion.js +15 -0
  72. package/lib-module/ExpandCollapse/Control.js +136 -0
  73. package/lib-module/ExpandCollapse/ExpandCollapse.js +95 -0
  74. package/lib-module/ExpandCollapse/Panel.js +151 -0
  75. package/lib-module/ExpandCollapse/index.js +7 -0
  76. package/lib-module/Feedback/Feedback.js +157 -0
  77. package/lib-module/Feedback/index.js +2 -0
  78. package/lib-module/Fieldset/Fieldset.js +153 -0
  79. package/lib-module/Fieldset/FieldsetContainer.js +32 -0
  80. package/lib-module/Fieldset/FieldsetContainer.native.js +23 -0
  81. package/lib-module/Fieldset/Legend.js +24 -0
  82. package/lib-module/Fieldset/Legend.native.js +31 -0
  83. package/lib-module/Fieldset/cssReset.js +14 -0
  84. package/lib-module/Fieldset/index.js +2 -0
  85. package/lib-module/FlexGrid/Col/Col.js +276 -0
  86. package/lib-module/FlexGrid/Col/index.js +2 -0
  87. package/lib-module/FlexGrid/FlexGrid.js +148 -0
  88. package/lib-module/FlexGrid/Row/Row.js +184 -0
  89. package/lib-module/FlexGrid/Row/index.js +2 -0
  90. package/lib-module/FlexGrid/helpers/index.js +18 -0
  91. package/lib-module/FlexGrid/index.js +2 -0
  92. package/lib-module/FlexGrid/providers/GutterContext.js +3 -0
  93. package/lib-module/HorizontalScroll/HorizontalScroll.js +175 -0
  94. package/lib-module/HorizontalScroll/HorizontalScrollButton.js +81 -0
  95. package/lib-module/HorizontalScroll/ScrollViewEnd.js +48 -0
  96. package/lib-module/HorizontalScroll/ScrollViewEnd.native.js +27 -0
  97. package/lib-module/HorizontalScroll/dictionary.js +11 -0
  98. package/lib-module/HorizontalScroll/index.js +11 -0
  99. package/lib-module/HorizontalScroll/itemPositions.js +112 -0
  100. package/lib-module/Icon/Icon.js +62 -0
  101. package/lib-module/Icon/IconText.js +83 -0
  102. package/lib-module/Icon/index.js +4 -0
  103. package/lib-module/IconButton/IconButton.js +122 -0
  104. package/lib-module/IconButton/index.js +2 -0
  105. package/lib-module/InputLabel/InputLabel.js +148 -0
  106. package/lib-module/InputLabel/LabelContent.js +27 -0
  107. package/lib-module/InputLabel/LabelContent.native.js +19 -0
  108. package/lib-module/InputLabel/index.js +2 -0
  109. package/lib-module/InputSupports/InputSupports.js +96 -0
  110. package/lib-module/InputSupports/index.js +2 -0
  111. package/lib-module/InputSupports/useInputSupports.js +32 -0
  112. package/lib-module/Link/ChevronLink.js +52 -0
  113. package/lib-module/Link/InlinePressable.js +40 -0
  114. package/lib-module/Link/InlinePressable.native.js +89 -0
  115. package/lib-module/Link/Link.js +28 -0
  116. package/lib-module/Link/LinkBase.js +240 -0
  117. package/lib-module/Link/TextButton.js +35 -0
  118. package/lib-module/Link/index.js +5 -0
  119. package/lib-module/List/List.js +62 -0
  120. package/lib-module/List/ListItem.js +248 -0
  121. package/lib-module/List/index.js +5 -0
  122. package/lib-module/Modal/Modal.js +222 -0
  123. package/lib-module/Modal/dictionary.js +9 -0
  124. package/lib-module/Modal/index.js +2 -0
  125. package/lib-module/Notification/Notification.js +209 -0
  126. package/lib-module/Notification/dictionary.js +8 -0
  127. package/lib-module/Notification/index.js +2 -0
  128. package/lib-module/Pagination/PageButton.js +66 -0
  129. package/lib-module/Pagination/Pagination.js +153 -0
  130. package/lib-module/Pagination/SideButton.js +106 -0
  131. package/lib-module/Pagination/dictionary.js +18 -0
  132. package/lib-module/Pagination/index.js +2 -0
  133. package/lib-module/Pagination/usePagination.js +73 -0
  134. package/lib-module/Progress/Progress.js +89 -0
  135. package/lib-module/Progress/ProgressBar.js +138 -0
  136. package/lib-module/Progress/ProgressBarBackground.js +42 -0
  137. package/lib-module/Progress/index.js +4 -0
  138. package/lib-module/Radio/Radio.js +285 -0
  139. package/lib-module/Radio/RadioButton.js +138 -0
  140. package/lib-module/Radio/RadioGroup.js +243 -0
  141. package/lib-module/Radio/RadioInput.js +62 -0
  142. package/lib-module/Radio/RadioInput.native.js +6 -0
  143. package/lib-module/Radio/index.js +3 -0
  144. package/lib-module/RadioCard/RadioCard.js +219 -0
  145. package/lib-module/RadioCard/RadioCardGroup.js +250 -0
  146. package/lib-module/RadioCard/index.js +3 -0
  147. package/lib-module/Search/Search.js +261 -0
  148. package/lib-module/Search/dictionary.js +12 -0
  149. package/lib-module/Search/index.js +2 -0
  150. package/lib-module/Select/Group.js +21 -0
  151. package/lib-module/Select/Group.native.js +15 -0
  152. package/lib-module/Select/Item.js +20 -0
  153. package/lib-module/Select/Item.native.js +3 -0
  154. package/lib-module/Select/Picker.js +68 -0
  155. package/lib-module/Select/Picker.native.js +120 -0
  156. package/lib-module/Select/Select.js +337 -0
  157. package/lib-module/Select/index.js +6 -0
  158. package/lib-module/SideNav/Item.js +145 -0
  159. package/lib-module/SideNav/ItemContent.js +48 -0
  160. package/lib-module/SideNav/ItemsGroup.js +117 -0
  161. package/lib-module/SideNav/SideNav.js +136 -0
  162. package/lib-module/SideNav/index.js +1 -0
  163. package/lib-module/Skeleton/Skeleton.js +179 -0
  164. package/lib-module/Skeleton/index.js +2 -0
  165. package/lib-module/Skeleton/skeleton.constant.js +3 -0
  166. package/lib-module/Skeleton/skeletonWebAnimation.js +18 -0
  167. package/lib-module/Skeleton/useSkeletonNativeAnimation.js +24 -0
  168. package/lib-module/Spacer/Spacer.js +98 -0
  169. package/lib-module/Spacer/index.js +2 -0
  170. package/lib-module/StackView/StackView.js +125 -0
  171. package/lib-module/StackView/StackWrap.js +50 -0
  172. package/lib-module/StackView/StackWrap.native.js +3 -0
  173. package/lib-module/StackView/StackWrapBox.js +115 -0
  174. package/lib-module/StackView/StackWrapGap.js +59 -0
  175. package/lib-module/StackView/common.js +35 -0
  176. package/lib-module/StackView/getStackedContent.js +124 -0
  177. package/lib-module/StackView/index.js +5 -0
  178. package/lib-module/StepTracker/Step.js +248 -0
  179. package/lib-module/StepTracker/StepTracker.js +185 -0
  180. package/lib-module/StepTracker/dictionary.js +10 -0
  181. package/lib-module/StepTracker/index.js +2 -0
  182. package/lib-module/Tabs/Tabs.js +143 -0
  183. package/lib-module/Tabs/TabsItem.js +224 -0
  184. package/lib-module/Tabs/index.js +2 -0
  185. package/lib-module/Tags/Tags.js +251 -0
  186. package/lib-module/Tags/index.js +2 -0
  187. package/lib-module/TextInput/TextArea.js +94 -0
  188. package/lib-module/TextInput/TextInput.js +72 -0
  189. package/lib-module/TextInput/TextInputBase.js +245 -0
  190. package/lib-module/TextInput/index.js +3 -0
  191. package/lib-module/TextInput/propTypes.js +37 -0
  192. package/lib-module/ThemeProvider/ThemeProvider.js +36 -0
  193. package/lib-module/ThemeProvider/index.js +6 -0
  194. package/lib-module/ThemeProvider/useSetTheme.js +25 -0
  195. package/lib-module/ThemeProvider/useTheme.js +14 -0
  196. package/lib-module/ThemeProvider/useThemeTokens.js +110 -0
  197. package/lib-module/ThemeProvider/utils/index.js +2 -0
  198. package/lib-module/ThemeProvider/utils/styles.js +181 -0
  199. package/lib-module/ThemeProvider/utils/theme-tokens.js +163 -0
  200. package/lib-module/ToggleSwitch/ToggleSwitch.js +250 -0
  201. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +220 -0
  202. package/lib-module/ToggleSwitch/index.js +3 -0
  203. package/lib-module/Tooltip/Backdrop.js +45 -0
  204. package/lib-module/Tooltip/Backdrop.native.js +44 -0
  205. package/lib-module/Tooltip/Tooltip.js +348 -0
  206. package/lib-module/Tooltip/dictionary.js +8 -0
  207. package/lib-module/Tooltip/getTooltipPosition.js +175 -0
  208. package/lib-module/Tooltip/index.js +2 -0
  209. package/lib-module/TooltipButton/TooltipButton.js +78 -0
  210. package/lib-module/TooltipButton/index.js +2 -0
  211. package/lib-module/Typography/Typography.js +124 -0
  212. package/lib-module/Typography/index.js +2 -0
  213. package/lib-module/ViewportProvider/ViewportProvider.js +29 -0
  214. package/lib-module/ViewportProvider/index.js +3 -0
  215. package/lib-module/ViewportProvider/useViewport.js +3 -0
  216. package/lib-module/ViewportProvider/useViewportListener.js +46 -0
  217. package/lib-module/index.js +48 -0
  218. package/lib-module/utils/a11y/index.js +2 -0
  219. package/lib-module/utils/a11y/semantics.js +157 -0
  220. package/lib-module/utils/a11y/textSize.js +36 -0
  221. package/lib-module/utils/animation/index.js +2 -0
  222. package/lib-module/utils/animation/useVerticalExpandAnimation.js +88 -0
  223. package/lib-module/utils/children.js +119 -0
  224. package/lib-module/utils/containUniqueFields.js +26 -0
  225. package/lib-module/utils/index.js +16 -0
  226. package/lib-module/utils/info/index.js +7 -0
  227. package/lib-module/utils/info/platform/index.js +11 -0
  228. package/lib-module/utils/info/platform/platform.android.js +1 -0
  229. package/lib-module/utils/info/platform/platform.ios.js +1 -0
  230. package/lib-module/utils/info/platform/platform.js +1 -0
  231. package/lib-module/utils/info/platform/platform.native.js +4 -0
  232. package/lib-module/utils/info/versions.js +5 -0
  233. package/lib-module/utils/input.js +179 -0
  234. package/lib-module/utils/pressability.js +111 -0
  235. package/lib-module/utils/props/a11yProps.js +140 -0
  236. package/lib-module/utils/props/clickProps.js +26 -0
  237. package/lib-module/utils/props/componentPropType.js +63 -0
  238. package/lib-module/utils/props/copyPropTypes.js +2 -0
  239. package/lib-module/utils/props/getPropSelector.js +9 -0
  240. package/lib-module/utils/props/handlerProps.js +65 -0
  241. package/lib-module/utils/props/hrefAttrsProp.js +33 -0
  242. package/lib-module/utils/props/index.js +19 -0
  243. package/lib-module/utils/props/inputSupportsProps.js +62 -0
  244. package/lib-module/utils/props/linkProps.js +44 -0
  245. package/lib-module/utils/props/paddingProp.js +9 -0
  246. package/lib-module/utils/props/pressProps.js +42 -0
  247. package/lib-module/utils/props/rectProp.js +9 -0
  248. package/lib-module/utils/props/responsiveProps.js +30 -0
  249. package/lib-module/utils/props/selectSystemProps.js +24 -0
  250. package/lib-module/utils/props/spacingProps.js +56 -0
  251. package/lib-module/utils/props/textInputProps.js +194 -0
  252. package/lib-module/utils/props/textProps.js +59 -0
  253. package/lib-module/utils/props/tokens.js +133 -0
  254. package/lib-module/utils/props/variantProp.js +18 -0
  255. package/lib-module/utils/props/viewProps.js +22 -0
  256. package/lib-module/utils/ssr.js +38 -0
  257. package/lib-module/utils/useCopy.js +44 -0
  258. package/lib-module/utils/useHash.js +45 -0
  259. package/lib-module/utils/useHash.native.js +7 -0
  260. package/lib-module/utils/useResponsiveProp.js +47 -0
  261. package/lib-module/utils/useSpacingScale.js +125 -0
  262. package/lib-module/utils/useUniqueId.js +13 -0
  263. package/lib-module/utils/withLinkRouter.js +83 -0
  264. package/package.json +2 -2
  265. package/src/ExpandCollapse/Panel.jsx +2 -19
  266. package/src/List/List.jsx +6 -2
  267. package/src/Tabs/Tabs.jsx +24 -2
  268. package/src/Tabs/TabsItem.jsx +6 -5
  269. package/src/utils/animation/useVerticalExpandAnimation.js +47 -13
@@ -0,0 +1,271 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import Pressable from "react-native-web/dist/exports/Pressable";
4
+ import View from "react-native-web/dist/exports/View";
5
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
6
+ import Platform from "react-native-web/dist/exports/Platform";
7
+ import { applyTextStyles, applyShadowToken, applyOuterBorder } from '../ThemeProvider/utils';
8
+ import buttonPropTypes from './propTypes';
9
+ import { a11yProps, clickProps, focusHandlerProps, getCursorStyle, linkProps, resolvePressableState, resolvePressableTokens, selectSystemProps, viewProps, wrapStringsInText, withLinkRouter } from '../utils';
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, linkProps, viewProps]);
12
+
13
+ const getOuterBorderOffset = _ref => {
14
+ let {
15
+ outerBorderGap = 0,
16
+ outerBorderWidth = 0
17
+ } = _ref;
18
+ return outerBorderGap + outerBorderWidth;
19
+ };
20
+
21
+ const selectOuterContainerStyles = _ref2 => {
22
+ let {
23
+ alignSelf,
24
+ opacity,
25
+ outerBorderColor,
26
+ outerBorderWidth,
27
+ outerBorderGap,
28
+ borderRadius,
29
+ outerBackgroundColor
30
+ } = _ref2;
31
+ return {
32
+ alignSelf,
33
+ backgroundColor: outerBackgroundColor,
34
+ opacity,
35
+ ...applyOuterBorder({
36
+ outerBorderGap,
37
+ outerBorderWidth,
38
+ outerBorderColor,
39
+ borderRadius
40
+ })
41
+ };
42
+ };
43
+
44
+ const selectOuterWidthStyles = _ref3 => {
45
+ let {
46
+ outerBorderGap,
47
+ outerBorderWidth,
48
+ width
49
+ } = _ref3;
50
+ // The inner container's bounding box is the bounding box of the button overall
51
+ // so this many device pixels will sit outside of the overall bounding box
52
+ const outerBorderOffset = getOuterBorderOffset({
53
+ outerBorderGap,
54
+ outerBorderWidth
55
+ });
56
+ const widthStyles = {};
57
+
58
+ if (!width) {
59
+ return { ...widthStyles,
60
+ // Wrap content, stopping a flex parent's default align-items: stretch stretching focus ring beyond content
61
+ ...Platform.select({
62
+ // width: fit-content isn't supported on Firefox; can't cascade props like CSS `width: fit-content; width: --moz-fit-content;`
63
+ web: {
64
+ display: 'inline-flex'
65
+ }
66
+ })
67
+ };
68
+ } // Apply width tokens: number === pixels, string === explicit units e.g. %
69
+
70
+
71
+ if (typeof width === 'number') {
72
+ widthStyles.width = width + outerBorderOffset * 2;
73
+ return widthStyles;
74
+ } // Ensure the negative margin doesn't make element off-centre
75
+
76
+
77
+ if (Platform.OS === 'web') {
78
+ widthStyles.width = "calc(".concat(width, " + ").concat(outerBorderOffset * 2, "px)");
79
+ return widthStyles;
80
+ } // Can't use calc() on native but (unlike on web) flexGrow fills the container width here
81
+
82
+
83
+ if (width === '100%') {
84
+ widthStyles.flexGrow = 1;
85
+ return widthStyles;
86
+ } // Slight offset not such a concern if % width < 100%, as the button isn't centered anyway.
87
+ // If centering support is added (e.g. alignSelf: center), set marginHorizontal 0 when centered.
88
+
89
+
90
+ widthStyles.width = width;
91
+ return widthStyles;
92
+ };
93
+
94
+ const selectInnerContainerStyles = _ref4 => {
95
+ let {
96
+ backgroundColor,
97
+ paddingLeft,
98
+ paddingRight,
99
+ paddingTop,
100
+ paddingBottom,
101
+ shadow,
102
+ borderWidth,
103
+ minWidth
104
+ } = _ref4;
105
+
106
+ // Subtract border width from padding so overall button width/height doesn't
107
+ // jump around if the border width changes (avoiding NaN and negative padding)
108
+ const offsetBorder = value => typeof value === 'number' && typeof borderWidth === 'number' ? Math.max(0, value - borderWidth) : value;
109
+
110
+ return {
111
+ paddingLeft: offsetBorder(paddingLeft),
112
+ paddingRight: offsetBorder(paddingRight),
113
+ paddingTop: offsetBorder(paddingTop),
114
+ paddingBottom: offsetBorder(paddingBottom),
115
+ backgroundColor,
116
+ minWidth,
117
+ ...applyShadowToken(shadow)
118
+ };
119
+ };
120
+
121
+ const selectBorderStyles = _ref5 => {
122
+ let {
123
+ borderColor,
124
+ borderWidth,
125
+ borderRadius
126
+ } = _ref5;
127
+ return {
128
+ borderColor,
129
+ borderWidth,
130
+ borderRadius
131
+ };
132
+ };
133
+
134
+ const selectTextStyles = _ref6 => {
135
+ let {
136
+ fontSize,
137
+ color,
138
+ lineHeight,
139
+ fontName,
140
+ fontWeight,
141
+ textAlign
142
+ } = _ref6;
143
+ return applyTextStyles({
144
+ fontSize,
145
+ color,
146
+ lineHeight,
147
+ fontName,
148
+ fontWeight,
149
+ textAlign
150
+ });
151
+ };
152
+
153
+ const selectWebOnlyStyles = (inactive, themeTokens, _ref7) => {
154
+ let {
155
+ accessibilityRole
156
+ } = _ref7;
157
+ return Platform.select({
158
+ web: {
159
+ // if it would overflow the container, wraps instead
160
+ maxWidth: "calc(100% + ".concat(getOuterBorderOffset(themeTokens) * 2, "px)"),
161
+ outline: 'none',
162
+ // removes the default browser :focus outline
163
+ ...getCursorStyle(inactive, accessibilityRole)
164
+ },
165
+ default: {}
166
+ });
167
+ };
168
+
169
+ const ButtonBase = /*#__PURE__*/forwardRef((_ref8, ref) => {
170
+ let {
171
+ id,
172
+ href,
173
+ hrefAttrs,
174
+ children,
175
+ tokens = {},
176
+ disabled = false,
177
+ // alias for inactive
178
+ inactive = disabled,
179
+ selected = false,
180
+ ...rawRest
181
+ } = _ref8;
182
+ const {
183
+ onPress,
184
+ ...rest
185
+ } = clickProps.toPressProps(rawRest);
186
+ const extraButtonState = {
187
+ inactive,
188
+ selected
189
+ };
190
+
191
+ const resolveButtonTokens = pressableState => resolvePressableTokens(tokens, pressableState, extraButtonState);
192
+
193
+ const systemProps = selectProps(rest);
194
+
195
+ const getPressableStyle = pressableState => {
196
+ const themeTokens = resolveButtonTokens(pressableState);
197
+ return [staticStyles.row, selectWebOnlyStyles(inactive, themeTokens, systemProps), selectOuterContainerStyles(themeTokens), selectOuterWidthStyles(themeTokens)];
198
+ };
199
+
200
+ return /*#__PURE__*/_jsx(Pressable, {
201
+ ref: ref,
202
+ href: href,
203
+ onPress: linkProps.handleHref({
204
+ href,
205
+ onPress
206
+ }),
207
+ style: getPressableStyle,
208
+ disabled: inactive,
209
+ hrefAttrs: hrefAttrs,
210
+ ...systemProps,
211
+ children: pressableState => {
212
+ const themeTokens = resolveButtonTokens(pressableState);
213
+ const containerStyles = selectInnerContainerStyles(themeTokens);
214
+ const borderStyles = selectBorderStyles(themeTokens);
215
+ const textStyles = [selectTextStyles(themeTokens), staticStyles.text]; // If the container has a width set, fill it instead of sizing from content.
216
+ // If in future we support text alignments other than center, add here.
217
+
218
+ const stretchStyles = themeTokens.width ? staticStyles.stretch : staticStyles.align;
219
+ return /*#__PURE__*/_jsx(View, {
220
+ id: id,
221
+ style: [containerStyles, borderStyles, stretchStyles, staticStyles.row, Platform.select({
222
+ web: {
223
+ maxWidth: '100%',
224
+ // ensure overflowing content wraps
225
+ // TODO: https://github.com/telus/universal-design-system/issues/487
226
+ transition: 'background-color 200ms, border-color 200ms'
227
+ }
228
+ })],
229
+ children: wrapStringsInText(typeof children === 'function' ? children({ ...resolvePressableState(pressableState, extraButtonState),
230
+ textStyles
231
+ }) : children, {
232
+ style: textStyles
233
+ })
234
+ });
235
+ }
236
+ });
237
+ });
238
+ ButtonBase.displayName = 'ButtonBase';
239
+ ButtonBase.propTypes = {
240
+ id: PropTypes.string,
241
+ ...selectedSystemPropTypes,
242
+ ...buttonPropTypes
243
+ };
244
+ ButtonBase.defaultProps = {
245
+ id: undefined
246
+ };
247
+ const staticStyles = StyleSheet.create({
248
+ row: {
249
+ // Apply all button alignment horizontally; no vertical stacking within a button
250
+ flexDirection: 'row'
251
+ },
252
+ text: {
253
+ flexGrow: 1,
254
+ // On native but not web, flexShrink here wraps text prematurely
255
+ ...Platform.select({
256
+ // TODO: https://github.com/telus/universal-design-system/issues/487
257
+ web: {
258
+ transition: 'color 200ms'
259
+ }
260
+ })
261
+ },
262
+ align: {
263
+ alignItems: 'center'
264
+ },
265
+ stretch: {
266
+ flex: 1,
267
+ alignItems: 'center',
268
+ justifyContent: 'center'
269
+ }
270
+ });
271
+ export default withLinkRouter(ButtonBase);
@@ -0,0 +1,247 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ABBPropTypes from 'airbnb-prop-types';
4
+ import Platform from "react-native-web/dist/exports/Platform";
5
+ import ButtonBase from './ButtonBase';
6
+ import { StackWrap } from '../StackView';
7
+ import Fieldset from '../Fieldset';
8
+ import { useViewport } from '../ViewportProvider';
9
+ import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider';
10
+ import { a11yProps, containUniqueFields, focusHandlerProps, pressProps, getTokensPropType, selectSystemProps, selectTokens, useMultipleInputValues, variantProp, viewProps } from '../utils';
11
+ import { getPressHandlersWithArgs } from '../utils/pressability';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
14
+ const [selectItemProps, selectedItemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, pressProps, viewProps]);
15
+ const ButtonGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
16
+ let {
17
+ variant,
18
+ tokens,
19
+ items = [],
20
+ values,
21
+ initialValues,
22
+ maxValues = 1,
23
+ onChange,
24
+ readOnly = false,
25
+ inactive = false,
26
+ legend,
27
+ tooltip,
28
+ hint,
29
+ validation,
30
+ feedback,
31
+ name: inputGroupName,
32
+ copy,
33
+ accessibilityRole = maxValues === 1 ? 'radiogroup' // radiogroup is cross-platform; only web aria has generic groups
34
+ : Platform.select({
35
+ web: 'group',
36
+ default: 'none'
37
+ }),
38
+ ...rest
39
+ } = _ref;
40
+ const viewport = useViewport();
41
+ const themeTokens = useThemeTokens('ButtonGroup', tokens, variant, {
42
+ viewport
43
+ });
44
+ const stackTokens = selectTokens('StackView', themeTokens);
45
+ const {
46
+ direction,
47
+ space,
48
+ fieldSpace
49
+ } = themeTokens;
50
+ const getButtonTokens = useThemeTokensCallback('ButtonGroupItem', tokens, variant);
51
+ const {
52
+ currentValues,
53
+ toggleOneValue
54
+ } = useMultipleInputValues({
55
+ initialValues,
56
+ values,
57
+ maxValues,
58
+ onChange,
59
+ readOnly
60
+ });
61
+ const systemProps = selectProps({
62
+ accessibilityRole,
63
+ ...rest
64
+ });
65
+ const itemA11yRole = systemProps.accessibilityRole === 'radiogroup' ? 'radio' : 'checkbox';
66
+ const uniqueFields = ['id', 'label'];
67
+
68
+ if (!containUniqueFields(items, uniqueFields)) {
69
+ throw new Error("ButtonGroup items must have unique ".concat(uniqueFields.join(', ')));
70
+ } // Some web screenreaders e.g. MacOS Voiceover don't handle radiogroups properly unless radio is direct child of radiogroup
71
+
72
+
73
+ const innerRole = Platform.OS === 'web' && accessibilityRole === 'radiogroup' ? accessibilityRole : undefined;
74
+ return /*#__PURE__*/_jsx(Fieldset, { ...systemProps,
75
+ ref: ref,
76
+ name: inputGroupName,
77
+ legend: legend,
78
+ tooltip: tooltip,
79
+ hint: hint,
80
+ space: fieldSpace,
81
+ feedback: feedback,
82
+ readOnly: readOnly,
83
+ inactive: inactive,
84
+ validation: validation,
85
+ accessibilityRole: accessibilityRole,
86
+ ...selectProps(rest),
87
+ children: /*#__PURE__*/_jsx(StackWrap, {
88
+ accessibilityRole: innerRole,
89
+ space: space,
90
+ direction: direction,
91
+ tokens: stackTokens,
92
+ ref: ref,
93
+ children: items.map((_ref2, index) => {
94
+ let {
95
+ label,
96
+ id = label,
97
+ accessibilityLabel,
98
+ ref: itemRef,
99
+ ...itemRest
100
+ } = _ref2;
101
+ const isSelected = currentValues.includes(id); // Pass an object of relevant component state as first argument for any passed-in press handlers
102
+
103
+ const pressHandlers = getPressHandlersWithArgs(rest, [{
104
+ id,
105
+ label,
106
+ currentValues
107
+ }]);
108
+
109
+ const handlePress = event => {
110
+ if (pressHandlers.onPress) pressHandlers.onPress(event);
111
+ toggleOneValue(id, event);
112
+ };
113
+
114
+ const itemA11y = {
115
+ accessibilityState: {
116
+ checked: isSelected
117
+ },
118
+ accessibilityRole: itemA11yRole,
119
+ accessibilityLabel,
120
+ ...a11yProps.getPositionInSet(items.length, index)
121
+ }; // Ensure button is direct child of group as MacOS voiceover only applies "X of Y" to
122
+ // "radio" if it's a direct child of "radiogroup", even if aria-posinset etc exists
123
+
124
+ return /*#__PURE__*/_jsx(ButtonBase, {
125
+ ref: itemRef,
126
+ ...pressHandlers,
127
+ onPress: handlePress,
128
+ tokens: getButtonTokens,
129
+ selected: isSelected,
130
+ inactive: inactive,
131
+ ...itemA11y,
132
+ ...selectItemProps(itemRest),
133
+ children: label
134
+ }, id);
135
+ })
136
+ })
137
+ });
138
+ });
139
+ ButtonGroup.displayName = 'ButtonGroup';
140
+ ButtonGroup.propTypes = { ...selectedSystemPropTypes,
141
+ tokens: getTokensPropType('ButtonGroup'),
142
+ variant: variantProp.propType,
143
+
144
+ /**
145
+ * The maximum number of items a user may select at once. Defaults to 1 and behaves
146
+ * like radio buttons. To have no limit and allow any number of selections, pass `null`.
147
+ */
148
+ maxValues: PropTypes.number,
149
+
150
+ /**
151
+ * The options a user may select
152
+ */
153
+ items: PropTypes.arrayOf(PropTypes.shape({ ...selectedItemPropTypes,
154
+
155
+ /**
156
+ * The text displayed to the user in the button, describing this option,
157
+ * passed to the button as its child.
158
+ */
159
+ label: PropTypes.string.isRequired,
160
+
161
+ /**
162
+ * An optional accessibility label may be passed to ButtonGroup Buttons
163
+ * which is applied as normal for a React Native accessibilityLabel prop.
164
+ */
165
+ accessibilityLabel: PropTypes.string,
166
+
167
+ /**
168
+ * An optional unique string may be provided to identify this option,
169
+ * which will be used in code and passed to any onChange function.
170
+ * If not provided, the label is used.
171
+ */
172
+ id: PropTypes.string,
173
+
174
+ /**
175
+ * An optional ref for one individual button in the ButtonGroup
176
+ */
177
+ ref: ABBPropTypes.ref()
178
+ })),
179
+
180
+ /**
181
+ * If provided, this function is called when the current selection is changed
182
+ * and is passed an array of the `id`s of all currently selected `items`.
183
+ */
184
+ onChange: PropTypes.func,
185
+
186
+ /**
187
+ * If the selected item(s) in the button group are to be controlled externally by
188
+ * a parent component, pass an array of strings as well as an `onChange` handler.
189
+ * Passing an array for "values" makes the ButtonGroup a "controlled" component that
190
+ * expects its state to be handled via `onChange` and so doesn't handle it itself.
191
+ */
192
+ values: PropTypes.arrayOf(PropTypes.string),
193
+
194
+ /**
195
+ * If `values` is not passed, making the ButtonGroup an "uncontrolled" component
196
+ * managing its own selected state, a default set of selections may be provided.
197
+ * Changing the `initialValues` does not change the user's selections.
198
+ */
199
+ initialValues: PropTypes.arrayOf(PropTypes.string),
200
+
201
+ /**
202
+ * Main text used to describe this group, used in Fieldset's Legend element.
203
+ */
204
+ legend: PropTypes.string,
205
+
206
+ /**
207
+ * Optional additional text giving more detail to help a user make a choice.
208
+ */
209
+ hint: PropTypes.string,
210
+
211
+ /**
212
+ * Optional tooltip text content to include alongside the legend and hint.
213
+ */
214
+ tooltip: PropTypes.string,
215
+
216
+ /**
217
+ * Current validation status of the group, passed to the feedback element if there is one.
218
+ */
219
+ validation: PropTypes.oneOf(['error', 'success']),
220
+
221
+ /**
222
+ * If provided, a Feedback element is rendered containing this text.
223
+ */
224
+ feedback: PropTypes.string,
225
+
226
+ /**
227
+ * If true, the buttons cannot be selected by the user and simply show their current state.
228
+ */
229
+ readOnly: PropTypes.bool,
230
+
231
+ /**
232
+ * If true, the buttons cannot be interacted with, elements are set as `disabled` and if the
233
+ * theme supports `inactive` appearances rules, these are applied.
234
+ */
235
+ inactive: PropTypes.bool,
236
+
237
+ /**
238
+ * On Web, this is passed to the `name` attribute of the fieldset.
239
+ */
240
+ name: PropTypes.string,
241
+
242
+ /**
243
+ * Sets the language of microcopy in subcomponents (e.g. Tooltip's default accessibility label).
244
+ */
245
+ copy: PropTypes.oneOf(['en', 'fr'])
246
+ };
247
+ export default ButtonGroup;
@@ -0,0 +1,40 @@
1
+ import React, { forwardRef } from 'react';
2
+ import ButtonBase from './ButtonBase';
3
+ import buttonPropTypes, { textAndA11yText } from './propTypes';
4
+ import { a11yProps, hrefAttrsProp, linkProps } from '../utils/props';
5
+ import { useThemeTokensCallback } from '../ThemeProvider';
6
+ /**
7
+ * `ButtonLink` is a component with the semantics and behaviour of a link, but with the visual appearance of a button.
8
+ * ButtonLink is a block-level component and should not be used inline.
9
+ */
10
+
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ const ButtonLink = /*#__PURE__*/forwardRef((_ref, ref) => {
13
+ let {
14
+ accessibilityRole = 'link',
15
+ tokens,
16
+ variant,
17
+ dataSet,
18
+ ...props
19
+ } = _ref;
20
+ const {
21
+ hrefAttrs,
22
+ rest
23
+ } = hrefAttrsProp.bundle(props);
24
+ const getTokens = useThemeTokensCallback('Button', tokens, variant);
25
+ return /*#__PURE__*/_jsx(ButtonBase, {
26
+ ref: ref,
27
+ accessibilityRole: accessibilityRole,
28
+ tokens: getTokens,
29
+ hrefAttrs: hrefAttrs,
30
+ dataSet: dataSet,
31
+ ...rest
32
+ });
33
+ });
34
+ ButtonLink.displayName = 'ButtonLink';
35
+ ButtonLink.propTypes = { ...a11yProps.types,
36
+ ...buttonPropTypes,
37
+ ...linkProps.types,
38
+ children: textAndA11yText
39
+ };
40
+ export default ButtonLink;
@@ -0,0 +1,4 @@
1
+ import Button from './Button';
2
+ import ButtonLink from './ButtonLink';
3
+ import ButtonGroup from './ButtonGroup';
4
+ export { Button, ButtonGroup, ButtonLink };
@@ -0,0 +1,36 @@
1
+ import PropTypes from 'prop-types';
2
+ import ABBPropTypes from 'airbnb-prop-types';
3
+ import { variantProp, getTokensPropType } from '../utils/props';
4
+ import A11yText from '../A11yText';
5
+ export const textAndA11yText = ABBPropTypes.childrenOf(PropTypes.oneOfType([ABBPropTypes.elementType(A11yText), PropTypes.string]));
6
+ const buttonPropTypes = {
7
+ tokens: getTokensPropType('Button'),
8
+
9
+ /**
10
+ * If true, prevents the button from being pressed, changes the cursor (on web) and accessibility
11
+ * attributes to communicate this to the user, and applies `inactive: true` appearances from the theme
12
+ */
13
+ inactive: PropTypes.bool,
14
+
15
+ /**
16
+ * Alias for `inactive`
17
+ */
18
+ disabled: PropTypes.bool,
19
+
20
+ /**
21
+ * Button's children must be either:
22
+ * - One or more text strings and / or A11yText components
23
+ * - A render function with contents that responds to current button state by being passed an object of:
24
+ * ```
25
+ * { hovered<bool>, focused<bool>, pressed<bool>, inactive<bool>, selected<bool>, textStyles<RNStyle> }
26
+ * ```
27
+ */
28
+ children: PropTypes.oneOfType([PropTypes.func, textAndA11yText]).isRequired,
29
+
30
+ /**
31
+ * Function called when the button is pressed. Required unless the button has a href.
32
+ */
33
+ onPress: PropTypes.func,
34
+ variant: variantProp.propType
35
+ };
36
+ export default buttonPropTypes;
@@ -0,0 +1,84 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { useThemeTokens } from '../ThemeProvider';
4
+ import { getTokensPropType, variantProp } from '../utils';
5
+ import { useViewport } from '../ViewportProvider';
6
+ import { a11yProps, selectSystemProps, viewProps } from '../utils/props';
7
+ import CardBase from './CardBase';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
10
+ /**
11
+ * A basic card component, unstyled by default.
12
+ *
13
+ * ## Component API
14
+ *
15
+ * ### Background
16
+ *
17
+ * In order to control the background of a card, the following tokens are currently
18
+ * supported:
19
+ *
20
+ * - `backgroundColor`
21
+ *
22
+ * ### Border
23
+ *
24
+ * The following border tokens can be used:
25
+ *
26
+ * - `borderColor`
27
+ * - `borderRadius`
28
+ * - `borderWidth`
29
+ *
30
+ * ### Padding
31
+ *
32
+ * Please use the following tokens to control the padding:
33
+ *
34
+ * - `paddingBottom`
35
+ * - `paddingLeft`
36
+ * - `paddingRight`
37
+ * - `paddingTop`
38
+ *
39
+ * Note that various viewport sizes are supported as well.
40
+ *
41
+ * ### Shadow
42
+ *
43
+ * Feel free to use the following properties within the `shadow` token:
44
+ *
45
+ * - `inset`: boolean
46
+ * - `color`: string
47
+ * - `offsetX`: number
48
+ * - `offsetY`: number
49
+ * - `blur`: number
50
+ * - `spread`: number
51
+ *
52
+ * ## Accessibility
53
+ *
54
+ * Card supports all the common a11y props. Please remember that by marking a card as `accessible`
55
+ * you automatically make inaccessible its children, which may or may not be appropriate
56
+ * depending on what you are trying to achieve.
57
+ */
58
+
59
+ const Card = _ref => {
60
+ let {
61
+ children,
62
+ tokens,
63
+ variant,
64
+ dataSet,
65
+ ...rest
66
+ } = _ref;
67
+ const viewport = useViewport();
68
+ const themeTokens = useThemeTokens('Card', tokens, variant, {
69
+ viewport
70
+ });
71
+ return /*#__PURE__*/_jsx(CardBase, {
72
+ tokens: themeTokens,
73
+ dataSet: dataSet,
74
+ ...selectProps(rest),
75
+ children: children
76
+ });
77
+ };
78
+
79
+ Card.propTypes = { ...selectedSystemPropTypes,
80
+ children: PropTypes.node,
81
+ tokens: getTokensPropType('Card'),
82
+ variant: variantProp.propType
83
+ };
84
+ export default Card;