@telus-uds/components-base 1.0.1 → 1.3.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 (193) hide show
  1. package/.storybook/main.js +4 -0
  2. package/.storybook/preview.js +37 -0
  3. package/.turbo/turbo-build.log +5 -0
  4. package/CHANGELOG.md +32 -0
  5. package/README.md +1 -1
  6. package/__fixtures__/Accessible.js +4 -2
  7. package/__fixtures__/Accessible.native.js +5 -2
  8. package/__fixtures__/testTheme.js +9 -0
  9. package/__tests__/FlexGrid/Col.test.jsx +6 -10
  10. package/__tests__/HorizontalScroll/HorizontalScroll.test.jsx +1 -0
  11. package/__tests__/ToggleSwitch/ToggleSwitch.test.jsx +10 -0
  12. package/__tests__/ToggleSwitch/ToggleSwitchGroup.test.jsx +192 -0
  13. package/__tests__/utils/props.test.js +36 -0
  14. package/__tests__/utils/semantics.test.jsx +1 -10
  15. package/babel.config.js +9 -16
  16. package/component-docs.json +10142 -0
  17. package/generate-component-docs.js +59 -0
  18. package/lib/A11yText/index.js +2 -2
  19. package/lib/ActivityIndicator/index.js +3 -3
  20. package/lib/Box/Box.js +4 -4
  21. package/lib/Button/Button.js +2 -2
  22. package/lib/Button/ButtonBase.js +20 -6
  23. package/lib/Button/ButtonGroup.js +10 -12
  24. package/lib/Button/ButtonLink.js +4 -4
  25. package/lib/Button/propTypes.js +4 -2
  26. package/lib/Card/Card.js +2 -2
  27. package/lib/Card/CardBase.js +6 -9
  28. package/lib/Card/PressableCardBase.js +12 -6
  29. package/lib/Checkbox/Checkbox.js +3 -5
  30. package/lib/Divider/Divider.js +2 -2
  31. package/lib/FlexGrid/FlexGrid.js +4 -4
  32. package/lib/FlexGrid/helpers/index.js +1 -4
  33. package/lib/IconButton/IconButton.js +11 -6
  34. package/lib/Link/LinkBase.js +19 -12
  35. package/lib/List/List.js +4 -5
  36. package/lib/List/ListItem.js +14 -27
  37. package/lib/List/index.js +15 -0
  38. package/lib/Pagination/PageButton.js +4 -8
  39. package/lib/Pagination/Pagination.js +16 -4
  40. package/lib/Pagination/SideButton.js +3 -1
  41. package/lib/Progress/Progress.js +2 -2
  42. package/lib/Progress/ProgressBar.js +2 -2
  43. package/lib/Radio/Radio.js +3 -5
  44. package/lib/Spacer/Spacer.js +2 -2
  45. package/lib/StackView/StackWrap.js +9 -5
  46. package/lib/StackView/getStackedContent.js +1 -1
  47. package/lib/StepTracker/StepTracker.js +2 -2
  48. package/lib/Tabs/Tabs.js +12 -4
  49. package/lib/Tabs/TabsItem.js +12 -6
  50. package/lib/Tags/Tags.js +9 -9
  51. package/lib/ThemeProvider/useThemeTokens.js +3 -3
  52. package/lib/ThemeProvider/utils/theme-tokens.js +3 -3
  53. package/lib/ToggleSwitch/ToggleSwitch.js +105 -43
  54. package/lib/ToggleSwitch/ToggleSwitchGroup.js +230 -0
  55. package/lib/ToggleSwitch/index.js +14 -4
  56. package/lib/index.js +28 -9
  57. package/lib/utils/a11y/semantics.js +4 -3
  58. package/lib/utils/index.js +14 -5
  59. package/lib/utils/pressability.js +2 -2
  60. package/lib/utils/props/a11yProps.js +153 -0
  61. package/lib/utils/props/clickProps.js +36 -0
  62. package/lib/utils/props/componentPropType.js +70 -0
  63. package/lib/utils/props/copyPropTypes.js +14 -0
  64. package/lib/utils/props/getPropSelector.js +13 -0
  65. package/lib/utils/props/hrefAttrsProp.js +41 -0
  66. package/lib/utils/props/index.js +149 -0
  67. package/lib/utils/props/linkProps.js +64 -0
  68. package/lib/utils/props/paddingProp.js +20 -0
  69. package/lib/utils/props/pressProps.js +57 -0
  70. package/lib/utils/props/rectProp.js +20 -0
  71. package/lib/utils/props/responsiveProps.js +40 -0
  72. package/lib/utils/props/selectSystemProps.js +31 -0
  73. package/lib/utils/props/spacingProps.js +71 -0
  74. package/lib/utils/props/tokens.js +145 -0
  75. package/lib/utils/props/variantProp.js +28 -0
  76. package/lib/utils/props/viewProps.js +34 -0
  77. package/lib/utils/useResponsiveProp.js +1 -1
  78. package/lib/utils/useSpacingScale.js +4 -4
  79. package/lib/utils/withLinkRouter.js +98 -0
  80. package/package.json +9 -5
  81. package/release-context.json +4 -4
  82. package/src/A11yText/index.jsx +1 -1
  83. package/src/ActivityIndicator/index.jsx +1 -1
  84. package/src/Box/Box.jsx +5 -4
  85. package/src/Button/Button.jsx +1 -1
  86. package/src/Button/ButtonBase.jsx +11 -4
  87. package/src/Button/ButtonGroup.jsx +17 -8
  88. package/src/Button/ButtonLink.jsx +1 -1
  89. package/src/Button/propTypes.js +2 -1
  90. package/src/Card/Card.jsx +1 -1
  91. package/src/Card/CardBase.jsx +6 -5
  92. package/src/Card/PressableCardBase.jsx +7 -5
  93. package/src/Checkbox/Checkbox.jsx +1 -3
  94. package/src/Divider/Divider.jsx +2 -2
  95. package/src/FlexGrid/FlexGrid.jsx +11 -5
  96. package/src/FlexGrid/helpers/index.js +1 -3
  97. package/src/IconButton/IconButton.jsx +7 -5
  98. package/src/Link/LinkBase.jsx +7 -5
  99. package/src/List/List.jsx +2 -4
  100. package/src/List/ListItem.jsx +11 -26
  101. package/src/List/index.js +5 -0
  102. package/src/Pagination/PageButton.jsx +5 -8
  103. package/src/Pagination/Pagination.jsx +29 -2
  104. package/src/Pagination/SideButton.jsx +2 -2
  105. package/src/Progress/Progress.jsx +1 -1
  106. package/src/Progress/ProgressBar.jsx +1 -1
  107. package/src/Radio/Radio.jsx +1 -3
  108. package/src/Spacer/Spacer.jsx +2 -2
  109. package/src/StackView/StackWrap.jsx +7 -6
  110. package/src/StackView/getStackedContent.jsx +1 -1
  111. package/src/StepTracker/StepTracker.jsx +1 -1
  112. package/src/Tabs/Tabs.jsx +49 -22
  113. package/src/Tabs/TabsItem.jsx +11 -7
  114. package/src/Tags/Tags.jsx +1 -7
  115. package/src/ThemeProvider/useThemeTokens.js +3 -3
  116. package/src/ThemeProvider/utils/theme-tokens.js +3 -3
  117. package/src/ToggleSwitch/ToggleSwitch.jsx +93 -41
  118. package/src/ToggleSwitch/ToggleSwitchGroup.jsx +203 -0
  119. package/src/ToggleSwitch/index.js +2 -1
  120. package/src/index.js +2 -2
  121. package/src/utils/a11y/semantics.js +3 -2
  122. package/src/utils/index.js +2 -1
  123. package/src/utils/pressability.js +1 -1
  124. package/src/utils/props/a11yProps.js +151 -0
  125. package/src/utils/props/clickProps.js +31 -0
  126. package/src/utils/props/componentPropType.js +67 -0
  127. package/src/utils/props/copyPropTypes.js +3 -0
  128. package/src/utils/props/getPropSelector.js +14 -0
  129. package/src/utils/props/hrefAttrsProp.js +25 -0
  130. package/src/utils/props/index.js +15 -0
  131. package/src/utils/props/linkProps.js +43 -0
  132. package/src/utils/props/paddingProp.js +10 -0
  133. package/src/utils/props/pressProps.js +45 -0
  134. package/src/utils/props/rectProp.js +10 -0
  135. package/src/utils/props/responsiveProps.js +30 -0
  136. package/src/utils/props/selectSystemProps.js +25 -0
  137. package/src/utils/props/spacingProps.js +58 -0
  138. package/src/utils/props/tokens.js +150 -0
  139. package/src/utils/props/variantProp.js +20 -0
  140. package/src/utils/props/viewProps.js +23 -0
  141. package/src/utils/useResponsiveProp.js +1 -1
  142. package/src/utils/useSpacingScale.js +4 -4
  143. package/src/utils/withLinkRouter.jsx +68 -0
  144. package/stories/A11yText/A11yText.stories.jsx +1 -1
  145. package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +1 -1
  146. package/stories/Box/Box.stories.jsx +1 -1
  147. package/stories/Button/Button.stories.jsx +1 -1
  148. package/stories/Button/ButtonGroup.stories.jsx +1 -1
  149. package/stories/Button/ButtonLink.stories.jsx +1 -1
  150. package/stories/Card/Card.stories.jsx +1 -1
  151. package/stories/Checkbox/Checkbox.stories.jsx +1 -1
  152. package/stories/Divider/Divider.stories.jsx +1 -1
  153. package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +1 -1
  154. package/stories/Feedback/Feedback.stories.jsx +1 -1
  155. package/stories/FlexGrid/01 FlexGrid.stories.jsx +1 -1
  156. package/stories/FlexGrid/02 Row.stories.jsx +1 -1
  157. package/stories/FlexGrid/03 Col.stories.jsx +1 -1
  158. package/stories/Icon/Icon.stories.jsx +1 -1
  159. package/stories/IconButton/IconButton.stories.jsx +1 -1
  160. package/stories/InputLabel/InputLabel.stories.jsx +1 -1
  161. package/stories/Link/ChevronLink.stories.jsx +1 -1
  162. package/stories/Link/Link.stories.jsx +1 -1
  163. package/stories/Link/TextButton.stories.jsx +1 -1
  164. package/stories/List/List.stories.jsx +1 -1
  165. package/stories/Modal/Modal.stories.jsx +1 -1
  166. package/stories/Notification/Notification.stories.jsx +1 -1
  167. package/stories/Pagination/Pagination.stories.jsx +1 -1
  168. package/stories/Progress/Progress.stories.jsx +1 -1
  169. package/stories/Radio/Radio.stories.jsx +1 -1
  170. package/stories/RadioCard/RadioCard.stories.jsx +1 -1
  171. package/stories/Search/Search.stories.jsx +1 -1
  172. package/stories/Select/Select.stories.jsx +1 -1
  173. package/stories/SideNav/SideNav.stories.jsx +1 -1
  174. package/stories/SideNav/SideNavItem.stories.jsx +1 -1
  175. package/stories/SideNav/SideNavItemsGroup.stories.jsx +1 -1
  176. package/stories/Skeleton/Skeleton.stories.jsx +1 -1
  177. package/stories/Spacer/Spacer.stories.jsx +1 -1
  178. package/stories/StackView/StackView.stories.jsx +1 -1
  179. package/stories/StackView/StackWrap.stories.jsx +1 -1
  180. package/stories/StepTracker/StepTracker.stories.jsx +1 -1
  181. package/stories/Tabs/Tabs.stories.jsx +1 -1
  182. package/stories/Tags/Tags.stories.jsx +1 -1
  183. package/stories/TextInput/TextArea.stories.jsx +2 -1
  184. package/stories/TextInput/TextInput.stories.jsx +1 -1
  185. package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +6 -2
  186. package/stories/ToggleSwitch/ToggleSwitchGroup.stories.jsx +81 -0
  187. package/stories/Tooltip/Tooltip.stories.jsx +1 -1
  188. package/stories/TooltipButton/TooltipButton.stories.jsx +1 -1
  189. package/stories/Typography/Typography.stories.jsx +1 -1
  190. package/stories/supports.jsx +2 -3
  191. package/.ultra.cache.json +0 -1
  192. package/lib/utils/propTypes.js +0 -623
  193. package/src/utils/propTypes.js +0 -640
@@ -11,18 +11,24 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
12
  var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
13
13
 
14
+ var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
15
+
14
16
  var _View = _interopRequireDefault(require("react-native-web/dist/cjs/exports/View"));
15
17
 
16
- var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
18
+ var _InputLabel = _interopRequireDefault(require("../InputLabel"));
17
19
 
18
20
  var _ButtonBase = _interopRequireDefault(require("../Button/ButtonBase"));
19
21
 
22
+ var _StackView = _interopRequireDefault(require("../StackView"));
23
+
20
24
  var _ThemeProvider = require("../ThemeProvider");
21
25
 
22
- var _propTypes2 = require("../utils/propTypes");
26
+ var _props = require("../utils/props");
23
27
 
24
28
  var _input = require("../utils/input");
25
29
 
30
+ var _utils = require("../utils");
31
+
26
32
  var _jsxRuntime = require("react/jsx-runtime");
27
33
 
28
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -31,7 +37,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
31
37
 
32
38
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
33
39
 
34
- const selectButtonTokens = tokens => (0, _propTypes2.selectTokens)('Button', { ...tokens,
40
+ const selectButtonTokens = tokens => (0, _props.selectTokens)('Button', { ...tokens,
35
41
  // Width tokens are applied to our inner track. Disable Button width token so it wraps our track width.
36
42
  width: null
37
43
  }); // Map and rename icon-specific tokens to name used within Icon
@@ -80,16 +86,41 @@ const selectSwitchStyles = ({
80
86
  })
81
87
  });
82
88
 
89
+ const selectLabelStyles = ({
90
+ labelMarginLeft
91
+ }) => ({
92
+ marginLeft: labelMarginLeft
93
+ });
94
+
95
+ const selectLabelTokens = ({
96
+ labelColor,
97
+ labelFontName,
98
+ labelFontSize,
99
+ labelFontWeight,
100
+ labelLineHeight
101
+ }) => ({
102
+ color: labelColor,
103
+ fontName: labelFontName,
104
+ fontWeight: labelFontWeight,
105
+ fontSize: labelFontSize,
106
+ lineHeight: labelLineHeight
107
+ });
108
+
83
109
  const ToggleSwitch = /*#__PURE__*/(0, _react.forwardRef)(({
84
110
  value,
85
111
  initialValue,
86
112
  onChange,
113
+ id,
114
+ label,
87
115
  inactive,
88
116
  tokens,
117
+ tooltip,
89
118
  variant,
90
- accessibilityRole = 'switch'
119
+ accessibilityRole = 'switch',
120
+ accessibilityLabel = label
91
121
  }, ref) => {
92
122
  const getTokens = (0, _ThemeProvider.useThemeTokensCallback)('ToggleSwitch', tokens, variant);
123
+ const themeTokens = getTokens();
93
124
  const {
94
125
  currentValue,
95
126
  setValue
@@ -103,48 +134,64 @@ const ToggleSwitch = /*#__PURE__*/(0, _react.forwardRef)(({
103
134
 
104
135
  const getButtonTokens = buttonState => selectButtonTokens(getTokens(buttonState));
105
136
 
106
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonBase.default, {
107
- ref: ref,
108
- selected: currentValue,
109
- inactive: inactive,
110
- tokens: getButtonTokens,
111
- accessibilityRole: accessibilityRole,
112
- accessibilityState: {
113
- checked: currentValue
114
- },
115
- onPress: handlePress,
116
- children: buttonState => {
117
- const themeTokens = getTokens(buttonState);
118
- const IconComponent = themeTokens.icon;
119
- const switchStyles = selectSwitchStyles(themeTokens);
120
- const trackStyles = selectTrackStyles(themeTokens);
121
- const iconTokens = selectIconTokens(themeTokens); // If drag-slide support is needed, use a PanResponder and apply these to an Animated value.
122
- // Use translate transforms for smoothest non-thread-blocking animations and to allow drag.
123
-
124
- const slideStart = 0;
125
- const slideEnd = themeTokens.width - themeTokens.switchSize - themeTokens.trackBorderWidth * 2;
126
- const switchOffset = buttonState.selected ? slideEnd : slideStart;
127
- const switchPositionStyle = {
128
- transform: [{
129
- translateX: switchOffset
130
- }]
131
- };
132
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
133
- style: [staticStyles.track, trackStyles],
134
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
135
- style: [staticStyles.switch, switchStyles, switchPositionStyle],
136
- children: IconComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(IconComponent, { ...iconTokens
137
+ const uniqueId = (0, _utils.useUniqueId)('toggleSwitch');
138
+ const inputId = id ?? uniqueId;
139
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StackView.default, {
140
+ space: 2,
141
+ direction: "row",
142
+ children: [Boolean(label) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
143
+ style: selectLabelStyles(themeTokens),
144
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_InputLabel.default, {
145
+ forId: inputId,
146
+ label: label,
147
+ tokens: selectLabelTokens(themeTokens),
148
+ tooltip: tooltip
149
+ })
150
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonBase.default, {
151
+ id: id,
152
+ ref: ref,
153
+ selected: currentValue,
154
+ inactive: inactive,
155
+ tokens: getButtonTokens,
156
+ accessibilityLabel: accessibilityLabel,
157
+ accessibilityRole: accessibilityRole,
158
+ accessibilityState: {
159
+ checked: currentValue
160
+ },
161
+ onPress: handlePress,
162
+ children: buttonState => {
163
+ const stateTokens = getTokens(buttonState);
164
+ const IconComponent = stateTokens.icon;
165
+ const switchStyles = selectSwitchStyles(stateTokens);
166
+ const trackStyles = selectTrackStyles(stateTokens);
167
+ const iconTokens = selectIconTokens(stateTokens); // If drag-slide support is needed, use a PanResponder and apply these to an Animated value.
168
+ // Use translate transforms for smoothest non-thread-blocking animations and to allow drag.
169
+
170
+ const slideStart = 0;
171
+ const slideEnd = stateTokens.width - stateTokens.switchSize - stateTokens.trackBorderWidth * 2;
172
+ const switchOffset = buttonState.selected ? slideEnd : slideStart;
173
+ const switchPositionStyle = {
174
+ transform: [{
175
+ translateX: switchOffset
176
+ }]
177
+ };
178
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
179
+ style: [staticStyles.track, trackStyles],
180
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
181
+ style: [staticStyles.switch, switchStyles, switchPositionStyle],
182
+ children: IconComponent && /*#__PURE__*/(0, _jsxRuntime.jsx)(IconComponent, { ...iconTokens
183
+ })
137
184
  })
138
- })
139
- });
140
- }
185
+ });
186
+ }
187
+ })]
141
188
  });
142
189
  });
143
190
  ToggleSwitch.displayName = 'ToggleSwitch';
144
- ToggleSwitch.propTypes = { ..._propTypes2.a11yProps.propTypes,
145
- ..._propTypes2.pressProps.propTypes,
146
- tokens: (0, _propTypes2.getTokensPropType)('ToggleSwitch'),
147
- variant: _propTypes2.variantProp.propType,
191
+ ToggleSwitch.propTypes = { ..._props.a11yProps.propTypes,
192
+ ..._props.pressProps.propTypes,
193
+ tokens: (0, _props.getTokensPropType)('ToggleSwitch'),
194
+ variant: _props.variantProp.propType,
148
195
 
149
196
  /**
150
197
  * If this is a "controlled" component and a parent handles its selected state,
@@ -165,11 +212,26 @@ ToggleSwitch.propTypes = { ..._propTypes2.a11yProps.propTypes,
165
212
  */
166
213
  onChange: _propTypes.default.func,
167
214
 
215
+ /**
216
+ * Input ID.
217
+ */
218
+ id: _propTypes.default.string,
219
+
220
+ /**
221
+ * An optional label.
222
+ */
223
+ label: _propTypes.default.string,
224
+
168
225
  /**
169
226
  * If passed, the switch does not respond to user input and may recieve different
170
227
  * theme tokens if the theme supports inactive appearance.
171
228
  */
172
- inactive: _propTypes.default.bool
229
+ inactive: _propTypes.default.bool,
230
+
231
+ /**
232
+ * Content of an optional Tooltip. If set, a tooltip button will be shown next to the label.
233
+ */
234
+ tooltip: _propTypes.default.string
173
235
  };
174
236
 
175
237
  const staticStyles = _StyleSheet.default.create({
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireWildcard(require("react"));
9
+
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
12
+ var _airbnbPropTypes = _interopRequireDefault(require("airbnb-prop-types"));
13
+
14
+ var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
15
+
16
+ var _ToggleSwitch = _interopRequireDefault(require("./ToggleSwitch"));
17
+
18
+ var _Fieldset = _interopRequireDefault(require("../Fieldset"));
19
+
20
+ var _StackView = require("../StackView");
21
+
22
+ var _ViewportProvider = require("../ViewportProvider");
23
+
24
+ var _ThemeProvider = require("../ThemeProvider");
25
+
26
+ var _props = require("../utils/props");
27
+
28
+ var _input = require("../utils/input");
29
+
30
+ var _jsxRuntime = require("react/jsx-runtime");
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
+
34
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
+
36
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
37
+
38
+ const ToggleSwitchGroup = /*#__PURE__*/(0, _react.forwardRef)(({
39
+ variant,
40
+ tokens,
41
+ items = [],
42
+ values,
43
+ initialValues,
44
+ maxValues = 1,
45
+ onChange,
46
+ readOnly = false,
47
+ inactive = false,
48
+ feedback,
49
+ hint,
50
+ tooltip,
51
+ legend,
52
+ name: inputGroupName,
53
+ accessibilityRole = maxValues === 1 ? 'radiogroup' // radiogroup is cross-platform; only web aria has generic groups
54
+ : _Platform.default.select({
55
+ web: 'group',
56
+ default: 'none'
57
+ }),
58
+ toggleSwitchTokens,
59
+ validation,
60
+ ...rest
61
+ }, ref) => {
62
+ const viewport = (0, _ViewportProvider.useViewport)();
63
+ const {
64
+ space,
65
+ fieldSpace
66
+ } = (0, _ThemeProvider.useThemeTokens)('ToggleSwitchGroup', tokens, variant, {
67
+ viewport
68
+ });
69
+ const {
70
+ currentValues,
71
+ toggleOneValue
72
+ } = (0, _input.useMultipleInputValues)({
73
+ initialValues,
74
+ values,
75
+ maxValues,
76
+ onChange,
77
+ readOnly
78
+ });
79
+
80
+ const a11y = _props.a11yProps.select({
81
+ accessibilityRole,
82
+ ...rest
83
+ });
84
+
85
+ const itemA11yRole = a11y.accessibilityRole === 'radiogroup' ? 'radio' : 'switch';
86
+ const toggleSwitches = items.map(({
87
+ label,
88
+ id = label,
89
+ accessibilityLabel = label,
90
+ onChange: itemOnChange,
91
+ ref: itemRef,
92
+ tooltip: itemTooltip
93
+ }, index) => {
94
+ const isSelected = currentValues.includes(id);
95
+
96
+ const handleChange = (newCheckedState, event) => {
97
+ if (typeof itemOnChange === 'function') itemOnChange(newCheckedState, event);
98
+ toggleOneValue(id, event);
99
+ };
100
+
101
+ const itemA11y = {
102
+ accessibilityState: {
103
+ checked: isSelected
104
+ },
105
+ accessibilityRole: itemA11yRole,
106
+ accessibilityLabel,
107
+ ..._props.a11yProps.getPositionInSet(items.length, index)
108
+ };
109
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ToggleSwitch.default, {
110
+ id: id,
111
+ ref: itemRef,
112
+ onChange: handleChange,
113
+ tokens: toggleSwitchTokens,
114
+ value: isSelected,
115
+ inactive: inactive,
116
+ label: label,
117
+ tooltip: itemTooltip,
118
+ ...itemA11y
119
+ }, id);
120
+ });
121
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Fieldset.default, {
122
+ ref: ref,
123
+ name: inputGroupName,
124
+ legend: legend,
125
+ tooltip: tooltip,
126
+ hint: hint,
127
+ space: fieldSpace,
128
+ feedback: feedback,
129
+ inactive: inactive,
130
+ validation: validation,
131
+ ...a11y,
132
+ children: (0, _StackView.getStackedContent)(toggleSwitches, {
133
+ space,
134
+ direction: 'column'
135
+ })
136
+ });
137
+ });
138
+ ToggleSwitchGroup.displayName = 'ToggleSwitchGroup';
139
+ ToggleSwitchGroup.propTypes = { ..._props.a11yProps.propTypes,
140
+ ..._props.pressProps.propTypes,
141
+ tokens: (0, _props.getTokensPropType)('ToggleSwitchGroup'),
142
+ variant: _props.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.default.number,
149
+
150
+ /**
151
+ * The options a user may select
152
+ */
153
+ items: _propTypes.default.arrayOf(_propTypes.default.shape({
154
+ /**
155
+ * The text displayed to the user on the label.
156
+ */
157
+ label: _propTypes.default.string.isRequired,
158
+
159
+ /**
160
+ * An optional accessibility label may be passed to each ToggleSwitch
161
+ * and will be applied as normal for a React Native accessibilityLabel prop.
162
+ */
163
+ accessibilityLabel: _propTypes.default.string,
164
+
165
+ /**
166
+ * An optional unique string may be provided to identify this option,
167
+ * which will be used in code and passed to any onChange function.
168
+ * If not provided, the label is used.
169
+ */
170
+ id: _propTypes.default.string,
171
+
172
+ /**
173
+ * An optional ref for one individual ToggleSwitch in the ToggleSwitchGroup
174
+ */
175
+ ref: _airbnbPropTypes.default.ref()
176
+ })),
177
+
178
+ /**
179
+ * If provided, this function is called when the current selection is changed
180
+ * and is passed an array of the `id`s of all currently selected `items`.
181
+ */
182
+ onChange: _propTypes.default.func,
183
+
184
+ /**
185
+ * If the selected item(s) in the toggle switch group are to be controlled externally by
186
+ * a parent component, pass an array of strings as well as an `onChange` handler.
187
+ * Passing an array for "values" makes the ToggleSwitchGroup a "controlled" component that
188
+ * expects its state to be handled via `onChange` and so doesn't handle it itself.
189
+ */
190
+ values: _propTypes.default.arrayOf(_propTypes.default.string),
191
+
192
+ /**
193
+ * If `values` is not passed, making the ToggleSwitchGroup an "uncontrolled" component
194
+ * managing its own selected state, a default set of selections may be provided.
195
+ * Changing the `initialValues` does not change the user's selections.
196
+ */
197
+ initialValues: _propTypes.default.arrayOf(_propTypes.default.string),
198
+
199
+ /**
200
+ * Optional additional text giving more detail to help a user make a choice.
201
+ */
202
+ hint: _propTypes.default.string,
203
+
204
+ /**
205
+ * Optional tooltip text content to include alongside the legend and hint.
206
+ */
207
+ tooltip: _propTypes.default.string,
208
+
209
+ /**
210
+ * If provided, a Feedback element is rendered containing this text.
211
+ */
212
+ feedback: _propTypes.default.string,
213
+
214
+ /**
215
+ * Main text used to describe this group, used in Fieldset's Legend element.
216
+ */
217
+ legend: _propTypes.default.string,
218
+
219
+ /**
220
+ * Toggle switch token overrides.
221
+ */
222
+ toggleSwitchTokens: (0, _props.getTokensPropType)('ToggleSwitch'),
223
+
224
+ /**
225
+ * Current validation status of the group, passed to the feedback element if there is one.
226
+ */
227
+ validation: _propTypes.default.oneOf(['error', 'success'])
228
+ };
229
+ var _default = ToggleSwitchGroup;
230
+ exports.default = _default;
@@ -3,11 +3,21 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ Object.defineProperty(exports, "ToggleSwitch", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _ToggleSwitch.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ToggleSwitchGroup", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _ToggleSwitchGroup.default;
16
+ }
17
+ });
7
18
 
8
19
  var _ToggleSwitch = _interopRequireDefault(require("./ToggleSwitch"));
9
20
 
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+ var _ToggleSwitchGroup = _interopRequireDefault(require("./ToggleSwitchGroup"));
11
22
 
12
- var _default = _ToggleSwitch.default;
13
- exports.default = _default;
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
package/lib/index.js CHANGED
@@ -21,6 +21,8 @@ var _exportNames = {
21
21
  IconButton: true,
22
22
  InputLabel: true,
23
23
  List: true,
24
+ ListItem: true,
25
+ ListBase: true,
24
26
  Modal: true,
25
27
  Notification: true,
26
28
  Pagination: true,
@@ -36,7 +38,6 @@ var _exportNames = {
36
38
  StepTracker: true,
37
39
  Tabs: true,
38
40
  Tags: true,
39
- ToggleSwitch: true,
40
41
  Tooltip: true,
41
42
  TooltipButton: true,
42
43
  Typography: true,
@@ -153,6 +154,18 @@ Object.defineProperty(exports, "List", {
153
154
  return _List.default;
154
155
  }
155
156
  });
157
+ Object.defineProperty(exports, "ListItem", {
158
+ enumerable: true,
159
+ get: function () {
160
+ return _List.ListItem;
161
+ }
162
+ });
163
+ Object.defineProperty(exports, "ListBase", {
164
+ enumerable: true,
165
+ get: function () {
166
+ return _List.ListBase;
167
+ }
168
+ });
156
169
  Object.defineProperty(exports, "Modal", {
157
170
  enumerable: true,
158
171
  get: function () {
@@ -243,12 +256,6 @@ Object.defineProperty(exports, "Tags", {
243
256
  return _Tags.default;
244
257
  }
245
258
  });
246
- Object.defineProperty(exports, "ToggleSwitch", {
247
- enumerable: true,
248
- get: function () {
249
- return _ToggleSwitch.default;
250
- }
251
- });
252
259
  Object.defineProperty(exports, "Tooltip", {
253
260
  enumerable: true,
254
261
  get: function () {
@@ -420,7 +427,7 @@ Object.keys(_Link).forEach(function (key) {
420
427
  });
421
428
  });
422
429
 
423
- var _List = _interopRequireDefault(require("./List"));
430
+ var _List = _interopRequireWildcard(require("./List"));
424
431
 
425
432
  var _Modal = _interopRequireDefault(require("./Modal"));
426
433
 
@@ -502,7 +509,19 @@ Object.keys(_TextInput).forEach(function (key) {
502
509
  });
503
510
  });
504
511
 
505
- var _ToggleSwitch = _interopRequireDefault(require("./ToggleSwitch"));
512
+ var _ToggleSwitch = require("./ToggleSwitch");
513
+
514
+ Object.keys(_ToggleSwitch).forEach(function (key) {
515
+ if (key === "default" || key === "__esModule") return;
516
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
517
+ if (key in exports && exports[key] === _ToggleSwitch[key]) return;
518
+ Object.defineProperty(exports, key, {
519
+ enumerable: true,
520
+ get: function () {
521
+ return _ToggleSwitch[key];
522
+ }
523
+ });
524
+ });
506
525
 
507
526
  var _Tooltip = _interopRequireDefault(require("./Tooltip"));
508
527
 
@@ -154,9 +154,10 @@ const getA11yPropsFromHtmlTag = (tag, nativeRole) => {
154
154
  };
155
155
 
156
156
  if (tag) {
157
- const accessibilityRole = tagsToRoles[tag];
158
- if (accessibilityRole) return {
159
- accessibilityRole
157
+ // aria roles don't have native counterparts and RN may throw an error if an unrecognised role is passed
158
+ const ariaRole = _Platform.default.OS === 'web' && tagsToRoles[tag];
159
+ if (ariaRole) return {
160
+ accessibilityRole: ariaRole
160
161
  };
161
162
  const accessibilityLevel = getHeadingLevel(tag);
162
163
  if (accessibilityLevel) return {
@@ -9,7 +9,8 @@ var _exportNames = {
9
9
  useHash: true,
10
10
  useSpacingScale: true,
11
11
  useResponsiveProp: true,
12
- useUniqueId: true
12
+ useUniqueId: true,
13
+ withLinkRouter: true
13
14
  };
14
15
  Object.defineProperty(exports, "info", {
15
16
  enumerable: true,
@@ -47,6 +48,12 @@ Object.defineProperty(exports, "useUniqueId", {
47
48
  return _useUniqueId.default;
48
49
  }
49
50
  });
51
+ Object.defineProperty(exports, "withLinkRouter", {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _withLinkRouter.default;
55
+ }
56
+ });
50
57
 
51
58
  var _a11y = require("./a11y");
52
59
 
@@ -118,16 +125,16 @@ Object.keys(_pressability).forEach(function (key) {
118
125
  });
119
126
  });
120
127
 
121
- var _propTypes = require("./propTypes");
128
+ var _props = require("./props");
122
129
 
123
- Object.keys(_propTypes).forEach(function (key) {
130
+ Object.keys(_props).forEach(function (key) {
124
131
  if (key === "default" || key === "__esModule") return;
125
132
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
126
- if (key in exports && exports[key] === _propTypes[key]) return;
133
+ if (key in exports && exports[key] === _props[key]) return;
127
134
  Object.defineProperty(exports, key, {
128
135
  enumerable: true,
129
136
  get: function () {
130
- return _propTypes[key];
137
+ return _props[key];
131
138
  }
132
139
  });
133
140
  });
@@ -156,6 +163,8 @@ Object.keys(_useResponsiveProp).forEach(function (key) {
156
163
 
157
164
  var _useUniqueId = _interopRequireDefault(require("./useUniqueId"));
158
165
 
166
+ var _withLinkRouter = _interopRequireDefault(require("./withLinkRouter"));
167
+
159
168
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
160
169
 
161
170
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -9,7 +9,7 @@ var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/export
9
9
 
10
10
  var _StyleSheet = _interopRequireDefault(require("react-native-web/dist/cjs/exports/StyleSheet"));
11
11
 
12
- var _propTypes = require("./propTypes");
12
+ var _pressProps = _interopRequireDefault(require("./props/pressProps"));
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
@@ -108,7 +108,7 @@ const staticStyles = _StyleSheet.default.create(_Platform.default.select({
108
108
 
109
109
  const getPressHandlersWithArgs = (pressableProps = {}, args = []) => {
110
110
  // Allow handlers to be passed down for blur, hover, focus, pressIn, etc
111
- const pressHandlers = Object.fromEntries(Object.entries(_propTypes.pressProps.selectHandlers(pressableProps)).map(([key, handler]) => ({
111
+ const pressHandlers = Object.fromEntries(Object.entries(_pressProps.default.selectHandlers(pressableProps)).map(([key, handler]) => ({
112
112
  [key]: (...defaultArgs) => {
113
113
  // Pass each handler data on this button and current selection
114
114
  handler(...args, ...defaultArgs);