@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.
- package/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +12 -0
- package/__tests__/FlexGrid/Col.test.jsx +6 -10
- package/__tests__/utils/props.test.js +36 -0
- package/__tests__/utils/semantics.test.jsx +1 -10
- package/component-docs.json +64 -53
- package/generate-component-docs.js +3 -0
- package/lib/A11yText/index.js +2 -2
- package/lib/ActivityIndicator/index.js +3 -3
- package/lib/Box/Box.js +4 -4
- package/lib/Button/Button.js +2 -2
- package/lib/Button/ButtonGroup.js +10 -12
- package/lib/Button/ButtonLink.js +4 -4
- package/lib/Button/propTypes.js +4 -2
- package/lib/Card/Card.js +2 -2
- package/lib/Card/CardBase.js +6 -9
- package/lib/Card/PressableCardBase.js +3 -3
- package/lib/Checkbox/Checkbox.js +3 -3
- package/lib/Divider/Divider.js +2 -2
- package/lib/FlexGrid/FlexGrid.js +4 -4
- package/lib/FlexGrid/helpers/index.js +1 -4
- package/lib/IconButton/IconButton.js +3 -3
- package/lib/Link/LinkBase.js +10 -10
- package/lib/List/List.js +3 -3
- package/lib/Progress/Progress.js +2 -2
- package/lib/Progress/ProgressBar.js +2 -2
- package/lib/Radio/Radio.js +3 -3
- package/lib/Spacer/Spacer.js +2 -2
- package/lib/StackView/getStackedContent.js +1 -1
- package/lib/StepTracker/StepTracker.js +2 -2
- package/lib/Tags/Tags.js +9 -9
- package/lib/ThemeProvider/useThemeTokens.js +3 -3
- package/lib/ThemeProvider/utils/theme-tokens.js +3 -3
- package/lib/ToggleSwitch/ToggleSwitch.js +6 -6
- package/lib/ToggleSwitch/ToggleSwitchGroup.js +8 -8
- package/lib/utils/a11y/semantics.js +4 -3
- package/lib/utils/index.js +4 -4
- package/lib/utils/pressability.js +2 -2
- package/lib/utils/props/a11yProps.js +153 -0
- package/lib/utils/props/clickProps.js +36 -0
- package/lib/utils/props/componentPropType.js +70 -0
- package/lib/utils/props/copyPropTypes.js +14 -0
- package/lib/utils/props/getPropSelector.js +13 -0
- package/lib/utils/props/hrefAttrsProp.js +41 -0
- package/lib/utils/props/index.js +149 -0
- package/lib/utils/props/linkProps.js +64 -0
- package/lib/utils/props/paddingProp.js +20 -0
- package/lib/utils/props/pressProps.js +57 -0
- package/lib/utils/props/rectProp.js +20 -0
- package/lib/utils/props/responsiveProps.js +40 -0
- package/lib/utils/props/selectSystemProps.js +31 -0
- package/lib/utils/props/spacingProps.js +71 -0
- package/lib/utils/props/tokens.js +145 -0
- package/lib/utils/props/variantProp.js +28 -0
- package/lib/utils/props/viewProps.js +34 -0
- package/lib/utils/useResponsiveProp.js +1 -1
- package/lib/utils/useSpacingScale.js +4 -4
- package/package.json +3 -3
- package/release-context.json +4 -4
- package/src/A11yText/index.jsx +1 -1
- package/src/ActivityIndicator/index.jsx +1 -1
- package/src/Box/Box.jsx +5 -4
- package/src/Button/Button.jsx +1 -1
- package/src/Button/ButtonGroup.jsx +17 -8
- package/src/Button/ButtonLink.jsx +1 -1
- package/src/Button/propTypes.js +2 -1
- package/src/Card/Card.jsx +1 -1
- package/src/Card/CardBase.jsx +6 -5
- package/src/Card/PressableCardBase.jsx +1 -1
- package/src/Checkbox/Checkbox.jsx +1 -1
- package/src/Divider/Divider.jsx +2 -2
- package/src/FlexGrid/FlexGrid.jsx +11 -5
- package/src/FlexGrid/helpers/index.js +1 -3
- package/src/IconButton/IconButton.jsx +1 -1
- package/src/Link/LinkBase.jsx +1 -1
- package/src/List/List.jsx +1 -1
- package/src/Progress/Progress.jsx +1 -1
- package/src/Progress/ProgressBar.jsx +1 -1
- package/src/Radio/Radio.jsx +1 -1
- package/src/Spacer/Spacer.jsx +2 -2
- package/src/StackView/getStackedContent.jsx +1 -1
- package/src/StepTracker/StepTracker.jsx +1 -1
- package/src/Tags/Tags.jsx +1 -7
- package/src/ThemeProvider/useThemeTokens.js +3 -3
- package/src/ThemeProvider/utils/theme-tokens.js +3 -3
- package/src/ToggleSwitch/ToggleSwitch.jsx +1 -7
- package/src/ToggleSwitch/ToggleSwitchGroup.jsx +1 -1
- package/src/utils/a11y/semantics.js +3 -2
- package/src/utils/index.js +1 -1
- package/src/utils/pressability.js +1 -1
- package/src/utils/props/a11yProps.js +151 -0
- package/src/utils/props/clickProps.js +31 -0
- package/src/utils/props/componentPropType.js +67 -0
- package/src/utils/props/copyPropTypes.js +3 -0
- package/src/utils/props/getPropSelector.js +14 -0
- package/src/utils/props/hrefAttrsProp.js +25 -0
- package/src/utils/props/index.js +15 -0
- package/src/utils/props/linkProps.js +43 -0
- package/src/utils/props/paddingProp.js +10 -0
- package/src/utils/props/pressProps.js +45 -0
- package/src/utils/props/rectProp.js +10 -0
- package/src/utils/props/responsiveProps.js +30 -0
- package/src/utils/props/selectSystemProps.js +25 -0
- package/src/utils/props/spacingProps.js +58 -0
- package/src/utils/props/tokens.js +150 -0
- package/src/utils/props/variantProp.js +20 -0
- package/src/utils/props/viewProps.js +23 -0
- package/src/utils/useResponsiveProp.js +1 -1
- package/src/utils/useSpacingScale.js +4 -4
- package/.ultra.cache.json +0 -1
- package/lib/utils/a11y/propTypes.js +0 -61
- package/lib/utils/a11y/propTypes.native.js +0 -47
- package/lib/utils/propTypes.js +0 -566
- package/src/utils/a11y/propTypes.js +0 -61
- package/src/utils/a11y/propTypes.native.js +0 -39
- package/src/utils/propTypes.js +0 -561
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
const clickHandlerMapping = {
|
|
13
|
+
onClick: 'onPress',
|
|
14
|
+
mouseDown: 'onPressIn',
|
|
15
|
+
mouseUp: 'onPressOut'
|
|
16
|
+
};
|
|
17
|
+
var _default = {
|
|
18
|
+
/**
|
|
19
|
+
* Web-oriented HTML click handlers that may be mapped to React Native press handlers
|
|
20
|
+
*/
|
|
21
|
+
types: Object.fromEntries(Object.keys(clickHandlerMapping).map(mouseName => [mouseName, _propTypes.default.func])),
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Takes a set of props and converts HTML mouse click oriented event handlers to closest
|
|
25
|
+
* equivalent React Native press event handler.
|
|
26
|
+
*
|
|
27
|
+
* Use this when a component that expects press-oriented props may need to support third-party
|
|
28
|
+
* web-oriented tooling that injects web-oriented event handlers directly. For example, for
|
|
29
|
+
* to support use with NextJS's 'next/link' component, which injects `onClick` prop into its child.
|
|
30
|
+
*/
|
|
31
|
+
toPressProps: props => Object.fromEntries(Object.entries(props).map(([originalName, value]) => {
|
|
32
|
+
const translatedName = clickHandlerMapping[originalName];
|
|
33
|
+
return translatedName ? [translatedName, value] : [originalName, value];
|
|
34
|
+
}))
|
|
35
|
+
};
|
|
36
|
+
exports.default = _default;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = componentPropType;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns a prop type validator which checks whether a prop is either a component or an array of
|
|
10
|
+
* components of a given type, based on their `name` or `displayName` properties.
|
|
11
|
+
* Use an array of strings for `passedName` to accept more than one component type.
|
|
12
|
+
* For an array the validation fails on the first occurrence of an invalid element.
|
|
13
|
+
*
|
|
14
|
+
* @param {string|string[]} passedName
|
|
15
|
+
* @return {function}
|
|
16
|
+
*/
|
|
17
|
+
function componentPropType(passedName) {
|
|
18
|
+
const passedNames = typeof passedName === 'string' ? [passedName] : passedName;
|
|
19
|
+
|
|
20
|
+
const checkProp = (props, propName, componentName) => {
|
|
21
|
+
var _props$propName$type, _props$propName$type2;
|
|
22
|
+
|
|
23
|
+
if (props[propName] === undefined || props[propName] === null) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (Array.isArray(props[propName])) {
|
|
28
|
+
// Iterates through every child and try to find the first element that does not match the passed name
|
|
29
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
30
|
+
return props[propName].map((_, index) => checkProp(props[propName], index, componentName)).find(Boolean);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
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);
|
|
34
|
+
|
|
35
|
+
if (!nameInProp || !passedNames.includes(nameInProp)) {
|
|
36
|
+
const propDescription = nameInProp ? `Component ${nameInProp}` : typeof props[propName];
|
|
37
|
+
return new Error(`${componentName}: ${propDescription} was passed to \`${propName}\` prop; should be ${passedNames.join(' or ')}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return undefined;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const checkRequired = (props, propName, componentName) => {
|
|
44
|
+
if (props[propName] === undefined) {
|
|
45
|
+
return new Error(`The prop \`${propName}\` is marked as required in \`${componentName}\`, but its value is ${props[propName]}.`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return undefined;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const createValidate = isRequired => {
|
|
52
|
+
if (isRequired) {
|
|
53
|
+
return (props, propName, componentName) => {
|
|
54
|
+
const checkForError = checkProp(props, propName, componentName);
|
|
55
|
+
|
|
56
|
+
if (checkForError) {
|
|
57
|
+
return checkForError;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return checkRequired(props, propName, componentName);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return checkProp;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const validate = createValidate();
|
|
68
|
+
validate.isRequired = createValidate(true);
|
|
69
|
+
return validate;
|
|
70
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var _default = _propTypes.default.oneOf(['en', 'fr']);
|
|
13
|
+
|
|
14
|
+
exports.default = _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getPropSelector;
|
|
7
|
+
|
|
8
|
+
function getPropSelector(propTypes, regexp) {
|
|
9
|
+
const keys = Object.keys(propTypes);
|
|
10
|
+
return props => Object.entries(props).reduce((items, [key, value]) => keys.includes(key) || regexp && regexp.test(key) ? { ...items,
|
|
11
|
+
[key]: value
|
|
12
|
+
} : items, {});
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
// Props related to HTML <a> anchor link attributes.
|
|
13
|
+
const targetValues = ['_self', '_blank', '_parent', '_top'];
|
|
14
|
+
var _default = {
|
|
15
|
+
types: {
|
|
16
|
+
// React Native Web >= 0.15.0 supports hrefAttrs prop with only these properties
|
|
17
|
+
// and passes them to <a> if an element has a href prop or accessibilityRole "link"
|
|
18
|
+
download: _propTypes.default.string,
|
|
19
|
+
rel: _propTypes.default.string,
|
|
20
|
+
target: _propTypes.default.oneOf(targetValues)
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Takes a props object, bundles any hrefAttrs props present into one object
|
|
25
|
+
* and returns that keyed as `hrefAttrs` and non-hrefAttrs props keyed as `rest`
|
|
26
|
+
*/
|
|
27
|
+
bundle: ({
|
|
28
|
+
download,
|
|
29
|
+
rel,
|
|
30
|
+
target,
|
|
31
|
+
...rest
|
|
32
|
+
}) => ({
|
|
33
|
+
hrefAttrs: {
|
|
34
|
+
download,
|
|
35
|
+
rel,
|
|
36
|
+
target
|
|
37
|
+
},
|
|
38
|
+
rest
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
exports.default = _default;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
a11yProps: true,
|
|
8
|
+
clickProps: true,
|
|
9
|
+
copyPropTypes: true,
|
|
10
|
+
componentPropType: true,
|
|
11
|
+
hrefAttrsProp: true,
|
|
12
|
+
linkProps: true,
|
|
13
|
+
pressProps: true,
|
|
14
|
+
paddingProp: true,
|
|
15
|
+
rectProp: true,
|
|
16
|
+
responsiveProps: true,
|
|
17
|
+
spacingProps: true,
|
|
18
|
+
selectSystemProps: true,
|
|
19
|
+
variantProp: true,
|
|
20
|
+
viewProps: true
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "a11yProps", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return _a11yProps.default;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "clickProps", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _clickProps.default;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "copyPropTypes", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return _copyPropTypes.default;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "componentPropType", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return _componentPropType.default;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "hrefAttrsProp", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function () {
|
|
49
|
+
return _hrefAttrsProp.default;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, "linkProps", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () {
|
|
55
|
+
return _linkProps.default;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(exports, "pressProps", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
get: function () {
|
|
61
|
+
return _pressProps.default;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, "paddingProp", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return _paddingProp.default;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(exports, "rectProp", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function () {
|
|
73
|
+
return _rectProp.default;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, "responsiveProps", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _responsiveProps.default;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(exports, "spacingProps", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function () {
|
|
85
|
+
return _spacingProps.default;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, "selectSystemProps", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () {
|
|
91
|
+
return _selectSystemProps.default;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(exports, "variantProp", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function () {
|
|
97
|
+
return _variantProp.default;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(exports, "viewProps", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function () {
|
|
103
|
+
return _viewProps.default;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
var _tokens = require("./tokens");
|
|
108
|
+
|
|
109
|
+
Object.keys(_tokens).forEach(function (key) {
|
|
110
|
+
if (key === "default" || key === "__esModule") return;
|
|
111
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
112
|
+
if (key in exports && exports[key] === _tokens[key]) return;
|
|
113
|
+
Object.defineProperty(exports, key, {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function () {
|
|
116
|
+
return _tokens[key];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
var _a11yProps = _interopRequireDefault(require("./a11yProps"));
|
|
122
|
+
|
|
123
|
+
var _clickProps = _interopRequireDefault(require("./clickProps"));
|
|
124
|
+
|
|
125
|
+
var _copyPropTypes = _interopRequireDefault(require("./copyPropTypes"));
|
|
126
|
+
|
|
127
|
+
var _componentPropType = _interopRequireDefault(require("./componentPropType"));
|
|
128
|
+
|
|
129
|
+
var _hrefAttrsProp = _interopRequireDefault(require("./hrefAttrsProp"));
|
|
130
|
+
|
|
131
|
+
var _linkProps = _interopRequireDefault(require("./linkProps"));
|
|
132
|
+
|
|
133
|
+
var _pressProps = _interopRequireDefault(require("./pressProps"));
|
|
134
|
+
|
|
135
|
+
var _paddingProp = _interopRequireDefault(require("./paddingProp"));
|
|
136
|
+
|
|
137
|
+
var _rectProp = _interopRequireDefault(require("./rectProp"));
|
|
138
|
+
|
|
139
|
+
var _responsiveProps = _interopRequireDefault(require("./responsiveProps"));
|
|
140
|
+
|
|
141
|
+
var _spacingProps = _interopRequireDefault(require("./spacingProps"));
|
|
142
|
+
|
|
143
|
+
var _selectSystemProps = _interopRequireDefault(require("./selectSystemProps"));
|
|
144
|
+
|
|
145
|
+
var _variantProp = _interopRequireDefault(require("./variantProp"));
|
|
146
|
+
|
|
147
|
+
var _viewProps = _interopRequireDefault(require("./viewProps"));
|
|
148
|
+
|
|
149
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _Linking = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Linking"));
|
|
9
|
+
|
|
10
|
+
var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
|
|
11
|
+
|
|
12
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
+
|
|
14
|
+
var _pressProps = require("./pressProps");
|
|
15
|
+
|
|
16
|
+
var _a11yProps = _interopRequireDefault(require("./a11yProps"));
|
|
17
|
+
|
|
18
|
+
var _hrefAttrsProp = _interopRequireDefault(require("./hrefAttrsProp"));
|
|
19
|
+
|
|
20
|
+
var _getPropSelector = _interopRequireDefault(require("./getPropSelector"));
|
|
21
|
+
|
|
22
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
+
|
|
24
|
+
const linkPropTypes = { ..._pressProps.pressPropTypes,
|
|
25
|
+
href: _propTypes.default.string,
|
|
26
|
+
hrefAttrs: _propTypes.default.shape(_hrefAttrsProp.default.types),
|
|
27
|
+
..._a11yProps.default.types
|
|
28
|
+
};
|
|
29
|
+
var _default = {
|
|
30
|
+
/**
|
|
31
|
+
* Proptypes for components that, on Web, can output <a href="..."> link elements
|
|
32
|
+
*/
|
|
33
|
+
types: linkPropTypes,
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Filters a props object, returning only the platform-relevant link props defined above
|
|
37
|
+
*/
|
|
38
|
+
select: (0, _getPropSelector.default)(linkPropTypes),
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Turn hrefs into press handlers on Native and throw if not given `onPress` or `href`.
|
|
42
|
+
*
|
|
43
|
+
* @param {({ onPress?: () => void, href?: string })}
|
|
44
|
+
* @returns {(() => void)|undefined} Returns a press handler, or undefined on web if href
|
|
45
|
+
* string is provided. Expects calling component to use href string on web (e.g. in `<a>`).
|
|
46
|
+
*/
|
|
47
|
+
handleHref: ({
|
|
48
|
+
onPress,
|
|
49
|
+
href
|
|
50
|
+
}) => {
|
|
51
|
+
if (!href && !onPress) {
|
|
52
|
+
throw new Error('handleHref requires either href or onPress');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return _Platform.default.select({
|
|
56
|
+
web: onPress,
|
|
57
|
+
default: (...args) => {
|
|
58
|
+
if (onPress) onPress(...args);
|
|
59
|
+
if (href) _Linking.default.openURL(href);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.default = _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var _default = {
|
|
13
|
+
propType: _propTypes.default.shape({
|
|
14
|
+
paddingBottom: _propTypes.default.number,
|
|
15
|
+
paddingLeft: _propTypes.default.number,
|
|
16
|
+
paddingRight: _propTypes.default.number,
|
|
17
|
+
paddingTop: _propTypes.default.number
|
|
18
|
+
})
|
|
19
|
+
};
|
|
20
|
+
exports.default = _default;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.pressPropTypes = void 0;
|
|
7
|
+
|
|
8
|
+
var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _rectProp = _interopRequireDefault(require("./rectProp"));
|
|
13
|
+
|
|
14
|
+
var _getPropSelector = _interopRequireDefault(require("./getPropSelector"));
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
const pressHandlerPropTypes = {
|
|
19
|
+
onPress: _propTypes.default.func,
|
|
20
|
+
onPressIn: _propTypes.default.func,
|
|
21
|
+
onPressOut: _propTypes.default.func,
|
|
22
|
+
..._Platform.default.select({
|
|
23
|
+
web: {
|
|
24
|
+
onMouseEnter: _propTypes.default.func,
|
|
25
|
+
onMouseLeave: _propTypes.default.func,
|
|
26
|
+
onFocus: _propTypes.default.func,
|
|
27
|
+
onBlur: _propTypes.default.func
|
|
28
|
+
},
|
|
29
|
+
default: {
|
|
30
|
+
onLongPress: _propTypes.default.func
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
};
|
|
34
|
+
const pressPropTypes = { ...pressHandlerPropTypes,
|
|
35
|
+
disabled: _propTypes.default.bool,
|
|
36
|
+
..._Platform.default.select({
|
|
37
|
+
web: {},
|
|
38
|
+
default: {
|
|
39
|
+
hitSlop: _propTypes.default.number,
|
|
40
|
+
pressRetentionOffset: _propTypes.default.oneOfType([_propTypes.default.number, _rectProp.default.propType])
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
exports.pressPropTypes = pressPropTypes;
|
|
45
|
+
var _default = {
|
|
46
|
+
/**
|
|
47
|
+
* Proptypes for clickable or pressable components, including web-only props
|
|
48
|
+
*/
|
|
49
|
+
types: pressPropTypes,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Filters a props object, returning only the platform-relevant press props defined above
|
|
53
|
+
*/
|
|
54
|
+
select: (0, _getPropSelector.default)(pressPropTypes),
|
|
55
|
+
selectHandlers: (0, _getPropSelector.default)(pressHandlerPropTypes)
|
|
56
|
+
};
|
|
57
|
+
exports.default = _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var _default = {
|
|
13
|
+
propType: _propTypes.default.shape({
|
|
14
|
+
bottom: _propTypes.default.number,
|
|
15
|
+
left: _propTypes.default.number,
|
|
16
|
+
right: _propTypes.default.number,
|
|
17
|
+
top: _propTypes.default.number
|
|
18
|
+
})
|
|
19
|
+
};
|
|
20
|
+
exports.default = _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
const getByViewport = propType => ({
|
|
13
|
+
xs: propType,
|
|
14
|
+
sm: propType,
|
|
15
|
+
md: propType,
|
|
16
|
+
lg: propType,
|
|
17
|
+
xl: propType
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* Utilities for props that allow different values to be applied at different viewports.
|
|
21
|
+
*
|
|
22
|
+
* These should apply viewport inheritance such that if a viewport is undefined, the value is
|
|
23
|
+
* taken from the next smallest viewport for which a value is available. For example, a
|
|
24
|
+
* responsive prop { xs: 2, lg: 3 } should apply 2 at sizes sm and md, and 3 at size xl.
|
|
25
|
+
*
|
|
26
|
+
* @property {Function} getByViewport - returns an object where each each viewport has a key
|
|
27
|
+
* containing the provided argument.
|
|
28
|
+
* @property {Function} getTypeByViewport - returns a PropTypes shape validator for an object where
|
|
29
|
+
* each viewport has a key containing the provided proptype.
|
|
30
|
+
* @property {Function} getTypeOptionallyByViewport - returns a PropTypes validator that accepts
|
|
31
|
+
* either the provided proptype on its own, or the output of getTypeByViewport
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var _default = {
|
|
36
|
+
getByViewport,
|
|
37
|
+
getTypeByViewport: propType => _propTypes.default.shape(getByViewport(propType)),
|
|
38
|
+
getTypeOptionallyByViewport: propType => _propTypes.default.oneOfType([propType, _propTypes.default.shape(getByViewport(propType))])
|
|
39
|
+
};
|
|
40
|
+
exports.default = _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = selectSystemProps;
|
|
7
|
+
|
|
8
|
+
// Returns a selector for requested prop kinds as well as the propTypes for
|
|
9
|
+
// those props merged into one object
|
|
10
|
+
function selectSystemProps(systemPropHelpers) {
|
|
11
|
+
const selectProps = props => systemPropHelpers.reduce((acc, propHelper) => {
|
|
12
|
+
if (typeof (propHelper === null || propHelper === void 0 ? void 0 : propHelper.select) !== 'function') {
|
|
13
|
+
throw new Error(`An invalid system prop helper has been passed to 'selectSystemProps': prop selector ('.select') is missing in ${propHelper}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return { ...acc,
|
|
17
|
+
...propHelper.select(props)
|
|
18
|
+
};
|
|
19
|
+
}, {});
|
|
20
|
+
|
|
21
|
+
const selectedPropTypes = systemPropHelpers.reduce((acc, propHelper) => {
|
|
22
|
+
if (!(propHelper !== null && propHelper !== void 0 && propHelper.types)) {
|
|
23
|
+
throw new Error(`An invalid system prop helper has been passed to 'selectSystemProps': types selector ('.types') is missing in ${propHelper}`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { ...acc,
|
|
27
|
+
...propHelper.types
|
|
28
|
+
};
|
|
29
|
+
}, {});
|
|
30
|
+
return [selectProps, selectedPropTypes];
|
|
31
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
var _responsiveProps = _interopRequireDefault(require("./responsiveProps"));
|
|
11
|
+
|
|
12
|
+
var _variantProp = _interopRequireDefault(require("./variantProp"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @typedef {0|1|2|3|4|5|6|7|8|9|10|11} SpacingIndex - value used to select a size on the spacing scale
|
|
18
|
+
*
|
|
19
|
+
* @typedef SpacingOptions
|
|
20
|
+
* @property {VariantProp} [SpacingOptions.variant] - optional theme scale variants e.g. compact, wide
|
|
21
|
+
* @property {number} [SpacingOptions.size] - optional override to force a particular pixel size
|
|
22
|
+
* @property {number} [SpacingOptions.subtract] - optional number to subtract from final pixel size
|
|
23
|
+
*
|
|
24
|
+
* @typedef SpacingObject
|
|
25
|
+
* @property {SpacingIndex} [SpacingObject.xs] - space scale index to use above xs viewport
|
|
26
|
+
* @property {SpacingIndex} [SpacingObject.sm] - space scale index to use above sm viewport
|
|
27
|
+
* @property {SpacingIndex} [SpacingObject.md] - space scale index to use above md viewport
|
|
28
|
+
* @property {SpacingIndex} [SpacingObject.lg] - space scale index to use above lg viewport
|
|
29
|
+
* @property {SpacingIndex} [SpacingObject.xl] - space scale index to use above xl viewport
|
|
30
|
+
* @property {SpacingIndex} [SpacingObject.space] - space scale index to use at all viewports
|
|
31
|
+
* @property {SpacingOptions} [SpacingObject.options] - optional options for this spacing
|
|
32
|
+
*
|
|
33
|
+
* @typedef {SpacingIndex|SpacingObject} SpacingValue
|
|
34
|
+
*/
|
|
35
|
+
const spacingScale = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
36
|
+
|
|
37
|
+
const spacingIndexPropType = _propTypes.default.oneOf(spacingScale);
|
|
38
|
+
|
|
39
|
+
const spacingObjectPropType = _propTypes.default.shape({ ..._responsiveProps.default.getByViewport(spacingIndexPropType),
|
|
40
|
+
space: spacingIndexPropType,
|
|
41
|
+
options: _propTypes.default.shape({
|
|
42
|
+
variant: _variantProp.default.propType,
|
|
43
|
+
size: _propTypes.default.number
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Components and utilities that assign fixed space between components use a theme-defined spacing scale.
|
|
48
|
+
*
|
|
49
|
+
* They typically take one or more props of the {@link SpacingValue} type and turn it into a pixel size value
|
|
50
|
+
* using the hook `useSpacingScale`, which resolves any options or responsive behaviour and returns the
|
|
51
|
+
* appropriate value from the theme spacing scale.
|
|
52
|
+
*
|
|
53
|
+
* - see /ADRs/inter-component-spacing/README.md - ADR on this structure
|
|
54
|
+
* - see /src/utils/spacing/useSpacingScale.js - hook that processes spacing values
|
|
55
|
+
* - @see {@link SpacingIndex} - themes provide spacing scales of up to 12 sizes with optional theme rules.
|
|
56
|
+
* - @see {@link SpacingValue} - either a simple number referencing an index position on the spacing
|
|
57
|
+
* scale, or an object with an optional `options` key and one or more spacing indexes keyed either by
|
|
58
|
+
* viewports or `space` to apply at all viewports.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
var _default = {
|
|
63
|
+
scale: spacingScale,
|
|
64
|
+
types: {
|
|
65
|
+
spacingIndex: spacingIndexPropType,
|
|
66
|
+
spacingObject: spacingObjectPropType,
|
|
67
|
+
// Most spacing components and utilities take this prop / arg type:
|
|
68
|
+
spacingValue: _propTypes.default.oneOfType([spacingIndexPropType, spacingObjectPropType])
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.default = _default;
|