@telus-uds/components-base 1.0.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.storybook/main.js +4 -0
- package/.storybook/preview.js +37 -0
- package/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +32 -0
- package/README.md +1 -1
- package/__fixtures__/Accessible.js +4 -2
- package/__fixtures__/Accessible.native.js +5 -2
- package/__fixtures__/testTheme.js +9 -0
- package/__tests__/FlexGrid/Col.test.jsx +6 -10
- package/__tests__/HorizontalScroll/HorizontalScroll.test.jsx +1 -0
- package/__tests__/ToggleSwitch/ToggleSwitch.test.jsx +10 -0
- package/__tests__/ToggleSwitch/ToggleSwitchGroup.test.jsx +192 -0
- package/__tests__/utils/props.test.js +36 -0
- package/__tests__/utils/semantics.test.jsx +1 -10
- package/babel.config.js +9 -16
- package/component-docs.json +10142 -0
- package/generate-component-docs.js +59 -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/ButtonBase.js +20 -6
- 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 +12 -6
- package/lib/Checkbox/Checkbox.js +3 -5
- 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 +11 -6
- package/lib/Link/LinkBase.js +19 -12
- package/lib/List/List.js +4 -5
- package/lib/List/ListItem.js +14 -27
- package/lib/List/index.js +15 -0
- package/lib/Pagination/PageButton.js +4 -8
- package/lib/Pagination/Pagination.js +16 -4
- package/lib/Pagination/SideButton.js +3 -1
- package/lib/Progress/Progress.js +2 -2
- package/lib/Progress/ProgressBar.js +2 -2
- package/lib/Radio/Radio.js +3 -5
- package/lib/Spacer/Spacer.js +2 -2
- package/lib/StackView/StackWrap.js +9 -5
- package/lib/StackView/getStackedContent.js +1 -1
- package/lib/StepTracker/StepTracker.js +2 -2
- package/lib/Tabs/Tabs.js +12 -4
- package/lib/Tabs/TabsItem.js +12 -6
- 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 +105 -43
- package/lib/ToggleSwitch/ToggleSwitchGroup.js +230 -0
- package/lib/ToggleSwitch/index.js +14 -4
- package/lib/index.js +28 -9
- package/lib/utils/a11y/semantics.js +4 -3
- package/lib/utils/index.js +14 -5
- 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/lib/utils/withLinkRouter.js +98 -0
- package/package.json +9 -5
- 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/ButtonBase.jsx +11 -4
- 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 +7 -5
- package/src/Checkbox/Checkbox.jsx +1 -3
- 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 +7 -5
- package/src/Link/LinkBase.jsx +7 -5
- package/src/List/List.jsx +2 -4
- package/src/List/ListItem.jsx +11 -26
- package/src/List/index.js +5 -0
- package/src/Pagination/PageButton.jsx +5 -8
- package/src/Pagination/Pagination.jsx +29 -2
- package/src/Pagination/SideButton.jsx +2 -2
- package/src/Progress/Progress.jsx +1 -1
- package/src/Progress/ProgressBar.jsx +1 -1
- package/src/Radio/Radio.jsx +1 -3
- package/src/Spacer/Spacer.jsx +2 -2
- package/src/StackView/StackWrap.jsx +7 -6
- package/src/StackView/getStackedContent.jsx +1 -1
- package/src/StepTracker/StepTracker.jsx +1 -1
- package/src/Tabs/Tabs.jsx +49 -22
- package/src/Tabs/TabsItem.jsx +11 -7
- 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 +93 -41
- package/src/ToggleSwitch/ToggleSwitchGroup.jsx +203 -0
- package/src/ToggleSwitch/index.js +2 -1
- package/src/index.js +2 -2
- package/src/utils/a11y/semantics.js +3 -2
- package/src/utils/index.js +2 -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/src/utils/withLinkRouter.jsx +68 -0
- package/stories/A11yText/A11yText.stories.jsx +1 -1
- package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +1 -1
- package/stories/Box/Box.stories.jsx +1 -1
- package/stories/Button/Button.stories.jsx +1 -1
- package/stories/Button/ButtonGroup.stories.jsx +1 -1
- package/stories/Button/ButtonLink.stories.jsx +1 -1
- package/stories/Card/Card.stories.jsx +1 -1
- package/stories/Checkbox/Checkbox.stories.jsx +1 -1
- package/stories/Divider/Divider.stories.jsx +1 -1
- package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +1 -1
- package/stories/Feedback/Feedback.stories.jsx +1 -1
- package/stories/FlexGrid/01 FlexGrid.stories.jsx +1 -1
- package/stories/FlexGrid/02 Row.stories.jsx +1 -1
- package/stories/FlexGrid/03 Col.stories.jsx +1 -1
- package/stories/Icon/Icon.stories.jsx +1 -1
- package/stories/IconButton/IconButton.stories.jsx +1 -1
- package/stories/InputLabel/InputLabel.stories.jsx +1 -1
- package/stories/Link/ChevronLink.stories.jsx +1 -1
- package/stories/Link/Link.stories.jsx +1 -1
- package/stories/Link/TextButton.stories.jsx +1 -1
- package/stories/List/List.stories.jsx +1 -1
- package/stories/Modal/Modal.stories.jsx +1 -1
- package/stories/Notification/Notification.stories.jsx +1 -1
- package/stories/Pagination/Pagination.stories.jsx +1 -1
- package/stories/Progress/Progress.stories.jsx +1 -1
- package/stories/Radio/Radio.stories.jsx +1 -1
- package/stories/RadioCard/RadioCard.stories.jsx +1 -1
- package/stories/Search/Search.stories.jsx +1 -1
- package/stories/Select/Select.stories.jsx +1 -1
- package/stories/SideNav/SideNav.stories.jsx +1 -1
- package/stories/SideNav/SideNavItem.stories.jsx +1 -1
- package/stories/SideNav/SideNavItemsGroup.stories.jsx +1 -1
- package/stories/Skeleton/Skeleton.stories.jsx +1 -1
- package/stories/Spacer/Spacer.stories.jsx +1 -1
- package/stories/StackView/StackView.stories.jsx +1 -1
- package/stories/StackView/StackWrap.stories.jsx +1 -1
- package/stories/StepTracker/StepTracker.stories.jsx +1 -1
- package/stories/Tabs/Tabs.stories.jsx +1 -1
- package/stories/Tags/Tags.stories.jsx +1 -1
- package/stories/TextInput/TextArea.stories.jsx +2 -1
- package/stories/TextInput/TextInput.stories.jsx +1 -1
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +6 -2
- package/stories/ToggleSwitch/ToggleSwitchGroup.stories.jsx +81 -0
- package/stories/Tooltip/Tooltip.stories.jsx +1 -1
- package/stories/TooltipButton/TooltipButton.stories.jsx +1 -1
- package/stories/Typography/Typography.stories.jsx +1 -1
- package/stories/supports.jsx +2 -3
- package/.ultra.cache.json +0 -1
- package/lib/utils/propTypes.js +0 -623
- package/src/utils/propTypes.js +0 -640
|
@@ -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;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTokensSetPropType = exports.getTokensPropType = exports.selectTokens = exports.getTokenNames = void 0;
|
|
7
|
+
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
|
|
10
|
+
var _systemThemeTokens = require("@telus-uds/system-theme-tokens");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
// Tokens can be primitive values (e.g. `'rgba(0,0,0,0'`, `12`), or objects of such values,
|
|
15
|
+
// such as tokens that describe shadow (e.g. shadow: { inset: true, color: 'rgba(...)' ... }),
|
|
16
|
+
// or components (e.g. Icon tokens)
|
|
17
|
+
const tokenValue = _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool, _propTypes.default.elementType]);
|
|
18
|
+
|
|
19
|
+
const tokenValueType = _propTypes.default.oneOfType([tokenValue, _propTypes.default.objectOf(tokenValue)]);
|
|
20
|
+
|
|
21
|
+
const getTokenNames = componentName => {
|
|
22
|
+
const componentTokenSchema = _systemThemeTokens.components[componentName];
|
|
23
|
+
|
|
24
|
+
if (!componentTokenSchema) {
|
|
25
|
+
throw new Error(`No "${componentName}" tokenKeys in @telus-uds/system-theme-tokens`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return Object.keys(componentTokenSchema);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Returns the subset of a set of tokens that may be accepted by the `tokens` prop of a named component
|
|
32
|
+
* or by a provided array of tokens. A prefix may be provided, for example:
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```jsx
|
|
36
|
+
* // returns tokens from `themeTokens` that exist in the theme schema for `Button`.
|
|
37
|
+
* selectTokens('Button', themeTokens)
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```jsx
|
|
42
|
+
* // returns `{ backgroundColor, width }` where the values of those keys come from
|
|
43
|
+
* // the source object's `{ containerBackgroundColor, containerWidth }` properties.
|
|
44
|
+
* selectTokens(['backgroundColor', 'width'], themeTokens, 'container')
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```jsx
|
|
49
|
+
* // returns tokens that are defined in the `Button` theme schema, from tokens with
|
|
50
|
+
* // a prefix `'button'` e.g. a token `buttonBorderWidth` outputs as `borderWidth`.
|
|
51
|
+
* selectTokens('Button', themeTokens, 'button')
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @param {string[]|string} specifier - a name of a component in the theme schema, or an array of token names
|
|
55
|
+
* @param {object} tokens - a source object of theme tokens
|
|
56
|
+
* @param {string} [prefix] - if provided, matches keys in the source object with this as the first camelCase item
|
|
57
|
+
* @returns {object} - subset of theme tokens
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
exports.getTokenNames = getTokenNames;
|
|
62
|
+
|
|
63
|
+
const selectTokens = (specifier, tokens, prefix) => {
|
|
64
|
+
const tokenNames = typeof specifier === 'string' ? getTokenNames(specifier) : specifier;
|
|
65
|
+
const filteredTokens = tokenNames.reduce((validTokens, key) => {
|
|
66
|
+
const prefixedKey = prefix ? `${prefix}${key[0].toUpperCase()}${key.slice(1)}` : key;
|
|
67
|
+
const token = tokens[prefixedKey];
|
|
68
|
+
return token !== undefined ? { ...validTokens,
|
|
69
|
+
[key]: token
|
|
70
|
+
} : validTokens;
|
|
71
|
+
}, {});
|
|
72
|
+
return filteredTokens;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* @typedef {string|number|boolean|{[key: string]:string|number|boolean}} TokenValue
|
|
76
|
+
* @typedef {{[key: string]: TokenValue}} TokensSet
|
|
77
|
+
* @typedef {(AppearanceSet) => TokensSet} TokensGetter
|
|
78
|
+
* @typedef {TokensSet|TokensGetter} TokensProp
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 'tokens' is an optional object prop on all themable components. Its keys must match the
|
|
83
|
+
* token keys in the component's theme schema.
|
|
84
|
+
*
|
|
85
|
+
* This prop is intended to be used as an 'escape hatch' for difficult or exceptional cases
|
|
86
|
+
* where the main theming system doesn't apply. It is intentionally permissive about values.
|
|
87
|
+
*
|
|
88
|
+
* @param {...string} componentsNames - one or more ComponentName, which tokens keys are accepted
|
|
89
|
+
* @return {function} - a custom PropTypes validator
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* Component.propTypes = {
|
|
93
|
+
* // accepts all tokens keys defined in Component schema
|
|
94
|
+
* tokens: getTokensPropType('Component')
|
|
95
|
+
* }
|
|
96
|
+
*
|
|
97
|
+
* Component.propTypes = {
|
|
98
|
+
* // accepts all tokens keys defined in schemas for Component1 and Component2
|
|
99
|
+
* tokens: getTokensPropType('Component1', 'Component2')
|
|
100
|
+
* }
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
exports.selectTokens = selectTokens;
|
|
105
|
+
|
|
106
|
+
const getTokensPropType = (...componentsNames) => (props, propName, componentName) => {
|
|
107
|
+
_propTypes.default.checkPropTypes({
|
|
108
|
+
[propName]: _propTypes.default.oneOfType([_propTypes.default.object, _propTypes.default.func])
|
|
109
|
+
}, props, propName, componentName);
|
|
110
|
+
|
|
111
|
+
if (typeof props[propName] !== 'function') {
|
|
112
|
+
_propTypes.default.checkPropTypes({
|
|
113
|
+
[propName]: _propTypes.default.exact(Object.fromEntries(componentsNames.flatMap(component => getTokenNames(component).map(key => [key, tokenValueType]))))
|
|
114
|
+
}, props, propName, componentName);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Get a proptypes validator for a set of tokens that is not based on a component in the theme schema.
|
|
119
|
+
*
|
|
120
|
+
* For example, for a set of tokens used in a common style, or for a set of tokens required by
|
|
121
|
+
* a themeless component whose tokens are set by a parent but requires tokens of a certain shape.
|
|
122
|
+
*
|
|
123
|
+
* By default, requires an object with a complete set of tokens (allowing `null`, but not `undefined`).
|
|
124
|
+
*
|
|
125
|
+
* @param {string[]} componentTokenKeys - array of strings of token names
|
|
126
|
+
* @param {object} [options]
|
|
127
|
+
* @param {boolean} [options.partial] - if true, allows tokens to be undefined
|
|
128
|
+
* @param {boolean} [options.allowFunction] - if true, allows functions as well as tokens objects
|
|
129
|
+
* @returns
|
|
130
|
+
*/
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
exports.getTokensPropType = getTokensPropType;
|
|
134
|
+
|
|
135
|
+
const getTokensSetPropType = (componentTokenKeys, {
|
|
136
|
+
partial = false,
|
|
137
|
+
allowFunction = false
|
|
138
|
+
} = {}) => {
|
|
139
|
+
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
|
|
140
|
+
(props, propName, ...args) => props[propName] !== null && tokenValueType.isRequired(props, propName, ...args)])));
|
|
141
|
+
|
|
142
|
+
return allowFunction ? _propTypes.default.oneOfType([tokensObjectValidator, _propTypes.default.func]) : tokensObjectValidator;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
exports.getTokensSetPropType = getTokensSetPropType;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
/**
|
|
13
|
+
* @typedef {{[key: string]: string|number|boolean}} AppearanceSet
|
|
14
|
+
* @typedef {AppearanceSet} VariantProp
|
|
15
|
+
*/
|
|
16
|
+
var _default = {
|
|
17
|
+
/**
|
|
18
|
+
* 'variant' is an optional object prop on all themable components.
|
|
19
|
+
*
|
|
20
|
+
* Contains an object with keys that correspond to the current component theme's allowed
|
|
21
|
+
* appearances and values that correspond to the allowed values of that component.
|
|
22
|
+
*
|
|
23
|
+
* Since the particular keys and values depend on which theme is currently active,
|
|
24
|
+
* the exact shape of variant props is not enforced using PropTypes.
|
|
25
|
+
*/
|
|
26
|
+
propType: _propTypes.default.objectOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number, _propTypes.default.bool]))
|
|
27
|
+
};
|
|
28
|
+
exports.default = _default;
|
|
@@ -0,0 +1,34 @@
|
|
|
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 _getPropSelector = _interopRequireDefault(require("./getPropSelector"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
const viewPropTypes = {
|
|
15
|
+
pointerEvents: _propTypes.default.oneOf(['all', 'none', 'box-only', 'box-none']),
|
|
16
|
+
onLayout: _propTypes.default.func,
|
|
17
|
+
nativeID: _propTypes.default.string,
|
|
18
|
+
testID: _propTypes.default.string,
|
|
19
|
+
dataSet: _propTypes.default.object
|
|
20
|
+
};
|
|
21
|
+
var _default = {
|
|
22
|
+
/**
|
|
23
|
+
* Subset of `View` proptypes that could conceivably be needed on any component
|
|
24
|
+
* that renders a single View.
|
|
25
|
+
*/
|
|
26
|
+
types: viewPropTypes,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Filters a props object, returning only cross-platform View props that are potentially
|
|
30
|
+
* relevant to any basic layout component that renders one View.
|
|
31
|
+
*/
|
|
32
|
+
select: (0, _getPropSelector.default)(viewPropTypes)
|
|
33
|
+
};
|
|
34
|
+
exports.default = _default;
|
|
@@ -40,7 +40,7 @@ const resolveResponsiveProp = (prop, viewport, defaultValue) => {
|
|
|
40
40
|
* For example, if passed `{ sm: 4, lg: 8 }`, it will return 8 on `xl` and `lg` viewports,
|
|
41
41
|
* 4 on `md` and `sm` viewports, and `undefined` (or a provided `defaultValue`) on `xs` viewports.
|
|
42
42
|
*
|
|
43
|
-
* To generate propTypes for responsive props, see `responsiveProps` in `./utils/
|
|
43
|
+
* To generate propTypes for responsive props, see `responsiveProps` in `./utils/props/responsiveProps.js`.
|
|
44
44
|
*
|
|
45
45
|
* @param {*} prop - any value which may be an object with viewport keys
|
|
46
46
|
* @param {*} [defaultValue] - default value to provide if no matches found for the current viewport
|
|
@@ -13,10 +13,10 @@ var _useResponsiveProp = require("./useResponsiveProp");
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {import('@telus-uds/system-constants/viewports').Viewport} Viewport
|
|
16
|
-
* @typedef {import('./
|
|
17
|
-
* @typedef {import('./
|
|
18
|
-
* @typedef {import('./
|
|
19
|
-
* @typedef {import('./
|
|
16
|
+
* @typedef {import('./props/spacingProps.js').SpacingValue} SpacingValue
|
|
17
|
+
* @typedef {import('./props/spacingProps.js').SpacingIndex} SpacingIndex
|
|
18
|
+
* @typedef {import('./props/spacingProps.js').SpacingObject} SpacingObject
|
|
19
|
+
* @typedef {import('./props/spacingProps.js').SpacingOptions} SpacingOptions
|
|
20
20
|
*/
|
|
21
21
|
const resolveSpacingOptions = space => {
|
|
22
22
|
if (!(space !== null && space !== void 0 && space.options)) return {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
|
|
18
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
+
|
|
20
|
+
// Prototype-safe alternative to (linter-forbidden) someObject.hasOwnProperty()
|
|
21
|
+
const hasOwnProperty = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
|
|
22
|
+
/**
|
|
23
|
+
* Higher-order component that has no effect unless an additional prop `LinkRouter` is passed.
|
|
24
|
+
* This may be used to provide custom wrappers for integrations with third party libraries.
|
|
25
|
+
*
|
|
26
|
+
* If LinkRouter is passed, LinkRouter is rendered in place of the main component and is passed:
|
|
27
|
+
*
|
|
28
|
+
* - `linkRouterProps`: an optional object passed alongside LinkRouter, for props needed by the wrapper
|
|
29
|
+
* that are not valid props for the wrapped component.
|
|
30
|
+
* - `Component`: automatically provided, the original component to render inside the wrapper.
|
|
31
|
+
* - `ref`: forwarded `ref` passed down to `Component`
|
|
32
|
+
* - All other props passed to the outer component
|
|
33
|
+
*
|
|
34
|
+
* @example A LinkRouter component to be used with link-like components might look like:
|
|
35
|
+
*
|
|
36
|
+
* ```jsx
|
|
37
|
+
* const LinkLinkRouter = forwardRef(({ Component, linkRouterProps: { to, options }, href, ...rest }, ref) => {
|
|
38
|
+
* const { href: resolvedHref, onClick } = useSomeRouterHook({ to, href, options })
|
|
39
|
+
* return <Component href={resolvedHref} onPress={onClick} {...rest} />
|
|
40
|
+
* })
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* Any component that takes href and onPress props may then use this wrapper:
|
|
44
|
+
*
|
|
45
|
+
* ```jsx
|
|
46
|
+
* <Link href={href} LinkRouter={LinkLinkRouter} linkRouterProps={{ to, options }}>Some link</Link>
|
|
47
|
+
* <IconButton icon={SomeIcon} LinkRouter={LinkLinkRouter} linkRouterProps={{ to, options }} ref={iconRef} />
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const withLinkRouter = Component => {
|
|
53
|
+
const wrappedComponent = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
54
|
+
LinkRouter,
|
|
55
|
+
linkRouterProps,
|
|
56
|
+
...props
|
|
57
|
+
}, ref) => {
|
|
58
|
+
if (!LinkRouter) return /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, { ...props,
|
|
59
|
+
ref: ref
|
|
60
|
+
});
|
|
61
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(LinkRouter, {
|
|
62
|
+
linkRouterProps: linkRouterProps,
|
|
63
|
+
Component: Component,
|
|
64
|
+
ref: ref,
|
|
65
|
+
...props
|
|
66
|
+
});
|
|
67
|
+
}); // Ensure the returned component has appropriate outer properties set:
|
|
68
|
+
|
|
69
|
+
/* eslint-disable-next-line react/forbid-foreign-prop-types */
|
|
70
|
+
|
|
71
|
+
const {
|
|
72
|
+
displayName,
|
|
73
|
+
name,
|
|
74
|
+
propTypes,
|
|
75
|
+
...otherProperties
|
|
76
|
+
} = Component; // Apply unique component name as a displayName
|
|
77
|
+
|
|
78
|
+
wrappedComponent.displayName = Component.displayName || Component.name; // Apply proptypes including wrapper props - is safely { ...undefined, ...undefined } in prod
|
|
79
|
+
|
|
80
|
+
wrappedComponent.propTypes = { ...Component.propTypes,
|
|
81
|
+
...withLinkRouter.propTypes
|
|
82
|
+
}; // Forward any other properties explicitly set e.g. Component.SubComponent
|
|
83
|
+
|
|
84
|
+
Object.keys(otherProperties).forEach(key => {
|
|
85
|
+
// Skip internal React properties from wrappedComponent's forwardRef (render, $$typeof, etc)
|
|
86
|
+
if (hasOwnProperty(Component, key) && !hasOwnProperty(wrappedComponent, key)) {
|
|
87
|
+
wrappedComponent[key] = Component[key];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
return wrappedComponent;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
withLinkRouter.propTypes = {
|
|
94
|
+
LinkRouter: _propTypes.default.elementType,
|
|
95
|
+
linkRouterProps: _propTypes.default.object
|
|
96
|
+
};
|
|
97
|
+
var _default = withLinkRouter;
|
|
98
|
+
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telus-uds/components-base",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Base components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"base"
|
|
@@ -23,8 +23,11 @@
|
|
|
23
23
|
"lint": "telus-standard",
|
|
24
24
|
"lint:fix": "telus-standard --fix",
|
|
25
25
|
"format": "prettier --write .",
|
|
26
|
-
"build": "
|
|
27
|
-
"
|
|
26
|
+
"build": "yarn build:code && yarn build:docs",
|
|
27
|
+
"build:code": "babel src -d lib",
|
|
28
|
+
"build:docs": "babel-node --plugins=react-docgen-alpha generate-component-docs.js",
|
|
29
|
+
"storybook": "start-storybook",
|
|
30
|
+
"dev": "yarn build:code --watch",
|
|
28
31
|
"release": "standard-version"
|
|
29
32
|
},
|
|
30
33
|
"bugs": {
|
|
@@ -43,6 +46,7 @@
|
|
|
43
46
|
"react-native-web": "^0.17.0"
|
|
44
47
|
},
|
|
45
48
|
"devDependencies": {
|
|
49
|
+
"@telus-uds/browserslist-config": "^1.0.0",
|
|
46
50
|
"@testing-library/jest-native": "^4.0.1",
|
|
47
51
|
"@testing-library/react-hooks": "^7.0.1",
|
|
48
52
|
"@testing-library/react-native": "^7.2.0",
|
|
@@ -50,8 +54,8 @@
|
|
|
50
54
|
},
|
|
51
55
|
"dependencies": {
|
|
52
56
|
"airbnb-prop-types": "^2.16.0",
|
|
53
|
-
"@telus-uds/system-constants": "^1.0.
|
|
54
|
-
"@telus-uds/system-theme-tokens": "^1.
|
|
57
|
+
"@telus-uds/system-constants": "^1.0.1",
|
|
58
|
+
"@telus-uds/system-theme-tokens": "^1.2.1",
|
|
55
59
|
"lodash.debounce": "^4.0.8",
|
|
56
60
|
"lodash.merge": "^4.6.2",
|
|
57
61
|
"prop-types": "^15.7.2",
|
package/release-context.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"previousReleaseTag": "@telus-uds/components-base/v1.
|
|
3
|
-
"changelog": "
|
|
4
|
-
"releaseTag": "@telus-uds/components-base/v1.0
|
|
5
|
-
"newVersion": "1.0
|
|
2
|
+
"previousReleaseTag": "@telus-uds/components-base/v1.2.0",
|
|
3
|
+
"changelog": "## [1.3.0](https://github.com/telus/universal-design-system/compare/@telus-uds/components-base/v1.2.0...@telus-uds/components-base/v1.3.0) (2022-03-21)\n\n\n### Features\n\n* **components-base:** add common system props handler and restructure props-related utils ([#1444](https://github.com/telus/universal-design-system/issues/1444)) ([ab655ec](https://github.com/telus/universal-design-system/commit/ab655ec61796b6a6d7094c2c42ceef8b5197c634))\n* **docs:** add tokens override documentation ([#1330](https://github.com/telus/universal-design-system/issues/1330)) ([49092e5](https://github.com/telus/universal-design-system/commit/49092e5d5f6c2d3a85de930a74a03afff8a60062))\n\n\n### Bug Fixes\n\n* **base:** inherit FlexGrid.Col responsive size if 0 ([#1419](https://github.com/telus/universal-design-system/issues/1419)) ([9defeb0](https://github.com/telus/universal-design-system/commit/9defeb0da08099afb83df9e7ee902f037cb4de02))\n* **ds-allium:** fix some errors in RN builds ([#1448](https://github.com/telus/universal-design-system/issues/1448)) ([8bc4778](https://github.com/telus/universal-design-system/commit/8bc477890f0183584fdc1009d7929b71d23820a3))\n",
|
|
4
|
+
"releaseTag": "@telus-uds/components-base/v1.3.0",
|
|
5
|
+
"newVersion": "1.3.0",
|
|
6
6
|
"packageName": "@telus-uds/components-base"
|
|
7
7
|
}
|
package/src/A11yText/index.jsx
CHANGED
|
@@ -2,7 +2,7 @@ import React, { forwardRef } from 'react'
|
|
|
2
2
|
import { Platform, StyleSheet, View } from 'react-native'
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
4
|
|
|
5
|
-
import { a11yProps } from '../utils/
|
|
5
|
+
import { a11yProps } from '../utils/props'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* A11yText is a zero-size invisible element that adds text to be read by screen readers.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import { useThemeTokens } from '../ThemeProvider'
|
|
4
|
-
import { getTokensPropType, variantProp } from '../utils/
|
|
4
|
+
import { getTokensPropType, variantProp } from '../utils/props'
|
|
5
5
|
|
|
6
6
|
import Spinner from './Spinner'
|
|
7
7
|
|
package/src/Box/Box.jsx
CHANGED
|
@@ -12,11 +12,12 @@ import {
|
|
|
12
12
|
getA11yPropsFromHtmlTag,
|
|
13
13
|
layoutTags
|
|
14
14
|
} from '../utils'
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
|
-
* @typedef {import('../utils/
|
|
17
|
-
* @typedef {import('../utils/
|
|
18
|
-
* @typedef {import('../utils/
|
|
19
|
-
* @typedef {import('../utils/
|
|
17
|
+
* @typedef {import('../utils/props/spacingProps.js').SpacingValue} SpacingValue
|
|
18
|
+
* @typedef {import('../utils/props/spacingProps.js').SpacingIndex} SpacingIndex
|
|
19
|
+
* @typedef {import('../utils/props/spacingProps.js').SpacingObject} SpacingObject
|
|
20
|
+
* @typedef {import('../utils/props/spacingProps.js').SpacingOptions} SpacingOptions
|
|
20
21
|
*/
|
|
21
22
|
|
|
22
23
|
const selectBoxStyles = (tokens) => {
|
package/src/Button/Button.jsx
CHANGED
|
@@ -3,7 +3,7 @@ import React, { forwardRef } from 'react'
|
|
|
3
3
|
import ButtonBase from './ButtonBase'
|
|
4
4
|
import buttonPropTypes, { textAndA11yText } from './propTypes'
|
|
5
5
|
import { useThemeTokensCallback } from '../ThemeProvider'
|
|
6
|
-
import { a11yProps } from '../utils/
|
|
6
|
+
import { a11yProps } from '../utils/props'
|
|
7
7
|
|
|
8
8
|
const Button = forwardRef(({ accessibilityRole = 'button', tokens, variant, ...props }, ref) => {
|
|
9
9
|
const getTokens = useThemeTokensCallback('Button', tokens, variant)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
2
3
|
import { Pressable, View, StyleSheet, Platform } from 'react-native'
|
|
3
4
|
|
|
4
5
|
import { applyTextStyles, applyShadowToken, applyOuterBorder } from '../ThemeProvider/utils'
|
|
@@ -6,10 +7,12 @@ import buttonPropTypes from './propTypes'
|
|
|
6
7
|
import {
|
|
7
8
|
a11yProps,
|
|
8
9
|
getCursorStyle,
|
|
10
|
+
clickProps,
|
|
9
11
|
linkProps,
|
|
10
12
|
resolvePressableState,
|
|
11
13
|
resolvePressableTokens,
|
|
12
|
-
wrapStringsInText
|
|
14
|
+
wrapStringsInText,
|
|
15
|
+
withLinkRouter
|
|
13
16
|
} from '../utils'
|
|
14
17
|
|
|
15
18
|
const getOuterBorderOffset = ({ outerBorderGap = 0, outerBorderWidth = 0 }) =>
|
|
@@ -133,19 +136,20 @@ const selectWebOnlyStyles = (inactive, themeTokens, { accessibilityRole }) => {
|
|
|
133
136
|
const ButtonBase = forwardRef(
|
|
134
137
|
(
|
|
135
138
|
{
|
|
139
|
+
id,
|
|
136
140
|
href,
|
|
137
141
|
hrefAttrs,
|
|
138
142
|
children,
|
|
139
|
-
onPress,
|
|
140
143
|
tokens = {},
|
|
141
144
|
disabled = false, // alias for inactive
|
|
142
145
|
inactive = disabled,
|
|
143
146
|
selected = false,
|
|
144
147
|
dataSet,
|
|
145
|
-
...
|
|
148
|
+
...rawRest
|
|
146
149
|
},
|
|
147
150
|
ref
|
|
148
151
|
) => {
|
|
152
|
+
const { onPress, ...rest } = clickProps.toPressProps(rawRest)
|
|
149
153
|
const extraButtonState = { inactive, selected }
|
|
150
154
|
const resolveButtonTokens = (pressableState) =>
|
|
151
155
|
resolvePressableTokens(tokens, pressableState, extraButtonState)
|
|
@@ -185,6 +189,7 @@ const ButtonBase = forwardRef(
|
|
|
185
189
|
|
|
186
190
|
return (
|
|
187
191
|
<View
|
|
192
|
+
id={id}
|
|
188
193
|
style={[
|
|
189
194
|
containerStyles,
|
|
190
195
|
borderStyles,
|
|
@@ -218,10 +223,12 @@ const ButtonBase = forwardRef(
|
|
|
218
223
|
ButtonBase.displayName = 'ButtonBase'
|
|
219
224
|
|
|
220
225
|
ButtonBase.propTypes = {
|
|
226
|
+
id: PropTypes.string,
|
|
221
227
|
...a11yProps.types,
|
|
222
228
|
...buttonPropTypes,
|
|
223
229
|
...linkProps.types
|
|
224
230
|
}
|
|
231
|
+
ButtonBase.defaultProps = { id: undefined }
|
|
225
232
|
|
|
226
233
|
const staticStyles = StyleSheet.create({
|
|
227
234
|
row: {
|
|
@@ -245,4 +252,4 @@ const staticStyles = StyleSheet.create({
|
|
|
245
252
|
}
|
|
246
253
|
})
|
|
247
254
|
|
|
248
|
-
export default ButtonBase
|
|
255
|
+
export default withLinkRouter(ButtonBase)
|
|
@@ -10,13 +10,17 @@ import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider'
|
|
|
10
10
|
import {
|
|
11
11
|
a11yProps,
|
|
12
12
|
pressProps,
|
|
13
|
-
variantProp,
|
|
14
13
|
getTokensPropType,
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
selectSystemProps,
|
|
15
|
+
selectTokens,
|
|
16
|
+
variantProp,
|
|
17
|
+
viewProps
|
|
18
|
+
} from '../utils/props'
|
|
17
19
|
import { useMultipleInputValues } from '../utils/input'
|
|
18
20
|
import { getPressHandlersWithArgs } from '../utils/pressability'
|
|
19
21
|
|
|
22
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, pressProps, viewProps])
|
|
23
|
+
|
|
20
24
|
const ButtonGroup = forwardRef(
|
|
21
25
|
(
|
|
22
26
|
{
|
|
@@ -51,14 +55,20 @@ const ButtonGroup = forwardRef(
|
|
|
51
55
|
readOnly
|
|
52
56
|
})
|
|
53
57
|
|
|
54
|
-
const
|
|
58
|
+
const systemProps = selectProps({
|
|
55
59
|
accessibilityRole,
|
|
56
60
|
...rest
|
|
57
61
|
})
|
|
58
|
-
const itemA11yRole =
|
|
62
|
+
const itemA11yRole = systemProps.accessibilityRole === 'radiogroup' ? 'radio' : 'checkbox'
|
|
59
63
|
|
|
60
64
|
return (
|
|
61
|
-
<StackWrap
|
|
65
|
+
<StackWrap
|
|
66
|
+
{...systemProps}
|
|
67
|
+
space={space}
|
|
68
|
+
direction={direction}
|
|
69
|
+
tokens={stackTokens}
|
|
70
|
+
ref={ref}
|
|
71
|
+
>
|
|
62
72
|
{items.map(({ label, id = label, accessibilityLabel, ref: itemRef }, index) => {
|
|
63
73
|
const isSelected = currentValues.includes(id)
|
|
64
74
|
|
|
@@ -101,8 +111,7 @@ const ButtonGroup = forwardRef(
|
|
|
101
111
|
ButtonGroup.displayName = 'ButtonGroup'
|
|
102
112
|
|
|
103
113
|
ButtonGroup.propTypes = {
|
|
104
|
-
...
|
|
105
|
-
...pressProps.propTypes,
|
|
114
|
+
...selectedSystemPropTypes,
|
|
106
115
|
tokens: getTokensPropType('ButtonGroup'),
|
|
107
116
|
variant: variantProp.propType,
|
|
108
117
|
/**
|