@telus-uds/components-base 1.14.3 → 1.15.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 (139) hide show
  1. package/CHANGELOG.md +15 -2
  2. package/__tests17__/A11yText/A11yText.test.jsx +34 -0
  3. package/__tests17__/ActivityIndicator/ActivityIndicator.test.jsx +68 -0
  4. package/__tests17__/ActivityIndicator/__snapshots__/ActivityIndicator.test.jsx.snap +299 -0
  5. package/__tests17__/Box/Box.test.jsx +111 -0
  6. package/__tests17__/Button/Button.test.jsx +86 -0
  7. package/__tests17__/Button/ButtonBase.test.jsx +82 -0
  8. package/__tests17__/Button/ButtonGroup.test.jsx +347 -0
  9. package/__tests17__/Button/ButtonLink.test.jsx +61 -0
  10. package/__tests17__/Card/Card.test.jsx +63 -0
  11. package/__tests17__/Carousel/Carousel.test.jsx +128 -0
  12. package/__tests17__/Carousel/CarouselTabs.test.jsx +142 -0
  13. package/__tests17__/Checkbox/Checkbox.test.jsx +94 -0
  14. package/__tests17__/Checkbox/CheckboxGroup.test.jsx +246 -0
  15. package/__tests17__/Divider/Divider.test.jsx +91 -0
  16. package/__tests17__/ExpandCollapse/ExpandCollapse.test.jsx +109 -0
  17. package/__tests17__/Feedback/Feedback.test.jsx +42 -0
  18. package/__tests17__/FlexGrid/Col.test.jsx +261 -0
  19. package/__tests17__/FlexGrid/FlexGrid.test.jsx +136 -0
  20. package/__tests17__/FlexGrid/Row.test.jsx +273 -0
  21. package/__tests17__/HorizontalScroll/HorizontalScroll.test.jsx +165 -0
  22. package/__tests17__/Icon/Icon.test.jsx +61 -0
  23. package/__tests17__/IconButton/IconButton.test.jsx +52 -0
  24. package/__tests17__/InputLabel/InputLabel.test.jsx +28 -0
  25. package/__tests17__/InputLabel/__snapshots__/InputLabel.test.jsx.snap +3 -0
  26. package/__tests17__/InputSupports/InputSupports.test.jsx +60 -0
  27. package/__tests17__/Link/Link.test.jsx +63 -0
  28. package/__tests17__/Link/TextButton.test.jsx +35 -0
  29. package/__tests17__/List/List.test.jsx +82 -0
  30. package/__tests17__/Modal/Modal.test.jsx +47 -0
  31. package/__tests17__/Notification/Notification.test.jsx +20 -0
  32. package/__tests17__/Pagination/Pagination.test.jsx +160 -0
  33. package/__tests17__/Progress/Progress.test.jsx +79 -0
  34. package/__tests17__/Radio/Radio.test.jsx +87 -0
  35. package/__tests17__/Radio/RadioGroup.test.jsx +220 -0
  36. package/__tests17__/RadioCard/RadioCard.test.jsx +87 -0
  37. package/__tests17__/RadioCard/RadioCardGroup.test.jsx +246 -0
  38. package/__tests17__/Search/Search.test.jsx +87 -0
  39. package/__tests17__/Select/Select.test.jsx +94 -0
  40. package/__tests17__/SideNav/SideNav.test.jsx +110 -0
  41. package/__tests17__/Skeleton/Skeleton.test.jsx +61 -0
  42. package/__tests17__/SkipLink/SkipLink.test.jsx +61 -0
  43. package/__tests17__/Spacer/Spacer.test.jsx +63 -0
  44. package/__tests17__/StackView/StackView.test.jsx +211 -0
  45. package/__tests17__/StackView/StackWrap.test.jsx +47 -0
  46. package/__tests17__/StackView/getStackedContent.test.jsx +295 -0
  47. package/__tests17__/StepTracker/StepTracker.test.jsx +108 -0
  48. package/__tests17__/Tabs/Tabs.test.jsx +49 -0
  49. package/__tests17__/Tags/Tags.test.jsx +327 -0
  50. package/__tests17__/TextInput/TextArea.test.jsx +35 -0
  51. package/__tests17__/TextInput/TextInputBase.test.jsx +125 -0
  52. package/__tests17__/ThemeProvider/ThemeProvider.test.jsx +80 -0
  53. package/__tests17__/ThemeProvider/useThemeTokens.test.jsx +514 -0
  54. package/__tests17__/ThemeProvider/utils/theme-tokens.test.js +41 -0
  55. package/__tests17__/ToggleSwitch/ToggleSwitch.test.jsx +82 -0
  56. package/__tests17__/ToggleSwitch/ToggleSwitchGroup.test.jsx +192 -0
  57. package/__tests17__/Tooltip/Tooltip.test.jsx +65 -0
  58. package/__tests17__/Tooltip/getTooltipPosition.test.js +79 -0
  59. package/__tests17__/Typography/typography.test.jsx +90 -0
  60. package/__tests17__/utils/children.test.jsx +128 -0
  61. package/__tests17__/utils/containUniqueFields.test.js +25 -0
  62. package/__tests17__/utils/input.test.js +375 -0
  63. package/__tests17__/utils/props.test.js +36 -0
  64. package/__tests17__/utils/semantics.test.jsx +34 -0
  65. package/__tests17__/utils/useCopy.test.js +42 -0
  66. package/__tests17__/utils/useResponsiveProp.test.jsx +202 -0
  67. package/__tests17__/utils/useSpacingScale.test.jsx +273 -0
  68. package/__tests17__/utils/useUniqueId.test.js +31 -0
  69. package/component-docs.json +85 -438
  70. package/lib/A11yInfoProvider/index.js +14 -5
  71. package/lib/Button/ButtonGroup.js +3 -2
  72. package/lib/Checkbox/Checkbox.js +9 -6
  73. package/lib/ExpandCollapse/Control.js +6 -5
  74. package/lib/ExpandCollapse/Panel.js +5 -4
  75. package/lib/List/ListItem.js +10 -236
  76. package/lib/List/ListItemBase.js +162 -0
  77. package/lib/List/ListItemContent.js +85 -0
  78. package/lib/List/ListItemMark.js +158 -0
  79. package/lib/List/PressableListItemBase.js +147 -0
  80. package/lib/Notification/Notification.js +2 -1
  81. package/lib/Pagination/Pagination.js +4 -3
  82. package/lib/Radio/Radio.js +9 -6
  83. package/lib/RadioCard/RadioCard.js +9 -6
  84. package/lib/Tabs/Tabs.js +12 -3
  85. package/lib/Tags/Tags.js +3 -3
  86. package/lib/TextInput/TextInput.js +5 -4
  87. package/lib/ViewportProvider/useViewportListener.js +11 -5
  88. package/lib/utils/hasOwnProperty.js +18 -0
  89. package/lib/utils/props/a11yProps.js +212 -45
  90. package/lib/utils/props/getPropSelector.js +47 -5
  91. package/lib/utils/useResponsiveProp.js +5 -3
  92. package/lib/utils/withLinkRouter.js +3 -5
  93. package/lib-module/A11yInfoProvider/index.js +14 -4
  94. package/lib-module/Button/ButtonGroup.js +3 -2
  95. package/lib-module/Checkbox/Checkbox.js +9 -6
  96. package/lib-module/ExpandCollapse/Control.js +6 -5
  97. package/lib-module/ExpandCollapse/Panel.js +5 -4
  98. package/lib-module/List/ListItem.js +13 -235
  99. package/lib-module/List/ListItemBase.js +139 -0
  100. package/lib-module/List/ListItemContent.js +66 -0
  101. package/lib-module/List/ListItemMark.js +143 -0
  102. package/lib-module/List/PressableListItemBase.js +117 -0
  103. package/lib-module/Notification/Notification.js +2 -1
  104. package/lib-module/Pagination/Pagination.js +5 -3
  105. package/lib-module/Radio/Radio.js +9 -6
  106. package/lib-module/RadioCard/RadioCard.js +9 -6
  107. package/lib-module/Tabs/Tabs.js +13 -4
  108. package/lib-module/Tags/Tags.js +3 -3
  109. package/lib-module/TextInput/TextInput.js +5 -4
  110. package/lib-module/ViewportProvider/useViewportListener.js +10 -4
  111. package/lib-module/utils/hasOwnProperty.js +11 -0
  112. package/lib-module/utils/props/a11yProps.js +210 -45
  113. package/lib-module/utils/props/getPropSelector.js +44 -5
  114. package/lib-module/utils/useResponsiveProp.js +3 -4
  115. package/lib-module/utils/withLinkRouter.js +3 -5
  116. package/package.json +11 -16
  117. package/src/A11yInfoProvider/index.jsx +20 -4
  118. package/src/Button/ButtonGroup.jsx +4 -2
  119. package/src/Checkbox/Checkbox.jsx +7 -3
  120. package/src/ExpandCollapse/Control.jsx +8 -5
  121. package/src/ExpandCollapse/Panel.jsx +7 -5
  122. package/src/List/ListItem.jsx +12 -191
  123. package/src/List/ListItemBase.jsx +118 -0
  124. package/src/List/ListItemContent.jsx +52 -0
  125. package/src/List/ListItemMark.jsx +99 -0
  126. package/src/List/PressableListItemBase.jsx +102 -0
  127. package/src/Notification/Notification.jsx +1 -1
  128. package/src/Pagination/Pagination.jsx +6 -1
  129. package/src/Radio/Radio.jsx +7 -3
  130. package/src/RadioCard/RadioCard.jsx +7 -3
  131. package/src/Tabs/Tabs.jsx +19 -2
  132. package/src/Tags/Tags.jsx +3 -3
  133. package/src/TextInput/TextInput.jsx +4 -4
  134. package/src/ViewportProvider/useViewportListener.js +10 -5
  135. package/src/utils/hasOwnProperty.js +11 -0
  136. package/src/utils/props/a11yProps.js +168 -55
  137. package/src/utils/props/getPropSelector.js +45 -4
  138. package/src/utils/useResponsiveProp.js +3 -3
  139. package/src/utils/withLinkRouter.jsx +1 -3
@@ -48,53 +48,213 @@ const nativeA11yPropTypes = {
48
48
  onAccessibilityEscape: _propTypes.default.func,
49
49
  onAccessibilityTap: _propTypes.default.func
50
50
  };
51
- const a11yPropTypes = { ...nativeA11yPropTypes,
51
+
52
+ const a11yPropTypes = _Platform.default.select({
52
53
  // React Native Web adds many a11y props that alias aria-* attributes
53
54
  // Types based on https://necolas.github.io/react-native-web/docs/accessibility/
54
- accessibilityActiveDescendant: _propTypes.default.string,
55
- accessibilityAtomic: _propTypes.default.bool,
56
- accessibilityAutoComplete: _propTypes.default.string,
57
- accessibilityBusy: _propTypes.default.bool,
58
- accessibilityChecked: _propTypes.default.oneOf([true, false, 'mixed']),
59
- accessibilityColumnCount: _propTypes.default.number,
60
- accessibilityColumnIndex: _propTypes.default.number,
61
- accessibilityColumnSpan: _propTypes.default.number,
62
- accessibilityControls: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
63
- accessibilityCurrent: _propTypes.default.oneOf([true, false, 'page', 'step', 'location', 'date', 'time']),
64
- accessibilityDescribedBy: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
65
- accessibilityDetails: _propTypes.default.string,
66
- accessibilityDisabled: _propTypes.default.bool,
67
- accessibilityErrorMessage: _propTypes.default.string,
68
- accessibilityExpanded: _propTypes.default.bool,
69
- accessibilityFlowTo: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
70
- accessibilityHasPopup: _propTypes.default.string,
71
- accessibilityHidden: _propTypes.default.bool,
72
- accessibilityInvalid: _propTypes.default.bool,
73
- accessibilityKeyShortcuts: _propTypes.default.string,
74
- accessibilityLabelledBy: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
75
- accessibilityLevel: _propTypes.default.number,
76
- accessibilityModal: _propTypes.default.bool,
77
- accessibilityMultiline: _propTypes.default.bool,
78
- accessibilityMultiSelectable: _propTypes.default.bool,
79
- accessibilityOrientation: _propTypes.default.oneOf(['horizontal', 'vertical']),
80
- accessibilityOwns: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
81
- accessibilityPlaceholder: _propTypes.default.string,
82
- accessibilityPosInSet: _propTypes.default.number,
83
- accessibilityPressed: _propTypes.default.bool,
84
- accessibilityReadOnly: _propTypes.default.bool,
85
- accessibilityRequired: _propTypes.default.bool,
86
- accessibilityRoleDescription: _propTypes.default.string,
87
- accessibilityRowCount: _propTypes.default.number,
88
- accessibilityRowIndex: _propTypes.default.number,
89
- accessibilityRowSpan: _propTypes.default.number,
90
- accessibilitySelected: _propTypes.default.bool,
91
- accessibilitySetSize: _propTypes.default.number,
92
- accessibilitySort: _propTypes.default.oneOf(['ascending', 'descending', 'none', 'other']),
93
- accessibilityValueMax: _propTypes.default.number,
94
- accessibilityValueMin: _propTypes.default.number,
95
- accessibilityValueNow: _propTypes.default.number,
96
- accessibilityValueText: _propTypes.default.string
55
+ web: { ...nativeA11yPropTypes,
56
+ accessibilityActiveDescendant: _propTypes.default.string,
57
+ accessibilityAtomic: _propTypes.default.bool,
58
+ accessibilityAutoComplete: _propTypes.default.string,
59
+ accessibilityBusy: _propTypes.default.bool,
60
+ accessibilityChecked: _propTypes.default.oneOf([true, false, 'mixed']),
61
+ accessibilityColumnCount: _propTypes.default.number,
62
+ accessibilityColumnIndex: _propTypes.default.number,
63
+ accessibilityColumnSpan: _propTypes.default.number,
64
+ accessibilityControls: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
65
+ accessibilityCurrent: _propTypes.default.oneOf([true, false, 'page', 'step', 'location', 'date', 'time']),
66
+ accessibilityDescribedBy: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
67
+ accessibilityDetails: _propTypes.default.string,
68
+ accessibilityDisabled: _propTypes.default.bool,
69
+ accessibilityErrorMessage: _propTypes.default.string,
70
+ accessibilityExpanded: _propTypes.default.bool,
71
+ accessibilityFlowTo: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
72
+ accessibilityHasPopup: _propTypes.default.string,
73
+ accessibilityHidden: _propTypes.default.bool,
74
+ accessibilityInvalid: _propTypes.default.bool,
75
+ accessibilityKeyShortcuts: _propTypes.default.string,
76
+ accessibilityLabelledBy: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
77
+ accessibilityLevel: _propTypes.default.number,
78
+ accessibilityModal: _propTypes.default.bool,
79
+ accessibilityMultiline: _propTypes.default.bool,
80
+ accessibilityMultiSelectable: _propTypes.default.bool,
81
+ accessibilityOrientation: _propTypes.default.oneOf(['horizontal', 'vertical']),
82
+ accessibilityOwns: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
83
+ accessibilityPlaceholder: _propTypes.default.string,
84
+ accessibilityPosInSet: _propTypes.default.number,
85
+ accessibilityPressed: _propTypes.default.bool,
86
+ accessibilityReadOnly: _propTypes.default.bool,
87
+ accessibilityRequired: _propTypes.default.bool,
88
+ accessibilityRoleDescription: _propTypes.default.string,
89
+ accessibilityRowCount: _propTypes.default.number,
90
+ accessibilityRowIndex: _propTypes.default.number,
91
+ accessibilityRowSpan: _propTypes.default.number,
92
+ accessibilitySelected: _propTypes.default.bool,
93
+ accessibilitySetSize: _propTypes.default.number,
94
+ accessibilitySort: _propTypes.default.oneOf(['ascending', 'descending', 'none', 'other']),
95
+ accessibilityValueMax: _propTypes.default.number,
96
+ accessibilityValueMin: _propTypes.default.number,
97
+ accessibilityValueNow: _propTypes.default.number,
98
+ accessibilityValueText: _propTypes.default.string
99
+ },
100
+ // Ignore web-only props in native builds
101
+ default: nativeA11yPropTypes
102
+ }); // These RNW-only props only exist in RNW >=0.18. Catch them and map them according to platform
103
+ // so all props work on RN, RNW >=0.18 and RNW <=0.18, regardless of which they were written for:
104
+ // - On native, bundle them into objects, like `accessibilityValue: { max: 100 }`
105
+ // - On web, split them into both of:
106
+ // - The appropriate aria-* attr, like `aria-valuenow`, which will work regardless of RNW version
107
+ // - The corresponding RNW >=0.18 prop, like `accessibilityValueNow`, which in some cases does more
108
+ // than just add the aria-* (e.g. `accessibilityDisabled` adds `disabled` if element supports it,
109
+ // and future releases might add more features here).
110
+
111
+
112
+ const rwnPropMappings = {
113
+ // Former accessibilityValue props.
114
+ accessibilityValueMax: value => _Platform.default.select({
115
+ web: {
116
+ 'aria-valuemax': value,
117
+ accessibilityValueMax: value
118
+ },
119
+ default: {
120
+ accessibilityValue: {
121
+ max: value
122
+ }
123
+ }
124
+ }),
125
+ accessibilityValueMin: value => _Platform.default.select({
126
+ web: {
127
+ 'aria-valuemin': value,
128
+ accessibilityValueMin: value
129
+ },
130
+ default: {
131
+ accessibilityValue: {
132
+ min: value
133
+ }
134
+ }
135
+ }),
136
+ accessibilityValueNow: value => _Platform.default.select({
137
+ web: {
138
+ 'aria-valuenow': value,
139
+ accessibilityValueNow: value
140
+ },
141
+ default: {
142
+ accessibilityValue: {
143
+ now: value
144
+ }
145
+ }
146
+ }),
147
+ accessibilityValueText: value => _Platform.default.select({
148
+ web: {
149
+ 'aria-valuetext': value,
150
+ accessibilityValueText: value
151
+ },
152
+ default: {
153
+ accessibilityValue: {
154
+ text: value
155
+ }
156
+ }
157
+ }),
158
+ // Former accessibilityState props
159
+ accessibilityBusy: value => _Platform.default.select({
160
+ web: {
161
+ 'aria-busy': value,
162
+ accessibilityBusy: value
163
+ },
164
+ default: {
165
+ accessibilityState: {
166
+ busy: value
167
+ }
168
+ }
169
+ }),
170
+ accessibilityChecked: value => _Platform.default.select({
171
+ web: {
172
+ 'aria-checked': value,
173
+ accessibilityChecked: value
174
+ },
175
+ default: {
176
+ accessibilityState: {
177
+ checked: value
178
+ }
179
+ }
180
+ }),
181
+ accessibilityDisabled: value => _Platform.default.select({
182
+ web: {
183
+ 'aria-disabled': value,
184
+ // RNW >= 0.18 maps `accessibilityDisabled` to `disabled` attr if element supports it
185
+ accessibilityDisabled: value,
186
+ // As of RNW 0.18.9, Pressable doesn't support `accessibilityDisabled`, only `disabled`,
187
+ // but everything else supports `accessibilityDisabled` but not `disabled`.
188
+ disabled: value
189
+ },
190
+ default: {
191
+ accessibilityState: {
192
+ disabled: value
193
+ }
194
+ }
195
+ }),
196
+ accessibilityExpanded: value => _Platform.default.select({
197
+ web: {
198
+ 'aria-expanded': value,
199
+ accessibilityExpanded: value
200
+ },
201
+ default: {
202
+ accessibilityState: {
203
+ expanded: value
204
+ }
205
+ }
206
+ }),
207
+ accessibilitySelected: value => _Platform.default.select({
208
+ web: {
209
+ 'aria-selected': value,
210
+ accessibilitySelected: value
211
+ },
212
+ default: {
213
+ accessibilityState: {
214
+ selected: value
215
+ }
216
+ }
217
+ })
97
218
  };
219
+
220
+ if (_Platform.default.OS === 'web') {
221
+ const mapIfDefined = (value, fn) => value === undefined ? undefined : fn(value); // On Web only, these React Native object props need manual mapping in RNW >=0.18
222
+ // which dropped support for the React Native shape of these props.
223
+ // Re-use our RNW 0.18 prop mappings to support both RNW <0.18 (aria-*) and
224
+ // new features added in >=0.18 (e.g. for accessibilityDisabled).
225
+
226
+
227
+ rwnPropMappings.accessibilityValue = function () {
228
+ let {
229
+ max,
230
+ min,
231
+ now,
232
+ text
233
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
234
+ return { ...mapIfDefined(max, rwnPropMappings.accessibilityValueMax),
235
+ ...mapIfDefined(min, rwnPropMappings.accessibilityValueMin),
236
+ ...mapIfDefined(now, rwnPropMappings.accessibilityValueNow),
237
+ ...mapIfDefined(text, rwnPropMappings.accessibilityValueText)
238
+ };
239
+ };
240
+
241
+ rwnPropMappings.accessibilityState = function () {
242
+ let {
243
+ busy,
244
+ checked,
245
+ disabled,
246
+ expanded,
247
+ selected
248
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
249
+ return { ...mapIfDefined(busy, rwnPropMappings.accessibilityBusy),
250
+ ...mapIfDefined(checked, rwnPropMappings.accessibilityChecked),
251
+ ...mapIfDefined(disabled, rwnPropMappings.accessibilityDisabled),
252
+ ...mapIfDefined(expanded, rwnPropMappings.accessibilityExpanded),
253
+ ...mapIfDefined(selected, rwnPropMappings.accessibilitySelected)
254
+ };
255
+ };
256
+ }
257
+
98
258
  var _default = {
99
259
  /**
100
260
  * Proptypes for recognised React Native accessiblity (a11y) props.
@@ -108,7 +268,14 @@ var _default = {
108
268
  * Where components accept React Native a11y props, pass { ...rest } from its props to this,
109
269
  * then spread the returned object into the component's props (usually its outer container).
110
270
  */
111
- select: (0, _getPropSelector.default)(a11yPropTypes, /^aria-/),
271
+ select: (0, _getPropSelector.default)( // Allow all React Native accessibility props
272
+ a11yPropTypes, // Allow any `aria-*` attribute on web; ignore them on native
273
+ _Platform.default.OS === 'web' && /^aria-/, // For the props added and deprecated in React Native Web 0.18, convert them to
274
+ // a form that is platform-appropriate and RNW-version safe
275
+ (key, value) => {
276
+ const rnwPropMapper = rwnPropMappings[key];
277
+ return rnwPropMapper ? rnwPropMapper(value) : undefined;
278
+ }),
112
279
 
113
280
  /**
114
281
  * Use this to disable focus for elements which are visually hidden but still rendered.
@@ -5,12 +5,54 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = getPropSelector;
7
7
 
8
- function getPropSelector(propTypes, regexp) {
9
- const keys = Object.keys(propTypes);
8
+ var _lodash = _interopRequireDefault(require("lodash.merge"));
9
+
10
+ var _hasOwnProperty = _interopRequireDefault(require("../hasOwnProperty"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ /**
15
+ * @callback PropSelectorCallback - a callback called for each prop passed to a component
16
+ * @param {string} key - the key for the prop to be tested
17
+ * @param {*} value - the value of the prop being passed in to the component
18
+ * @returns {object|undefined}
19
+ */
20
+
21
+ /**
22
+ * @param {PropSelectorCallback} callback
23
+ * @param {object} items
24
+ * @param {string} key
25
+ * @param {*} value
26
+ * @returns {object|undefined}
27
+ */
28
+ const applyCallback = (callback, items, key, value) => {
29
+ // If there's no callback, continue and look up keys as normal
30
+ if (typeof callback !== 'function') return undefined;
31
+ const newItems = callback(key, value); // If the callback doesn't return anything, continue and look up keys as normal
32
+
33
+ if (!newItems) return undefined; // If the callback returns items, merge them in, deep merging props that are objects
34
+
35
+ return (0, _lodash.default)({}, items, newItems);
36
+ };
37
+ /**
38
+ * Generates a function to filter an object of props down to a subset of allowed props, with
39
+ * optional prop alteration and re-mapping via an optional callback.
40
+ *
41
+ * @param {object} propTypes - an object where every defined key is a valid prop
42
+ * @param {*} [regexp] - an optional regular expression where any match is a valid prop
43
+ * @param {PropSelectorCallback} callback - optional function taking `(key, value)` returning either undefined or an object of new props to merge in
44
+ * @returns {object} - valid props for this component
45
+ */
46
+
47
+
48
+ function getPropSelector(propTypes, regexp, callback) {
10
49
  return props => Object.entries(props).reduce((items, _ref) => {
11
50
  let [key, value] = _ref;
12
- return keys.includes(key) || regexp && regexp.test(key) ? { ...items,
13
- [key]: value
14
- } : items;
51
+ return (// If there's a callback and it matches something, applyCallback merges it in; return that
52
+ applyCallback(callback, items, key, value) || ( // If there's no callback match, check if this prop is valid and merge it in if it is
53
+ (0, _hasOwnProperty.default)(propTypes, key) || regexp && regexp.test(key) ? { ...items,
54
+ [key]: value
55
+ } : items)
56
+ );
15
57
  }, {});
16
58
  }
@@ -9,9 +9,11 @@ var _systemConstants = require("@telus-uds/system-constants");
9
9
 
10
10
  var _ViewportProvider = require("../ViewportProvider");
11
11
 
12
- const hasOwn = (objectProp, key) => Object.prototype.hasOwnProperty.call(objectProp, key);
12
+ var _hasOwnProperty = _interopRequireDefault(require("./hasOwnProperty"));
13
13
 
14
- const hasResponsiveProperties = objectProp => _systemConstants.viewports.keys.some(key => hasOwn(objectProp, key));
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const hasResponsiveProperties = objectProp => _systemConstants.viewports.keys.some(key => (0, _hasOwnProperty.default)(objectProp, key));
15
17
  /**
16
18
  * Resolves a prop which may be a responsive object with keys for viewports.
17
19
  *
@@ -29,7 +31,7 @@ const resolveResponsiveProp = (prop, viewport, defaultValue) => {
29
31
  if (!prop || typeof prop !== 'object' || !hasResponsiveProperties(prop)) return prop;
30
32
  const value = _systemConstants.viewports.keys.includes(viewport) ? // If there's a current viewport, return the closest match at or below it
31
33
  _systemConstants.viewports.inherit(prop)[viewport] : // If no current viewport is available, default to smallest viewport
32
- prop[_systemConstants.viewports.keys.find(key => hasOwn(prop, key))];
34
+ prop[_systemConstants.viewports.keys.find(key => (0, _hasOwnProperty.default)(prop, key))];
33
35
  return value === undefined ? defaultValue : value;
34
36
  };
35
37
  /**
@@ -9,6 +9,8 @@ var _react = _interopRequireWildcard(require("react"));
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
12
+ var _hasOwnProperty = _interopRequireDefault(require("./hasOwnProperty"));
13
+
12
14
  var _jsxRuntime = require("react/jsx-runtime");
13
15
 
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -17,8 +19,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
17
19
 
18
20
  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; }
19
21
 
20
- // Prototype-safe alternative to (linter-forbidden) someObject.hasOwnProperty()
21
- const hasOwnProperty = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
22
22
  /**
23
23
  * Higher-order component that has no effect unless an additional prop `LinkRouter` is passed.
24
24
  * This may be used to provide custom wrappers for integrations with third party libraries.
@@ -47,8 +47,6 @@ const hasOwnProperty = (object, prop) => Object.prototype.hasOwnProperty.call(ob
47
47
  * <IconButton icon={SomeIcon} LinkRouter={LinkLinkRouter} linkRouterProps={{ to, options }} ref={iconRef} />
48
48
  * ```
49
49
  */
50
-
51
-
52
50
  const withLinkRouter = Component => {
53
51
  const wrappedComponent = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
54
52
  let {
@@ -84,7 +82,7 @@ const withLinkRouter = Component => {
84
82
 
85
83
  Object.keys(otherProperties).forEach(key => {
86
84
  // Skip internal React properties from wrappedComponent's forwardRef (render, $$typeof, etc)
87
- if (hasOwnProperty(Component, key) && !hasOwnProperty(wrappedComponent, key)) {
85
+ if ((0, _hasOwnProperty.default)(Component, key) && !(0, _hasOwnProperty.default)(wrappedComponent, key)) {
88
86
  wrappedComponent[key] = Component[key];
89
87
  }
90
88
  });
@@ -19,8 +19,8 @@ const A11yInfoProvider = _ref => {
19
19
  return () => {};
20
20
  }
21
21
 
22
- AccessibilityInfo.addEventListener('reduceMotionChanged', setReduceMotionEnabled);
23
- AccessibilityInfo.addEventListener('screenReaderChanged', setScreenReaderEnabled);
22
+ const motionSubscription = AccessibilityInfo.addEventListener('reduceMotionChanged', setReduceMotionEnabled);
23
+ const screenReaderSubscription = AccessibilityInfo.addEventListener('screenReaderChanged', setScreenReaderEnabled);
24
24
 
25
25
  const setInitialA11yInfo = async () => {
26
26
  const [initialReduceMotionEnabled, initialScreenReaderEnabled] = await Promise.all([AccessibilityInfo.isReduceMotionEnabled(), AccessibilityInfo.isScreenReaderEnabled()]); // Browsers can't detect screen readers; in RNW isScreenReaderEnabled() is always `true`
@@ -36,8 +36,18 @@ const A11yInfoProvider = _ref => {
36
36
  }
37
37
 
38
38
  return () => {
39
- AccessibilityInfo.removeEventListener('reduceMotionChanged', setReduceMotionEnabled);
40
- AccessibilityInfo.removeEventListener('screenReaderChanged', setScreenReaderEnabled);
39
+ // From react-native 0.65, AccessibilityInfo.removeEventListener is deprecated for `remove` on addEventListener return value
40
+ if (typeof (motionSubscription === null || motionSubscription === void 0 ? void 0 : motionSubscription.remove) === 'function') {
41
+ motionSubscription === null || motionSubscription === void 0 ? void 0 : motionSubscription.remove();
42
+ } else if (typeof AccessibilityInfo.removeEventListener === 'function') {
43
+ AccessibilityInfo.removeEventListener('reduceMotionChanged', setReduceMotionEnabled);
44
+ }
45
+
46
+ if (typeof (screenReaderSubscription === null || screenReaderSubscription === void 0 ? void 0 : screenReaderSubscription.remove) === 'function') {
47
+ screenReaderSubscription === null || screenReaderSubscription === void 0 ? void 0 : screenReaderSubscription.remove();
48
+ } else if (typeof AccessibilityInfo.removeEventListener === 'function') {
49
+ AccessibilityInfo.removeEventListener('screenReaderChanged', setScreenReaderEnabled);
50
+ }
41
51
  };
42
52
  }, []);
43
53
  return /*#__PURE__*/_jsx(ReducedMotionContext.Provider, {
@@ -130,8 +130,9 @@ const ButtonGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
130
130
  tokens: getButtonTokens,
131
131
  selected: isSelected,
132
132
  inactive: inactive,
133
- ...itemA11y,
134
- ...selectItemProps(itemRest),
133
+ ...selectItemProps({ ...itemRest,
134
+ ...itemA11y
135
+ }),
135
136
  children: label
136
137
  }, id);
137
138
  })
@@ -191,6 +191,14 @@ const Checkbox = /*#__PURE__*/forwardRef((_ref5, ref) => {
191
191
  const {
192
192
  themeOptions
193
193
  } = useTheme();
194
+ const selectedProps = selectProps({
195
+ accessibilityRole: 'checkbox',
196
+ accessibilityState: {
197
+ checked: isChecked,
198
+ disabled: inactive
199
+ },
200
+ ...rest
201
+ });
194
202
  return /*#__PURE__*/_jsx(View, {
195
203
  style: staticStyles.wrapper,
196
204
  ref: ref,
@@ -201,12 +209,7 @@ const Checkbox = /*#__PURE__*/forwardRef((_ref5, ref) => {
201
209
  disabled: inactive,
202
210
  onKeyDown: handleKeyDown,
203
211
  onPress: handleChange,
204
- accessibilityRole: "checkbox",
205
- accessibilityState: {
206
- checked: isChecked,
207
- disabled: inactive
208
- },
209
- ...selectProps(rest),
212
+ ...selectedProps,
210
213
  children: _ref6 => {
211
214
  let {
212
215
  focused: focus,
@@ -67,12 +67,13 @@ const ExpandCollapseControl = /*#__PURE__*/forwardRef((_ref3, ref) => {
67
67
  ...rest
68
68
  } = _ref3;
69
69
  const getTokens = useThemeTokensCallback('ExpandCollapseControl', tokens, variant);
70
- const selectedProps = selectProps({ ...rest,
71
- accessibilityRole
70
+ const selectedProps = selectProps({
71
+ accessibilityRole,
72
+ ...rest,
73
+ accessibilityState: { ...(rest.accessibilityState || {}),
74
+ expanded: isExpanded
75
+ }
72
76
  });
73
- selectedProps.accessibilityState = { ...(selectedProps.accessibilityState || {}),
74
- expanded: isExpanded
75
- };
76
77
 
77
78
  const getControlState = _ref4 => {
78
79
  let {
@@ -55,10 +55,11 @@ const ExpandCollapsePanel = /*#__PURE__*/forwardRef((_ref2, ref) => {
55
55
  } = _ref2;
56
56
  const [containerHeight, setContainerHeight] = useState(null);
57
57
  const isExpanded = openIds.includes(panelId);
58
- const selectedProps = selectProps(rest);
59
- selectedProps.accessibilityState = { ...(selectedProps.accessibilityState || {}),
60
- expanded: isExpanded
61
- };
58
+ const selectedProps = selectProps({ ...rest,
59
+ accessibilityState: { ...(rest.accessibilityState || {}),
60
+ expanded: isExpanded
61
+ }
62
+ });
62
63
  const themeTokens = useThemeTokens('ExpandCollapsePanel', tokens, variant, {
63
64
  expanded: isExpanded
64
65
  });