@telus-uds/components-base 1.14.1 → 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.
- package/CHANGELOG.md +33 -2
- package/__tests17__/A11yText/A11yText.test.jsx +34 -0
- package/__tests17__/ActivityIndicator/ActivityIndicator.test.jsx +68 -0
- package/__tests17__/ActivityIndicator/__snapshots__/ActivityIndicator.test.jsx.snap +299 -0
- package/__tests17__/Box/Box.test.jsx +111 -0
- package/__tests17__/Button/Button.test.jsx +86 -0
- package/__tests17__/Button/ButtonBase.test.jsx +82 -0
- package/__tests17__/Button/ButtonGroup.test.jsx +347 -0
- package/__tests17__/Button/ButtonLink.test.jsx +61 -0
- package/__tests17__/Card/Card.test.jsx +63 -0
- package/__tests17__/Carousel/Carousel.test.jsx +128 -0
- package/__tests17__/Carousel/CarouselTabs.test.jsx +142 -0
- package/__tests17__/Checkbox/Checkbox.test.jsx +94 -0
- package/__tests17__/Checkbox/CheckboxGroup.test.jsx +246 -0
- package/__tests17__/Divider/Divider.test.jsx +91 -0
- package/__tests17__/ExpandCollapse/ExpandCollapse.test.jsx +109 -0
- package/__tests17__/Feedback/Feedback.test.jsx +42 -0
- package/__tests17__/FlexGrid/Col.test.jsx +261 -0
- package/__tests17__/FlexGrid/FlexGrid.test.jsx +136 -0
- package/__tests17__/FlexGrid/Row.test.jsx +273 -0
- package/__tests17__/HorizontalScroll/HorizontalScroll.test.jsx +165 -0
- package/__tests17__/Icon/Icon.test.jsx +61 -0
- package/__tests17__/IconButton/IconButton.test.jsx +52 -0
- package/__tests17__/InputLabel/InputLabel.test.jsx +28 -0
- package/__tests17__/InputLabel/__snapshots__/InputLabel.test.jsx.snap +3 -0
- package/__tests17__/InputSupports/InputSupports.test.jsx +60 -0
- package/__tests17__/Link/Link.test.jsx +63 -0
- package/__tests17__/Link/TextButton.test.jsx +35 -0
- package/__tests17__/List/List.test.jsx +82 -0
- package/__tests17__/Modal/Modal.test.jsx +47 -0
- package/__tests17__/Notification/Notification.test.jsx +20 -0
- package/__tests17__/Pagination/Pagination.test.jsx +160 -0
- package/__tests17__/Progress/Progress.test.jsx +79 -0
- package/__tests17__/Radio/Radio.test.jsx +87 -0
- package/__tests17__/Radio/RadioGroup.test.jsx +220 -0
- package/__tests17__/RadioCard/RadioCard.test.jsx +87 -0
- package/__tests17__/RadioCard/RadioCardGroup.test.jsx +246 -0
- package/__tests17__/Search/Search.test.jsx +87 -0
- package/__tests17__/Select/Select.test.jsx +94 -0
- package/__tests17__/SideNav/SideNav.test.jsx +110 -0
- package/__tests17__/Skeleton/Skeleton.test.jsx +61 -0
- package/__tests17__/SkipLink/SkipLink.test.jsx +61 -0
- package/__tests17__/Spacer/Spacer.test.jsx +63 -0
- package/__tests17__/StackView/StackView.test.jsx +211 -0
- package/__tests17__/StackView/StackWrap.test.jsx +47 -0
- package/__tests17__/StackView/getStackedContent.test.jsx +295 -0
- package/__tests17__/StepTracker/StepTracker.test.jsx +108 -0
- package/__tests17__/Tabs/Tabs.test.jsx +49 -0
- package/__tests17__/Tags/Tags.test.jsx +327 -0
- package/__tests17__/TextInput/TextArea.test.jsx +35 -0
- package/__tests17__/TextInput/TextInputBase.test.jsx +125 -0
- package/__tests17__/ThemeProvider/ThemeProvider.test.jsx +80 -0
- package/__tests17__/ThemeProvider/useThemeTokens.test.jsx +514 -0
- package/__tests17__/ThemeProvider/utils/theme-tokens.test.js +41 -0
- package/__tests17__/ToggleSwitch/ToggleSwitch.test.jsx +82 -0
- package/__tests17__/ToggleSwitch/ToggleSwitchGroup.test.jsx +192 -0
- package/__tests17__/Tooltip/Tooltip.test.jsx +65 -0
- package/__tests17__/Tooltip/getTooltipPosition.test.js +79 -0
- package/__tests17__/Typography/typography.test.jsx +90 -0
- package/__tests17__/utils/children.test.jsx +128 -0
- package/__tests17__/utils/containUniqueFields.test.js +25 -0
- package/__tests17__/utils/input.test.js +375 -0
- package/__tests17__/utils/props.test.js +36 -0
- package/__tests17__/utils/semantics.test.jsx +34 -0
- package/__tests17__/utils/useCopy.test.js +42 -0
- package/__tests17__/utils/useResponsiveProp.test.jsx +202 -0
- package/__tests17__/utils/useSpacingScale.test.jsx +273 -0
- package/__tests17__/utils/useUniqueId.test.js +31 -0
- package/component-docs.json +95 -438
- package/lib/A11yInfoProvider/index.js +14 -5
- package/lib/Button/ButtonGroup.js +3 -2
- package/lib/Checkbox/Checkbox.js +9 -6
- package/lib/ExpandCollapse/Control.js +6 -5
- package/lib/ExpandCollapse/Panel.js +5 -4
- package/lib/List/ListItem.js +10 -236
- package/lib/List/ListItemBase.js +162 -0
- package/lib/List/ListItemContent.js +85 -0
- package/lib/List/ListItemMark.js +158 -0
- package/lib/List/PressableListItemBase.js +147 -0
- package/lib/Notification/Notification.js +2 -1
- package/lib/Pagination/Pagination.js +4 -3
- package/lib/Pagination/SideButton.js +17 -7
- package/lib/Radio/Radio.js +9 -6
- package/lib/RadioCard/RadioCard.js +9 -6
- package/lib/Select/Select.js +1 -0
- package/lib/Tabs/Tabs.js +12 -3
- package/lib/Tags/Tags.js +3 -3
- package/lib/TextInput/TextInput.js +5 -4
- package/lib/ViewportProvider/useViewportListener.js +11 -5
- package/lib/utils/hasOwnProperty.js +18 -0
- package/lib/utils/props/a11yProps.js +212 -45
- package/lib/utils/props/getPropSelector.js +47 -5
- package/lib/utils/ssr.js +116 -1
- package/lib/utils/useResponsiveProp.js +5 -3
- package/lib/utils/withLinkRouter.js +3 -5
- package/lib-module/A11yInfoProvider/index.js +14 -4
- package/lib-module/Button/ButtonGroup.js +3 -2
- package/lib-module/Checkbox/Checkbox.js +9 -6
- package/lib-module/ExpandCollapse/Control.js +6 -5
- package/lib-module/ExpandCollapse/Panel.js +5 -4
- package/lib-module/List/ListItem.js +13 -235
- package/lib-module/List/ListItemBase.js +139 -0
- package/lib-module/List/ListItemContent.js +66 -0
- package/lib-module/List/ListItemMark.js +143 -0
- package/lib-module/List/PressableListItemBase.js +117 -0
- package/lib-module/Notification/Notification.js +2 -1
- package/lib-module/Pagination/Pagination.js +5 -3
- package/lib-module/Pagination/SideButton.js +18 -8
- package/lib-module/Radio/Radio.js +9 -6
- package/lib-module/RadioCard/RadioCard.js +9 -6
- package/lib-module/Select/Select.js +1 -0
- package/lib-module/Tabs/Tabs.js +13 -4
- package/lib-module/Tags/Tags.js +3 -3
- package/lib-module/TextInput/TextInput.js +5 -4
- package/lib-module/ViewportProvider/useViewportListener.js +10 -4
- package/lib-module/utils/hasOwnProperty.js +11 -0
- package/lib-module/utils/props/a11yProps.js +210 -45
- package/lib-module/utils/props/getPropSelector.js +44 -5
- package/lib-module/utils/ssr.js +106 -0
- package/lib-module/utils/useResponsiveProp.js +3 -4
- package/lib-module/utils/withLinkRouter.js +3 -5
- package/package.json +12 -17
- package/src/A11yInfoProvider/index.jsx +20 -4
- package/src/Button/ButtonGroup.jsx +4 -2
- package/src/Checkbox/Checkbox.jsx +7 -3
- package/src/ExpandCollapse/Control.jsx +8 -5
- package/src/ExpandCollapse/Panel.jsx +7 -5
- package/src/List/ListItem.jsx +12 -191
- package/src/List/ListItemBase.jsx +118 -0
- package/src/List/ListItemContent.jsx +52 -0
- package/src/List/ListItemMark.jsx +99 -0
- package/src/List/PressableListItemBase.jsx +102 -0
- package/src/Notification/Notification.jsx +1 -1
- package/src/Pagination/Pagination.jsx +6 -1
- package/src/Pagination/SideButton.jsx +4 -1
- package/src/Radio/Radio.jsx +7 -3
- package/src/RadioCard/RadioCard.jsx +7 -3
- package/src/Select/Select.jsx +1 -1
- package/src/Tabs/Tabs.jsx +19 -2
- package/src/Tags/Tags.jsx +3 -3
- package/src/TextInput/TextInput.jsx +4 -4
- package/src/ViewportProvider/useViewportListener.js +10 -5
- package/src/utils/hasOwnProperty.js +11 -0
- package/src/utils/props/a11yProps.js +168 -55
- package/src/utils/props/getPropSelector.js +45 -4
- package/src/utils/ssr.jsx +124 -0
- package/src/utils/useResponsiveProp.js +3 -3
- package/src/utils/withLinkRouter.jsx +1 -3
- package/src/utils/ssr.js +0 -35
|
@@ -36,53 +36,211 @@ const nativeA11yPropTypes = {
|
|
|
36
36
|
onAccessibilityEscape: PropTypes.func,
|
|
37
37
|
onAccessibilityTap: PropTypes.func
|
|
38
38
|
};
|
|
39
|
-
const a11yPropTypes = {
|
|
39
|
+
const a11yPropTypes = Platform.select({
|
|
40
40
|
// React Native Web adds many a11y props that alias aria-* attributes
|
|
41
41
|
// Types based on https://necolas.github.io/react-native-web/docs/accessibility/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
42
|
+
web: { ...nativeA11yPropTypes,
|
|
43
|
+
accessibilityActiveDescendant: PropTypes.string,
|
|
44
|
+
accessibilityAtomic: PropTypes.bool,
|
|
45
|
+
accessibilityAutoComplete: PropTypes.string,
|
|
46
|
+
accessibilityBusy: PropTypes.bool,
|
|
47
|
+
accessibilityChecked: PropTypes.oneOf([true, false, 'mixed']),
|
|
48
|
+
accessibilityColumnCount: PropTypes.number,
|
|
49
|
+
accessibilityColumnIndex: PropTypes.number,
|
|
50
|
+
accessibilityColumnSpan: PropTypes.number,
|
|
51
|
+
accessibilityControls: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
52
|
+
accessibilityCurrent: PropTypes.oneOf([true, false, 'page', 'step', 'location', 'date', 'time']),
|
|
53
|
+
accessibilityDescribedBy: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
54
|
+
accessibilityDetails: PropTypes.string,
|
|
55
|
+
accessibilityDisabled: PropTypes.bool,
|
|
56
|
+
accessibilityErrorMessage: PropTypes.string,
|
|
57
|
+
accessibilityExpanded: PropTypes.bool,
|
|
58
|
+
accessibilityFlowTo: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
59
|
+
accessibilityHasPopup: PropTypes.string,
|
|
60
|
+
accessibilityHidden: PropTypes.bool,
|
|
61
|
+
accessibilityInvalid: PropTypes.bool,
|
|
62
|
+
accessibilityKeyShortcuts: PropTypes.string,
|
|
63
|
+
accessibilityLabelledBy: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
64
|
+
accessibilityLevel: PropTypes.number,
|
|
65
|
+
accessibilityModal: PropTypes.bool,
|
|
66
|
+
accessibilityMultiline: PropTypes.bool,
|
|
67
|
+
accessibilityMultiSelectable: PropTypes.bool,
|
|
68
|
+
accessibilityOrientation: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
69
|
+
accessibilityOwns: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
70
|
+
accessibilityPlaceholder: PropTypes.string,
|
|
71
|
+
accessibilityPosInSet: PropTypes.number,
|
|
72
|
+
accessibilityPressed: PropTypes.bool,
|
|
73
|
+
accessibilityReadOnly: PropTypes.bool,
|
|
74
|
+
accessibilityRequired: PropTypes.bool,
|
|
75
|
+
accessibilityRoleDescription: PropTypes.string,
|
|
76
|
+
accessibilityRowCount: PropTypes.number,
|
|
77
|
+
accessibilityRowIndex: PropTypes.number,
|
|
78
|
+
accessibilityRowSpan: PropTypes.number,
|
|
79
|
+
accessibilitySelected: PropTypes.bool,
|
|
80
|
+
accessibilitySetSize: PropTypes.number,
|
|
81
|
+
accessibilitySort: PropTypes.oneOf(['ascending', 'descending', 'none', 'other']),
|
|
82
|
+
accessibilityValueMax: PropTypes.number,
|
|
83
|
+
accessibilityValueMin: PropTypes.number,
|
|
84
|
+
accessibilityValueNow: PropTypes.number,
|
|
85
|
+
accessibilityValueText: PropTypes.string
|
|
86
|
+
},
|
|
87
|
+
// Ignore web-only props in native builds
|
|
88
|
+
default: nativeA11yPropTypes
|
|
89
|
+
}); // These RNW-only props only exist in RNW >=0.18. Catch them and map them according to platform
|
|
90
|
+
// so all props work on RN, RNW >=0.18 and RNW <=0.18, regardless of which they were written for:
|
|
91
|
+
// - On native, bundle them into objects, like `accessibilityValue: { max: 100 }`
|
|
92
|
+
// - On web, split them into both of:
|
|
93
|
+
// - The appropriate aria-* attr, like `aria-valuenow`, which will work regardless of RNW version
|
|
94
|
+
// - The corresponding RNW >=0.18 prop, like `accessibilityValueNow`, which in some cases does more
|
|
95
|
+
// than just add the aria-* (e.g. `accessibilityDisabled` adds `disabled` if element supports it,
|
|
96
|
+
// and future releases might add more features here).
|
|
97
|
+
|
|
98
|
+
const rwnPropMappings = {
|
|
99
|
+
// Former accessibilityValue props.
|
|
100
|
+
accessibilityValueMax: value => Platform.select({
|
|
101
|
+
web: {
|
|
102
|
+
'aria-valuemax': value,
|
|
103
|
+
accessibilityValueMax: value
|
|
104
|
+
},
|
|
105
|
+
default: {
|
|
106
|
+
accessibilityValue: {
|
|
107
|
+
max: value
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
accessibilityValueMin: value => Platform.select({
|
|
112
|
+
web: {
|
|
113
|
+
'aria-valuemin': value,
|
|
114
|
+
accessibilityValueMin: value
|
|
115
|
+
},
|
|
116
|
+
default: {
|
|
117
|
+
accessibilityValue: {
|
|
118
|
+
min: value
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}),
|
|
122
|
+
accessibilityValueNow: value => Platform.select({
|
|
123
|
+
web: {
|
|
124
|
+
'aria-valuenow': value,
|
|
125
|
+
accessibilityValueNow: value
|
|
126
|
+
},
|
|
127
|
+
default: {
|
|
128
|
+
accessibilityValue: {
|
|
129
|
+
now: value
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}),
|
|
133
|
+
accessibilityValueText: value => Platform.select({
|
|
134
|
+
web: {
|
|
135
|
+
'aria-valuetext': value,
|
|
136
|
+
accessibilityValueText: value
|
|
137
|
+
},
|
|
138
|
+
default: {
|
|
139
|
+
accessibilityValue: {
|
|
140
|
+
text: value
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}),
|
|
144
|
+
// Former accessibilityState props
|
|
145
|
+
accessibilityBusy: value => Platform.select({
|
|
146
|
+
web: {
|
|
147
|
+
'aria-busy': value,
|
|
148
|
+
accessibilityBusy: value
|
|
149
|
+
},
|
|
150
|
+
default: {
|
|
151
|
+
accessibilityState: {
|
|
152
|
+
busy: value
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}),
|
|
156
|
+
accessibilityChecked: value => Platform.select({
|
|
157
|
+
web: {
|
|
158
|
+
'aria-checked': value,
|
|
159
|
+
accessibilityChecked: value
|
|
160
|
+
},
|
|
161
|
+
default: {
|
|
162
|
+
accessibilityState: {
|
|
163
|
+
checked: value
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}),
|
|
167
|
+
accessibilityDisabled: value => Platform.select({
|
|
168
|
+
web: {
|
|
169
|
+
'aria-disabled': value,
|
|
170
|
+
// RNW >= 0.18 maps `accessibilityDisabled` to `disabled` attr if element supports it
|
|
171
|
+
accessibilityDisabled: value,
|
|
172
|
+
// As of RNW 0.18.9, Pressable doesn't support `accessibilityDisabled`, only `disabled`,
|
|
173
|
+
// but everything else supports `accessibilityDisabled` but not `disabled`.
|
|
174
|
+
disabled: value
|
|
175
|
+
},
|
|
176
|
+
default: {
|
|
177
|
+
accessibilityState: {
|
|
178
|
+
disabled: value
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}),
|
|
182
|
+
accessibilityExpanded: value => Platform.select({
|
|
183
|
+
web: {
|
|
184
|
+
'aria-expanded': value,
|
|
185
|
+
accessibilityExpanded: value
|
|
186
|
+
},
|
|
187
|
+
default: {
|
|
188
|
+
accessibilityState: {
|
|
189
|
+
expanded: value
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}),
|
|
193
|
+
accessibilitySelected: value => Platform.select({
|
|
194
|
+
web: {
|
|
195
|
+
'aria-selected': value,
|
|
196
|
+
accessibilitySelected: value
|
|
197
|
+
},
|
|
198
|
+
default: {
|
|
199
|
+
accessibilityState: {
|
|
200
|
+
selected: value
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
})
|
|
85
204
|
};
|
|
205
|
+
|
|
206
|
+
if (Platform.OS === 'web') {
|
|
207
|
+
const mapIfDefined = (value, fn) => value === undefined ? undefined : fn(value); // On Web only, these React Native object props need manual mapping in RNW >=0.18
|
|
208
|
+
// which dropped support for the React Native shape of these props.
|
|
209
|
+
// Re-use our RNW 0.18 prop mappings to support both RNW <0.18 (aria-*) and
|
|
210
|
+
// new features added in >=0.18 (e.g. for accessibilityDisabled).
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
rwnPropMappings.accessibilityValue = function () {
|
|
214
|
+
let {
|
|
215
|
+
max,
|
|
216
|
+
min,
|
|
217
|
+
now,
|
|
218
|
+
text
|
|
219
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
220
|
+
return { ...mapIfDefined(max, rwnPropMappings.accessibilityValueMax),
|
|
221
|
+
...mapIfDefined(min, rwnPropMappings.accessibilityValueMin),
|
|
222
|
+
...mapIfDefined(now, rwnPropMappings.accessibilityValueNow),
|
|
223
|
+
...mapIfDefined(text, rwnPropMappings.accessibilityValueText)
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
rwnPropMappings.accessibilityState = function () {
|
|
228
|
+
let {
|
|
229
|
+
busy,
|
|
230
|
+
checked,
|
|
231
|
+
disabled,
|
|
232
|
+
expanded,
|
|
233
|
+
selected
|
|
234
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
235
|
+
return { ...mapIfDefined(busy, rwnPropMappings.accessibilityBusy),
|
|
236
|
+
...mapIfDefined(checked, rwnPropMappings.accessibilityChecked),
|
|
237
|
+
...mapIfDefined(disabled, rwnPropMappings.accessibilityDisabled),
|
|
238
|
+
...mapIfDefined(expanded, rwnPropMappings.accessibilityExpanded),
|
|
239
|
+
...mapIfDefined(selected, rwnPropMappings.accessibilitySelected)
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
86
244
|
export default {
|
|
87
245
|
/**
|
|
88
246
|
* Proptypes for recognised React Native accessiblity (a11y) props.
|
|
@@ -96,7 +254,14 @@ export default {
|
|
|
96
254
|
* Where components accept React Native a11y props, pass { ...rest } from its props to this,
|
|
97
255
|
* then spread the returned object into the component's props (usually its outer container).
|
|
98
256
|
*/
|
|
99
|
-
select: getPropSelector(
|
|
257
|
+
select: getPropSelector( // Allow all React Native accessibility props
|
|
258
|
+
a11yPropTypes, // Allow any `aria-*` attribute on web; ignore them on native
|
|
259
|
+
Platform.OS === 'web' && /^aria-/, // For the props added and deprecated in React Native Web 0.18, convert them to
|
|
260
|
+
// a form that is platform-appropriate and RNW-version safe
|
|
261
|
+
(key, value) => {
|
|
262
|
+
const rnwPropMapper = rwnPropMappings[key];
|
|
263
|
+
return rnwPropMapper ? rnwPropMapper(value) : undefined;
|
|
264
|
+
}),
|
|
100
265
|
|
|
101
266
|
/**
|
|
102
267
|
* Use this to disable focus for elements which are visually hidden but still rendered.
|
|
@@ -1,9 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import merge from 'lodash.merge';
|
|
2
|
+
import hasOwnProperty from '../hasOwnProperty';
|
|
3
|
+
/**
|
|
4
|
+
* @callback PropSelectorCallback - a callback called for each prop passed to a component
|
|
5
|
+
* @param {string} key - the key for the prop to be tested
|
|
6
|
+
* @param {*} value - the value of the prop being passed in to the component
|
|
7
|
+
* @returns {object|undefined}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {PropSelectorCallback} callback
|
|
12
|
+
* @param {object} items
|
|
13
|
+
* @param {string} key
|
|
14
|
+
* @param {*} value
|
|
15
|
+
* @returns {object|undefined}
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const applyCallback = (callback, items, key, value) => {
|
|
19
|
+
// If there's no callback, continue and look up keys as normal
|
|
20
|
+
if (typeof callback !== 'function') return undefined;
|
|
21
|
+
const newItems = callback(key, value); // If the callback doesn't return anything, continue and look up keys as normal
|
|
22
|
+
|
|
23
|
+
if (!newItems) return undefined; // If the callback returns items, merge them in, deep merging props that are objects
|
|
24
|
+
|
|
25
|
+
return merge({}, items, newItems);
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Generates a function to filter an object of props down to a subset of allowed props, with
|
|
29
|
+
* optional prop alteration and re-mapping via an optional callback.
|
|
30
|
+
*
|
|
31
|
+
* @param {object} propTypes - an object where every defined key is a valid prop
|
|
32
|
+
* @param {*} [regexp] - an optional regular expression where any match is a valid prop
|
|
33
|
+
* @param {PropSelectorCallback} callback - optional function taking `(key, value)` returning either undefined or an object of new props to merge in
|
|
34
|
+
* @returns {object} - valid props for this component
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
export default function getPropSelector(propTypes, regexp, callback) {
|
|
3
39
|
return props => Object.entries(props).reduce((items, _ref) => {
|
|
4
40
|
let [key, value] = _ref;
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
41
|
+
return (// If there's a callback and it matches something, applyCallback merges it in; return that
|
|
42
|
+
applyCallback(callback, items, key, value) || ( // If there's no callback match, check if this prop is valid and merge it in if it is
|
|
43
|
+
hasOwnProperty(propTypes, key) || regexp && regexp.test(key) ? { ...items,
|
|
44
|
+
[key]: value
|
|
45
|
+
} : items)
|
|
46
|
+
);
|
|
8
47
|
}, {});
|
|
9
48
|
}
|
package/lib-module/utils/ssr.js
CHANGED
|
@@ -1,9 +1,113 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import AppRegistry from "react-native-web/dist/exports/AppRegistry";
|
|
2
3
|
/** @typedef {import('react').ComponentType} ReactComponent */
|
|
3
4
|
|
|
4
5
|
/** @typedef {import('react').ReactElement} ReactElement */
|
|
5
6
|
|
|
6
7
|
/**
|
|
8
|
+
* Returns object with `renderApp` and `getStyles` functions.
|
|
9
|
+
* Weave these into your app's server-side render process:
|
|
10
|
+
*
|
|
11
|
+
* - Call `renderApp` first to do the actual server-side render
|
|
12
|
+
* - After the render is complete, call `getStyles`
|
|
13
|
+
* - Include the style tags returned by `getStyles` in the SSR <head>
|
|
14
|
+
*
|
|
15
|
+
* @param {string} [appName] - optional unique identifier if ssrStyles is called multiple times for multiple apps
|
|
16
|
+
* @param {object} [options] -
|
|
17
|
+
* - `styleGetters`: optional array of additional style getter functions to call after render
|
|
18
|
+
* - `collectStyles`: optional function, takes the rendered app, returns either the same or a new app element
|
|
19
|
+
* @param {boolean} [options.styleGetters]
|
|
20
|
+
* @param {(ReactElement) => ReactElement} [options.collectStyles]
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
export const ssrStyles = function () {
|
|
25
|
+
let appName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'UDS app';
|
|
26
|
+
let {
|
|
27
|
+
styleGetters = [],
|
|
28
|
+
collectStyles
|
|
29
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30
|
+
let hasAppRendered = false;
|
|
31
|
+
return {
|
|
32
|
+
/**
|
|
33
|
+
* Server-side-renders the provided app in a way that supports collecting
|
|
34
|
+
* styles for Styled Components and React Native Web stylesheets.
|
|
35
|
+
*
|
|
36
|
+
* @param {ReactComponent} App - the root component for the app
|
|
37
|
+
* @param {object} [props] - props for this render e.g. page routing props
|
|
38
|
+
* @param {object} [options] -
|
|
39
|
+
* - `renderedByRNW`: pass as true if the main render is by AppRegistry.runApplication from React Native
|
|
40
|
+
* - `WrapperComponent`: Component rendered with no props around app content and inside root tag
|
|
41
|
+
* @param {boolean} [options.renderedByRNW]
|
|
42
|
+
* @param {ReactComponent} [options.WrapperComponent]
|
|
43
|
+
*
|
|
44
|
+
* @returns {ReactElement} - the rendered app output
|
|
45
|
+
*/
|
|
46
|
+
renderApp: function (App, props) {
|
|
47
|
+
let {
|
|
48
|
+
renderedByRNW = false,
|
|
49
|
+
WrapperComponent
|
|
50
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
51
|
+
AppRegistry.registerComponent(appName, () => App); // AppRegistry.getApplication renders the app in a container, and collects styles.
|
|
52
|
+
|
|
53
|
+
const {
|
|
54
|
+
element,
|
|
55
|
+
getStyleElement
|
|
56
|
+
} = AppRegistry.getApplication(appName, {
|
|
57
|
+
WrapperComponent,
|
|
58
|
+
initialProps: props
|
|
59
|
+
});
|
|
60
|
+
let renderedApp = // React Native Web's AppRegistry.getApplication assumes the app is rendered using
|
|
61
|
+
// AppRegistry.runApplication and wraps it in <AppContainer>, which wraps the entire app
|
|
62
|
+
// in two outer containers resembling <View style={{ flex: 1 }} pointerEvents="box-none">.
|
|
63
|
+
// So, use that IF user says AppRegistry.runApplication will do the client-side render.
|
|
64
|
+
renderedByRNW && element || // If the live app is not rendered using AppRegistry.runApplication, we need to
|
|
65
|
+
// re-render it without the <AppContainer> wrapper, to avoid SSR mismatch errors.
|
|
66
|
+
// Default to this as many platforms (e.g. NextJS) will use their own renderers.
|
|
67
|
+
WrapperComponent ? /*#__PURE__*/_jsx(WrapperComponent, {
|
|
68
|
+
children: /*#__PURE__*/_jsx(App, { ...props
|
|
69
|
+
})
|
|
70
|
+
}) : /*#__PURE__*/_jsx(App, { ...props
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const getRNWStyle = () => getStyleElement({
|
|
74
|
+
key: 'react-native-stylesheet'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
styleGetters.push(getRNWStyle);
|
|
78
|
+
|
|
79
|
+
if (typeof collectStyles === 'function') {
|
|
80
|
+
renderedApp = collectStyles(renderedApp);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
hasAppRendered = true;
|
|
84
|
+
return renderedApp;
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Turns styles collected during renderApp into an array of React elements of
|
|
89
|
+
* HTML <style> tags ready for insertion into the SSR HTML's <head>.
|
|
90
|
+
*
|
|
91
|
+
* Must be called after `renderApp` has completed.
|
|
92
|
+
*
|
|
93
|
+
* @param {...ReactElement} existingStyles - any existing style tag elements to merge in
|
|
94
|
+
* @returns {ReactElement[]} - flat array of <style> React elements
|
|
95
|
+
*/
|
|
96
|
+
getStyles: function () {
|
|
97
|
+
if (!hasAppRendered) throw new Error('Called getStyles before renderApp in ssrStyles');
|
|
98
|
+
|
|
99
|
+
for (var _len = arguments.length, existingStyles = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
100
|
+
existingStyles[_key] = arguments[_key];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return [...existingStyles, ...styleGetters.flatMap(getter => getter())];
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
export default ssrStyles;
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated - use ssrStyles instead
|
|
110
|
+
*
|
|
7
111
|
* Registers the app's root component with React Native Web and generates
|
|
8
112
|
* the main <style> tag containing React Native Web stylesheet styles.
|
|
9
113
|
*
|
|
@@ -21,6 +125,8 @@ export const getReactNativeWebSSRStyles = function (AppRoot) {
|
|
|
21
125
|
return [getStyleElement()];
|
|
22
126
|
};
|
|
23
127
|
/**
|
|
128
|
+
* @deprecated - use ssrStyles instead
|
|
129
|
+
*
|
|
24
130
|
* Gets style tags for each currently supported CSS-in-JS library and returns
|
|
25
131
|
* them alongside any existing style tags.
|
|
26
132
|
*
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { viewports } from '@telus-uds/system-constants';
|
|
2
2
|
import { useViewport } from '../ViewportProvider';
|
|
3
|
+
import hasOwnProperty from './hasOwnProperty';
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const hasResponsiveProperties = objectProp => viewports.keys.some(key => hasOwn(objectProp, key));
|
|
5
|
+
const hasResponsiveProperties = objectProp => viewports.keys.some(key => hasOwnProperty(objectProp, key));
|
|
7
6
|
/**
|
|
8
7
|
* Resolves a prop which may be a responsive object with keys for viewports.
|
|
9
8
|
*
|
|
@@ -21,7 +20,7 @@ export const resolveResponsiveProp = (prop, viewport, defaultValue) => {
|
|
|
21
20
|
if (!prop || typeof prop !== 'object' || !hasResponsiveProperties(prop)) return prop;
|
|
22
21
|
const value = viewports.keys.includes(viewport) ? // If there's a current viewport, return the closest match at or below it
|
|
23
22
|
viewports.inherit(prop)[viewport] : // If no current viewport is available, default to smallest viewport
|
|
24
|
-
prop[viewports.keys.find(key =>
|
|
23
|
+
prop[viewports.keys.find(key => hasOwnProperty(prop, key))];
|
|
25
24
|
return value === undefined ? defaultValue : value;
|
|
26
25
|
};
|
|
27
26
|
/**
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
|
|
6
|
-
const hasOwnProperty = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import hasOwnProperty from './hasOwnProperty';
|
|
7
4
|
/**
|
|
8
5
|
* Higher-order component that has no effect unless an additional prop `LinkRouter` is passed.
|
|
9
6
|
* This may be used to provide custom wrappers for integrations with third party libraries.
|
|
@@ -33,6 +30,7 @@ const hasOwnProperty = (object, prop) => Object.prototype.hasOwnProperty.call(ob
|
|
|
33
30
|
* ```
|
|
34
31
|
*/
|
|
35
32
|
|
|
33
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
36
34
|
|
|
37
35
|
const withLinkRouter = Component => {
|
|
38
36
|
const wrappedComponent = /*#__PURE__*/forwardRef((_ref, ref) => {
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"airbnb-prop-types": "^2.16.0",
|
|
11
11
|
"@telus-uds/system-constants": "^1.0.4",
|
|
12
|
-
"@telus-uds/system-theme-tokens": "^2.
|
|
12
|
+
"@telus-uds/system-theme-tokens": "^2.4.0",
|
|
13
13
|
"lodash.debounce": "^4.0.8",
|
|
14
14
|
"lodash.merge": "^4.6.2",
|
|
15
15
|
"prop-types": "^15.7.2",
|
|
@@ -18,17 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"description": "Base components",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@storybook/addon-a11y": "^6.5.6",
|
|
22
|
-
"@storybook/addon-essentials": "^6.5.6",
|
|
23
|
-
"@storybook/cli": "^6.5.6",
|
|
24
|
-
"@storybook/react": "^6.5.6",
|
|
25
|
-
"@storybook/builder-webpack5": "^6.5.6",
|
|
26
|
-
"@storybook/manager-webpack5": "^6.5.6",
|
|
27
21
|
"@telus-uds/browserslist-config": "^1.0.4",
|
|
28
22
|
"@testing-library/jest-native": "^4.0.1",
|
|
29
|
-
"@testing-library/react
|
|
30
|
-
"@testing-library/react-native": "
|
|
31
|
-
"react-test-renderer": "
|
|
23
|
+
"@testing-library/react": "^13.3.0",
|
|
24
|
+
"@testing-library/react-native": "11.0.0",
|
|
25
|
+
"react-test-renderer": "~18.0.0",
|
|
26
|
+
"@testing-library/react-hooks": "~7.0.1",
|
|
27
|
+
"@testing-library/react-native-17": "npm:@testing-library/react-native@7.2.0",
|
|
28
|
+
"react-test-renderer-17": "npm:react-test-renderer@17.0.2",
|
|
32
29
|
"webpack": "5.x"
|
|
33
30
|
},
|
|
34
31
|
"directories": {
|
|
@@ -44,10 +41,10 @@
|
|
|
44
41
|
"module": "lib-module/index.js",
|
|
45
42
|
"name": "@telus-uds/components-base",
|
|
46
43
|
"peerDependencies": {
|
|
47
|
-
"react": "^17.0.2",
|
|
48
|
-
"react-dom": "^17.0.2",
|
|
44
|
+
"react": "^17.0.2 || ~18.0.0",
|
|
45
|
+
"react-dom": "^17.0.2 || ~18.0.0",
|
|
49
46
|
"react-native": "*",
|
|
50
|
-
"react-native-web": "~0.17.
|
|
47
|
+
"react-native-web": "~0.17.7 || ~0.18.7"
|
|
51
48
|
},
|
|
52
49
|
"react-native": "src/index.js",
|
|
53
50
|
"repository": {
|
|
@@ -63,13 +60,11 @@
|
|
|
63
60
|
"build:main": "babel src -d lib",
|
|
64
61
|
"build:module": "babel src -d lib-module --env-name module",
|
|
65
62
|
"build:code": "npm run build:main && npm run build:module",
|
|
66
|
-
"build:docs": "babel-node --plugins=@nearform/babel-plugin-react-docgen generate-component-docs.js"
|
|
67
|
-
"storybook": "start-storybook",
|
|
68
|
-
"build-storybook": "build-storybook"
|
|
63
|
+
"build:docs": "babel-node --plugins=@nearform/babel-plugin-react-docgen generate-component-docs.js"
|
|
69
64
|
},
|
|
70
65
|
"sideEffects": false,
|
|
71
66
|
"standard-engine": {
|
|
72
67
|
"skip": true
|
|
73
68
|
},
|
|
74
|
-
"version": "1.
|
|
69
|
+
"version": "1.15.0"
|
|
75
70
|
}
|
|
@@ -16,8 +16,14 @@ const A11yInfoProvider = ({ children }) => {
|
|
|
16
16
|
return () => {}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
AccessibilityInfo.addEventListener(
|
|
20
|
-
|
|
19
|
+
const motionSubscription = AccessibilityInfo.addEventListener(
|
|
20
|
+
'reduceMotionChanged',
|
|
21
|
+
setReduceMotionEnabled
|
|
22
|
+
)
|
|
23
|
+
const screenReaderSubscription = AccessibilityInfo.addEventListener(
|
|
24
|
+
'screenReaderChanged',
|
|
25
|
+
setScreenReaderEnabled
|
|
26
|
+
)
|
|
21
27
|
|
|
22
28
|
const setInitialA11yInfo = async () => {
|
|
23
29
|
const [initialReduceMotionEnabled, initialScreenReaderEnabled] = await Promise.all([
|
|
@@ -38,8 +44,18 @@ const A11yInfoProvider = ({ children }) => {
|
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
return () => {
|
|
41
|
-
AccessibilityInfo.removeEventListener
|
|
42
|
-
|
|
47
|
+
// From react-native 0.65, AccessibilityInfo.removeEventListener is deprecated for `remove` on addEventListener return value
|
|
48
|
+
if (typeof motionSubscription?.remove === 'function') {
|
|
49
|
+
motionSubscription?.remove()
|
|
50
|
+
} else if (typeof AccessibilityInfo.removeEventListener === 'function') {
|
|
51
|
+
AccessibilityInfo.removeEventListener('reduceMotionChanged', setReduceMotionEnabled)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof screenReaderSubscription?.remove === 'function') {
|
|
55
|
+
screenReaderSubscription?.remove()
|
|
56
|
+
} else if (typeof AccessibilityInfo.removeEventListener === 'function') {
|
|
57
|
+
AccessibilityInfo.removeEventListener('screenReaderChanged', setScreenReaderEnabled)
|
|
58
|
+
}
|
|
43
59
|
}
|
|
44
60
|
}, [])
|
|
45
61
|
|
|
@@ -141,8 +141,10 @@ const ButtonGroup = forwardRef(
|
|
|
141
141
|
tokens={getButtonTokens}
|
|
142
142
|
selected={isSelected}
|
|
143
143
|
inactive={inactive}
|
|
144
|
-
{...
|
|
145
|
-
|
|
144
|
+
{...selectItemProps({
|
|
145
|
+
...itemRest,
|
|
146
|
+
...itemA11y
|
|
147
|
+
})}
|
|
146
148
|
>
|
|
147
149
|
{label}
|
|
148
150
|
</ButtonBase>
|
|
@@ -176,6 +176,12 @@ const Checkbox = forwardRef(
|
|
|
176
176
|
const inputId = id ?? uniqueId
|
|
177
177
|
const { themeOptions } = useTheme()
|
|
178
178
|
|
|
179
|
+
const selectedProps = selectProps({
|
|
180
|
+
accessibilityRole: 'checkbox',
|
|
181
|
+
accessibilityState: { checked: isChecked, disabled: inactive },
|
|
182
|
+
...rest
|
|
183
|
+
})
|
|
184
|
+
|
|
179
185
|
return (
|
|
180
186
|
<View style={staticStyles.wrapper} ref={ref}>
|
|
181
187
|
<StackView direction={feedbackPosition === 'top' ? 'column-reverse' : 'column'} space={0}>
|
|
@@ -183,9 +189,7 @@ const Checkbox = forwardRef(
|
|
|
183
189
|
disabled={inactive}
|
|
184
190
|
onKeyDown={handleKeyDown}
|
|
185
191
|
onPress={handleChange}
|
|
186
|
-
|
|
187
|
-
accessibilityState={{ checked: isChecked, disabled: inactive }}
|
|
188
|
-
{...selectProps(rest)}
|
|
192
|
+
{...selectedProps}
|
|
189
193
|
>
|
|
190
194
|
{({ focused: focus, hovered: hover, pressed }) => {
|
|
191
195
|
const { icon: IconComponent, ...stateTokens } = getTokens({ focus, hover, pressed })
|
|
@@ -56,11 +56,14 @@ const ExpandCollapseControl = forwardRef(
|
|
|
56
56
|
) => {
|
|
57
57
|
const getTokens = useThemeTokensCallback('ExpandCollapseControl', tokens, variant)
|
|
58
58
|
|
|
59
|
-
const selectedProps = selectProps({
|
|
60
|
-
|
|
61
|
-
...
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const selectedProps = selectProps({
|
|
60
|
+
accessibilityRole,
|
|
61
|
+
...rest,
|
|
62
|
+
accessibilityState: {
|
|
63
|
+
...(rest.accessibilityState || {}),
|
|
64
|
+
expanded: isExpanded
|
|
65
|
+
}
|
|
66
|
+
})
|
|
64
67
|
|
|
65
68
|
const getControlState = ({ pressed, hovered, focused }) => ({
|
|
66
69
|
pressed,
|