@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,251 @@
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 Text from "react-native-web/dist/exports/Text";
6
+ import View from "react-native-web/dist/exports/View";
7
+ import ButtonBase from '../Button/ButtonBase';
8
+ import Icon from '../Icon';
9
+ import { StackWrap, getStackedContent } from '../StackView';
10
+ import { useViewport } from '../ViewportProvider';
11
+ import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider';
12
+ import { a11yProps, containUniqueFields, focusHandlerProps, getTokensPropType, pressProps, selectSystemProps, selectTokens, useMultipleInputValues, variantProp, viewProps } from '../utils';
13
+ import { getPressHandlersWithArgs } from '../utils/pressability';
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
16
+ const [selectItemProps, selectedItemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, pressProps, viewProps]);
17
+
18
+ const selectIconTextTokens = _ref => {
19
+ let {
20
+ icon,
21
+ iconPosition,
22
+ iconSpace,
23
+ iconSize,
24
+ iconColor,
25
+ iconBackground,
26
+ iconBorderRadius,
27
+ iconAlignSelf,
28
+ iconPadding,
29
+ iconTranslateX,
30
+ iconTranslateY
31
+ } = _ref;
32
+ return {
33
+ icon,
34
+ iconPosition,
35
+ iconSpace,
36
+ iconWrapperStyle: {
37
+ backgroundColor: iconBackground,
38
+ borderRadius: iconBorderRadius,
39
+ alignSelf: iconAlignSelf,
40
+ padding: iconPadding,
41
+ ...Platform.select({
42
+ // TODO: https://github.com/telus/universal-design-system/issues/487
43
+ web: {
44
+ transition: 'color 200ms, background 200ms'
45
+ }
46
+ })
47
+ },
48
+ iconTokens: {
49
+ size: iconSize,
50
+ color: iconColor,
51
+ translateX: iconTranslateX,
52
+ translateY: iconTranslateY
53
+ }
54
+ };
55
+ };
56
+
57
+ const Tags = /*#__PURE__*/forwardRef((_ref2, ref) => {
58
+ let {
59
+ variant,
60
+ tokens,
61
+ items = [],
62
+ values,
63
+ initialValues,
64
+ maxValues,
65
+ onChange,
66
+ readOnly = false,
67
+ inactive = false,
68
+ accessibilityRole = Platform.select({
69
+ web: 'group',
70
+ default: 'none'
71
+ }),
72
+ ...rest
73
+ } = _ref2;
74
+ const viewport = useViewport();
75
+ const themeTokens = useThemeTokens('Tags', tokens, variant, {
76
+ viewport
77
+ });
78
+ const stackTokens = selectTokens('StackView', themeTokens);
79
+ const {
80
+ direction,
81
+ space
82
+ } = themeTokens;
83
+ const getItemTokens = useThemeTokensCallback('TagsItem', tokens, variant);
84
+
85
+ const getButtonTokens = buttonState => selectTokens('Button', getItemTokens(buttonState));
86
+
87
+ const {
88
+ currentValues,
89
+ toggleOneValue
90
+ } = useMultipleInputValues({
91
+ initialValues,
92
+ values,
93
+ maxValues,
94
+ onChange,
95
+ readOnly
96
+ });
97
+ const selectedProps = selectProps({
98
+ accessibilityRole,
99
+ ...rest
100
+ });
101
+ const itemA11yRole = 'checkbox';
102
+ const uniqueFields = ['id', 'label'];
103
+
104
+ if (!containUniqueFields(items, uniqueFields)) {
105
+ throw new Error("Tags items must have unique ".concat(uniqueFields.join(', ')));
106
+ }
107
+
108
+ return /*#__PURE__*/_jsx(StackWrap, {
109
+ ref: ref,
110
+ ...selectedProps,
111
+ space: space,
112
+ direction: direction,
113
+ tokens: stackTokens,
114
+ children: items.map((_ref3, index) => {
115
+ let {
116
+ label,
117
+ id = label,
118
+ ref: itemRef,
119
+ ...itemRest
120
+ } = _ref3;
121
+ const isSelected = currentValues.includes(id); // Pass an object of relevant component state as first argument for any passed-in press handlers
122
+
123
+ const pressHandlers = getPressHandlersWithArgs(rest, [{
124
+ id,
125
+ label,
126
+ currentValues
127
+ }]);
128
+
129
+ const handlePress = event => {
130
+ if (pressHandlers.onPress) pressHandlers.onPress(event);
131
+ toggleOneValue(id, event);
132
+ };
133
+
134
+ const itemProps = {
135
+ accessibilityState: {
136
+ checked: isSelected
137
+ },
138
+ accessibilityRole: itemA11yRole,
139
+ ...a11yProps.getPositionInSet(items.length, index),
140
+ ...selectItemProps(itemRest)
141
+ };
142
+ return /*#__PURE__*/_jsx(ButtonBase, {
143
+ ref: itemRef,
144
+ ...pressHandlers,
145
+ onPress: handlePress,
146
+ tokens: getButtonTokens,
147
+ selected: isSelected,
148
+ inactive: inactive,
149
+ ...itemProps,
150
+ children: _ref4 => {
151
+ let {
152
+ textStyles,
153
+ ...buttonState
154
+ } = _ref4;
155
+ // TODO: once Icon/IconButton designs are stable, see if this sort of styling around
156
+ // an icon should go in Icon itself, or possibly via an IconText token set. Related issues:
157
+ // - Icon: https://github.com/telus/universal-design-system/issues/327
158
+ // - IconButton: https://github.com/telus/universal-design-system/issues/281
159
+ // - Token sets: https://github.com/telus/universal-design-system/issues/782
160
+ const itemTokens = getItemTokens(buttonState);
161
+ const {
162
+ iconTokens,
163
+ iconPosition,
164
+ iconSpace,
165
+ iconWrapperStyle,
166
+ icon: IconComponent
167
+ } = selectIconTextTokens(itemTokens);
168
+ const iconContent = IconComponent ? /*#__PURE__*/_jsx(View, {
169
+ style: iconWrapperStyle,
170
+ children: /*#__PURE__*/_jsx(Icon, {
171
+ icon: IconComponent,
172
+ tokens: iconTokens
173
+ })
174
+ }) : null;
175
+
176
+ const textContent = /*#__PURE__*/_jsx(Text, {
177
+ style: textStyles,
178
+ children: label
179
+ });
180
+
181
+ return getStackedContent(iconPosition === 'left' ? [iconContent, textContent] : [textContent, iconContent], {
182
+ space: iconSpace,
183
+ direction: 'row'
184
+ });
185
+ }
186
+ }, id);
187
+ })
188
+ });
189
+ });
190
+ Tags.displayName = 'Tags';
191
+ Tags.propTypes = { ...selectedSystemPropTypes,
192
+ tokens: getTokensPropType('Tags'),
193
+ variant: variantProp.propType,
194
+
195
+ /**
196
+ * If provided, sets a maximum number of items a user may select at once.
197
+ */
198
+ maxValues: PropTypes.number,
199
+
200
+ /**
201
+ * The options a user may select
202
+ */
203
+ items: PropTypes.arrayOf(PropTypes.shape({ ...selectedItemPropTypes,
204
+
205
+ /**
206
+ * The text displayed to the user in the button, describing this option,
207
+ * passed to the button as its child.
208
+ */
209
+ label: PropTypes.string.isRequired,
210
+
211
+ /**
212
+ * An optional accessibility label may be passed to ButtonGroup Buttons
213
+ * which is applied as normal for a React Native accessibilityLabel prop.
214
+ */
215
+ accessibilityLabel: PropTypes.string,
216
+
217
+ /**
218
+ * An optional unique string may be provided to identify this option,
219
+ * which will be used in code and passed to any onChange function.
220
+ * If not provided, the label is used.
221
+ */
222
+ id: PropTypes.string,
223
+
224
+ /**
225
+ * An optional ref for one individual Tag button in the tags
226
+ */
227
+ ref: ABBPropTypes.ref()
228
+ })),
229
+
230
+ /**
231
+ * If provided, this function is called when the current selection is changed
232
+ * and is passed an array of the `id`s of all currently selected `items`.
233
+ */
234
+ onChange: PropTypes.func,
235
+
236
+ /**
237
+ * If the selected item(s) in the button group are to be controlled externally by
238
+ * a parent component, pass an array of strings as well as an `onChange` handler.
239
+ * Passing an array for "values" makes the ButtonGroup a "controlled" component that
240
+ * expects its state to be handled via `onChange` and so doesn't handle it itself.
241
+ */
242
+ values: PropTypes.arrayOf(PropTypes.string),
243
+
244
+ /**
245
+ * If `values` is not passed, making the ButtonGroup an "uncontrolled" component
246
+ * managing its own selected state, a default set of selections may be provided.
247
+ * Changing the `initialValues` does not change the user's selections.
248
+ */
249
+ initialValues: PropTypes.arrayOf(PropTypes.string)
250
+ };
251
+ export default Tags;
@@ -0,0 +1,2 @@
1
+ import Tags from './Tags';
2
+ export default Tags;
@@ -0,0 +1,94 @@
1
+ import React, { forwardRef, useState } from 'react';
2
+ import Platform from "react-native-web/dist/exports/Platform";
3
+ import { a11yProps, focusHandlerProps, getTokensPropType, inputSupportsProps, selectSystemProps, textInputHandlerProps, textInputProps, variantProp, viewProps } from '../utils';
4
+ import InputSupports from '../InputSupports';
5
+ import TextInputBase from './TextInputBase';
6
+ import { useThemeTokens } from '../ThemeProvider';
7
+ import textInputPropTypes from './propTypes';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, inputSupportsProps, textInputHandlerProps, textInputProps, viewProps]);
10
+ /**
11
+ * Use to collect long-form information such as product feedback or support queries.
12
+ * Due to React Native's implementation of `TextInput` it's not possible to access the current value by passing a ref.
13
+ * The `TextArea` height will automatically increase when new lines are added - this behavior can be limited within the theme.
14
+ *
15
+ * ## Controlled component
16
+ * If it is required that the state of the `TextArea` be controlled by the application or other external methods,
17
+ * `value` and `onChange` props must be passed to the `TextArea`.
18
+ * If the `TextArea` value should not be changed by user input, a `readOnly` prop must be provided.
19
+ *
20
+ * ## Uncontrolled component
21
+ * If it is not necessary to control the `TextArea` state, you can create one without a value prop.
22
+ * In this case its value can be accessed within the `onChange` callback.
23
+ *
24
+ * ## Getting feedback for entered values
25
+ * Use the `feedback` prop to give the user feedback regarding their input.
26
+ * You can affirm that the user's input was correct, or highlight errors that must be corrected, using the `validation` prop.
27
+ * Keep feedback text as brief as possible, should be limited to text and links.
28
+ *
29
+ * ## Supplying a hint
30
+ * Use the `hint` prop to succinctly clarify attributes of the expected input data, such as the expected format,
31
+ * or an indicator that the field is optional.
32
+ * It is a more usable and accessible option than the HTML `placeholder` attribute.
33
+ */
34
+
35
+ const TextArea = /*#__PURE__*/forwardRef((_ref, ref) => {
36
+ let {
37
+ tokens,
38
+ variant = {},
39
+ ...rest
40
+ } = _ref;
41
+ const themeTokens = useThemeTokens('TextArea', tokens, variant);
42
+ const [inputHeight, setInputHeight] = useState(); // adjust the text area's height as new lines are added to the content
43
+
44
+ const onHeightChange = _ref2 => {
45
+ let {
46
+ nativeEvent: {
47
+ contentSize: {
48
+ height
49
+ }
50
+ }
51
+ } = _ref2;
52
+
53
+ // on native this is happens out of the box
54
+ if (Platform.OS === 'web') {
55
+ setInputHeight(height);
56
+ }
57
+ };
58
+
59
+ const {
60
+ supportsProps,
61
+ ...selectedProps
62
+ } = selectProps(rest);
63
+ const inputProps = { ...selectedProps,
64
+ variant: { ...variant,
65
+ validation: supportsProps.validation
66
+ },
67
+ multiline: true,
68
+ onContentSizeChange: onHeightChange,
69
+ height: inputHeight,
70
+ tokens: themeTokens
71
+ };
72
+ return /*#__PURE__*/_jsx(InputSupports, { ...supportsProps,
73
+ children: _ref3 => {
74
+ let {
75
+ inputId,
76
+ ...props
77
+ } = _ref3;
78
+ return /*#__PURE__*/_jsx(TextInputBase, {
79
+ ref: ref,
80
+ ...inputProps,
81
+ nativeID: inputId,
82
+ ...props
83
+ });
84
+ }
85
+ });
86
+ });
87
+ TextArea.displayName = 'TextArea';
88
+ TextArea.propTypes = { ...selectedSystemPropTypes,
89
+ ...textInputPropTypes,
90
+ tokens: getTokensPropType('TextArea', 'TextInput'),
91
+ // TODO: support both TextArea and TextInput tokens
92
+ variant: variantProp.propType
93
+ };
94
+ export default TextArea;
@@ -0,0 +1,64 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { a11yProps, focusHandlerProps, getTokensPropType, inputSupportsProps, selectSystemProps, textInputHandlerProps, textInputProps, variantProp, viewProps } from '../utils';
3
+ import InputSupports from '../InputSupports';
4
+ import TextInputBase from './TextInputBase';
5
+ import textInputPropTypes from './propTypes';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, focusHandlerProps, inputSupportsProps, textInputHandlerProps, textInputProps, viewProps]);
8
+ /**
9
+ * A basic text input component. Use in forms or individually to receive user's input.
10
+ * Due to React Native's implementation of `TextInput` it's not possible to access the current value by passing a ref.
11
+ *
12
+ * ## Controlled component
13
+ * If it is required that the state of the `TextInput` be controlled by the application or other external methods,
14
+ * `value` and `onChange` props must be passed to the `TextInput`.
15
+ * If the `TextInput` value should not be changed by user input, a `readOnly` prop must be provided.
16
+ *
17
+ * ## Uncontrolled component
18
+ * If it is not necessary to control the `TextInput` state, you can create one without a value prop.
19
+ * In this case its value can be accessed within the `onChange` callback.
20
+ *
21
+ * NOTE: In order to support more advanced usages all additional props will be passed down to the React Native's
22
+ * `TextInput` component. See <a href="https://reactnative.dev/docs/textinput" target="_blank">React Native documentation</a> for
23
+ * supported props and <a href="https://reactnative.dev/docs/textinput" target="_blank">React Native Web documentation</a> for
24
+ * their implementation on the web.
25
+ */
26
+
27
+ const TextInput = /*#__PURE__*/forwardRef((_ref, ref) => {
28
+ let {
29
+ tokens,
30
+ variant = {},
31
+ ...rest
32
+ } = _ref;
33
+ const {
34
+ supportsProps,
35
+ ...selectedProps
36
+ } = selectProps(rest);
37
+ const inputProps = { ...selectedProps,
38
+ tokens,
39
+ variant: { ...variant,
40
+ validation: supportsProps.validation
41
+ }
42
+ };
43
+ return /*#__PURE__*/_jsx(InputSupports, { ...supportsProps,
44
+ children: _ref2 => {
45
+ let {
46
+ inputId,
47
+ ...props
48
+ } = _ref2;
49
+ return /*#__PURE__*/_jsx(TextInputBase, {
50
+ ref: ref,
51
+ ...inputProps,
52
+ nativeID: inputId,
53
+ ...props
54
+ });
55
+ }
56
+ });
57
+ });
58
+ TextInput.displayName = 'TextInput';
59
+ TextInput.propTypes = { ...selectedSystemPropTypes,
60
+ ...textInputPropTypes,
61
+ tokens: getTokensPropType('TextInput'),
62
+ variant: variantProp.propType
63
+ };
64
+ export default TextInput;
@@ -0,0 +1,254 @@
1
+ import React, { forwardRef, useEffect, useState } from 'react';
2
+ import Platform from "react-native-web/dist/exports/Platform";
3
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
4
+ import NativeTextInput from "react-native-web/dist/exports/TextInput";
5
+ import View from "react-native-web/dist/exports/View";
6
+ import PropTypes from 'prop-types';
7
+ import { applyTextStyles, useThemeTokens, applyOuterBorder } from '../ThemeProvider';
8
+ import { a11yProps, getTokensPropType, selectSystemProps, textInputHandlerProps, textInputProps, useInputValue, variantProp, 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, textInputHandlerProps, textInputProps, viewProps]);
12
+
13
+ const selectInputStyles = (_ref, inactive) => {
14
+ let {
15
+ backgroundColor,
16
+ color,
17
+ borderWidth = 0,
18
+ borderColor,
19
+ borderRadius,
20
+ paddingTop = 0,
21
+ paddingBottom = 0,
22
+ paddingLeft,
23
+ paddingRight = 0,
24
+ fontName,
25
+ fontSize,
26
+ fontWeight,
27
+ lineHeight,
28
+ icon,
29
+ iconSize = 0,
30
+ minLines,
31
+ maxLines,
32
+ width,
33
+ height
34
+ } = _ref;
35
+
36
+ // Subtract border width from padding so overall input width/height doesn't
37
+ // jump around if the border width changes (avoiding NaN and negative padding)
38
+ const offsetBorder = value => typeof value === 'number' ? Math.max(0, value - borderWidth) : value;
39
+
40
+ const textStyles = applyTextStyles({
41
+ fontName,
42
+ fontSize,
43
+ lineHeight,
44
+ fontWeight
45
+ });
46
+
47
+ function linesToHeight(lines) {
48
+ const {
49
+ lineHeight: absoluteLineHeight
50
+ } = textStyles;
51
+ return lines !== undefined ? lines * absoluteLineHeight + paddingTop + paddingBottom : undefined;
52
+ }
53
+
54
+ const minHeight = linesToHeight(minLines);
55
+ const maxHeight = linesToHeight(maxLines);
56
+ const webStyles = Platform.select({
57
+ web: {
58
+ outline: 'none',
59
+ cursor: inactive ? 'not-allowed' : undefined,
60
+ resize: minHeight !== maxHeight ? 'vertical' : 'none' // does nothing for an input, only needed for textarea
61
+
62
+ }
63
+ });
64
+ const paddingWithIcon = iconSize + paddingRight;
65
+ return {
66
+ backgroundColor,
67
+ color,
68
+ borderWidth,
69
+ borderColor,
70
+ borderRadius,
71
+ paddingLeft: offsetBorder(paddingLeft),
72
+ paddingRight: icon ? offsetBorder(paddingWithIcon) : offsetBorder(paddingRight),
73
+ paddingTop: offsetBorder(paddingTop),
74
+ paddingBottom: offsetBorder(paddingBottom),
75
+ minHeight,
76
+ maxHeight,
77
+ width,
78
+ height,
79
+ ...textStyles,
80
+ ...webStyles
81
+ };
82
+ };
83
+
84
+ const selectOuterBorderStyles = _ref2 => {
85
+ let {
86
+ outerBackgroundColor,
87
+ outerBorderWidth,
88
+ outerBorderColor,
89
+ borderRadius
90
+ } = _ref2;
91
+ return {
92
+ background: outerBackgroundColor,
93
+ ...applyOuterBorder({
94
+ outerBorderColor,
95
+ outerBorderWidth,
96
+ borderRadius
97
+ })
98
+ };
99
+ };
100
+
101
+ const selectIconTokens = _ref3 => {
102
+ let {
103
+ iconSize,
104
+ iconColor
105
+ } = _ref3;
106
+ return {
107
+ size: iconSize,
108
+ color: iconColor
109
+ };
110
+ };
111
+
112
+ const selectIconContainerStyles = _ref4 => {
113
+ let {
114
+ paddingRight,
115
+ paddingBottom
116
+ } = _ref4;
117
+ return {
118
+ paddingRight,
119
+ paddingBottom
120
+ };
121
+ };
122
+
123
+ const TextInputBase = /*#__PURE__*/forwardRef((_ref5, ref) => {
124
+ let {
125
+ value,
126
+ height,
127
+ initialValue,
128
+ inactive,
129
+ readOnly,
130
+ onChange,
131
+ onChangeText,
132
+ onFocus,
133
+ onBlur,
134
+ onMouseOver,
135
+ onMouseOut,
136
+ pattern,
137
+ tokens,
138
+ variant = {},
139
+ ...rest
140
+ } = _ref5;
141
+ const [isFocused, setIsFocused] = useState(false);
142
+
143
+ const handleFocus = event => {
144
+ setIsFocused(true);
145
+ if (typeof onFocus === 'function') onFocus(event);
146
+ };
147
+
148
+ const handleBlur = event => {
149
+ setIsFocused(false);
150
+ if (typeof onBlur === 'function') onBlur(event);
151
+ };
152
+
153
+ const [isHovered, setIsHovered] = useState(false);
154
+
155
+ const handleMouseOver = event => {
156
+ setIsHovered(true);
157
+ if (typeof onMouseOver === 'function') onMouseOver(event);
158
+ };
159
+
160
+ const handleMouseOut = event => {
161
+ setIsHovered(false);
162
+ if (typeof onMouseOut === 'function') onMouseOut(event);
163
+ };
164
+
165
+ const {
166
+ currentValue,
167
+ setValue,
168
+ isControlled
169
+ } = useInputValue({
170
+ value,
171
+ initialValue,
172
+ onChange,
173
+ readOnly
174
+ });
175
+ const element = ref === null || ref === void 0 ? void 0 : ref.current;
176
+ useEffect(() => {
177
+ if (Platform.OS === 'web' && pattern && element) {
178
+ // React Native Web doesn't support `pattern`, so we have to attach it via a ref,
179
+ // which a `pattern` user must provide anyway to call .checkValidity() on the element.
180
+ element.pattern = pattern;
181
+ }
182
+ }, [element, pattern]);
183
+
184
+ const handleChangeText = event => {
185
+ var _event$nativeEvent, _event$target;
186
+
187
+ const text = ((_event$nativeEvent = event.nativeEvent) === null || _event$nativeEvent === void 0 ? void 0 : _event$nativeEvent.text) || ((_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.value);
188
+ setValue(text, event);
189
+ if (typeof onChangeText === 'function') onChangeText(text, event);
190
+ };
191
+
192
+ const states = {
193
+ focus: isFocused,
194
+ hover: isHovered,
195
+ inactive
196
+ };
197
+ const themeTokens = useThemeTokens('TextInput', tokens, variant, states);
198
+ const {
199
+ icon: IconComponent
200
+ } = themeTokens;
201
+ const inputProps = { ...selectProps(rest),
202
+ editable: !inactive,
203
+ onFocus: handleFocus,
204
+ onBlur: handleBlur,
205
+ onMouseOver: handleMouseOver,
206
+ onMouseOut: handleMouseOut,
207
+ onChange: handleChangeText,
208
+ defaultValue: initialValue,
209
+ // currentValue is being updated even if the input is not controlled, passing it down to the
210
+ // Input could lead to changing its state from uncontrolled to controlled
211
+ value: isControlled ? currentValue : undefined
212
+ };
213
+ const nativeInputStyle = selectInputStyles({ ...themeTokens,
214
+ height
215
+ }, inactive);
216
+ return /*#__PURE__*/_jsxs(View, {
217
+ style: selectOuterBorderStyles(themeTokens),
218
+ children: [/*#__PURE__*/_jsx(NativeTextInput, {
219
+ ref: ref,
220
+ style: nativeInputStyle,
221
+ ...inputProps
222
+ }), IconComponent && /*#__PURE__*/_jsx(View, {
223
+ pointerEvents: "none" // avoid hijacking input press events
224
+ ,
225
+ style: [staticStyles.iconContainer, selectIconContainerStyles(themeTokens)],
226
+ children: /*#__PURE__*/_jsx(IconComponent, { ...selectIconTokens(themeTokens)
227
+ })
228
+ })]
229
+ });
230
+ });
231
+ TextInputBase.displayName = 'TextInputBase';
232
+ TextInputBase.propTypes = { ...selectedSystemPropTypes,
233
+ value: PropTypes.string,
234
+ height: PropTypes.number,
235
+ initialValue: PropTypes.string,
236
+ inactive: PropTypes.bool,
237
+ readOnly: PropTypes.bool,
238
+ onChange: PropTypes.func,
239
+ onChangeText: PropTypes.func,
240
+ onFocus: PropTypes.func,
241
+ onBlur: PropTypes.func,
242
+ onMouseOver: PropTypes.func,
243
+ onMouseOut: PropTypes.func,
244
+ tokens: getTokensPropType('TextInput', 'TextArea'),
245
+ variant: variantProp.propType
246
+ };
247
+ export default TextInputBase;
248
+ const staticStyles = StyleSheet.create({
249
+ iconContainer: {
250
+ position: 'absolute',
251
+ right: 0,
252
+ bottom: 0
253
+ }
254
+ });
@@ -0,0 +1,3 @@
1
+ import TextInput from './TextInput';
2
+ import TextArea from './TextArea';
3
+ export { TextInput, TextArea };
@@ -0,0 +1,33 @@
1
+ import PropTypes from 'prop-types'; // These are prop types specific to UDS TextInput; see also ../utils/props/textInputProps
2
+ // for generic React Native props and HTML input attrs that are passed through.
3
+
4
+ const textInputPropTypes = {
5
+ /**
6
+ * If the input's state is to be controlled by a parent component, use this prop
7
+ * together with the `onChange` to pass down and update the lifted state.
8
+ */
9
+ value: PropTypes.string,
10
+
11
+ /**
12
+ * Use this to set the initial value of an uncontrolled input.
13
+ * Updating `initialValue` will **not** update the actual value.
14
+ */
15
+ initialValue: PropTypes.string,
16
+
17
+ /**
18
+ * Disables all user interactions with the input.
19
+ */
20
+ inactive: PropTypes.bool,
21
+
22
+ /**
23
+ * Makes it impossible to change the input's value.
24
+ */
25
+ readOnly: PropTypes.bool,
26
+
27
+ /**
28
+ * Use to react upon input's value changes. Required when the `value` prop is set.
29
+ * Will receive the input's value as an argument.
30
+ */
31
+ onChange: PropTypes.func
32
+ };
33
+ export default textInputPropTypes;