@telus-uds/components-base 1.2.0 → 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 (116) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +12 -0
  3. package/__tests__/FlexGrid/Col.test.jsx +6 -10
  4. package/__tests__/utils/props.test.js +36 -0
  5. package/__tests__/utils/semantics.test.jsx +1 -10
  6. package/component-docs.json +64 -53
  7. package/generate-component-docs.js +3 -0
  8. package/lib/A11yText/index.js +2 -2
  9. package/lib/ActivityIndicator/index.js +3 -3
  10. package/lib/Box/Box.js +4 -4
  11. package/lib/Button/Button.js +2 -2
  12. package/lib/Button/ButtonGroup.js +10 -12
  13. package/lib/Button/ButtonLink.js +4 -4
  14. package/lib/Button/propTypes.js +4 -2
  15. package/lib/Card/Card.js +2 -2
  16. package/lib/Card/CardBase.js +6 -9
  17. package/lib/Card/PressableCardBase.js +3 -3
  18. package/lib/Checkbox/Checkbox.js +3 -3
  19. package/lib/Divider/Divider.js +2 -2
  20. package/lib/FlexGrid/FlexGrid.js +4 -4
  21. package/lib/FlexGrid/helpers/index.js +1 -4
  22. package/lib/IconButton/IconButton.js +3 -3
  23. package/lib/Link/LinkBase.js +10 -10
  24. package/lib/List/List.js +3 -3
  25. package/lib/Progress/Progress.js +2 -2
  26. package/lib/Progress/ProgressBar.js +2 -2
  27. package/lib/Radio/Radio.js +3 -3
  28. package/lib/Spacer/Spacer.js +2 -2
  29. package/lib/StackView/getStackedContent.js +1 -1
  30. package/lib/StepTracker/StepTracker.js +2 -2
  31. package/lib/Tags/Tags.js +9 -9
  32. package/lib/ThemeProvider/useThemeTokens.js +3 -3
  33. package/lib/ThemeProvider/utils/theme-tokens.js +3 -3
  34. package/lib/ToggleSwitch/ToggleSwitch.js +6 -6
  35. package/lib/ToggleSwitch/ToggleSwitchGroup.js +8 -8
  36. package/lib/utils/a11y/semantics.js +4 -3
  37. package/lib/utils/index.js +4 -4
  38. package/lib/utils/pressability.js +2 -2
  39. package/lib/utils/props/a11yProps.js +153 -0
  40. package/lib/utils/props/clickProps.js +36 -0
  41. package/lib/utils/props/componentPropType.js +70 -0
  42. package/lib/utils/props/copyPropTypes.js +14 -0
  43. package/lib/utils/props/getPropSelector.js +13 -0
  44. package/lib/utils/props/hrefAttrsProp.js +41 -0
  45. package/lib/utils/props/index.js +149 -0
  46. package/lib/utils/props/linkProps.js +64 -0
  47. package/lib/utils/props/paddingProp.js +20 -0
  48. package/lib/utils/props/pressProps.js +57 -0
  49. package/lib/utils/props/rectProp.js +20 -0
  50. package/lib/utils/props/responsiveProps.js +40 -0
  51. package/lib/utils/props/selectSystemProps.js +31 -0
  52. package/lib/utils/props/spacingProps.js +71 -0
  53. package/lib/utils/props/tokens.js +145 -0
  54. package/lib/utils/props/variantProp.js +28 -0
  55. package/lib/utils/props/viewProps.js +34 -0
  56. package/lib/utils/useResponsiveProp.js +1 -1
  57. package/lib/utils/useSpacingScale.js +4 -4
  58. package/package.json +3 -3
  59. package/release-context.json +4 -4
  60. package/src/A11yText/index.jsx +1 -1
  61. package/src/ActivityIndicator/index.jsx +1 -1
  62. package/src/Box/Box.jsx +5 -4
  63. package/src/Button/Button.jsx +1 -1
  64. package/src/Button/ButtonGroup.jsx +17 -8
  65. package/src/Button/ButtonLink.jsx +1 -1
  66. package/src/Button/propTypes.js +2 -1
  67. package/src/Card/Card.jsx +1 -1
  68. package/src/Card/CardBase.jsx +6 -5
  69. package/src/Card/PressableCardBase.jsx +1 -1
  70. package/src/Checkbox/Checkbox.jsx +1 -1
  71. package/src/Divider/Divider.jsx +2 -2
  72. package/src/FlexGrid/FlexGrid.jsx +11 -5
  73. package/src/FlexGrid/helpers/index.js +1 -3
  74. package/src/IconButton/IconButton.jsx +1 -1
  75. package/src/Link/LinkBase.jsx +1 -1
  76. package/src/List/List.jsx +1 -1
  77. package/src/Progress/Progress.jsx +1 -1
  78. package/src/Progress/ProgressBar.jsx +1 -1
  79. package/src/Radio/Radio.jsx +1 -1
  80. package/src/Spacer/Spacer.jsx +2 -2
  81. package/src/StackView/getStackedContent.jsx +1 -1
  82. package/src/StepTracker/StepTracker.jsx +1 -1
  83. package/src/Tags/Tags.jsx +1 -7
  84. package/src/ThemeProvider/useThemeTokens.js +3 -3
  85. package/src/ThemeProvider/utils/theme-tokens.js +3 -3
  86. package/src/ToggleSwitch/ToggleSwitch.jsx +1 -7
  87. package/src/ToggleSwitch/ToggleSwitchGroup.jsx +1 -1
  88. package/src/utils/a11y/semantics.js +3 -2
  89. package/src/utils/index.js +1 -1
  90. package/src/utils/pressability.js +1 -1
  91. package/src/utils/props/a11yProps.js +151 -0
  92. package/src/utils/props/clickProps.js +31 -0
  93. package/src/utils/props/componentPropType.js +67 -0
  94. package/src/utils/props/copyPropTypes.js +3 -0
  95. package/src/utils/props/getPropSelector.js +14 -0
  96. package/src/utils/props/hrefAttrsProp.js +25 -0
  97. package/src/utils/props/index.js +15 -0
  98. package/src/utils/props/linkProps.js +43 -0
  99. package/src/utils/props/paddingProp.js +10 -0
  100. package/src/utils/props/pressProps.js +45 -0
  101. package/src/utils/props/rectProp.js +10 -0
  102. package/src/utils/props/responsiveProps.js +30 -0
  103. package/src/utils/props/selectSystemProps.js +25 -0
  104. package/src/utils/props/spacingProps.js +58 -0
  105. package/src/utils/props/tokens.js +150 -0
  106. package/src/utils/props/variantProp.js +20 -0
  107. package/src/utils/props/viewProps.js +23 -0
  108. package/src/utils/useResponsiveProp.js +1 -1
  109. package/src/utils/useSpacingScale.js +4 -4
  110. package/.ultra.cache.json +0 -1
  111. package/lib/utils/a11y/propTypes.js +0 -61
  112. package/lib/utils/a11y/propTypes.native.js +0 -47
  113. package/lib/utils/propTypes.js +0 -566
  114. package/src/utils/a11y/propTypes.js +0 -61
  115. package/src/utils/a11y/propTypes.native.js +0 -39
  116. package/src/utils/propTypes.js +0 -561
@@ -1,566 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.copyPropTypes = exports.componentPropType = exports.spacingProps = exports.responsiveProps = exports.viewProps = exports.linkProps = exports.clickProps = exports.pressProps = exports.hrefAttrsProp = exports.a11yProps = exports.getTokensSetPropType = exports.getTokensPropType = exports.selectTokens = exports.getTokenNames = exports.variantProp = exports.rectProp = exports.paddingProp = void 0;
7
-
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
-
10
- var _Linking = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Linking"));
11
-
12
- var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
13
-
14
- var _systemThemeTokens = require("@telus-uds/system-theme-tokens");
15
-
16
- var _propTypes2 = _interopRequireDefault(require("./a11y/propTypes"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- const paddingProp = {
21
- propType: _propTypes.default.shape({
22
- paddingBottom: _propTypes.default.number,
23
- paddingLeft: _propTypes.default.number,
24
- paddingRight: _propTypes.default.number,
25
- paddingTop: _propTypes.default.number
26
- })
27
- };
28
- exports.paddingProp = paddingProp;
29
- const rectProp = {
30
- propType: _propTypes.default.shape({
31
- bottom: _propTypes.default.number,
32
- left: _propTypes.default.number,
33
- right: _propTypes.default.number,
34
- top: _propTypes.default.number
35
- })
36
- };
37
- /**
38
- * @typedef {{[key: string]: string|number|boolean}} AppearanceSet
39
- * @typedef {AppearanceSet} VariantProp
40
- */
41
-
42
- exports.rectProp = rectProp;
43
- const variantProp = {
44
- /**
45
- * 'variant' is an optional object prop on all themable components.
46
- *
47
- * Contains an object with keys that correspond to the current component theme's allowed
48
- * appearances and values that correspond to the allowed values of that component.
49
- *
50
- * Since the particular keys and values depend on which theme is currently active,
51
- * the exact shape of variant props is not enforced using PropTypes.
52
- */
53
- propType: _propTypes.default.objectOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool]))
54
- }; // Tokens can be primitive values (e.g. `'rgba(0,0,0,0'`, `12`), or objects of such values,
55
- // such as tokens that describe shadow (e.g. shadow: { inset: true, color: 'rgba(...)' ... }),
56
- // or components (e.g. Icon tokens)
57
-
58
- exports.variantProp = variantProp;
59
-
60
- const tokenValue = _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool, _propTypes.default.elementType]);
61
-
62
- const tokenValueType = _propTypes.default.oneOfType([tokenValue, _propTypes.default.objectOf(tokenValue)]);
63
-
64
- const getTokenNames = componentName => {
65
- const componentTokenSchema = _systemThemeTokens.components[componentName];
66
-
67
- if (!componentTokenSchema) {
68
- throw new Error(`No "${componentName}" tokenKeys in @telus-uds/system-theme-tokens`);
69
- }
70
-
71
- return Object.keys(componentTokenSchema);
72
- };
73
- /**
74
- * Returns the subset of a set of tokens that may be accepted by the `tokens` prop of a named component
75
- * or by a provided array of tokens. A prefix may be provided, for example:
76
- *
77
- * @example
78
- * ```jsx
79
- * // returns tokens from `themeTokens` that exist in the theme schema for `Button`.
80
- * selectTokens('Button', themeTokens)
81
- * ```
82
- *
83
- * @example
84
- * ```jsx
85
- * // returns `{ backgroundColor, width }` where the values of those keys come from
86
- * // the source object's `{ containerBackgroundColor, containerWidth }` properties.
87
- * selectTokens(['backgroundColor', 'width'], themeTokens, 'container')
88
- * ```
89
- *
90
- * @example
91
- * ```jsx
92
- * // returns tokens that are defined in the `Button` theme schema, from tokens with
93
- * // a prefix `'button'` e.g. a token `buttonBorderWidth` outputs as `borderWidth`.
94
- * selectTokens('Button', themeTokens, 'button')
95
- * ```
96
- *
97
- * @param {string[]|string} specifier - a name of a component in the theme schema, or an array of token names
98
- * @param {object} tokens - a source object of theme tokens
99
- * @param {string} [prefix] - if provided, matches keys in the source object with this as the first camelCase item
100
- * @returns {object} - subset of theme tokens
101
- */
102
-
103
-
104
- exports.getTokenNames = getTokenNames;
105
-
106
- const selectTokens = (specifier, tokens, prefix) => {
107
- const tokenNames = typeof specifier === 'string' ? getTokenNames(specifier) : specifier;
108
- const filteredTokens = tokenNames.reduce((validTokens, key) => {
109
- const prefixedKey = prefix ? `${prefix}${key[0].toUpperCase()}${key.slice(1)}` : key;
110
- const token = tokens[prefixedKey];
111
- return token !== undefined ? { ...validTokens,
112
- [key]: token
113
- } : validTokens;
114
- }, {});
115
- return filteredTokens;
116
- };
117
- /**
118
- * @typedef {string|number|boolean|{[key: string]:string|number|boolean}} TokenValue
119
- * @typedef {{[key: string]: TokenValue}} TokensSet
120
- * @typedef {(AppearanceSet) => TokensSet} TokensGetter
121
- * @typedef {TokensSet|TokensGetter} TokensProp
122
- */
123
-
124
- /**
125
- * 'tokens' is an optional object prop on all themable components. Its keys must match the
126
- * token keys in the component's theme schema.
127
- *
128
- * This prop is intended to be used as an 'escape hatch' for difficult or exceptional cases
129
- * where the main theming system doesn't apply. It is intentionally permissive about values.
130
- *
131
- * @param {...string} componentsNames - one or more ComponentName, which tokens keys are accepted
132
- * @return {function} - a custom PropTypes validator
133
- *
134
- * @example
135
- * Component.propTypes = {
136
- * // accepts all tokens keys defined in Component schema
137
- * tokens: getTokensPropType('Component')
138
- * }
139
- *
140
- * Component.propTypes = {
141
- * // accepts all tokens keys defined in schemas for Component1 and Component2
142
- * tokens: getTokensPropType('Component1', 'Component2')
143
- * }
144
- */
145
-
146
-
147
- exports.selectTokens = selectTokens;
148
-
149
- const getTokensPropType = (...componentsNames) => (props, propName, componentName) => {
150
- _propTypes.default.checkPropTypes({
151
- [propName]: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.func])
152
- }, props, propName, componentName);
153
-
154
- if (typeof props[propName] !== 'function') {
155
- _propTypes.default.checkPropTypes({
156
- [propName]: _propTypes.default.exact(Object.fromEntries(componentsNames.flatMap(component => getTokenNames(component).map(key => [key, tokenValueType]))))
157
- }, props, propName, componentName);
158
- }
159
- };
160
- /**
161
- * Get a proptypes validator for a set of tokens that is not based on a component in the theme schema.
162
- *
163
- * For example, for a set of tokens used in a common style, or for a set of tokens required by
164
- * a themeless component whose tokens are set by a parent but requires tokens of a certain shape.
165
- *
166
- * By default, requires an object with a complete set of tokens (allowing `null`, but not `undefined`).
167
- *
168
- * @param {string[]} componentTokenKeys - array of strings of token names
169
- * @param {object} [options]
170
- * @param {boolean} [options.partial] - if true, allows tokens to be undefined
171
- * @param {boolean} [options.allowFunction] - if true, allows functions as well as tokens objects
172
- * @returns
173
- */
174
-
175
-
176
- exports.getTokensPropType = getTokensPropType;
177
-
178
- const getTokensSetPropType = (componentTokenKeys, {
179
- partial = false,
180
- allowFunction = false
181
- } = {}) => {
182
- const tokensObjectValidator = _propTypes.default.exact(Object.fromEntries(componentTokenKeys.map(key => [key, partial ? tokenValueType : // Some theme tokens can validly resolve to `null`, but .isRequired treats null as undefined
183
- (props, propName, ...args) => props[propName] !== null && tokenValueType.isRequired(props, propName, ...args)])));
184
-
185
- return allowFunction ? _propTypes.default.oneOfType([tokensObjectValidator, _propTypes.default.func]) : tokensObjectValidator;
186
- };
187
-
188
- exports.getTokensSetPropType = getTokensSetPropType;
189
-
190
- function getPropSelector(propTypes, regexp) {
191
- const keys = Object.keys(propTypes);
192
- return props => Object.entries(props).reduce((items, [key, value]) => keys.includes(key) || regexp && regexp.test(key) ? { ...items,
193
- [key]: value
194
- } : items, {});
195
- }
196
-
197
- const a11yProps = {
198
- /**
199
- * Proptypes for recognised React Native accessiblity (a11y) props.
200
- * Spread this in the propTypes of components that accept React Native a11y props.
201
- */
202
- types: _propTypes2.default,
203
-
204
- /**
205
- * Filters a props object, returning only recognised React Native accessiblity (a11y) props.
206
- *
207
- * Where components accept React Native a11y props, pass { ...rest } from its props to this,
208
- * then spread the returned object into the component's props (usually its outer container).
209
- */
210
- select: getPropSelector(_propTypes2.default, /^aria-/),
211
-
212
- /**
213
- * Use this to disable focus for elements which are visually hidden but still rendered.
214
- */
215
- nonFocusableProps: {
216
- focusable: false,
217
- // for android, and for keyboard nav in web
218
- ..._Platform.default.select({
219
- web: {
220
- accessibilityHidden: true // web screenreaders
221
-
222
- },
223
- android: {
224
- importantForAccessibility: 'no-hide-descendants'
225
- },
226
- ios: {
227
- accessibilityElementsHidden: true
228
- }
229
- })
230
- },
231
-
232
- /**
233
- * Generates an object of platform-appropriate a11y props describing an item that has an
234
- * ordered position in a set. Examples of usage by accessibility tools includes screenreaders
235
- * saying "Item X of Y" when this item is select.
236
- *
237
- * @param {number} itemsCount - the number of items in the set
238
- * @param {number} index - the current item's index in the set
239
- * @returns {object} - platform-applicable a11y props describing this position (if available)
240
- */
241
- getPositionInSet: (itemsCount, index) => _Platform.default.select({
242
- web: {
243
- // accessibilityPosInSet etc exists in React Native Web main branch
244
- // but not in a release compatible with Expo etc; just use `aria-*`
245
- 'aria-setsize': itemsCount,
246
- 'aria-posinset': index + 1
247
- },
248
- // No equivalents exist on the native side
249
- default: {}
250
- })
251
- }; // Props related to HTML <a> anchor link attributes.
252
-
253
- exports.a11yProps = a11yProps;
254
- const targetValues = ['_self', '_blank', '_parent', '_top'];
255
- const hrefAttrsProp = {
256
- types: {
257
- // React Native Web >= 0.15.0 supports hrefAttrs prop with only these properties
258
- // and passes them to <a> if an element has a href prop or accessibilityRole "link"
259
- download: _propTypes.default.string,
260
- rel: _propTypes.default.string,
261
- target: _propTypes.default.oneOf(targetValues)
262
- },
263
-
264
- /**
265
- * Takes a props object, bundles any hrefAttrs props present into one object
266
- * and returns that keyed as `hrefAttrs` and non-hrefAttrs props keyed as `rest`
267
- */
268
- bundle: ({
269
- download,
270
- rel,
271
- target,
272
- ...rest
273
- }) => ({
274
- hrefAttrs: {
275
- download,
276
- rel,
277
- target
278
- },
279
- rest
280
- })
281
- };
282
- exports.hrefAttrsProp = hrefAttrsProp;
283
- const pressHandlerPropTypes = {
284
- onPress: _propTypes.default.func,
285
- onPressIn: _propTypes.default.func,
286
- onPressOut: _propTypes.default.func,
287
- ..._Platform.default.select({
288
- web: {
289
- onMouseEnter: _propTypes.default.func,
290
- onMouseLeave: _propTypes.default.func,
291
- onFocus: _propTypes.default.func,
292
- onBlur: _propTypes.default.func
293
- },
294
- default: {
295
- onLongPress: _propTypes.default.func
296
- }
297
- })
298
- };
299
- const pressPropTypes = { ...pressHandlerPropTypes,
300
- disabled: _propTypes.default.bool,
301
- ..._Platform.default.select({
302
- web: {},
303
- default: {
304
- hitSlop: _propTypes.default.number,
305
- pressRetentionOffset: _propTypes.default.oneOfType([_propTypes.default.number, rectProp.propType])
306
- }
307
- })
308
- };
309
- const pressProps = {
310
- /**
311
- * Proptypes for clickable or pressable components, including web-only props
312
- */
313
- types: pressPropTypes,
314
-
315
- /**
316
- * Filters a props object, returning only the platform-relevant press props defined above
317
- */
318
- select: getPropSelector(pressPropTypes),
319
- selectHandlers: getPropSelector(pressHandlerPropTypes)
320
- };
321
- exports.pressProps = pressProps;
322
- const clickHandlerMapping = {
323
- onClick: 'onPress',
324
- mouseDown: 'onPressIn',
325
- mouseUp: 'onPressOut'
326
- };
327
- const clickProps = {
328
- /**
329
- * Web-oriented HTML click handlers that may be mapped to React Native press handlers
330
- */
331
- types: Object.fromEntries(Object.keys(clickHandlerMapping).map(mouseName => [mouseName, _propTypes.default.func])),
332
-
333
- /**
334
- * Takes a set of props and converts HTML mouse click oriented event handlers to closest
335
- * equivalent React Native press event handler.
336
- *
337
- * Use this when a component that expects press-oriented props may need to support third-party
338
- * web-oriented tooling that injects web-oriented event handlers directly. For example, for
339
- * to support use with NextJS's 'next/link' component, which injects `onClick` prop into its child.
340
- */
341
- toPressProps: props => Object.fromEntries(Object.entries(props).map(([originalName, value]) => {
342
- const translatedName = clickHandlerMapping[originalName];
343
- return translatedName ? [translatedName, value] : [originalName, value];
344
- }))
345
- };
346
- exports.clickProps = clickProps;
347
- const linkPropTypes = { ...pressPropTypes,
348
- href: _propTypes.default.string,
349
- hrefAttrs: _propTypes.default.shape(hrefAttrsProp.types),
350
- ..._propTypes2.default
351
- };
352
- const linkProps = {
353
- /**
354
- * Proptypes for components that, on Web, can output <a href="..."> link elements
355
- */
356
- types: linkPropTypes,
357
-
358
- /**
359
- * Filters a props object, returning only the platform-relevant link props defined above
360
- */
361
- select: getPropSelector(linkPropTypes),
362
-
363
- /**
364
- * Turn hrefs into press handlers on Native and throw if not given `onPress` or `href`.
365
- *
366
- * @param {({ onPress?: () => void, href?: string })}
367
- * @returns {(() => void)|undefined} Returns a press handler, or undefined on web if href
368
- * string is provided. Expects calling component to use href string on web (e.g. in `<a>`).
369
- */
370
- handleHref: ({
371
- onPress,
372
- href
373
- }) => {
374
- if (!href && !onPress) {
375
- throw new Error('handleHref requires either href or onPress');
376
- }
377
-
378
- return _Platform.default.select({
379
- web: onPress,
380
- default: (...args) => {
381
- if (onPress) onPress(...args);
382
- if (href) _Linking.default.openURL(href);
383
- }
384
- });
385
- }
386
- };
387
- exports.linkProps = linkProps;
388
- const viewPropTypes = {
389
- pointerEvents: _propTypes.default.oneOf(['all', 'none', 'box-only', 'box-none']),
390
- onLayout: _propTypes.default.func,
391
- nativeID: _propTypes.default.string,
392
- testID: _propTypes.default.string,
393
- dataSet: _propTypes.default.object
394
- };
395
- const viewProps = {
396
- /**
397
- * Subset of `View` proptypes that could conceivably be needed on any component
398
- * that renders a single View.
399
- */
400
- types: viewPropTypes,
401
-
402
- /**
403
- * Filters a props object, returning only cross-platform View props that are potentially
404
- * relevant to any basic layout component that renders one View.
405
- */
406
- select: getPropSelector(viewPropTypes)
407
- };
408
- exports.viewProps = viewProps;
409
-
410
- const getByViewport = propType => ({
411
- xs: propType,
412
- sm: propType,
413
- md: propType,
414
- lg: propType,
415
- xl: propType
416
- });
417
- /**
418
- * Utilities for props that allow different values to be applied at different viewports.
419
- *
420
- * These should apply viewport inheritance such that if a viewport is undefined, the value is
421
- * taken from the next smallest viewport for which a value is available. For example, a
422
- * responsive prop { xs: 2, lg: 3 } should apply 2 at sizes sm and md, and 3 at size xl.
423
- *
424
- * @property {Function} getByViewport - returns an object where each each viewport has a key
425
- * containing the provided argument.
426
- * @property {Function} getTypeByViewport - returns a PropTypes shape validator for an object where
427
- * each viewport has a key containing the provided proptype.
428
- * @property {Function} getTypeOptionallyByViewport - returns a PropTypes validator that accepts
429
- * either the provided proptype on its own, or the output of getTypeByViewport
430
- */
431
-
432
-
433
- const responsiveProps = {
434
- getByViewport,
435
- getTypeByViewport: propType => _propTypes.default.shape(getByViewport(propType)),
436
- getTypeOptionallyByViewport: propType => _propTypes.default.oneOfType([propType, _propTypes.default.shape(getByViewport(propType))])
437
- };
438
- /**
439
- * @typedef {0|1|2|3|4|5|6|7|8|9|10|11} SpacingIndex - value used to select a size on the spacing scale
440
- *
441
- * @typedef SpacingOptions
442
- * @property {VariantProp} [SpacingOptions.variant] - optional theme scale variants e.g. compact, wide
443
- * @property {number} [SpacingOptions.size] - optional override to force a particular pixel size
444
- * @property {number} [SpacingOptions.subtract] - optional number to subtract from final pixel size
445
- *
446
- * @typedef SpacingObject
447
- * @property {SpacingIndex} [SpacingObject.xs] - space scale index to use above xs viewport
448
- * @property {SpacingIndex} [SpacingObject.sm] - space scale index to use above sm viewport
449
- * @property {SpacingIndex} [SpacingObject.md] - space scale index to use above md viewport
450
- * @property {SpacingIndex} [SpacingObject.lg] - space scale index to use above lg viewport
451
- * @property {SpacingIndex} [SpacingObject.xl] - space scale index to use above xl viewport
452
- * @property {SpacingIndex} [SpacingObject.space] - space scale index to use at all viewports
453
- * @property {SpacingOptions} [SpacingObject.options] - optional options for this spacing
454
- *
455
- * @typedef {SpacingIndex|SpacingObject} SpacingValue
456
- */
457
-
458
- exports.responsiveProps = responsiveProps;
459
- const spacingScale = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
460
-
461
- const spacingIndexPropType = _propTypes.default.oneOf(spacingScale);
462
-
463
- const spacingObjectPropType = _propTypes.default.shape({ ...responsiveProps.getByViewport(spacingIndexPropType),
464
- space: spacingIndexPropType,
465
- options: _propTypes.default.shape({
466
- variant: variantProp.propType,
467
- size: _propTypes.default.number
468
- })
469
- });
470
- /**
471
- * Components and utilities that assign fixed space between components use a theme-defined spacing scale.
472
- *
473
- * They typically take one or more props of the {@link SpacingValue} type and turn it into a pixel size value
474
- * using the hook `useSpacingScale`, which resolves any options or responsive behaviour and returns the
475
- * appropriate value from the theme spacing scale.
476
- *
477
- * - see /ADRs/inter-component-spacing/README.md - ADR on this structure
478
- * - see /src/utils/spacing/useSpacingScale.js - hook that processes spacing values
479
- * - @see {@link SpacingIndex} - themes provide spacing scales of up to 12 sizes with optional theme rules.
480
- * - @see {@link SpacingValue} - either a simple number referencing an index position on the spacing
481
- * scale, or an object with an optional `options` key and one or more spacing indexes keyed either by
482
- * viewports or `space` to apply at all viewports.
483
- */
484
-
485
-
486
- const spacingProps = {
487
- scale: spacingScale,
488
- types: {
489
- spacingIndex: spacingIndexPropType,
490
- spacingObject: spacingObjectPropType,
491
- // Most spacing components and utilities take this prop / arg type:
492
- spacingValue: _propTypes.default.oneOfType([spacingIndexPropType, spacingObjectPropType])
493
- }
494
- };
495
- /**
496
- * Returns a prop type validator which checks whether a prop is either a component or an array of
497
- * components of a given type, based on their `name` or `displayName` properties.
498
- * Use an array of strings for `passedName` to accept more than one component type.
499
- * For an array the validation fails on the first occurrence of an invalid element.
500
- *
501
- * @param {string|string[]} passedName
502
- * @return {function}
503
- */
504
-
505
- exports.spacingProps = spacingProps;
506
-
507
- const componentPropType = passedName => {
508
- const passedNames = typeof passedName === 'string' ? [passedName] : passedName;
509
-
510
- const checkProp = (props, propName, componentName) => {
511
- var _props$propName$type, _props$propName$type2;
512
-
513
- if (props[propName] === undefined || props[propName] === null) {
514
- return undefined;
515
- }
516
-
517
- if (Array.isArray(props[propName])) {
518
- // Iterates through every child and try to find the first element that does not match the passed name
519
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
520
- return props[propName].map((_, index) => checkProp(props[propName], index, componentName)).find(Boolean);
521
- }
522
-
523
- const nameInProp = ((_props$propName$type = props[propName].type) === null || _props$propName$type === void 0 ? void 0 : _props$propName$type.displayName) || ((_props$propName$type2 = props[propName].type) === null || _props$propName$type2 === void 0 ? void 0 : _props$propName$type2.name);
524
-
525
- if (!nameInProp || !passedNames.includes(nameInProp)) {
526
- const propDescription = nameInProp ? `Component ${nameInProp}` : typeof props[propName];
527
- return new Error(`${componentName}: ${propDescription} was passed to \`${propName}\` prop; should be ${passedNames.join(' or ')}`);
528
- }
529
-
530
- return undefined;
531
- };
532
-
533
- const checkRequired = (props, propName, componentName) => {
534
- if (props[propName] === undefined) {
535
- return new Error(`The prop \`${propName}\` is marked as required in \`${componentName}\`, but its value is ${props[propName]}.`);
536
- }
537
-
538
- return undefined;
539
- };
540
-
541
- const createValidate = isRequired => {
542
- if (isRequired) {
543
- return (props, propName, componentName) => {
544
- const checkForError = checkProp(props, propName, componentName);
545
-
546
- if (checkForError) {
547
- return checkForError;
548
- }
549
-
550
- return checkRequired(props, propName, componentName);
551
- };
552
- }
553
-
554
- return checkProp;
555
- };
556
-
557
- const validate = createValidate();
558
- validate.isRequired = createValidate(true);
559
- return validate;
560
- };
561
-
562
- exports.componentPropType = componentPropType;
563
-
564
- const copyPropTypes = _propTypes.default.oneOf(['en', 'fr']);
565
-
566
- exports.copyPropTypes = copyPropTypes;
@@ -1,61 +0,0 @@
1
- import PropTypes from 'prop-types'
2
-
3
- import nativePropTypes from './propTypes.native'
4
-
5
- export default {
6
- ...nativePropTypes,
7
- // React Native Web adds many a11y props that alias aria-* attributes
8
- // Types based on https://necolas.github.io/react-native-web/docs/accessibility/
9
- accessibilityActiveDescendant: PropTypes.string,
10
- accessibilityAtomic: PropTypes.bool,
11
- accessibilityAutoComplete: PropTypes.string,
12
- accessibilityBusy: PropTypes.bool,
13
- accessibilityChecked: PropTypes.oneOf([true, false, 'mixed']),
14
- accessibilityColumnCount: PropTypes.number,
15
- accessibilityColumnIndex: PropTypes.number,
16
- accessibilityColumnSpan: PropTypes.number,
17
- accessibilityControls: PropTypes.oneOfType([
18
- PropTypes.string,
19
- PropTypes.arrayOf(PropTypes.string)
20
- ]),
21
- accessibilityCurrent: PropTypes.oneOf([true, false, 'page', 'step', 'location', 'date', 'time']),
22
- accessibilityDescribedBy: PropTypes.oneOfType([
23
- PropTypes.string,
24
- PropTypes.arrayOf(PropTypes.string)
25
- ]),
26
- accessibilityDetails: PropTypes.string,
27
- accessibilityDisabled: PropTypes.bool,
28
- accessibilityErrorMessage: PropTypes.string,
29
- accessibilityExpanded: PropTypes.bool,
30
- accessibilityFlowTo: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
31
- accessibilityHasPopup: PropTypes.string,
32
- accessibilityHidden: PropTypes.bool,
33
- accessibilityInvalid: PropTypes.bool,
34
- accessibilityKeyShortcuts: PropTypes.string,
35
- accessibilityLabelledBy: PropTypes.oneOfType([
36
- PropTypes.string,
37
- PropTypes.arrayOf(PropTypes.string)
38
- ]),
39
- accessibilityLevel: PropTypes.number,
40
- accessibilityModal: PropTypes.bool,
41
- accessibilityMultiline: PropTypes.bool,
42
- accessibilityMultiSelectable: PropTypes.bool,
43
- accessibilityOrientation: PropTypes.oneOf(['horizontal', 'vertical']),
44
- accessibilityOwns: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
45
- accessibilityPlaceholder: PropTypes.string,
46
- accessibilityPosInSet: PropTypes.number,
47
- accessibilityPressed: PropTypes.bool,
48
- accessibilityReadOnly: PropTypes.bool,
49
- accessibilityRequired: PropTypes.bool,
50
- accessibilityRoleDescription: PropTypes.string,
51
- accessibilityRowCount: PropTypes.number,
52
- accessibilityRowIndex: PropTypes.number,
53
- accessibilityRowSpan: PropTypes.number,
54
- accessibilitySelected: PropTypes.bool,
55
- accessibilitySetSize: PropTypes.number,
56
- accessibilitySort: PropTypes.oneOf(['ascending', 'descending', 'none', 'other']),
57
- accessibilityValueMax: PropTypes.number,
58
- accessibilityValueMin: PropTypes.number,
59
- accessibilityValueNow: PropTypes.number,
60
- accessibilityValueText: PropTypes.string
61
- }
@@ -1,39 +0,0 @@
1
- import PropTypes from 'prop-types'
2
-
3
- // React Native exports a11y prop definitions as TypeScript Interfaces, but no longer exports PropTypes
4
- // so we have to define them ourselves.
5
- export default {
6
- accessible: PropTypes.bool,
7
- focusable: PropTypes.bool,
8
-
9
- accessibilityElementsHidden: PropTypes.bool,
10
- accessibilityHint: PropTypes.string, // react-native-web ignores `accessibilityHint`
11
- accessibilityIgnoresInvertColors: PropTypes.bool,
12
- accessibilityLabel: PropTypes.string,
13
- accessibilityRole: PropTypes.string,
14
- accessibilityActions: PropTypes.arrayOf(
15
- PropTypes.shape({
16
- name: PropTypes.string.isRequired,
17
- label: PropTypes.string
18
- })
19
- ),
20
- accessibilityLiveRegion: PropTypes.oneOf(['none', 'polite', 'assertive']),
21
- accessibilityState: PropTypes.shape({
22
- disabled: PropTypes.bool,
23
- selected: PropTypes.bool,
24
- checked: PropTypes.oneOf([true, false, 'mixed']),
25
- busy: PropTypes.bool,
26
- expanded: PropTypes.bool
27
- }),
28
- accessibilityValue: PropTypes.shape({
29
- min: PropTypes.number,
30
- max: PropTypes.number,
31
- now: PropTypes.number,
32
- text: PropTypes.string
33
- }),
34
- accessibilityViewIsModal: PropTypes.bool,
35
- importantForAccessibility: PropTypes.oneOf(['auto', 'yes', 'no', 'no-hide-descendants']),
36
- onAccessibilityAction: PropTypes.func,
37
- onAccessibilityEscape: PropTypes.func,
38
- onAccessibilityTap: PropTypes.func
39
- }