@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,337 @@
1
+ import React, { forwardRef, useState } from 'react';
2
+ import View from "react-native-web/dist/exports/View";
3
+ import Platform from "react-native-web/dist/exports/Platform";
4
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
5
+ import PropTypes from 'prop-types';
6
+ import { applyTextStyles, useThemeTokens, applyOuterBorder } from '../ThemeProvider';
7
+ import { a11yProps, componentPropType, getTokensPropType, inputSupportsProps, selectSystemProps, useInputValue, variantProp, viewProps } from '../utils';
8
+ import Picker from './Picker';
9
+ import InputSupports from '../InputSupports';
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, inputSupportsProps, viewProps]);
13
+
14
+ const selectInputStyles = (_ref, inactive) => {
15
+ let {
16
+ backgroundColor,
17
+ color,
18
+ borderWidth = 0,
19
+ borderColor,
20
+ borderRadius,
21
+ paddingTop,
22
+ paddingBottom,
23
+ paddingLeft = 0,
24
+ paddingRight,
25
+ fontName,
26
+ fontSize,
27
+ fontWeight,
28
+ lineHeight,
29
+ icon,
30
+ iconSize = 0,
31
+ validationIcon,
32
+ validationIconSize = 0,
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
+ const webStyles = Platform.select({
47
+ web: {
48
+ appearance: 'none',
49
+ WebkitAppearance: 'none',
50
+ // since iOS Safari needs a prefix
51
+ outline: 'none',
52
+ cursor: inactive ? 'not-allowed' : undefined,
53
+ opacity: inactive ? 1 : undefined // override Chrome's default fadeout of a disabled select
54
+
55
+ }
56
+ });
57
+ let paddingWithIcons = paddingRight;
58
+
59
+ if (Platform.OS !== 'android') {
60
+ if (icon) {
61
+ paddingWithIcons += iconSize;
62
+ }
63
+
64
+ if (validationIcon) {
65
+ paddingWithIcons += validationIconSize;
66
+ }
67
+ }
68
+
69
+ return {
70
+ backgroundColor,
71
+ color,
72
+ borderWidth,
73
+ borderColor,
74
+ borderRadius,
75
+ paddingLeft: offsetBorder(paddingLeft),
76
+ paddingRight: offsetBorder(paddingWithIcons),
77
+ paddingTop: offsetBorder(paddingTop),
78
+ paddingBottom: offsetBorder(paddingBottom),
79
+ height,
80
+ ...textStyles,
81
+ ...webStyles
82
+ };
83
+ };
84
+
85
+ const selectOuterBorderStyles = _ref2 => {
86
+ let {
87
+ outerBackgroundColor,
88
+ outerBorderWidth,
89
+ outerBorderColor,
90
+ borderRadius
91
+ } = _ref2;
92
+ return {
93
+ background: outerBackgroundColor,
94
+ ...applyOuterBorder({
95
+ outerBorderColor,
96
+ outerBorderWidth,
97
+ borderRadius
98
+ })
99
+ };
100
+ };
101
+
102
+ const selectIconTokens = _ref3 => {
103
+ let {
104
+ iconSize,
105
+ iconColor
106
+ } = _ref3;
107
+ return {
108
+ size: iconSize,
109
+ color: iconColor
110
+ };
111
+ };
112
+
113
+ const selectIconContainerStyles = _ref4 => {
114
+ let {
115
+ paddingRight,
116
+ paddingBottom
117
+ } = _ref4;
118
+ return {
119
+ paddingRight,
120
+ paddingBottom
121
+ };
122
+ };
123
+
124
+ const selectValidationIconTokens = _ref5 => {
125
+ let {
126
+ validationIconSize,
127
+ validationIconColor
128
+ } = _ref5;
129
+ return {
130
+ size: validationIconSize,
131
+ color: validationIconColor
132
+ };
133
+ };
134
+
135
+ const selectValidationIconContainerStyles = _ref6 => {
136
+ let {
137
+ icon,
138
+ iconSize = 0,
139
+ paddingRight = 0,
140
+ paddingBottom
141
+ } = _ref6;
142
+ return {
143
+ paddingRight: icon ? paddingRight + iconSize : paddingRight,
144
+ paddingBottom
145
+ };
146
+ };
147
+ /**
148
+ * A basic form single-choice select component. Use in forms or individually to receive user's input.
149
+ *
150
+ * ## Usage criteria
151
+ * - Include a `placeholder` to provide instructions such as "Please select..." as an unselectable option (recommended)
152
+ * - Use when options are between 7-15 (recommended)
153
+ * - For options are 6 and under, use `Radio` groups or `ButtonGroup`.
154
+ * - For options 15 and above, look for alternatives (e.g grouping into categories, or input field with auto-complete etc.)
155
+ *
156
+ * ## Controlled component
157
+ * If it is required that the state of the `Select` be controlled by the application or other external methods,
158
+ * `value` and `onChange` props must be passed to the `Select`.
159
+ * If the `Select` value should not be changed by user input, a `readOnly` prop must be provided.
160
+ *
161
+ * ## Uncontrolled component
162
+ * If it is not necessary to control the `Select` state, you can create one without a value prop.
163
+ * In this case its value can be accessed within the `onChange` callback. Use the `initialValue` prop to set the
164
+ * default value for an uncontrolled `Select`.
165
+ *
166
+ * ## Getting feedback for entered values
167
+ * Use the `feedback` prop to give the user feedback regarding their selection.
168
+ * You can affirm that the user's selection was correct, or highlight errors that must be corrected, using the `validation` prop.
169
+ * Keep feedback text as brief as possible, should be limited to text and links.
170
+ *
171
+ * ## Using a tooltip
172
+ * When a more in-depth explanation is needed to fill out a `Select` properly, the tooltip prop may be used.
173
+ *
174
+ * ## Grouping options
175
+ * `Select` supports option groups. Use a `Select.Group` component to render an `<optgroup>` element with its items.
176
+ * NOTE: this does not work on native platforms - the grouped items will be shown at the same level as the non-grouped items.
177
+ *
178
+ */
179
+
180
+
181
+ const Select = /*#__PURE__*/forwardRef((_ref7, ref) => {
182
+ let {
183
+ value,
184
+ initialValue,
185
+ onChange,
186
+ children,
187
+ inactive,
188
+ readOnly,
189
+ placeholder,
190
+ validation,
191
+ tokens,
192
+ variant,
193
+ testID,
194
+ ...rest
195
+ } = _ref7;
196
+ const {
197
+ currentValue,
198
+ setValue
199
+ } = useInputValue({
200
+ value,
201
+ initialValue,
202
+ onChange,
203
+ readOnly
204
+ });
205
+ const [isFocused, setIsFocused] = useState(false);
206
+
207
+ const handleFocus = () => setIsFocused(true);
208
+
209
+ const handleBlur = () => setIsFocused(false);
210
+
211
+ const [isHovered, setIsHovered] = useState(false);
212
+
213
+ const handleMouseOver = () => setIsHovered(true);
214
+
215
+ const handleMouseOut = () => setIsHovered(false);
216
+
217
+ const {
218
+ supportsProps,
219
+ ...selectedProps
220
+ } = selectProps(rest);
221
+ const themeTokens = useThemeTokens('Select', tokens, variant, {
222
+ focus: isFocused,
223
+ hover: isHovered,
224
+ inactive,
225
+ validation
226
+ });
227
+ const {
228
+ icon: IconComponent,
229
+ validationIcon: ValidationIconComponent
230
+ } = themeTokens;
231
+ return /*#__PURE__*/_jsx(InputSupports, { ...supportsProps,
232
+ ...selectedProps,
233
+ children: _ref8 => {
234
+ let {
235
+ inputId,
236
+ ...props
237
+ } = _ref8;
238
+ return /*#__PURE__*/_jsxs(View, {
239
+ style: selectOuterBorderStyles(themeTokens),
240
+ children: [/*#__PURE__*/_jsx(Picker, {
241
+ ref: ref,
242
+ style: selectInputStyles(themeTokens, inactive),
243
+ onFocus: handleFocus,
244
+ onBlur: handleBlur,
245
+ onMouseOver: handleMouseOver,
246
+ onMouseOut: handleMouseOut,
247
+ onChange: setValue,
248
+ value: currentValue,
249
+ inactive: inactive,
250
+ placeholder: placeholder !== undefined ? {
251
+ label: placeholder,
252
+ value: ''
253
+ } : undefined,
254
+ ...props,
255
+ nativeID: inputId,
256
+ testID: testID,
257
+ children: children
258
+ }), ValidationIconComponent && /*#__PURE__*/_jsx(View, {
259
+ pointerEvents: "none",
260
+ style: [staticStyles.iconContainer, selectValidationIconContainerStyles(themeTokens)],
261
+ children: /*#__PURE__*/_jsx(ValidationIconComponent, { ...selectValidationIconTokens(themeTokens)
262
+ })
263
+ }), IconComponent && Platform.OS !== 'android' &&
264
+ /*#__PURE__*/
265
+ // we can't hide the default caret of a native picker on android
266
+ _jsx(View, {
267
+ pointerEvents: "none",
268
+ style: [staticStyles.iconContainer, selectIconContainerStyles(themeTokens)],
269
+ children: /*#__PURE__*/_jsx(IconComponent, { ...selectIconTokens(themeTokens)
270
+ })
271
+ })]
272
+ });
273
+ }
274
+ });
275
+ });
276
+ Select.displayName = 'Select';
277
+ Select.propTypes = { ...selectedSystemPropTypes,
278
+
279
+ /**
280
+ * Initial value for the uncontrolled version.
281
+ */
282
+ initialValue: PropTypes.string,
283
+
284
+ /**
285
+ * Current value to be set as selected.
286
+ */
287
+ value: PropTypes.string,
288
+
289
+ /**
290
+ * Callback to be called when the value changes.
291
+ */
292
+ onChange: PropTypes.func,
293
+
294
+ /**
295
+ * An array of items or item groups to be used as options.
296
+ */
297
+ children: componentPropType(['Item', 'Group']),
298
+
299
+ /**
300
+ * Whether the select is disabled.
301
+ */
302
+ inactive: PropTypes.bool,
303
+
304
+ /**
305
+ * Whether the select is read-only.
306
+ */
307
+ readOnly: PropTypes.bool,
308
+
309
+ /**
310
+ * A placeholder to provide instructions (such as "Please select...")
311
+ * as an unselectable option
312
+ */
313
+ placeholder: PropTypes.string,
314
+
315
+ /**
316
+ * Select tokens.
317
+ */
318
+ tokens: getTokensPropType('Select'),
319
+
320
+ /**
321
+ * Select variant.
322
+ */
323
+ variant: variantProp.propType,
324
+
325
+ /**
326
+ * Dedicated ID for testing.
327
+ */
328
+ testID: PropTypes.string
329
+ };
330
+ export default Select;
331
+ const staticStyles = StyleSheet.create({
332
+ iconContainer: {
333
+ position: 'absolute',
334
+ right: 0,
335
+ bottom: 0
336
+ }
337
+ });
@@ -0,0 +1,6 @@
1
+ import Select from './Select';
2
+ import Group from './Group';
3
+ import Item from './Item';
4
+ Select.Group = Group;
5
+ Select.Item = Item;
6
+ export default Select;
@@ -0,0 +1,145 @@
1
+ import React, { forwardRef } from 'react';
2
+ import Pressable from "react-native-web/dist/exports/Pressable";
3
+ import PropTypes from 'prop-types';
4
+ import { a11yProps, getTokensPropType, hrefAttrsProp, linkProps, selectSystemProps, variantProp, viewProps } from '../utils';
5
+ import { useThemeTokensCallback, verticalAlignRow } from '../ThemeProvider';
6
+ import ItemContent from './ItemContent';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, linkProps, viewProps]);
9
+
10
+ function selectItemStyles(_ref) {
11
+ let {
12
+ backgroundColor,
13
+ borderColor,
14
+ borderWidth,
15
+ borderStyle,
16
+ paddingLeft,
17
+ paddingRight,
18
+ paddingTop,
19
+ paddingBottom,
20
+ justifyContent,
21
+ verticalAlign
22
+ } = _ref;
23
+ return {
24
+ backgroundColor,
25
+ borderTopColor: borderColor,
26
+ borderTopWidth: borderWidth,
27
+ borderTopStyle: borderStyle,
28
+ paddingLeft,
29
+ paddingRight,
30
+ paddingTop,
31
+ paddingBottom,
32
+ justifyContent,
33
+ ...verticalAlignRow(verticalAlign)
34
+ };
35
+ }
36
+ /**
37
+ `SideNav.Item` is a navigational element that is used within `SideNav` or `SideNav.ItemsGroup`.
38
+
39
+ This component can only be accessed as a name-spaced component: `SideNav.Item`.
40
+ */
41
+
42
+
43
+ const Item = /*#__PURE__*/forwardRef((_ref2, ref) => {
44
+ let {
45
+ children,
46
+ itemId,
47
+ groupId,
48
+ onPress,
49
+ isActive = false,
50
+ isExpanded = false,
51
+ tokens,
52
+ variant,
53
+ href,
54
+ accessibilityRole = 'link',
55
+ testID,
56
+ ...props
57
+ } = _ref2;
58
+
59
+ const handlePress = () => onPress(itemId, groupId);
60
+
61
+ const {
62
+ hrefAttrs,
63
+ rest
64
+ } = hrefAttrsProp.bundle(props);
65
+ const selectedProps = selectProps({
66
+ accessibilityRole,
67
+ href,
68
+ onPress: handlePress,
69
+ hrefAttrs,
70
+ ...rest
71
+ });
72
+ const getTokens = useThemeTokensCallback('SideNavItem', tokens, variant);
73
+
74
+ const getAppearanceState = _ref3 => {
75
+ let {
76
+ hovered
77
+ } = _ref3;
78
+ return {
79
+ hover: hovered,
80
+ active: isActive,
81
+ expanded: isExpanded
82
+ };
83
+ };
84
+
85
+ const getPressableStyle = pressableState => selectItemStyles(getTokens(getAppearanceState(pressableState)));
86
+
87
+ return /*#__PURE__*/_jsx(Pressable, {
88
+ ref: ref,
89
+ style: getPressableStyle,
90
+ accessibilityState: {
91
+ selected: isActive
92
+ },
93
+ ...selectedProps,
94
+ children: pressableState => {
95
+ const themeTokens = getTokens(getAppearanceState(pressableState));
96
+ return /*#__PURE__*/_jsx(ItemContent, {
97
+ tokens: themeTokens,
98
+ children: children
99
+ });
100
+ }
101
+ });
102
+ });
103
+ Item.displayName = 'Item';
104
+ Item.propTypes = { ...selectedSystemPropTypes,
105
+
106
+ /**
107
+ * Text content of the `Item`.
108
+ */
109
+ children: PropTypes.node.isRequired,
110
+
111
+ /**
112
+ * @ignore
113
+ * Set internally in `SideNav` render function - used to keep track of active item.
114
+ */
115
+ itemId: PropTypes.string,
116
+
117
+ /**
118
+ * @ignore
119
+ * Set internally in `SideNav` render function - used to keep track of expanded items groups.
120
+ */
121
+ groupId: PropTypes.string,
122
+ onPress: PropTypes.func,
123
+ href: PropTypes.string,
124
+
125
+ /**
126
+ * On Web if href is passed, React Native Web maps this object's props to
127
+ * `rel`, `target` and `download` attrs.
128
+ */
129
+ hrefAttrs: PropTypes.shape(hrefAttrsProp.types),
130
+
131
+ /**
132
+ * @ignore
133
+ * Set internally in `SideNav` render function.
134
+ */
135
+ isActive: PropTypes.bool,
136
+
137
+ /**
138
+ * @ignore
139
+ * Set internally in `SideNav.ItemsGroup` render function. Used to mark expanded `ItemsGroup` parent.
140
+ */
141
+ isExpanded: PropTypes.bool,
142
+ tokens: getTokensPropType('SideNavItem'),
143
+ variant: variantProp.propType
144
+ };
145
+ export default Item;
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import View from "react-native-web/dist/exports/View";
4
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
5
+ import Typography from '../Typography';
6
+ import { selectTokens, getTokensPropType } from '../utils';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ import { Fragment as _Fragment } from "react/jsx-runtime";
9
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
+ export function selectAccentStyles(tokens) {
11
+ return {
12
+ left: tokens.accentOffset,
13
+ top: tokens.accentPadding,
14
+ bottom: tokens.accentPadding,
15
+ backgroundColor: tokens.accentBackgroundColor,
16
+ width: tokens.accentWidth,
17
+ position: 'absolute'
18
+ };
19
+ }
20
+ /**
21
+ * Content inside an item or control in a SideNav, themed by the SideNavItem theme
22
+ */
23
+
24
+ const ItemContent = _ref => {
25
+ let {
26
+ children,
27
+ tokens
28
+ } = _ref;
29
+ return /*#__PURE__*/_jsxs(_Fragment, {
30
+ children: [/*#__PURE__*/_jsx(Typography, {
31
+ tokens: selectTokens('Typography', tokens),
32
+ children: children
33
+ }), /*#__PURE__*/_jsx(View, {
34
+ style: [staticStyles.absolute, selectAccentStyles(tokens)]
35
+ })]
36
+ });
37
+ };
38
+
39
+ ItemContent.propTypes = {
40
+ tokens: getTokensPropType('SideNavItem'),
41
+ children: PropTypes.node
42
+ };
43
+ const staticStyles = StyleSheet.create({
44
+ absolute: {
45
+ position: 'absolute'
46
+ }
47
+ });
48
+ export default ItemContent;
@@ -0,0 +1,117 @@
1
+ import React, { forwardRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import ItemContent from './ItemContent';
4
+ import ExpandCollapse from '../ExpandCollapse';
5
+ import { getTokensPropType, variantProp, componentPropType, selectTokens } from '../utils';
6
+ import { useThemeTokensCallback } from '../ThemeProvider';
7
+ /**
8
+ Expandable content areas for use within `SideNav`.
9
+
10
+ This component can only be accessed as a name-spaced component: `SideNav.ItemsGroup`.
11
+
12
+ `SideNav.ItemsGroup` contains a label and a list of items. Items can link to in-page elements or route to other pages.
13
+
14
+ ## Usage Criteria
15
+ - Use `SideNav.ItemsGroup` with large pages that have multiple sections
16
+ */
17
+
18
+ import { jsx as _jsx } from "react/jsx-runtime";
19
+ const ItemsGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
20
+ let {
21
+ children,
22
+ label,
23
+ openGroups,
24
+ groupId,
25
+ isActive = false,
26
+ variant,
27
+ tokens,
28
+ itemTokens,
29
+ onToggle
30
+ } = _ref;
31
+
32
+ // A SideNav control uses the same style and theme as SideNavItem, with a 'parent' variant,
33
+ // plus control-specific tokens from the SideNavItemsGroup theme (e.g. open/close icon, etc).
34
+ const getAppearance = appearance => ({ ...variant,
35
+ ...appearance,
36
+ active: isActive
37
+ });
38
+
39
+ const getItemAppearance = appearance => ({ ...getAppearance(appearance),
40
+ type: 'parent'
41
+ });
42
+
43
+ const getGroupTokens = useThemeTokensCallback('SideNavItemsGroup', tokens, variant);
44
+
45
+ const getPanelTokens = appearance => selectTokens('ExpandCollapsePanel', getGroupTokens(getAppearance(appearance)));
46
+
47
+ const getItemTokens = useThemeTokensCallback('SideNavItem', itemTokens, variant);
48
+
49
+ const getControlTokens = appearance => selectTokens('ExpandCollapseControl', { ...getItemTokens(getItemAppearance(appearance)),
50
+ // main style from SideNavItem
51
+ ...getGroupTokens(getAppearance(appearance)) // control-specific tokens like icon etc
52
+
53
+ });
54
+
55
+ const controlContent = controlState => {
56
+ const currentItemTokens = getItemTokens(getItemAppearance(controlState));
57
+ return /*#__PURE__*/_jsx(ItemContent, {
58
+ tokens: currentItemTokens,
59
+ children: label
60
+ });
61
+ };
62
+
63
+ return /*#__PURE__*/_jsx(ExpandCollapse.Panel, {
64
+ ref: ref,
65
+ openIds: openGroups,
66
+ panelId: groupId,
67
+ onToggle: onToggle,
68
+ tokens: getPanelTokens,
69
+ controlTokens: getControlTokens,
70
+ control: controlContent,
71
+ accessibilityState: {
72
+ active: isActive
73
+ } // ExpandCollapse.Panel handles expanded state
74
+ ,
75
+ children: children
76
+ });
77
+ });
78
+ ItemsGroup.displayName = 'ItemsGroup';
79
+ ItemsGroup.propTypes = {
80
+ /**
81
+ * Specifies the links contained within. It may only contain `SideNav.Item`.
82
+ */
83
+ children: componentPropType('Item'),
84
+
85
+ /**
86
+ * Text content of the group's parent `SideNav.Item`.
87
+ */
88
+ label: PropTypes.string.isRequired,
89
+
90
+ /**
91
+ * @ignore
92
+ * Set internally in `SideNav` render function - used to keep track of expanded items groups.
93
+ */
94
+ groupId: PropTypes.string,
95
+
96
+ /**
97
+ * @ignore
98
+ * Set internally in `SideNav` render function. Called when the group is expanded/collapsed.
99
+ */
100
+ onToggle: PropTypes.func,
101
+
102
+ /**
103
+ * @ignore
104
+ * Set internally in `SideNav` render function. Contains `groupId`s of currently open groups.
105
+ */
106
+ openGroups: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
107
+
108
+ /**
109
+ * @ignore
110
+ * Set internally in `SideNav` render function. Used to mark group containing the currently active `SideNav.Item`.
111
+ */
112
+ isActive: PropTypes.bool,
113
+ variant: variantProp.propType,
114
+ tokens: getTokensPropType('SideNavItemsGroup'),
115
+ itemTokens: getTokensPropType('SideNavItem')
116
+ };
117
+ export default ItemsGroup;