@telus-uds/components-base 1.8.3 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -2
- package/component-docs.json +1 -1
- package/lib/ActivityIndicator/Spinner.js +7 -7
- package/lib/ActivityIndicator/Spinner.native.js +2 -2
- package/lib/Button/ButtonBase.js +2 -2
- package/lib/Button/ButtonGroup.js +1 -1
- package/lib/Checkbox/Checkbox.js +1 -1
- package/lib/Checkbox/CheckboxGroup.js +2 -2
- package/lib/Divider/Divider.js +2 -2
- package/lib/ExpandCollapse/Panel.js +2 -17
- package/lib/FlexGrid/Col/Col.js +1 -1
- package/lib/Icon/Icon.js +1 -1
- package/lib/List/List.js +8 -2
- package/lib/Pagination/PageButton.js +2 -2
- package/lib/Pagination/Pagination.js +5 -3
- package/lib/Pagination/usePagination.js +2 -2
- package/lib/Progress/ProgressBar.js +3 -3
- package/lib/Progress/ProgressBarBackground.js +3 -3
- package/lib/Radio/Radio.js +2 -2
- package/lib/Radio/RadioGroup.js +2 -2
- package/lib/RadioCard/RadioCard.js +1 -1
- package/lib/RadioCard/RadioCardGroup.js +2 -2
- package/lib/Search/Search.js +1 -1
- package/lib/SideNav/SideNav.js +2 -2
- package/lib/Skeleton/Skeleton.js +1 -1
- package/lib/Skeleton/skeletonWebAnimation.js +1 -1
- package/lib/StackView/StackWrap.js +3 -1
- package/lib/StackView/getStackedContent.js +2 -2
- package/lib/Tabs/Tabs.js +28 -3
- package/lib/Tabs/TabsItem.js +5 -6
- package/lib/Tags/Tags.js +1 -1
- package/lib/ThemeProvider/utils/styles.js +2 -2
- package/lib/ThemeProvider/utils/theme-tokens.js +7 -9
- package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
- package/lib/ToggleSwitch/ToggleSwitchGroup.js +1 -1
- package/lib/Tooltip/Backdrop.js +2 -10
- package/lib/utils/animation/useVerticalExpandAnimation.js +40 -14
- package/lib/utils/children.js +2 -2
- package/lib/utils/input.js +6 -12
- package/lib/utils/props/componentPropType.js +3 -3
- package/lib/utils/props/selectSystemProps.js +2 -2
- package/lib/utils/props/tokens.js +2 -2
- package/lib/utils/useSpacingScale.js +3 -1
- package/lib/utils/useUniqueId.js +1 -1
- package/lib-module/A11yInfoProvider/index.js +63 -0
- package/lib-module/A11yText/index.js +56 -0
- package/lib-module/ActivityIndicator/Spinner.js +77 -0
- package/lib-module/ActivityIndicator/Spinner.native.js +144 -0
- package/lib-module/ActivityIndicator/index.js +41 -0
- package/lib-module/ActivityIndicator/shared.js +12 -0
- package/lib-module/BaseProvider/index.js +29 -0
- package/lib-module/Box/Box.js +244 -0
- package/lib-module/Box/index.js +2 -0
- package/lib-module/Button/Button.js +26 -0
- package/lib-module/Button/ButtonBase.js +271 -0
- package/lib-module/Button/ButtonGroup.js +247 -0
- package/lib-module/Button/ButtonLink.js +40 -0
- package/lib-module/Button/index.js +4 -0
- package/lib-module/Button/propTypes.js +36 -0
- package/lib-module/Card/Card.js +84 -0
- package/lib-module/Card/CardBase.js +66 -0
- package/lib-module/Card/PressableCardBase.js +114 -0
- package/lib-module/Card/index.js +4 -0
- package/lib-module/Checkbox/Checkbox.js +346 -0
- package/lib-module/Checkbox/CheckboxGroup.js +233 -0
- package/lib-module/Checkbox/CheckboxInput.js +60 -0
- package/lib-module/Checkbox/CheckboxInput.native.js +6 -0
- package/lib-module/Checkbox/index.js +3 -0
- package/lib-module/Divider/Divider.js +124 -0
- package/lib-module/Divider/index.js +2 -0
- package/lib-module/ExpandCollapse/Accordion.js +15 -0
- package/lib-module/ExpandCollapse/Control.js +136 -0
- package/lib-module/ExpandCollapse/ExpandCollapse.js +95 -0
- package/lib-module/ExpandCollapse/Panel.js +151 -0
- package/lib-module/ExpandCollapse/index.js +7 -0
- package/lib-module/Feedback/Feedback.js +157 -0
- package/lib-module/Feedback/index.js +2 -0
- package/lib-module/Fieldset/Fieldset.js +153 -0
- package/lib-module/Fieldset/FieldsetContainer.js +32 -0
- package/lib-module/Fieldset/FieldsetContainer.native.js +23 -0
- package/lib-module/Fieldset/Legend.js +24 -0
- package/lib-module/Fieldset/Legend.native.js +31 -0
- package/lib-module/Fieldset/cssReset.js +14 -0
- package/lib-module/Fieldset/index.js +2 -0
- package/lib-module/FlexGrid/Col/Col.js +276 -0
- package/lib-module/FlexGrid/Col/index.js +2 -0
- package/lib-module/FlexGrid/FlexGrid.js +148 -0
- package/lib-module/FlexGrid/Row/Row.js +184 -0
- package/lib-module/FlexGrid/Row/index.js +2 -0
- package/lib-module/FlexGrid/helpers/index.js +18 -0
- package/lib-module/FlexGrid/index.js +2 -0
- package/lib-module/FlexGrid/providers/GutterContext.js +3 -0
- package/lib-module/HorizontalScroll/HorizontalScroll.js +175 -0
- package/lib-module/HorizontalScroll/HorizontalScrollButton.js +81 -0
- package/lib-module/HorizontalScroll/ScrollViewEnd.js +48 -0
- package/lib-module/HorizontalScroll/ScrollViewEnd.native.js +27 -0
- package/lib-module/HorizontalScroll/dictionary.js +11 -0
- package/lib-module/HorizontalScroll/index.js +11 -0
- package/lib-module/HorizontalScroll/itemPositions.js +112 -0
- package/lib-module/Icon/Icon.js +62 -0
- package/lib-module/Icon/IconText.js +83 -0
- package/lib-module/Icon/index.js +4 -0
- package/lib-module/IconButton/IconButton.js +122 -0
- package/lib-module/IconButton/index.js +2 -0
- package/lib-module/InputLabel/InputLabel.js +148 -0
- package/lib-module/InputLabel/LabelContent.js +27 -0
- package/lib-module/InputLabel/LabelContent.native.js +19 -0
- package/lib-module/InputLabel/index.js +2 -0
- package/lib-module/InputSupports/InputSupports.js +96 -0
- package/lib-module/InputSupports/index.js +2 -0
- package/lib-module/InputSupports/useInputSupports.js +32 -0
- package/lib-module/Link/ChevronLink.js +52 -0
- package/lib-module/Link/InlinePressable.js +40 -0
- package/lib-module/Link/InlinePressable.native.js +89 -0
- package/lib-module/Link/Link.js +28 -0
- package/lib-module/Link/LinkBase.js +240 -0
- package/lib-module/Link/TextButton.js +35 -0
- package/lib-module/Link/index.js +5 -0
- package/lib-module/List/List.js +62 -0
- package/lib-module/List/ListItem.js +248 -0
- package/lib-module/List/index.js +5 -0
- package/lib-module/Modal/Modal.js +222 -0
- package/lib-module/Modal/dictionary.js +9 -0
- package/lib-module/Modal/index.js +2 -0
- package/lib-module/Notification/Notification.js +209 -0
- package/lib-module/Notification/dictionary.js +8 -0
- package/lib-module/Notification/index.js +2 -0
- package/lib-module/Pagination/PageButton.js +66 -0
- package/lib-module/Pagination/Pagination.js +153 -0
- package/lib-module/Pagination/SideButton.js +106 -0
- package/lib-module/Pagination/dictionary.js +18 -0
- package/lib-module/Pagination/index.js +2 -0
- package/lib-module/Pagination/usePagination.js +73 -0
- package/lib-module/Progress/Progress.js +89 -0
- package/lib-module/Progress/ProgressBar.js +138 -0
- package/lib-module/Progress/ProgressBarBackground.js +42 -0
- package/lib-module/Progress/index.js +4 -0
- package/lib-module/Radio/Radio.js +285 -0
- package/lib-module/Radio/RadioButton.js +138 -0
- package/lib-module/Radio/RadioGroup.js +243 -0
- package/lib-module/Radio/RadioInput.js +62 -0
- package/lib-module/Radio/RadioInput.native.js +6 -0
- package/lib-module/Radio/index.js +3 -0
- package/lib-module/RadioCard/RadioCard.js +219 -0
- package/lib-module/RadioCard/RadioCardGroup.js +250 -0
- package/lib-module/RadioCard/index.js +3 -0
- package/lib-module/Search/Search.js +261 -0
- package/lib-module/Search/dictionary.js +12 -0
- package/lib-module/Search/index.js +2 -0
- package/lib-module/Select/Group.js +21 -0
- package/lib-module/Select/Group.native.js +15 -0
- package/lib-module/Select/Item.js +20 -0
- package/lib-module/Select/Item.native.js +3 -0
- package/lib-module/Select/Picker.js +68 -0
- package/lib-module/Select/Picker.native.js +120 -0
- package/lib-module/Select/Select.js +337 -0
- package/lib-module/Select/index.js +6 -0
- package/lib-module/SideNav/Item.js +145 -0
- package/lib-module/SideNav/ItemContent.js +48 -0
- package/lib-module/SideNav/ItemsGroup.js +117 -0
- package/lib-module/SideNav/SideNav.js +136 -0
- package/lib-module/SideNav/index.js +1 -0
- package/lib-module/Skeleton/Skeleton.js +179 -0
- package/lib-module/Skeleton/index.js +2 -0
- package/lib-module/Skeleton/skeleton.constant.js +3 -0
- package/lib-module/Skeleton/skeletonWebAnimation.js +18 -0
- package/lib-module/Skeleton/useSkeletonNativeAnimation.js +24 -0
- package/lib-module/Spacer/Spacer.js +98 -0
- package/lib-module/Spacer/index.js +2 -0
- package/lib-module/StackView/StackView.js +125 -0
- package/lib-module/StackView/StackWrap.js +50 -0
- package/lib-module/StackView/StackWrap.native.js +3 -0
- package/lib-module/StackView/StackWrapBox.js +115 -0
- package/lib-module/StackView/StackWrapGap.js +59 -0
- package/lib-module/StackView/common.js +35 -0
- package/lib-module/StackView/getStackedContent.js +124 -0
- package/lib-module/StackView/index.js +5 -0
- package/lib-module/StepTracker/Step.js +248 -0
- package/lib-module/StepTracker/StepTracker.js +185 -0
- package/lib-module/StepTracker/dictionary.js +10 -0
- package/lib-module/StepTracker/index.js +2 -0
- package/lib-module/Tabs/Tabs.js +143 -0
- package/lib-module/Tabs/TabsItem.js +224 -0
- package/lib-module/Tabs/index.js +2 -0
- package/lib-module/Tags/Tags.js +251 -0
- package/lib-module/Tags/index.js +2 -0
- package/lib-module/TextInput/TextArea.js +94 -0
- package/lib-module/TextInput/TextInput.js +72 -0
- package/lib-module/TextInput/TextInputBase.js +245 -0
- package/lib-module/TextInput/index.js +3 -0
- package/lib-module/TextInput/propTypes.js +37 -0
- package/lib-module/ThemeProvider/ThemeProvider.js +36 -0
- package/lib-module/ThemeProvider/index.js +6 -0
- package/lib-module/ThemeProvider/useSetTheme.js +25 -0
- package/lib-module/ThemeProvider/useTheme.js +14 -0
- package/lib-module/ThemeProvider/useThemeTokens.js +110 -0
- package/lib-module/ThemeProvider/utils/index.js +2 -0
- package/lib-module/ThemeProvider/utils/styles.js +181 -0
- package/lib-module/ThemeProvider/utils/theme-tokens.js +163 -0
- package/lib-module/ToggleSwitch/ToggleSwitch.js +250 -0
- package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +220 -0
- package/lib-module/ToggleSwitch/index.js +3 -0
- package/lib-module/Tooltip/Backdrop.js +45 -0
- package/lib-module/Tooltip/Backdrop.native.js +44 -0
- package/lib-module/Tooltip/Tooltip.js +348 -0
- package/lib-module/Tooltip/dictionary.js +8 -0
- package/lib-module/Tooltip/getTooltipPosition.js +175 -0
- package/lib-module/Tooltip/index.js +2 -0
- package/lib-module/TooltipButton/TooltipButton.js +78 -0
- package/lib-module/TooltipButton/index.js +2 -0
- package/lib-module/Typography/Typography.js +124 -0
- package/lib-module/Typography/index.js +2 -0
- package/lib-module/ViewportProvider/ViewportProvider.js +29 -0
- package/lib-module/ViewportProvider/index.js +3 -0
- package/lib-module/ViewportProvider/useViewport.js +3 -0
- package/lib-module/ViewportProvider/useViewportListener.js +46 -0
- package/lib-module/index.js +48 -0
- package/lib-module/utils/a11y/index.js +2 -0
- package/lib-module/utils/a11y/semantics.js +157 -0
- package/lib-module/utils/a11y/textSize.js +36 -0
- package/lib-module/utils/animation/index.js +2 -0
- package/lib-module/utils/animation/useVerticalExpandAnimation.js +88 -0
- package/lib-module/utils/children.js +119 -0
- package/lib-module/utils/containUniqueFields.js +26 -0
- package/lib-module/utils/index.js +16 -0
- package/lib-module/utils/info/index.js +7 -0
- package/lib-module/utils/info/platform/index.js +11 -0
- package/lib-module/utils/info/platform/platform.android.js +1 -0
- package/lib-module/utils/info/platform/platform.ios.js +1 -0
- package/lib-module/utils/info/platform/platform.js +1 -0
- package/lib-module/utils/info/platform/platform.native.js +4 -0
- package/lib-module/utils/info/versions.js +5 -0
- package/lib-module/utils/input.js +179 -0
- package/lib-module/utils/pressability.js +111 -0
- package/lib-module/utils/props/a11yProps.js +140 -0
- package/lib-module/utils/props/clickProps.js +26 -0
- package/lib-module/utils/props/componentPropType.js +63 -0
- package/lib-module/utils/props/copyPropTypes.js +2 -0
- package/lib-module/utils/props/getPropSelector.js +9 -0
- package/lib-module/utils/props/handlerProps.js +65 -0
- package/lib-module/utils/props/hrefAttrsProp.js +33 -0
- package/lib-module/utils/props/index.js +19 -0
- package/lib-module/utils/props/inputSupportsProps.js +62 -0
- package/lib-module/utils/props/linkProps.js +44 -0
- package/lib-module/utils/props/paddingProp.js +9 -0
- package/lib-module/utils/props/pressProps.js +42 -0
- package/lib-module/utils/props/rectProp.js +9 -0
- package/lib-module/utils/props/responsiveProps.js +30 -0
- package/lib-module/utils/props/selectSystemProps.js +24 -0
- package/lib-module/utils/props/spacingProps.js +56 -0
- package/lib-module/utils/props/textInputProps.js +194 -0
- package/lib-module/utils/props/textProps.js +59 -0
- package/lib-module/utils/props/tokens.js +133 -0
- package/lib-module/utils/props/variantProp.js +18 -0
- package/lib-module/utils/props/viewProps.js +22 -0
- package/lib-module/utils/ssr.js +38 -0
- package/lib-module/utils/useCopy.js +44 -0
- package/lib-module/utils/useHash.js +45 -0
- package/lib-module/utils/useHash.native.js +7 -0
- package/lib-module/utils/useResponsiveProp.js +47 -0
- package/lib-module/utils/useSpacingScale.js +125 -0
- package/lib-module/utils/useUniqueId.js +13 -0
- package/lib-module/utils/withLinkRouter.js +83 -0
- package/package.json +2 -2
- package/src/ExpandCollapse/Panel.jsx +2 -19
- package/src/List/List.jsx +6 -2
- package/src/Tabs/Tabs.jsx +24 -2
- package/src/Tabs/TabsItem.jsx +6 -5
- package/src/utils/animation/useVerticalExpandAnimation.js +47 -13
package/lib/Tags/Tags.js
CHANGED
|
@@ -129,7 +129,7 @@ const Tags = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) => {
|
|
|
129
129
|
const uniqueFields = ['id', 'label'];
|
|
130
130
|
|
|
131
131
|
if (!(0, _utils.containUniqueFields)(items, uniqueFields)) {
|
|
132
|
-
throw new Error(
|
|
132
|
+
throw new Error("Tags items must have unique ".concat(uniqueFields.join(', ')));
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_StackView.StackWrap, {
|
|
@@ -51,7 +51,7 @@ function applyTextStyles(_ref) {
|
|
|
51
51
|
if (fontName) {
|
|
52
52
|
// Don't set undefined font families. May need some validation here that the font is available.
|
|
53
53
|
// Android doesn't recognise font weights natively so apply custom font weights via `fontFamily`.
|
|
54
|
-
styles.fontFamily =
|
|
54
|
+
styles.fontFamily = "".concat(fontName).concat(fontWeight).concat(fontStyle);
|
|
55
55
|
} else if (fontWeight) {
|
|
56
56
|
// If using system default font, apply the font weight directly.
|
|
57
57
|
// Font weight support in Android is limited to 'bold' or anything else === 'normal'.
|
|
@@ -101,7 +101,7 @@ function applyWebShadow(_ref2) {
|
|
|
101
101
|
} = _ref2;
|
|
102
102
|
const insetString = inset ? 'inset ' : '';
|
|
103
103
|
const boxShadow = {
|
|
104
|
-
boxShadow:
|
|
104
|
+
boxShadow: "".concat(insetString).concat(offsetX, "px ").concat(offsetY, "px ").concat(blur, "px ").concat(spread, "px ").concat(color)
|
|
105
105
|
};
|
|
106
106
|
return boxShadow;
|
|
107
107
|
}
|
|
@@ -28,19 +28,19 @@ const getComponentTheme = (theme, componentName) => {
|
|
|
28
28
|
// Give clear and understandable error messages for common dev errors, for example,
|
|
29
29
|
// typo in component name, missing export or accessing old version of theme
|
|
30
30
|
if (!theme) {
|
|
31
|
-
throw new Error(
|
|
31
|
+
throw new Error("Called useTheme's getStyle on \"".concat(componentName, "\" with no theme provided"));
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const themeName = ((_theme$metadata = theme.metadata) === null || _theme$metadata === void 0 ? void 0 : _theme$metadata.name) || '';
|
|
35
35
|
|
|
36
36
|
if (!theme.components) {
|
|
37
|
-
throw new Error(
|
|
37
|
+
throw new Error("Theme \"".concat(themeName, "\" has no components defined (looking for \"").concat(componentName, "\")"));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const componentTheme = theme.components[componentName];
|
|
41
41
|
|
|
42
42
|
if (!componentTheme) {
|
|
43
|
-
throw new Error(
|
|
43
|
+
throw new Error("Theme \"".concat(themeName, "\" does not have styles for component \"").concat(componentName, "\""));
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
return componentTheme;
|
|
@@ -49,9 +49,11 @@ const getComponentTheme = (theme, componentName) => {
|
|
|
49
49
|
exports.getComponentTheme = getComponentTheme;
|
|
50
50
|
|
|
51
51
|
const doesThemeConditionApply = (_ref, appearances) => {
|
|
52
|
+
var _appearances$key;
|
|
53
|
+
|
|
52
54
|
let [key, value] = _ref;
|
|
53
55
|
// use null rather than undefined so we can serialise the value in themes
|
|
54
|
-
const appearanceValue = appearances[key]
|
|
56
|
+
const appearanceValue = (_appearances$key = appearances[key]) !== null && _appearances$key !== void 0 ? _appearances$key : null;
|
|
55
57
|
return Array.isArray(value) ? value.includes(appearanceValue) : value === appearanceValue;
|
|
56
58
|
};
|
|
57
59
|
|
|
@@ -192,11 +194,7 @@ const validateThemeTokensVersion = theme => {
|
|
|
192
194
|
const actualThemeTokensVersion = theme === null || theme === void 0 ? void 0 : (_theme$metadata2 = theme.metadata) === null || _theme$metadata2 === void 0 ? void 0 : _theme$metadata2.themeTokensVersion;
|
|
193
195
|
|
|
194
196
|
if (!(0, _satisfies.default)(actualThemeTokensVersion, expectedThemeTokensVersion)) {
|
|
195
|
-
throw new Error(
|
|
196
|
-
|
|
197
|
-
The UDS base components ${_package.default.name} v${_package.default.version} are only compatible with UDS themes that are built with @telus-uds/system-theme-tokens version that is semver compatible with ${expectedThemeTokensVersion}. The current theme was built with @telus-uds/system-theme-tokens v${actualThemeTokensVersion}.
|
|
198
|
-
|
|
199
|
-
If you see this error than most likely you have attempted to install ${_package.default.name} and a UDS theme manually because you are building a multi-brand application. If you are building a single brand application, consider installing the brand specific design system package such as @telus-uds/ds-allium. For more information, see https://github.com/telus/universal-design-system/blob/main/packages/docs-uds/docs/multi-brand-usage.md`);
|
|
197
|
+
throw new Error("Invalid UDS token schema version detected.\n\nThe UDS base components ".concat(_package.default.name, " v").concat(_package.default.version, " are only compatible with UDS themes that are built with @telus-uds/system-theme-tokens version that is semver compatible with ").concat(expectedThemeTokensVersion, ". The current theme was built with @telus-uds/system-theme-tokens v").concat(actualThemeTokensVersion, ".\n\nIf you see this error than most likely you have attempted to install ").concat(_package.default.name, " and a UDS theme manually because you are building a multi-brand application. If you are building a single brand application, consider installing the brand specific design system package such as @telus-uds/ds-allium. For more information, see https://github.com/telus/universal-design-system/blob/main/packages/docs-uds/docs/multi-brand-usage.md"));
|
|
200
198
|
}
|
|
201
199
|
};
|
|
202
200
|
|
|
@@ -153,7 +153,7 @@ const ToggleSwitch = /*#__PURE__*/(0, _react.forwardRef)((_ref6, ref) => {
|
|
|
153
153
|
const getButtonTokens = buttonState => selectButtonTokens(getTokens(buttonState));
|
|
154
154
|
|
|
155
155
|
const uniqueId = (0, _utils.useUniqueId)('toggleSwitch');
|
|
156
|
-
const inputId = id
|
|
156
|
+
const inputId = id !== null && id !== void 0 ? id : uniqueId;
|
|
157
157
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_StackView.default, {
|
|
158
158
|
space: 2,
|
|
159
159
|
direction: "row",
|
|
@@ -86,7 +86,7 @@ const ToggleSwitchGroup = /*#__PURE__*/(0, _react.forwardRef)((_ref, ref) => {
|
|
|
86
86
|
const uniqueFields = ['id', 'label'];
|
|
87
87
|
|
|
88
88
|
if (!(0, _utils.containUniqueFields)(items, uniqueFields)) {
|
|
89
|
-
throw new Error(
|
|
89
|
+
throw new Error("ToggleSwitchGroup items must have unique ".concat(uniqueFields.join(', ')));
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const toggleSwitches = items.map((_ref2, index) => {
|
package/lib/Tooltip/Backdrop.js
CHANGED
|
@@ -19,15 +19,7 @@ function createPortalNode(nodeId) {
|
|
|
19
19
|
// this way the backdrop stays in place when scrolling the window - that's why we need to
|
|
20
20
|
// position it at the scroll position when rendering
|
|
21
21
|
|
|
22
|
-
node.style.cssText =
|
|
23
|
-
position: absolute;
|
|
24
|
-
top: ${window.scrollY}px;
|
|
25
|
-
left: ${window.scrollX}px;
|
|
26
|
-
right: 0;
|
|
27
|
-
bottom: 0;
|
|
28
|
-
z-index: 9999;
|
|
29
|
-
pointer-events: none;
|
|
30
|
-
`;
|
|
22
|
+
node.style.cssText = "\n position: absolute; \n top: ".concat(window.scrollY, "px;\n left: ").concat(window.scrollX, "px; \n right: 0; \n bottom: 0; \n z-index: 9999; \n pointer-events: none;\n ");
|
|
31
23
|
document.body.appendChild(node);
|
|
32
24
|
return node;
|
|
33
25
|
}
|
|
@@ -48,7 +40,7 @@ function Backdrop(_ref) {
|
|
|
48
40
|
} = _ref;
|
|
49
41
|
const [portalNode, setPortalNode] = (0, _react.useState)();
|
|
50
42
|
(0, _react.useEffect)(() => {
|
|
51
|
-
const nodeId =
|
|
43
|
+
const nodeId = "tooltip-backdrop-".concat(Date.now());
|
|
52
44
|
const node = createPortalNode(nodeId);
|
|
53
45
|
setPortalNode(node);
|
|
54
46
|
return () => {
|
|
@@ -24,16 +24,22 @@ function useVerticalExpandAnimation(_ref) {
|
|
|
24
24
|
tokens
|
|
25
25
|
} = _ref;
|
|
26
26
|
const [isAnimating, setIsAnimating] = (0, _react.useState)(false);
|
|
27
|
+
const [wasExpanded, setWasExpanded] = (0, _react.useState)(isExpanded);
|
|
28
|
+
const expandStateChanged = isExpanded !== wasExpanded;
|
|
27
29
|
const expandAnimatedValue = (0, _react.useRef)(new _Animated.default.Value(0)).current;
|
|
28
30
|
const elementRef = (0, _react.useRef)(null);
|
|
29
31
|
const {
|
|
30
32
|
expandDuration,
|
|
31
33
|
collapseDuration
|
|
32
|
-
} = tokens;
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
} = tokens;
|
|
35
|
+
(0, _react.useLayoutEffect)(() => {
|
|
36
|
+
if (expandStateChanged) {
|
|
37
|
+
setIsAnimating(true);
|
|
38
|
+
setWasExpanded(isExpanded);
|
|
39
|
+
}
|
|
40
|
+
}, [expandStateChanged, isExpanded]);
|
|
35
41
|
(0, _react.useEffect)(() => {
|
|
36
|
-
const onComplete = () =>
|
|
42
|
+
const onComplete = () => setIsAnimating(false);
|
|
37
43
|
|
|
38
44
|
if (_Platform.default.OS === 'web') {
|
|
39
45
|
if (!elementRef.current) return () => {}; // React Native Web does not pass `onTransitionEnd` through, must attach manually.
|
|
@@ -55,20 +61,40 @@ function useVerticalExpandAnimation(_ref) {
|
|
|
55
61
|
|
|
56
62
|
animation.start(onComplete);
|
|
57
63
|
return () => animation.stop();
|
|
58
|
-
}, [isExpanded, expandAnimatedValue, containerHeight, expandDuration, collapseDuration]);
|
|
64
|
+
}, [isExpanded, expandAnimatedValue, containerHeight, expandDuration, collapseDuration]);
|
|
65
|
+
const containerStyles = {};
|
|
66
|
+
if (isAnimating || expandStateChanged) containerStyles.overflow = 'hidden';
|
|
59
67
|
|
|
60
|
-
|
|
61
|
-
visibility: 'hidden'
|
|
62
|
-
} : {}; // don't visually collapse the container until we have it measured
|
|
63
|
-
|
|
64
|
-
if (containerHeight !== null) {
|
|
68
|
+
if (!isExpanded && !isAnimating && !expandStateChanged) {
|
|
65
69
|
if (_Platform.default.OS === 'web') {
|
|
66
|
-
|
|
67
|
-
containerStyles.
|
|
68
|
-
containerStyles.height = isExpanded ? containerHeight : 0;
|
|
70
|
+
// Without `visibility: 'hidden', descendents are focusable on web even when collapsed.
|
|
71
|
+
containerStyles.visibility = 'hidden';
|
|
69
72
|
} else {
|
|
70
|
-
|
|
73
|
+
// There's no `visibility: hidden` in React Native, and display: none causes a flicker on expand.
|
|
74
|
+
// Without some form of hiding, some children leak through even when closed e.g. `List.Item` bullets.
|
|
75
|
+
containerStyles.opacity = 0;
|
|
76
|
+
}
|
|
77
|
+
} // don't visually collapse the container until we have it measured
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
if (containerHeight === null) {
|
|
81
|
+
if (_Platform.default.OS === 'web') {
|
|
82
|
+
// on web we can hide the contents until we have the container measured and avoid occasional jitter
|
|
83
|
+
// this won't work on native platforms
|
|
84
|
+
containerStyles.height = 0;
|
|
85
|
+
containerStyles.visibility = 'hidden';
|
|
71
86
|
}
|
|
87
|
+
} else if (_Platform.default.OS === 'web') {
|
|
88
|
+
const transitionDuration = isExpanded ? expandDuration : collapseDuration;
|
|
89
|
+
containerStyles.transition = "height ".concat(transitionDuration, "ms ease-in-out");
|
|
90
|
+
containerStyles.height = isExpanded ? containerHeight : 0;
|
|
91
|
+
} else if (_Platform.default.OS === 'ios' && isExpanded && !isAnimating && !expandStateChanged && typeof containerHeight === 'number') {
|
|
92
|
+
// iOS reflows text while the height animation is in progress. Sometimes, it hits a timing bug where
|
|
93
|
+
// it fails to reflow properly after the last animation frame, leaving the last line of text not visible.
|
|
94
|
+
// Force reflow after animation completes with a static height non-identical to the last animated height.
|
|
95
|
+
containerStyles.height = containerHeight + 1;
|
|
96
|
+
} else {
|
|
97
|
+
containerStyles.height = expandAnimatedValue;
|
|
72
98
|
}
|
|
73
99
|
|
|
74
100
|
return [containerStyles, elementRef];
|
package/lib/utils/children.js
CHANGED
|
@@ -73,7 +73,7 @@ const isWrapable = child => {
|
|
|
73
73
|
return isStringOrNumber(child) || child.type === _A11yText.default || ((_child$type = child.type) === null || _child$type === void 0 ? void 0 : _child$type.name) === 'FootnoteLink';
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
const combineKeys = childrenArray => childrenArray.reduce((newKey, child) =>
|
|
76
|
+
const combineKeys = childrenArray => childrenArray.reduce((newKey, child) => "".concat(newKey).concat(child.key || ''), ''); // Group wrappable children for one `<Text>` parent, merging adjacent text nodes
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
const wrapChild = (child, wrappedText) => {
|
|
@@ -82,7 +82,7 @@ const wrapChild = (child, wrappedText) => {
|
|
|
82
82
|
|
|
83
83
|
if (lastIndex >= 0 && isStringOrNumber(child) && isStringOrNumber(wrappedText[lastIndex])) {
|
|
84
84
|
/* eslint-disable-next-line no-param-reassign */
|
|
85
|
-
wrappedText[lastIndex] =
|
|
85
|
+
wrappedText[lastIndex] = "".concat(wrappedText[lastIndex]).concat(child);
|
|
86
86
|
} else {
|
|
87
87
|
wrappedText.push(child);
|
|
88
88
|
}
|
package/lib/utils/input.js
CHANGED
|
@@ -28,29 +28,23 @@ const validateProps = (_ref, _ref2, hookName) => {
|
|
|
28
28
|
const usageError = error => {
|
|
29
29
|
// Errors inside hooks in React Native get incomplete stack traces pointing at parent component only.
|
|
30
30
|
// Help devs out by telling them exactly which hook threw the error as well as why.
|
|
31
|
-
throw new Error(
|
|
32
|
-
|
|
33
|
-
Consumers of this hook must be one of:
|
|
34
|
-
1. An "uncontrolled" component responding directly to user actions, with an optional \`initialValue${s}\` but no \`value${s}\` prop,
|
|
35
|
-
2. A "controlled" component where an always-defined \`value${s}\` prop is managed by an \`onChange\` handler, with no \`initialValue${s}\`,
|
|
36
|
-
3. A "read-only" component, with \`readOnly\` prop set as \`true\`.
|
|
37
|
-
`);
|
|
31
|
+
throw new Error("".concat(hookName, " ").concat(error, ".\n\nConsumers of this hook must be one of:\n1. An \"uncontrolled\" component responding directly to user actions, with an optional `initialValue").concat(s, "` but no `value").concat(s, "` prop,\n2. A \"controlled\" component where an always-defined `value").concat(s, "` prop is managed by an `onChange` handler, with no `initialValue").concat(s, "`,\n3. A \"read-only\" component, with `readOnly` prop set as `true`.\n"));
|
|
38
32
|
};
|
|
39
33
|
|
|
40
34
|
if (value && !onChange && !readOnly) {
|
|
41
|
-
usageError(
|
|
35
|
+
usageError("has `value".concat(s, "` prop without `onChange` or `readOnly`"));
|
|
42
36
|
}
|
|
43
37
|
|
|
44
38
|
if (initialValue && value) {
|
|
45
|
-
usageError(
|
|
39
|
+
usageError("has both `initialValue".concat(s, "` and `value").concat(s, "`"));
|
|
46
40
|
}
|
|
47
41
|
|
|
48
42
|
if (isControlled && !isCurrentlyControlled) {
|
|
49
|
-
usageError(
|
|
43
|
+
usageError("stopped receiving `value".concat(s, "` from parent after delegating state management"));
|
|
50
44
|
}
|
|
51
45
|
|
|
52
46
|
if (!isControlled && isCurrentlyControlled) {
|
|
53
|
-
usageError(
|
|
47
|
+
usageError("started receiving `value".concat(s, "` from parent after starting managing own state"));
|
|
54
48
|
}
|
|
55
49
|
};
|
|
56
50
|
/**
|
|
@@ -164,7 +158,7 @@ const useMultipleInputValues = function () {
|
|
|
164
158
|
onChange,
|
|
165
159
|
value: values,
|
|
166
160
|
// if we're controlling our own state, always start with an array
|
|
167
|
-
initialValue: initialValues
|
|
161
|
+
initialValue: initialValues !== null && initialValues !== void 0 ? initialValues : values === undefined ? [] : undefined
|
|
168
162
|
}, 'useMultipleInputValues');
|
|
169
163
|
const enforceMaxValues = (0, _react.useCallback)(newValues => {
|
|
170
164
|
if (!maxValues) return newValues;
|
|
@@ -33,8 +33,8 @@ function componentPropType(passedName) {
|
|
|
33
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
34
|
|
|
35
35
|
if (!nameInProp || !passedNames.includes(nameInProp)) {
|
|
36
|
-
const propDescription = nameInProp ?
|
|
37
|
-
return new Error(
|
|
36
|
+
const propDescription = nameInProp ? "Component ".concat(nameInProp) : typeof props[propName];
|
|
37
|
+
return new Error("".concat(componentName, ": ").concat(propDescription, " was passed to `").concat(propName, "` prop; should be ").concat(passedNames.join(' or ')));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
return undefined;
|
|
@@ -42,7 +42,7 @@ function componentPropType(passedName) {
|
|
|
42
42
|
|
|
43
43
|
const checkRequired = (props, propName, componentName) => {
|
|
44
44
|
if (props[propName] === undefined) {
|
|
45
|
-
return new Error(
|
|
45
|
+
return new Error("The prop `".concat(propName, "` is marked as required in `").concat(componentName, "`, but its value is ").concat(props[propName], "."));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return undefined;
|
|
@@ -10,7 +10,7 @@ exports.default = selectSystemProps;
|
|
|
10
10
|
function selectSystemProps(systemPropHelpers) {
|
|
11
11
|
const selectProps = props => systemPropHelpers.reduce((acc, propHelper) => {
|
|
12
12
|
if (typeof (propHelper === null || propHelper === void 0 ? void 0 : propHelper.select) !== 'function') {
|
|
13
|
-
throw new Error(
|
|
13
|
+
throw new Error("An invalid system prop helper has been passed to 'selectSystemProps': prop selector ('.select') is missing in ".concat(propHelper));
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
return { ...acc,
|
|
@@ -20,7 +20,7 @@ function selectSystemProps(systemPropHelpers) {
|
|
|
20
20
|
|
|
21
21
|
const selectedPropTypes = systemPropHelpers.reduce((acc, propHelper) => {
|
|
22
22
|
if (!(propHelper !== null && propHelper !== void 0 && propHelper.types)) {
|
|
23
|
-
throw new Error(
|
|
23
|
+
throw new Error("An invalid system prop helper has been passed to 'selectSystemProps': types selector ('.types') is missing in ".concat(propHelper));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
return { ...acc,
|
|
@@ -22,7 +22,7 @@ const getTokenNames = componentName => {
|
|
|
22
22
|
const componentTokenSchema = _systemThemeTokens.components[componentName];
|
|
23
23
|
|
|
24
24
|
if (!componentTokenSchema) {
|
|
25
|
-
throw new Error(
|
|
25
|
+
throw new Error("No \"".concat(componentName, "\" tokenKeys in @telus-uds/system-theme-tokens"));
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
return Object.keys(componentTokenSchema);
|
|
@@ -63,7 +63,7 @@ exports.getTokenNames = getTokenNames;
|
|
|
63
63
|
const selectTokens = (specifier, tokens, prefix) => {
|
|
64
64
|
const tokenNames = typeof specifier === 'string' ? getTokenNames(specifier) : specifier;
|
|
65
65
|
const filteredTokens = tokenNames.reduce((validTokens, key) => {
|
|
66
|
-
const prefixedKey = prefix ?
|
|
66
|
+
const prefixedKey = prefix ? "".concat(prefix).concat(key[0].toUpperCase()).concat(key.slice(1)) : key;
|
|
67
67
|
const token = tokens[prefixedKey];
|
|
68
68
|
return token !== undefined ? { ...validTokens,
|
|
69
69
|
[key]: token
|
|
@@ -110,6 +110,8 @@ const resolveSpacingOptions = space => {
|
|
|
110
110
|
|
|
111
111
|
|
|
112
112
|
const useSpacingScale = spaceValue => {
|
|
113
|
+
var _spaceValue$space;
|
|
114
|
+
|
|
113
115
|
// In future, may need to consider window height as well as width, particularly for native apps,
|
|
114
116
|
// e.g. to ensure designs don't look lost on large, tall, not-so-wide portrait screens.
|
|
115
117
|
const viewport = (0, _ViewportProvider.useViewport)();
|
|
@@ -119,7 +121,7 @@ const useSpacingScale = spaceValue => {
|
|
|
119
121
|
overridden,
|
|
120
122
|
subtract = 0
|
|
121
123
|
} = resolveSpacingOptions(spaceValue);
|
|
122
|
-
const space = !overridden && ((spaceValue === null || spaceValue === void 0 ? void 0 : spaceValue.space)
|
|
124
|
+
const space = !overridden && ((_spaceValue$space = spaceValue === null || spaceValue === void 0 ? void 0 : spaceValue.space) !== null && _spaceValue$space !== void 0 ? _spaceValue$space : (0, _useResponsiveProp.resolveResponsiveProp)(spaceValue, viewport, 0));
|
|
123
125
|
const {
|
|
124
126
|
size
|
|
125
127
|
} = (0, _ThemeProvider.useThemeTokens)('spacingScale', tokens, variant, {
|
package/lib/utils/useUniqueId.js
CHANGED
|
@@ -13,7 +13,7 @@ function useUniqueId() {
|
|
|
13
13
|
let prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
14
14
|
const [uniqueId] = (0, _react.useState)(() => {
|
|
15
15
|
id += 1;
|
|
16
|
-
return
|
|
16
|
+
return "".concat(prefix, "-").concat(id);
|
|
17
17
|
});
|
|
18
18
|
return uniqueId;
|
|
19
19
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import AccessibilityInfo from "react-native-web/dist/exports/AccessibilityInfo";
|
|
4
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const ScreenReaderContext = /*#__PURE__*/createContext(false);
|
|
7
|
+
const ReducedMotionContext = /*#__PURE__*/createContext(false);
|
|
8
|
+
|
|
9
|
+
const A11yInfoProvider = _ref => {
|
|
10
|
+
let {
|
|
11
|
+
children
|
|
12
|
+
} = _ref;
|
|
13
|
+
const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false);
|
|
14
|
+
const [screenReaderEnabled, setScreenReaderEnabled] = useState(false);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (process.env.NODE_ENV === 'test') {
|
|
17
|
+
// On Jest these effects do nothing but can cause `act` state change warnings
|
|
18
|
+
// and "...after the Jest environment has been torn down" errors, so skip them.
|
|
19
|
+
return () => {};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
AccessibilityInfo.addEventListener('reduceMotionChanged', setReduceMotionEnabled);
|
|
23
|
+
AccessibilityInfo.addEventListener('screenReaderChanged', setScreenReaderEnabled);
|
|
24
|
+
|
|
25
|
+
const setInitialA11yInfo = async () => {
|
|
26
|
+
const [initialReduceMotionEnabled, initialScreenReaderEnabled] = await Promise.all([AccessibilityInfo.isReduceMotionEnabled(), AccessibilityInfo.isScreenReaderEnabled()]); // Browsers can't detect screen readers; in RNW isScreenReaderEnabled() is always `true`
|
|
27
|
+
// https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/exports/AccessibilityInfo/index.js#L14
|
|
28
|
+
|
|
29
|
+
setScreenReaderEnabled(Platform.OS !== 'web' && !!initialScreenReaderEnabled); // RNW does support isReduceMotionEnabled looking for 'prefers-reduced-motion' state
|
|
30
|
+
|
|
31
|
+
setReduceMotionEnabled(!!initialReduceMotionEnabled);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (AccessibilityInfo.isReduceMotionEnabled && AccessibilityInfo.isScreenReaderEnabled) {
|
|
35
|
+
setInitialA11yInfo();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return () => {
|
|
39
|
+
AccessibilityInfo.removeEventListener('reduceMotionChanged', setReduceMotionEnabled);
|
|
40
|
+
AccessibilityInfo.removeEventListener('screenReaderChanged', setScreenReaderEnabled);
|
|
41
|
+
};
|
|
42
|
+
}, []);
|
|
43
|
+
return /*#__PURE__*/_jsx(ReducedMotionContext.Provider, {
|
|
44
|
+
value: reduceMotionEnabled,
|
|
45
|
+
children: /*#__PURE__*/_jsx(ScreenReaderContext.Provider, {
|
|
46
|
+
value: screenReaderEnabled,
|
|
47
|
+
children: children
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
A11yInfoProvider.propTypes = {
|
|
53
|
+
children: PropTypes.node.isRequired
|
|
54
|
+
};
|
|
55
|
+
export default A11yInfoProvider;
|
|
56
|
+
export const useA11yInfo = () => {
|
|
57
|
+
const screenReaderEnabled = useContext(ScreenReaderContext);
|
|
58
|
+
const reduceMotionEnabled = useContext(ReducedMotionContext);
|
|
59
|
+
return {
|
|
60
|
+
reduceMotionEnabled,
|
|
61
|
+
screenReaderEnabled
|
|
62
|
+
};
|
|
63
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
3
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
4
|
+
import View from "react-native-web/dist/exports/View";
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { a11yProps, selectSystemProps, viewProps } from '../utils/props';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
9
|
+
/**
|
|
10
|
+
* A11yText is a zero-size invisible element that adds text to be read by screen readers.
|
|
11
|
+
*
|
|
12
|
+
* It should be used to add selectable screen-reader-only text to the main document flow,
|
|
13
|
+
* as a sibling to blocks of text like paragraphs and interactive elements like buttons.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const A11yText = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
17
|
+
let {
|
|
18
|
+
text,
|
|
19
|
+
heading,
|
|
20
|
+
...rest
|
|
21
|
+
} = _ref;
|
|
22
|
+
const selectedProps = selectProps({
|
|
23
|
+
// On iOS, needs `accessible` to be true to be focusable without non-a11y content.
|
|
24
|
+
// On Web, `accessible` causes RNW to set attributes that may make the element be treated as a group.
|
|
25
|
+
// On Android, may cause this to be skipped when with `<Text>` siblings in an `accessible` View,
|
|
26
|
+
// see https://github.com/facebook/react-native/issues/30851#issuecomment-790165489
|
|
27
|
+
accessible: Platform.OS === 'ios',
|
|
28
|
+
accessibilityLabel: text,
|
|
29
|
+
accessibilityRole: heading ? 'header' : 'text',
|
|
30
|
+
...rest
|
|
31
|
+
});
|
|
32
|
+
return /*#__PURE__*/_jsx(View, {
|
|
33
|
+
style: styles.invisible,
|
|
34
|
+
ref: ref,
|
|
35
|
+
...selectedProps
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
A11yText.displayName = 'A11yText';
|
|
39
|
+
A11yText.propTypes = { ...selectedSystemPropTypes,
|
|
40
|
+
text: PropTypes.string.isRequired,
|
|
41
|
+
heading: PropTypes.bool
|
|
42
|
+
};
|
|
43
|
+
const styles = StyleSheet.create({
|
|
44
|
+
invisible: {
|
|
45
|
+
// Without width or height it is not shown
|
|
46
|
+
minHeight: 1,
|
|
47
|
+
minWidth: 1,
|
|
48
|
+
// Ensures it doesn't occupy space
|
|
49
|
+
// position: 'absolute' causes it to be read first in its container
|
|
50
|
+
marginEnd: -1,
|
|
51
|
+
marginBottom: -1,
|
|
52
|
+
// Ensures it is in the correct position on Native
|
|
53
|
+
top: -1
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
export default A11yText;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { DURATION, MIN_EMPTY_ANGLE, MIN_STROKE_ANGLE, BEZIER, propTypes } from './shared';
|
|
3
|
+
import { useA11yInfo } from '../A11yInfoProvider';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
6
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
const SVG_RADIUS = 20;
|
|
8
|
+
const SVG_CIRCUMFERENCE = SVG_RADIUS * 2 * Math.PI;
|
|
9
|
+
const MIN_SVG_LENGTH = MIN_STROKE_ANGLE / 360 * SVG_CIRCUMFERENCE;
|
|
10
|
+
const MAX_SVG_LENGTH = (1 - MIN_EMPTY_ANGLE / 360) * SVG_CIRCUMFERENCE;
|
|
11
|
+
const animationProps = {
|
|
12
|
+
begin: '0s',
|
|
13
|
+
dur: "".concat(DURATION, "ms"),
|
|
14
|
+
fill: 'freeze',
|
|
15
|
+
repeatCount: 'indefinite'
|
|
16
|
+
};
|
|
17
|
+
const bezierProps = {
|
|
18
|
+
calcMode: 'spline',
|
|
19
|
+
keyTimes: '0; 0.5; 1',
|
|
20
|
+
keySplines: "".concat(BEZIER.join(', '), " ; ").concat(BEZIER.join(', '))
|
|
21
|
+
}; // We're using svg rather than css here to define the animation to avoid needing to introduce css injection mechanism
|
|
22
|
+
// It's possible to replicate this functionality with RNW animations, but it snags on chrome at least, see https://github.com/telus/universal-design-system/pull/477 for details.
|
|
23
|
+
|
|
24
|
+
const Spinner = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
25
|
+
let {
|
|
26
|
+
size,
|
|
27
|
+
color,
|
|
28
|
+
thickness,
|
|
29
|
+
label
|
|
30
|
+
} = _ref;
|
|
31
|
+
const {
|
|
32
|
+
reduceMotionEnabled
|
|
33
|
+
} = useA11yInfo();
|
|
34
|
+
return /*#__PURE__*/_jsx("svg", {
|
|
35
|
+
ref: ref,
|
|
36
|
+
width: "".concat(size, "px"),
|
|
37
|
+
height: "".concat(size, "px"),
|
|
38
|
+
viewBox: "0 0 48 48",
|
|
39
|
+
"aria-valuetext": label,
|
|
40
|
+
role: "progressbar",
|
|
41
|
+
"aria-busy": true,
|
|
42
|
+
children: /*#__PURE__*/_jsxs("g", {
|
|
43
|
+
children: [reduceMotionEnabled ? null : /*#__PURE__*/_jsx("animateTransform", {
|
|
44
|
+
attributeName: "transform",
|
|
45
|
+
type: "rotate",
|
|
46
|
+
values: "-180 24 24;".concat(360 + MIN_STROKE_ANGLE - 180, " 24 24"),
|
|
47
|
+
...animationProps
|
|
48
|
+
}), /*#__PURE__*/_jsx("circle", {
|
|
49
|
+
fill: "none",
|
|
50
|
+
stroke: color,
|
|
51
|
+
strokeWidth: thickness * 48 / size,
|
|
52
|
+
strokeLinecap: "round",
|
|
53
|
+
cx: "24",
|
|
54
|
+
cy: "24",
|
|
55
|
+
r: "20",
|
|
56
|
+
strokeDasharray: reduceMotionEnabled ? MAX_SVG_LENGTH : [MIN_SVG_LENGTH, SVG_CIRCUMFERENCE],
|
|
57
|
+
strokeDashoffset: 0,
|
|
58
|
+
children: reduceMotionEnabled ? null : /*#__PURE__*/_jsxs(_Fragment, {
|
|
59
|
+
children: [/*#__PURE__*/_jsx("animate", {
|
|
60
|
+
attributeName: "stroke-dashoffset",
|
|
61
|
+
values: "0;-10;".concat(MIN_SVG_LENGTH - SVG_CIRCUMFERENCE),
|
|
62
|
+
...animationProps,
|
|
63
|
+
...bezierProps
|
|
64
|
+
}), /*#__PURE__*/_jsx("animate", {
|
|
65
|
+
attributeName: "stroke-dasharray",
|
|
66
|
+
values: "".concat(MIN_SVG_LENGTH, ", 200;").concat(MAX_SVG_LENGTH, ", 200;").concat(MIN_SVG_LENGTH, ", 200"),
|
|
67
|
+
...animationProps,
|
|
68
|
+
...bezierProps
|
|
69
|
+
})]
|
|
70
|
+
})
|
|
71
|
+
})]
|
|
72
|
+
})
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
Spinner.displayName = 'Spinner';
|
|
76
|
+
Spinner.propTypes = propTypes;
|
|
77
|
+
export default Spinner;
|