@telus-uds/components-base 0.0.2-prerelease.9 → 1.1.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/.eslintrc.js +9 -0
- package/.storybook/main.js +4 -0
- package/.storybook/preview.js +37 -0
- package/.ultra.cache.json +1 -1
- package/CHANGELOG.md +50 -0
- package/README.md +4 -2
- package/__fixtures__/test-utils.js +25 -0
- package/__fixtures__/testTheme.js +4 -2
- package/__tests__/Button/ButtonGroup.test.jsx +4 -5
- package/__tests__/Checkbox/Checkbox.test.jsx +2 -2
- package/__tests__/Checkbox/CheckboxGroup.test.jsx +4 -5
- package/__tests__/ExpandCollapse/ExpandCollapse.test.jsx +2 -2
- package/__tests__/HorizontalScroll/HorizontalScroll.test.jsx +164 -0
- package/__tests__/Link/LinkBase.test.jsx +0 -14
- package/__tests__/Radio/Radio.test.jsx +2 -2
- package/__tests__/Radio/RadioGroup.test.jsx +4 -5
- package/__tests__/RadioCard/RadioCard.test.jsx +2 -2
- package/__tests__/RadioCard/RadioCardGroup.test.jsx +4 -5
- package/__tests__/Search/Search.test.jsx +9 -8
- package/__tests__/Select/Select.test.jsx +3 -2
- package/__tests__/Tabs/Tabs.test.jsx +1 -161
- package/__tests__/Tags/Tags.test.jsx +4 -5
- package/__tests__/TextInput/TextArea.test.jsx +3 -2
- package/__tests__/TextInput/TextInputBase.test.jsx +10 -5
- package/__tests__/ThemeProvider/ThemeProvider.test.jsx +77 -0
- package/__tests__/ThemeProvider/useThemeTokens.test.jsx +9 -5
- package/__tests__/ThemeProvider/utils/theme-tokens.test.js +41 -0
- package/__tests__/ToggleSwitch/ToggleSwitch.test.jsx +3 -2
- package/__tests__/utils/children.test.jsx +128 -0
- package/__tests__/utils/input.test.js +1 -1
- package/__tests__/utils/semantics.test.jsx +43 -0
- package/babel.config.js +9 -16
- package/component-docs.json +10313 -0
- package/generate-component-docs.js +56 -0
- package/lib/A11yText/index.js +10 -5
- package/lib/ActivityIndicator/Spinner.js +16 -13
- package/lib/ActivityIndicator/Spinner.native.js +12 -8
- package/lib/Box/Box.js +103 -8
- package/lib/Button/Button.js +9 -8
- package/lib/Button/ButtonBase.js +14 -7
- package/lib/Button/ButtonGroup.js +25 -10
- package/lib/Button/ButtonLink.js +10 -7
- package/lib/Card/Card.js +2 -0
- package/lib/Card/CardBase.js +13 -5
- package/lib/Card/PressableCardBase.js +12 -8
- package/lib/Checkbox/Checkbox.js +25 -14
- package/lib/Checkbox/CheckboxGroup.js +22 -12
- package/lib/Divider/Divider.js +12 -7
- package/lib/ExpandCollapse/Accordion.js +10 -4
- package/lib/ExpandCollapse/Control.js +12 -6
- package/lib/ExpandCollapse/ExpandCollapse.js +10 -5
- package/lib/ExpandCollapse/Panel.js +8 -7
- package/lib/Feedback/Feedback.js +10 -5
- package/lib/Fieldset/Fieldset.js +10 -5
- package/lib/Fieldset/FieldsetContainer.js +10 -5
- package/lib/Fieldset/FieldsetContainer.native.js +10 -5
- package/lib/Fieldset/Legend.js +10 -5
- package/lib/Fieldset/Legend.native.js +10 -5
- package/lib/FlexGrid/Col/Col.js +8 -5
- package/lib/FlexGrid/FlexGrid.js +31 -6
- package/lib/FlexGrid/Row/Row.js +12 -5
- package/lib/{Tabs → HorizontalScroll}/HorizontalScroll.js +5 -4
- package/lib/{Tabs/TabsScrollButton.js → HorizontalScroll/HorizontalScrollButton.js} +14 -8
- package/lib/{Tabs → HorizontalScroll}/ScrollViewEnd.js +0 -0
- package/lib/{Tabs → HorizontalScroll}/ScrollViewEnd.native.js +0 -0
- package/lib/{Tabs → HorizontalScroll}/dictionary.js +0 -0
- package/lib/HorizontalScroll/index.js +35 -0
- package/lib/{Tabs → HorizontalScroll}/itemPositions.js +0 -0
- package/lib/Icon/Icon.js +16 -9
- package/lib/Icon/IconText.js +8 -7
- package/lib/IconButton/IconButton.js +10 -5
- package/lib/InputLabel/InputLabel.js +33 -5
- package/lib/InputLabel/LabelContent.js +22 -12
- package/lib/InputLabel/LabelContent.native.js +23 -5
- package/lib/InputSupports/InputSupports.js +10 -5
- package/lib/Link/ChevronLink.js +12 -5
- package/lib/Link/InlinePressable.js +10 -4
- package/lib/Link/InlinePressable.native.js +5 -4
- package/lib/Link/Link.js +12 -5
- package/lib/Link/LinkBase.js +12 -5
- package/lib/Link/TextButton.js +10 -5
- package/lib/List/List.js +6 -6
- package/lib/List/ListItem.js +28 -33
- package/lib/List/index.js +15 -0
- package/lib/Modal/Modal.js +10 -5
- package/lib/Notification/Notification.js +21 -5
- package/lib/Pagination/PageButton.js +16 -11
- package/lib/Pagination/Pagination.js +12 -7
- package/lib/Pagination/SideButton.js +12 -7
- package/lib/Pagination/usePagination.js +2 -2
- package/lib/Progress/Progress.js +10 -5
- package/lib/Progress/ProgressBar.js +21 -10
- package/lib/Progress/ProgressBarBackground.js +12 -8
- package/lib/Radio/Radio.js +14 -13
- package/lib/Radio/RadioButton.js +20 -9
- package/lib/Radio/RadioGroup.js +24 -13
- package/lib/RadioCard/RadioCard.js +14 -10
- package/lib/RadioCard/RadioCardGroup.js +13 -12
- package/lib/Search/Search.js +29 -18
- package/lib/Select/Picker.js +11 -6
- package/lib/Select/Picker.native.js +21 -6
- package/lib/Select/Select.js +46 -4
- package/lib/SideNav/Item.js +10 -5
- package/lib/SideNav/ItemsGroup.js +10 -5
- package/lib/SideNav/SideNav.js +11 -7
- package/lib/Skeleton/Skeleton.js +15 -15
- package/lib/Skeleton/skeletonWebAnimation.js +1 -1
- package/lib/Spacer/Spacer.js +19 -7
- package/lib/StackView/StackView.js +26 -7
- package/lib/StackView/StackWrap.js +24 -13
- package/lib/StackView/StackWrapBox.js +34 -8
- package/lib/StackView/StackWrapGap.js +16 -7
- package/lib/StackView/common.js +4 -2
- package/lib/StackView/getStackedContent.js +2 -2
- package/lib/StepTracker/StepTracker.js +10 -5
- package/lib/Tabs/Tabs.js +26 -19
- package/lib/Tabs/TabsItem.js +16 -12
- package/lib/Tags/Tags.js +27 -11
- package/lib/TextInput/TextArea.js +7 -5
- package/lib/TextInput/TextInput.js +12 -6
- package/lib/TextInput/TextInputBase.js +12 -8
- package/lib/ThemeProvider/ThemeProvider.js +14 -10
- package/lib/ThemeProvider/useSetTheme.js +6 -1
- package/lib/ThemeProvider/utils/styles.js +2 -2
- package/lib/ThemeProvider/utils/theme-tokens.js +39 -8
- package/lib/ToggleSwitch/ToggleSwitch.js +11 -6
- package/lib/Tooltip/Backdrop.js +10 -2
- package/lib/Tooltip/Tooltip.js +5 -4
- package/lib/Typography/Typography.js +40 -24
- package/lib/index.js +36 -1
- package/lib/utils/a11y/index.js +13 -0
- package/lib/utils/a11y/propTypes.js +61 -0
- package/lib/utils/a11y/propTypes.native.js +47 -0
- package/lib/utils/a11y/semantics.js +173 -0
- package/lib/utils/animation/useVerticalExpandAnimation.js +1 -1
- package/lib/utils/children.js +55 -8
- package/lib/utils/input.js +27 -17
- package/lib/utils/propTypes.js +40 -68
- package/lib/utils/useCopy.js +1 -1
- package/lib/utils/useHash.js +8 -4
- package/lib/utils/useSpacingScale.js +1 -3
- package/lib/utils/useUniqueId.js +1 -1
- package/package.json +14 -6
- package/release-context.json +4 -4
- package/src/A11yText/index.jsx +6 -4
- package/src/ActivityIndicator/Spinner.jsx +5 -3
- package/src/ActivityIndicator/Spinner.native.jsx +5 -3
- package/src/Box/Box.jsx +125 -39
- package/src/Button/Button.jsx +7 -4
- package/src/Button/ButtonBase.jsx +86 -77
- package/src/Button/ButtonGroup.jsx +81 -69
- package/src/Button/ButtonLink.jsx +18 -13
- package/src/Card/Card.jsx +2 -2
- package/src/Card/CardBase.jsx +6 -4
- package/src/Card/PressableCardBase.jsx +71 -64
- package/src/Checkbox/Checkbox.jsx +118 -108
- package/src/Checkbox/CheckboxGroup.jsx +72 -62
- package/src/Divider/Divider.jsx +7 -4
- package/src/ExpandCollapse/Accordion.jsx +3 -2
- package/src/ExpandCollapse/Control.jsx +40 -43
- package/src/ExpandCollapse/ExpandCollapse.jsx +26 -23
- package/src/ExpandCollapse/Panel.jsx +69 -63
- package/src/Feedback/Feedback.jsx +36 -33
- package/src/Fieldset/Fieldset.jsx +63 -56
- package/src/Fieldset/FieldsetContainer.jsx +14 -5
- package/src/Fieldset/FieldsetContainer.native.jsx +7 -4
- package/src/Fieldset/Legend.jsx +7 -2
- package/src/Fieldset/Legend.native.jsx +7 -2
- package/src/FlexGrid/Col/Col.jsx +139 -132
- package/src/FlexGrid/FlexGrid.jsx +79 -51
- package/src/FlexGrid/Row/Row.jsx +55 -48
- package/src/HorizontalScroll/HorizontalScroll.jsx +168 -0
- package/src/HorizontalScroll/HorizontalScrollButton.jsx +105 -0
- package/src/{Tabs → HorizontalScroll}/ScrollViewEnd.jsx +0 -0
- package/src/{Tabs → HorizontalScroll}/ScrollViewEnd.native.jsx +0 -0
- package/src/{Tabs → HorizontalScroll}/dictionary.js +0 -0
- package/src/HorizontalScroll/index.js +17 -0
- package/src/{Tabs → HorizontalScroll}/itemPositions.js +0 -0
- package/src/Icon/Icon.jsx +37 -35
- package/src/Icon/IconText.jsx +22 -17
- package/src/IconButton/IconButton.jsx +49 -42
- package/src/InputLabel/InputLabel.jsx +53 -38
- package/src/InputLabel/LabelContent.jsx +14 -6
- package/src/InputLabel/LabelContent.native.jsx +11 -2
- package/src/InputSupports/InputSupports.jsx +29 -34
- package/src/Link/ChevronLink.jsx +26 -16
- package/src/Link/InlinePressable.jsx +5 -3
- package/src/Link/InlinePressable.native.jsx +5 -3
- package/src/Link/Link.jsx +22 -16
- package/src/Link/LinkBase.jsx +67 -58
- package/src/Link/TextButton.jsx +30 -23
- package/src/List/List.jsx +6 -7
- package/src/List/ListItem.jsx +70 -90
- package/src/List/index.js +5 -0
- package/src/Modal/Modal.jsx +9 -4
- package/src/Notification/Notification.jsx +58 -43
- package/src/Pagination/PageButton.jsx +37 -34
- package/src/Pagination/Pagination.jsx +88 -92
- package/src/Pagination/SideButton.jsx +44 -41
- package/src/Progress/Progress.jsx +5 -4
- package/src/Progress/ProgressBar.jsx +42 -29
- package/src/Progress/ProgressBarBackground.jsx +5 -3
- package/src/Radio/Radio.jsx +85 -78
- package/src/Radio/RadioButton.jsx +54 -43
- package/src/Radio/RadioGroup.jsx +74 -63
- package/src/RadioCard/RadioCard.jsx +75 -68
- package/src/RadioCard/RadioCardGroup.jsx +82 -75
- package/src/Search/Search.jsx +127 -106
- package/src/Select/Picker.jsx +49 -42
- package/src/Select/Picker.native.jsx +56 -49
- package/src/Select/Select.jsx +115 -72
- package/src/SideNav/Item.jsx +53 -46
- package/src/SideNav/ItemsGroup.jsx +50 -43
- package/src/SideNav/SideNav.jsx +68 -60
- package/src/Skeleton/Skeleton.jsx +9 -13
- package/src/Spacer/Spacer.jsx +11 -4
- package/src/StackView/StackView.jsx +47 -23
- package/src/StackView/StackWrap.jsx +14 -12
- package/src/StackView/StackWrapBox.jsx +62 -28
- package/src/StackView/StackWrapGap.jsx +46 -24
- package/src/StackView/common.jsx +3 -2
- package/src/StepTracker/StepTracker.jsx +73 -62
- package/src/Tabs/Tabs.jsx +70 -62
- package/src/Tabs/TabsItem.jsx +111 -103
- package/src/Tags/Tags.jsx +114 -102
- package/src/TextInput/TextArea.jsx +5 -4
- package/src/TextInput/TextInput.jsx +5 -4
- package/src/TextInput/TextInputBase.jsx +84 -77
- package/src/ThemeProvider/ThemeProvider.jsx +11 -7
- package/src/ThemeProvider/useSetTheme.js +4 -0
- package/src/ThemeProvider/utils/theme-tokens.js +28 -0
- package/src/ToggleSwitch/ToggleSwitch.jsx +49 -50
- package/src/Tooltip/Tooltip.jsx +134 -130
- package/src/Typography/Typography.jsx +67 -44
- package/src/index.js +3 -1
- package/src/utils/a11y/index.js +1 -0
- package/src/utils/a11y/propTypes.js +61 -0
- package/src/utils/a11y/propTypes.native.js +39 -0
- package/src/utils/a11y/semantics.js +162 -0
- package/src/utils/children.jsx +60 -7
- package/src/utils/input.js +20 -17
- package/src/utils/propTypes.js +30 -76
- package/src/utils/useCopy.js +1 -1
- package/src/utils/useHash.js +8 -3
- package/stories/A11yText/A11yText.stories.jsx +3 -3
- package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +2 -2
- package/stories/Box/Box.stories.jsx +2 -2
- package/stories/Button/Button.stories.jsx +3 -3
- package/stories/Button/ButtonGroup.stories.jsx +2 -2
- package/stories/Button/ButtonLink.stories.jsx +2 -2
- package/stories/Card/Card.stories.jsx +2 -2
- package/stories/Checkbox/Checkbox.stories.jsx +2 -2
- package/stories/Divider/Divider.stories.jsx +2 -2
- package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +3 -3
- package/stories/Feedback/Feedback.stories.jsx +2 -2
- package/stories/FlexGrid/01 FlexGrid.stories.jsx +2 -2
- package/stories/FlexGrid/02 Row.stories.jsx +2 -2
- package/stories/FlexGrid/03 Col.stories.jsx +2 -2
- package/stories/Icon/Icon.stories.jsx +2 -2
- package/stories/IconButton/IconButton.stories.jsx +2 -2
- package/stories/InputLabel/InputLabel.stories.jsx +2 -2
- package/stories/Link/ChevronLink.stories.jsx +2 -2
- package/stories/Link/Link.stories.jsx +2 -2
- package/stories/Link/TextButton.stories.jsx +2 -2
- package/stories/List/List.stories.jsx +2 -2
- package/stories/Modal/Modal.stories.jsx +2 -2
- package/stories/Notification/Notification.stories.jsx +2 -2
- package/stories/Pagination/Pagination.stories.jsx +2 -2
- package/stories/Progress/Progress.stories.jsx +2 -2
- package/stories/Radio/Radio.stories.jsx +2 -2
- package/stories/RadioCard/RadioCard.stories.jsx +2 -2
- package/stories/Search/Search.stories.jsx +2 -2
- package/stories/Select/Select.stories.jsx +2 -2
- package/stories/SideNav/SideNav.stories.jsx +2 -2
- package/stories/SideNav/SideNavItem.stories.jsx +2 -2
- package/stories/SideNav/SideNavItemsGroup.stories.jsx +2 -2
- package/stories/Skeleton/Skeleton.stories.jsx +3 -3
- package/stories/Spacer/Spacer.stories.jsx +2 -2
- package/stories/StackView/StackView.stories.jsx +2 -2
- package/stories/StackView/StackWrap.stories.jsx +2 -2
- package/stories/StepTracker/StepTracker.stories.jsx +2 -2
- package/stories/Tabs/Tabs.stories.jsx +2 -2
- package/stories/Tags/Tags.stories.jsx +2 -2
- package/stories/TextInput/TextArea.stories.jsx +2 -2
- package/stories/TextInput/TextInput.stories.jsx +2 -2
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +2 -2
- package/stories/Tooltip/Tooltip.stories.jsx +2 -2
- package/stories/TooltipButton/TooltipButton.stories.jsx +2 -2
- package/stories/Typography/Typography.stories.jsx +2 -2
- package/stories/platform-supports.jsx +1 -1
- package/stories/supports.jsx +4 -5
- package/src/Tabs/HorizontalScroll.jsx +0 -165
- package/src/Tabs/TabsScrollButton.jsx +0 -100
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -25,15 +25,13 @@ var _jsxRuntime = require("react/jsx-runtime");
|
|
|
25
25
|
|
|
26
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
27
|
|
|
28
|
+
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); }
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
|
-
*
|
|
30
|
-
* else returns false
|
|
33
|
+
* @typedef {import('../utils/a11y/semantics').TextTag} TextTag
|
|
31
34
|
*/
|
|
32
|
-
function getHeadingLevel(heading) {
|
|
33
|
-
const match = typeof heading === 'string' && heading.match(/^h(\d)$/);
|
|
34
|
-
return match && match[1];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
35
|
const selectTextStyles = ({
|
|
38
36
|
fontWeight,
|
|
39
37
|
fontSize,
|
|
@@ -55,16 +53,18 @@ const selectTextStyles = ({
|
|
|
55
53
|
}); // General-purpose flexible theme-neutral base component for text
|
|
56
54
|
|
|
57
55
|
|
|
58
|
-
const Typography = ({
|
|
56
|
+
const Typography = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
59
57
|
children,
|
|
60
58
|
variant,
|
|
61
59
|
heading,
|
|
60
|
+
tag = typeof heading === 'string' ? heading : undefined,
|
|
61
|
+
accessibilityRole = heading === true ? 'header' : undefined,
|
|
62
62
|
block = false,
|
|
63
63
|
align = undefined,
|
|
64
|
-
accessibilityRole = heading ? 'header' : 'text',
|
|
65
64
|
tokens,
|
|
65
|
+
dataSet,
|
|
66
66
|
...rest
|
|
67
|
-
}) => {
|
|
67
|
+
}, ref) => {
|
|
68
68
|
const viewport = (0, _ViewportProvider.useViewport)();
|
|
69
69
|
const themeTokens = (0, _ThemeProvider.useThemeTokens)('Typography', tokens, variant, {
|
|
70
70
|
viewport
|
|
@@ -73,34 +73,50 @@ const Typography = ({
|
|
|
73
73
|
style: selectTextStyles(align ? { ...themeTokens,
|
|
74
74
|
textAlign: align
|
|
75
75
|
} : themeTokens),
|
|
76
|
+
dataSet,
|
|
76
77
|
maxFontSizeMultiplier: (0, _utils2.getMaxFontMultiplier)(themeTokens)
|
|
77
78
|
};
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
accessibilityRole,
|
|
81
|
-
// On React Native Web, `accessibilityLevel` controls which heading tag (h1, h2 etc) is used.
|
|
82
|
-
...(headingLevel && {
|
|
83
|
-
accessibilityLevel: headingLevel
|
|
84
|
-
})
|
|
79
|
+
const a11y = { ...(0, _utils2.getA11yPropsFromHtmlTag)(tag, accessibilityRole),
|
|
80
|
+
..._utils2.a11yProps.select(rest)
|
|
85
81
|
};
|
|
86
|
-
return block ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
82
|
+
return block ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_View.default, {
|
|
83
|
+
ref: ref,
|
|
84
|
+
...a11y,
|
|
87
85
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, { ...textProps,
|
|
88
86
|
children: children
|
|
89
87
|
})
|
|
90
|
-
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, {
|
|
88
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.default, {
|
|
89
|
+
ref: ref,
|
|
90
|
+
...textProps,
|
|
91
91
|
...a11y,
|
|
92
92
|
children: children
|
|
93
93
|
});
|
|
94
|
-
};
|
|
95
|
-
|
|
94
|
+
});
|
|
95
|
+
Typography.displayName = 'Typography';
|
|
96
96
|
Typography.propTypes = { ..._utils2.a11yProps.types,
|
|
97
97
|
tokens: (0, _utils2.getTokensPropType)('Typography'),
|
|
98
98
|
variant: _utils2.variantProp.propType,
|
|
99
99
|
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* Renders the text as a semantic heading. If a html heading tag is provided, uses that tag on Web.
|
|
102
|
+
*
|
|
103
|
+
* Does not affect styling: <Typography heading="h2"> will render a <h2> that looks like plain text.
|
|
104
|
+
* Use both `heading` and `variant` props to render semantic headings that look like headings.
|
|
105
|
+
*
|
|
106
|
+
* In native apps, if this is `true` or any html heading tag string and accessibilityRole prop
|
|
107
|
+
* is not defined, the accessibilityRole will default to "heading".
|
|
108
|
+
*/
|
|
109
|
+
heading: _propTypes.default.oneOf([..._utils2.headingTags, true]),
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Optional semantic HTML tag, to apply to the text on web. Does not change styling.
|
|
113
|
+
*
|
|
114
|
+
* `tag` and `heading` props set the same thing, so shouldn't be used together (`tag` overrides `heading`).
|
|
115
|
+
*
|
|
116
|
+
* In native apps, if a header tag is provided ("h1", "h2" etc) and accessibilityRole prop
|
|
117
|
+
* is not defined, the accessibilityRole will default to "heading".
|
|
102
118
|
*/
|
|
103
|
-
|
|
119
|
+
tag: _propTypes.default.oneOf(_utils2.textTags),
|
|
104
120
|
|
|
105
121
|
/**
|
|
106
122
|
* If true, forces the element to behave as a View block even if nested in other text
|
package/lib/index.js
CHANGED
|
@@ -16,10 +16,13 @@ var _exportNames = {
|
|
|
16
16
|
Feedback: true,
|
|
17
17
|
Fieldset: true,
|
|
18
18
|
FlexGrid: true,
|
|
19
|
+
HorizontalScroll: true,
|
|
19
20
|
Icon: true,
|
|
20
21
|
IconButton: true,
|
|
21
22
|
InputLabel: true,
|
|
22
23
|
List: true,
|
|
24
|
+
ListItem: true,
|
|
25
|
+
ListBase: true,
|
|
23
26
|
Modal: true,
|
|
24
27
|
Notification: true,
|
|
25
28
|
Pagination: true,
|
|
@@ -122,6 +125,12 @@ Object.defineProperty(exports, "FlexGrid", {
|
|
|
122
125
|
return _FlexGrid.default;
|
|
123
126
|
}
|
|
124
127
|
});
|
|
128
|
+
Object.defineProperty(exports, "HorizontalScroll", {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function () {
|
|
131
|
+
return _HorizontalScroll.default;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
125
134
|
Object.defineProperty(exports, "Icon", {
|
|
126
135
|
enumerable: true,
|
|
127
136
|
get: function () {
|
|
@@ -146,6 +155,18 @@ Object.defineProperty(exports, "List", {
|
|
|
146
155
|
return _List.default;
|
|
147
156
|
}
|
|
148
157
|
});
|
|
158
|
+
Object.defineProperty(exports, "ListItem", {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
get: function () {
|
|
161
|
+
return _List.ListItem;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(exports, "ListBase", {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
get: function () {
|
|
167
|
+
return _List.ListBase;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
149
170
|
Object.defineProperty(exports, "Modal", {
|
|
150
171
|
enumerable: true,
|
|
151
172
|
get: function () {
|
|
@@ -367,6 +388,20 @@ var _Fieldset = _interopRequireDefault(require("./Fieldset"));
|
|
|
367
388
|
|
|
368
389
|
var _FlexGrid = _interopRequireDefault(require("./FlexGrid"));
|
|
369
390
|
|
|
391
|
+
var _HorizontalScroll = _interopRequireWildcard(require("./HorizontalScroll"));
|
|
392
|
+
|
|
393
|
+
Object.keys(_HorizontalScroll).forEach(function (key) {
|
|
394
|
+
if (key === "default" || key === "__esModule") return;
|
|
395
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
396
|
+
if (key in exports && exports[key] === _HorizontalScroll[key]) return;
|
|
397
|
+
Object.defineProperty(exports, key, {
|
|
398
|
+
enumerable: true,
|
|
399
|
+
get: function () {
|
|
400
|
+
return _HorizontalScroll[key];
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
|
|
370
405
|
var _Icon = _interopRequireWildcard(require("./Icon"));
|
|
371
406
|
|
|
372
407
|
Object.keys(_Icon).forEach(function (key) {
|
|
@@ -399,7 +434,7 @@ Object.keys(_Link).forEach(function (key) {
|
|
|
399
434
|
});
|
|
400
435
|
});
|
|
401
436
|
|
|
402
|
-
var _List =
|
|
437
|
+
var _List = _interopRequireWildcard(require("./List"));
|
|
403
438
|
|
|
404
439
|
var _Modal = _interopRequireDefault(require("./Modal"));
|
|
405
440
|
|
package/lib/utils/a11y/index.js
CHANGED
|
@@ -15,4 +15,17 @@ Object.keys(_textSize).forEach(function (key) {
|
|
|
15
15
|
return _textSize[key];
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
var _semantics = require("./semantics");
|
|
21
|
+
|
|
22
|
+
Object.keys(_semantics).forEach(function (key) {
|
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
|
24
|
+
if (key in exports && exports[key] === _semantics[key]) return;
|
|
25
|
+
Object.defineProperty(exports, key, {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _semantics[key];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
18
31
|
});
|
|
@@ -0,0 +1,61 @@
|
|
|
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 _propTypes2 = _interopRequireDefault(require("./propTypes.native"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
var _default = { ..._propTypes2.default,
|
|
15
|
+
// React Native Web adds many a11y props that alias aria-* attributes
|
|
16
|
+
// Types based on https://necolas.github.io/react-native-web/docs/accessibility/
|
|
17
|
+
accessibilityActiveDescendant: _propTypes.default.string,
|
|
18
|
+
accessibilityAtomic: _propTypes.default.bool,
|
|
19
|
+
accessibilityAutoComplete: _propTypes.default.string,
|
|
20
|
+
accessibilityBusy: _propTypes.default.bool,
|
|
21
|
+
accessibilityChecked: _propTypes.default.oneOf([true, false, 'mixed']),
|
|
22
|
+
accessibilityColumnCount: _propTypes.default.number,
|
|
23
|
+
accessibilityColumnIndex: _propTypes.default.number,
|
|
24
|
+
accessibilityColumnSpan: _propTypes.default.number,
|
|
25
|
+
accessibilityControls: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
26
|
+
accessibilityCurrent: _propTypes.default.oneOf([true, false, 'page', 'step', 'location', 'date', 'time']),
|
|
27
|
+
accessibilityDescribedBy: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
28
|
+
accessibilityDetails: _propTypes.default.string,
|
|
29
|
+
accessibilityDisabled: _propTypes.default.bool,
|
|
30
|
+
accessibilityErrorMessage: _propTypes.default.string,
|
|
31
|
+
accessibilityExpanded: _propTypes.default.bool,
|
|
32
|
+
accessibilityFlowTo: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
33
|
+
accessibilityHasPopup: _propTypes.default.string,
|
|
34
|
+
accessibilityHidden: _propTypes.default.bool,
|
|
35
|
+
accessibilityInvalid: _propTypes.default.bool,
|
|
36
|
+
accessibilityKeyShortcuts: _propTypes.default.string,
|
|
37
|
+
accessibilityLabelledBy: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
38
|
+
accessibilityLevel: _propTypes.default.number,
|
|
39
|
+
accessibilityModal: _propTypes.default.bool,
|
|
40
|
+
accessibilityMultiline: _propTypes.default.bool,
|
|
41
|
+
accessibilityMultiSelectable: _propTypes.default.bool,
|
|
42
|
+
accessibilityOrientation: _propTypes.default.oneOf(['horizontal', 'vertical']),
|
|
43
|
+
accessibilityOwns: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
44
|
+
accessibilityPlaceholder: _propTypes.default.string,
|
|
45
|
+
accessibilityPosInSet: _propTypes.default.number,
|
|
46
|
+
accessibilityPressed: _propTypes.default.bool,
|
|
47
|
+
accessibilityReadOnly: _propTypes.default.bool,
|
|
48
|
+
accessibilityRequired: _propTypes.default.bool,
|
|
49
|
+
accessibilityRoleDescription: _propTypes.default.string,
|
|
50
|
+
accessibilityRowCount: _propTypes.default.number,
|
|
51
|
+
accessibilityRowIndex: _propTypes.default.number,
|
|
52
|
+
accessibilityRowSpan: _propTypes.default.number,
|
|
53
|
+
accessibilitySelected: _propTypes.default.bool,
|
|
54
|
+
accessibilitySetSize: _propTypes.default.number,
|
|
55
|
+
accessibilitySort: _propTypes.default.oneOf(['ascending', 'descending', 'none', 'other']),
|
|
56
|
+
accessibilityValueMax: _propTypes.default.number,
|
|
57
|
+
accessibilityValueMin: _propTypes.default.number,
|
|
58
|
+
accessibilityValueNow: _propTypes.default.number,
|
|
59
|
+
accessibilityValueText: _propTypes.default.string
|
|
60
|
+
};
|
|
61
|
+
exports.default = _default;
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
// React Native exports a11y prop definitions as TypeScript Interfaces, but no longer exports PropTypes
|
|
13
|
+
// so we have to define them ourselves.
|
|
14
|
+
var _default = {
|
|
15
|
+
accessible: _propTypes.default.bool,
|
|
16
|
+
focusable: _propTypes.default.bool,
|
|
17
|
+
accessibilityElementsHidden: _propTypes.default.bool,
|
|
18
|
+
accessibilityHint: _propTypes.default.string,
|
|
19
|
+
// react-native-web ignores `accessibilityHint`
|
|
20
|
+
accessibilityIgnoresInvertColors: _propTypes.default.bool,
|
|
21
|
+
accessibilityLabel: _propTypes.default.string,
|
|
22
|
+
accessibilityRole: _propTypes.default.string,
|
|
23
|
+
accessibilityActions: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
24
|
+
name: _propTypes.default.string.isRequired,
|
|
25
|
+
label: _propTypes.default.string
|
|
26
|
+
})),
|
|
27
|
+
accessibilityLiveRegion: _propTypes.default.oneOf(['none', 'polite', 'assertive']),
|
|
28
|
+
accessibilityState: _propTypes.default.shape({
|
|
29
|
+
disabled: _propTypes.default.bool,
|
|
30
|
+
selected: _propTypes.default.bool,
|
|
31
|
+
checked: _propTypes.default.oneOf([true, false, 'mixed']),
|
|
32
|
+
busy: _propTypes.default.bool,
|
|
33
|
+
expanded: _propTypes.default.bool
|
|
34
|
+
}),
|
|
35
|
+
accessibilityValue: _propTypes.default.shape({
|
|
36
|
+
min: _propTypes.default.number,
|
|
37
|
+
max: _propTypes.default.number,
|
|
38
|
+
now: _propTypes.default.number,
|
|
39
|
+
text: _propTypes.default.string
|
|
40
|
+
}),
|
|
41
|
+
accessibilityViewIsModal: _propTypes.default.bool,
|
|
42
|
+
importantForAccessibility: _propTypes.default.oneOf(['auto', 'yes', 'no', 'no-hide-descendants']),
|
|
43
|
+
onAccessibilityAction: _propTypes.default.func,
|
|
44
|
+
onAccessibilityEscape: _propTypes.default.func,
|
|
45
|
+
onAccessibilityTap: _propTypes.default.func
|
|
46
|
+
};
|
|
47
|
+
exports.default = _default;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getA11yPropsFromHtmlTag = exports.getHeadingLevel = exports.textTags = exports.layoutTags = exports.supportedTags = exports.headingTags = exports.tagsToRoles = void 0;
|
|
7
|
+
|
|
8
|
+
var _Platform = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Platform"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {import('react-native').AccessibilityRole} AccessibilityRole
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This is based on the role-to-tag mapping that React Native Web uses to set HTML tags.
|
|
18
|
+
* It's not exported in any way from RNW, so we need to keep this up-to-date manually.
|
|
19
|
+
* https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/modules/AccessibilityUtil/propsToAccessibilityComponent.js
|
|
20
|
+
*
|
|
21
|
+
* Note: every role in this list is a web-only aria-role. There is no overlap between _these_ web tags
|
|
22
|
+
* or roles and native accessibilityRoles. Only h1, h2, h3 etc map to an RN equivalent ("heading").
|
|
23
|
+
*
|
|
24
|
+
* - RN "summary" native role maps to "region" aria-role, but setting `<section>`/"region" does not
|
|
25
|
+
* set React Native's "summary" role, which has a much narrower use case.
|
|
26
|
+
* - `<Header>`/"Banner" also do not map to RN's "heading". Only h1 / h2 etc map to RN "heading".
|
|
27
|
+
*
|
|
28
|
+
* Therefore, all of these tags / roles default to no accessibilityRole in native apps. This is not wrong:
|
|
29
|
+
* in general, RN accessibilityRoles tend to be more about interaction and less about semantics than web roles.
|
|
30
|
+
*
|
|
31
|
+
* RNW's one-way mapping of React Native accessibilityRoles to web aria-roles:
|
|
32
|
+
* https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/modules/AccessibilityUtil/propsToAriaRole.js
|
|
33
|
+
*/
|
|
34
|
+
// Adding `/** @type {const} */ ({...})` denotes object content as `readonly` in many IDEs
|
|
35
|
+
// eslint-disable-next-line prettier/prettier
|
|
36
|
+
const rolesToTags =
|
|
37
|
+
/** @type {const} */
|
|
38
|
+
{
|
|
39
|
+
article: 'article',
|
|
40
|
+
banner: 'header',
|
|
41
|
+
blockquote: 'blockquote',
|
|
42
|
+
code: 'code',
|
|
43
|
+
complementary: 'aside',
|
|
44
|
+
contentinfo: 'footer',
|
|
45
|
+
deletion: 'del',
|
|
46
|
+
emphasis: 'em',
|
|
47
|
+
figure: 'figure',
|
|
48
|
+
insertion: 'ins',
|
|
49
|
+
form: 'form',
|
|
50
|
+
list: 'ul',
|
|
51
|
+
listitem: 'li',
|
|
52
|
+
main: 'main',
|
|
53
|
+
navigation: 'nav',
|
|
54
|
+
region: 'section',
|
|
55
|
+
strong: 'strong',
|
|
56
|
+
// Add special cases that are in RNW's function logic but not in its mapping object
|
|
57
|
+
label: 'label' // eslint-disable-next-line prettier/prettier
|
|
58
|
+
|
|
59
|
+
}; // Invert React Native Web's mapping, so a tag gets the role that gets that tag
|
|
60
|
+
|
|
61
|
+
const tagsToRoles = Object.fromEntries(Object.entries(rolesToTags).map(([key, value]) => [value, key]));
|
|
62
|
+
/**
|
|
63
|
+
* Heading HTML tags map to the "heading" accessibilityRole in native apps, which is similar
|
|
64
|
+
* to headings on web but without the expectation of a hierarchy of headings within one screen.
|
|
65
|
+
*/
|
|
66
|
+
// eslint-disable-next-line prettier/prettier
|
|
67
|
+
|
|
68
|
+
exports.tagsToRoles = tagsToRoles;
|
|
69
|
+
const headingTags =
|
|
70
|
+
/** @type {const} */
|
|
71
|
+
['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
|
|
72
|
+
/**
|
|
73
|
+
* @typedef {typeof headingTags[number]} HeadingTag
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* All HTML tags that may be set via RNW accesibility props alone and therefore may be set using
|
|
78
|
+
* the getA11yPropsFromHtmlTag function without changing other behaviour.
|
|
79
|
+
*
|
|
80
|
+
* Of these, only headers (h1, h2, ...h5, h6) set a corresponding accessibilityRole in native apps ("heading").
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
exports.headingTags = headingTags;
|
|
84
|
+
const supportedTags = [...Object.keys(tagsToRoles), ...headingTags];
|
|
85
|
+
/**
|
|
86
|
+
* Uses readonly mapping keys/values to generate static types for IDEs that support TS in JSDoc.
|
|
87
|
+
* @typedef {keyof rolesToTags} RoleWithTag
|
|
88
|
+
* @typedef {typeof rolesToTags[RoleWithTag] | typeof headingTags[number]} SupportedTag
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Subset of supported HTML tags that may be used with layout containers like Box.
|
|
93
|
+
*
|
|
94
|
+
* Of these, only headers (h1, h2, ...h5, h6) set a corresponding accessibilityRole in native apps ("heading").
|
|
95
|
+
*/
|
|
96
|
+
// eslint-disable-next-line prettier/prettier
|
|
97
|
+
|
|
98
|
+
exports.supportedTags = supportedTags;
|
|
99
|
+
const layoutTags =
|
|
100
|
+
/** @type {const} */
|
|
101
|
+
[...headingTags, 'article', 'aside', 'blockquote', 'footer', 'figure', 'form', 'header', 'ul', 'li', 'main', 'nav', 'section', 'label' // eslint-disable-next-line prettier/prettier
|
|
102
|
+
];
|
|
103
|
+
/**
|
|
104
|
+
* @typedef {typeof layoutTags[number]} LayoutTag
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Subset of supported HTML tags that may be used with text elements like Typography.
|
|
109
|
+
*
|
|
110
|
+
* Of these, only headers (h1, h2, ...h5, h6) set a corresponding accessibilityRole in native apps ("heading").
|
|
111
|
+
*/
|
|
112
|
+
// eslint-disable-next-line prettier/prettier
|
|
113
|
+
|
|
114
|
+
exports.layoutTags = layoutTags;
|
|
115
|
+
const textTags =
|
|
116
|
+
/** @type {const} */
|
|
117
|
+
[...headingTags, 'blockquote', 'code', 'del', 'em', 'ins', 'li', 'strong', 'label' // eslint-disable-next-line prettier/prettier
|
|
118
|
+
];
|
|
119
|
+
/**
|
|
120
|
+
* @typedef {typeof layoutTags[number]} TextTag
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* If passed a heading tag string like 'h1', 'h2' etc, returns the heading number as a number
|
|
125
|
+
* ready for use in `accessibilityLevel` props and similar.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} [tag] - HTML tag string; returns undefined if not a {@link HeadingTag}
|
|
128
|
+
* @returns {'1' | '2' | '3' | '4' | '5' | '6' | undefined}
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
exports.textTags = textTags;
|
|
132
|
+
|
|
133
|
+
const getHeadingLevel = tag => headingTags.includes(tag) ? Number(tag[1]) : undefined;
|
|
134
|
+
/**
|
|
135
|
+
* Takes a supported HTML tag, and returns the accessibility props that, on web, make React Native Web
|
|
136
|
+
* render that tag.
|
|
137
|
+
*
|
|
138
|
+
* For cross-platform apps, a second argument may be passed with an [accessibilityRole](https://reactnative.dev/docs/accessibility#accessibilityrole)
|
|
139
|
+
* to use in native apps. Heading tags (h1, h2, ...h5, h6) map to "heading" role by default;
|
|
140
|
+
* no other supported semantic HTML tags have an equivalent native accessibilityRole.
|
|
141
|
+
*
|
|
142
|
+
* @param {SupportedTag} tag - HTML tag to use on web
|
|
143
|
+
* @param {AccessibilityRole | null} [nativeRole] - optional accessibilityRole for native apps
|
|
144
|
+
* @returns {{ accessibilityRole: string, accessibilityLevel?: string } | undefined}
|
|
145
|
+
*/
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
exports.getHeadingLevel = getHeadingLevel;
|
|
149
|
+
|
|
150
|
+
const getA11yPropsFromHtmlTag = (tag, nativeRole) => {
|
|
151
|
+
// Allow cross-platform apps to set accessibilityRoles alongside a web tag without conflict
|
|
152
|
+
if (nativeRole !== undefined && _Platform.default.OS !== 'web') return {
|
|
153
|
+
accessibilityRole: nativeRole
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
if (tag) {
|
|
157
|
+
const accessibilityRole = tagsToRoles[tag];
|
|
158
|
+
if (accessibilityRole) return {
|
|
159
|
+
accessibilityRole
|
|
160
|
+
};
|
|
161
|
+
const accessibilityLevel = getHeadingLevel(tag);
|
|
162
|
+
if (accessibilityLevel) return {
|
|
163
|
+
accessibilityRole: 'header',
|
|
164
|
+
accessibilityLevel
|
|
165
|
+
};
|
|
166
|
+
} // If nothing matches or no tag supplied, return undefined and let component decide how to fall back.
|
|
167
|
+
// Note that return value may always be spread in objects (it is safe to spread undefined like { ...undefined })
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
return undefined;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
exports.getA11yPropsFromHtmlTag = getA11yPropsFromHtmlTag;
|
|
@@ -47,7 +47,7 @@ function useVerticalExpandAnimation({
|
|
|
47
47
|
if (_Platform.default.OS === 'web') {
|
|
48
48
|
const transitionDuration = isExpanded ? expandDuration : collapseDuration;
|
|
49
49
|
containerStyles = {
|
|
50
|
-
transition:
|
|
50
|
+
transition: `height ${transitionDuration}ms ease-in-out`,
|
|
51
51
|
height: isExpanded ? containerHeight : 0
|
|
52
52
|
};
|
|
53
53
|
} else {
|
package/lib/utils/children.js
CHANGED
|
@@ -9,6 +9,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _Text = _interopRequireDefault(require("react-native-web/dist/cjs/exports/Text"));
|
|
11
11
|
|
|
12
|
+
var _A11yText = _interopRequireDefault(require("../A11yText"));
|
|
13
|
+
|
|
12
14
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
15
|
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -59,16 +61,38 @@ const unpackFragment = child => {
|
|
|
59
61
|
|
|
60
62
|
return child;
|
|
61
63
|
};
|
|
64
|
+
|
|
65
|
+
exports.unpackFragment = unpackFragment;
|
|
66
|
+
|
|
67
|
+
const isStringOrNumber = child => typeof child === 'string' || typeof child === 'number'; // Wrap an A11yText with neighouring text strings so it doesn't split them into multiple <Text>s
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
const isWrapable = child => isStringOrNumber(child) || child.type === _A11yText.default;
|
|
71
|
+
|
|
72
|
+
const combineKeys = childrenArray => childrenArray.reduce((newKey, child) => `${newKey}${child.key || ''}`, ''); // Group wrappable children for one `<Text>` parent, merging adjacent text nodes
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
const wrapChild = (child, wrappedText) => {
|
|
76
|
+
const lastIndex = wrappedText.length - 1; // If possible, simplify content by combining text nodes into one string.
|
|
77
|
+
// jest-native's `.toHaveTextContent` is buggy about array of text nodes in <Text> elements.
|
|
78
|
+
|
|
79
|
+
if (lastIndex >= 0 && isStringOrNumber(child) && isStringOrNumber(wrappedText[lastIndex])) {
|
|
80
|
+
/* eslint-disable-next-line no-param-reassign */
|
|
81
|
+
wrappedText[lastIndex] = `${wrappedText[lastIndex]}${child}`;
|
|
82
|
+
} else {
|
|
83
|
+
wrappedText.push(child);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
62
86
|
/**
|
|
63
87
|
* React Native on Native crashes if text content is rendered outside `<Text>`, and on web,
|
|
64
|
-
* text style inheritance
|
|
88
|
+
* text style inheritance behaves differently with text compared to regular HTML.
|
|
65
89
|
*
|
|
66
90
|
* Call this function on children that may contain text (strings or numbers) at the top level,
|
|
67
91
|
* and any that are found will be wrapped in a React Native `<Text>` element with supplied props.
|
|
68
92
|
*
|
|
69
|
-
* Note that this does not wrap strings that are nested children of
|
|
93
|
+
* Note that this does not wrap strings that are nested children of rendered top level children:
|
|
70
94
|
* `wrapStringsInText(<View>Some text</View>)` will not wrap the inner text and will still crash,
|
|
71
|
-
* but `wrapStringsInText(<>{someString}{anotherString}</>)`
|
|
95
|
+
* but `wrapStringsInText(<>{someString}{anotherString}</>)` wraps the strings inside the fragment.
|
|
72
96
|
*
|
|
73
97
|
* @param {ReactChildren} children
|
|
74
98
|
* @param {TextProps} props
|
|
@@ -76,12 +100,35 @@ const unpackFragment = child => {
|
|
|
76
100
|
*/
|
|
77
101
|
|
|
78
102
|
|
|
79
|
-
|
|
103
|
+
const wrapStringsInText = (children, textProps = {}) => {
|
|
104
|
+
const childrenArray = unpackFragment(_react.Children.toArray(children)); // Group adjacent wrapable children together in one Text element to create as few Text elements
|
|
105
|
+
// as possible, e.g. give <X>Text {someString}</X> one Text, same as <X>{`Text ${someString}`}</X>
|
|
80
106
|
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
107
|
+
const wrapables = [[]];
|
|
108
|
+
let wrapablesIndex = 0;
|
|
109
|
+
childrenArray.forEach(child => {
|
|
110
|
+
if (isWrapable(child)) {
|
|
111
|
+
// Make this child a child of the current `Text`
|
|
112
|
+
wrapChild(child, wrapables[wrapablesIndex]);
|
|
113
|
+
} else {
|
|
114
|
+
// Close current `Text` and start a new one after this child
|
|
115
|
+
wrapables.push(child, []);
|
|
116
|
+
wrapablesIndex += 2;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
const items = wrapables.reduce((flatChildren, group, index) => {
|
|
120
|
+
// Skip nullish children and empty arrays
|
|
121
|
+
if (!group || Array.isArray(group) && !group.length) return flatChildren;
|
|
122
|
+
return [...flatChildren, Array.isArray(group) && group.some(child => isStringOrNumber(child)) ?
|
|
123
|
+
/*#__PURE__*/
|
|
124
|
+
// Wrap text nodes and their wrappable neighbours in Text with as stable a key as possible.
|
|
125
|
+
// Avoid one-item arrays because jest-native's `.toHaveTextContent` is buggy
|
|
126
|
+
// and sometimes fails to match text content in arrays.
|
|
127
|
+
(0, _jsxRuntime.jsx)(_Text.default, { ...textProps,
|
|
128
|
+
children: group.length === 1 ? group[0] : group
|
|
129
|
+
}, combineKeys(group) || index) : group];
|
|
130
|
+
}, []);
|
|
131
|
+
return items.length === 1 ? items[0] : items;
|
|
85
132
|
};
|
|
86
133
|
|
|
87
134
|
exports.wrapStringsInText = wrapStringsInText;
|