@telus-uds/components-base 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -2
- package/CHANGELOG.json +38 -0
- package/CHANGELOG.md +15 -2
- package/__tests__/ActivityIndicator/ActivityIndicator.test.jsx +35 -0
- package/__tests__/ActivityIndicator/__snapshots__/ActivityIndicator.test.jsx.snap +287 -0
- package/babel.config.js +27 -5
- package/component-docs.json +88 -424
- package/lib/A11yText/index.js +5 -4
- package/lib/ActivityIndicator/Spinner.js +46 -37
- package/lib/ActivityIndicator/Spinner.native.js +26 -15
- package/lib/Box/Box.js +4 -4
- package/lib/Button/ButtonBase.js +7 -8
- package/lib/Card/Card.js +5 -4
- package/lib/Card/PressableCardBase.js +6 -11
- package/lib/Checkbox/Checkbox.js +4 -6
- package/lib/Divider/Divider.js +12 -11
- package/lib/ExpandCollapse/Control.js +7 -7
- package/lib/ExpandCollapse/ExpandCollapse.js +6 -2
- package/lib/ExpandCollapse/Panel.js +6 -7
- package/lib/Feedback/Feedback.js +6 -5
- package/lib/Fieldset/Fieldset.js +1 -3
- package/lib/HorizontalScroll/HorizontalScroll.js +5 -6
- package/lib/IconButton/IconButton.js +6 -6
- package/lib/InputLabel/InputLabel.js +7 -2
- package/lib/InputSupports/InputSupports.js +2 -2
- package/lib/Link/LinkBase.js +5 -6
- package/lib/List/List.js +4 -6
- package/lib/List/ListItem.js +6 -2
- package/lib/Modal/Modal.js +6 -2
- package/lib/Notification/Notification.js +7 -2
- package/lib/Pagination/Pagination.js +8 -3
- package/lib/Progress/Progress.js +5 -4
- package/lib/Progress/ProgressBar.js +8 -7
- package/lib/Radio/Radio.js +4 -6
- package/lib/Radio/RadioButton.js +6 -3
- package/lib/Radio/RadioGroup.js +7 -2
- package/lib/RadioCard/RadioCard.js +4 -4
- package/lib/RadioCard/RadioCardGroup.js +9 -6
- package/lib/Search/Search.js +7 -2
- package/lib/Select/Select.js +10 -9
- package/lib/SideNav/Item.js +7 -7
- package/lib/SideNav/SideNav.js +7 -3
- package/lib/Skeleton/Skeleton.js +6 -2
- package/lib/Spacer/Spacer.js +7 -18
- package/lib/StackView/StackView.js +7 -7
- package/lib/StackView/StackWrapBox.js +6 -7
- package/lib/StackView/StackWrapGap.js +6 -5
- package/lib/StepTracker/Step.js +7 -3
- package/lib/StepTracker/StepTracker.js +7 -7
- package/lib/Tabs/Tabs.js +6 -2
- package/lib/Tabs/TabsItem.js +6 -5
- package/lib/Tags/Tags.js +5 -6
- package/lib/TextInput/TextArea.js +13 -14
- package/lib/TextInput/TextInput.js +13 -14
- package/lib/TextInput/TextInputBase.js +5 -3
- package/lib/ToggleSwitch/ToggleSwitch.js +10 -9
- package/lib/ToggleSwitch/ToggleSwitchGroup.js +5 -7
- package/lib/Tooltip/Tooltip.js +7 -2
- package/lib/TooltipButton/TooltipButton.js +7 -2
- package/lib/Typography/Typography.js +8 -6
- package/lib/index.js +7 -0
- package/lib/utils/children.js +5 -1
- package/lib/utils/index.js +14 -0
- package/lib/utils/props/index.js +9 -0
- package/lib/{InputSupports/propTypes.js → utils/props/inputSupportsProps.js} +2 -3
- package/lib/utils/ssr.js +51 -0
- package/lib-module/A11yInfoProvider/index.js +62 -0
- package/lib-module/A11yText/index.js +55 -0
- package/lib-module/ActivityIndicator/Spinner.js +76 -0
- package/lib-module/ActivityIndicator/Spinner.native.js +143 -0
- package/lib-module/ActivityIndicator/index.js +40 -0
- package/lib-module/ActivityIndicator/shared.js +12 -0
- package/lib-module/BaseProvider/index.js +26 -0
- package/lib-module/Box/Box.js +243 -0
- package/lib-module/Box/index.js +2 -0
- package/lib-module/Button/Button.js +25 -0
- package/lib-module/Button/ButtonBase.js +254 -0
- package/lib-module/Button/ButtonGroup.js +164 -0
- package/lib-module/Button/ButtonLink.js +39 -0
- package/lib-module/Button/index.js +4 -0
- package/lib-module/Button/propTypes.js +36 -0
- package/lib-module/Card/Card.js +83 -0
- package/lib-module/Card/CardBase.js +62 -0
- package/lib-module/Card/PressableCardBase.js +113 -0
- package/lib-module/Card/index.js +4 -0
- package/lib-module/Checkbox/Checkbox.js +321 -0
- package/lib-module/Checkbox/CheckboxGroup.js +218 -0
- package/lib-module/Checkbox/CheckboxInput.js +58 -0
- package/lib-module/Checkbox/CheckboxInput.native.js +6 -0
- package/lib-module/Checkbox/index.js +3 -0
- package/lib-module/Divider/Divider.js +123 -0
- package/lib-module/Divider/index.js +2 -0
- package/lib-module/ExpandCollapse/Accordion.js +15 -0
- package/lib-module/ExpandCollapse/Control.js +130 -0
- package/lib-module/ExpandCollapse/ExpandCollapse.js +94 -0
- package/lib-module/ExpandCollapse/Panel.js +158 -0
- package/lib-module/ExpandCollapse/index.js +7 -0
- package/lib-module/Feedback/Feedback.js +144 -0
- package/lib-module/Feedback/index.js +2 -0
- package/lib-module/Fieldset/Fieldset.js +145 -0
- package/lib-module/Fieldset/FieldsetContainer.js +29 -0
- package/lib-module/Fieldset/FieldsetContainer.native.js +20 -0
- package/lib-module/Fieldset/Legend.js +21 -0
- package/lib-module/Fieldset/Legend.native.js +28 -0
- package/lib-module/Fieldset/cssReset.js +14 -0
- package/lib-module/Fieldset/index.js +2 -0
- package/lib-module/FlexGrid/Col/Col.js +265 -0
- package/lib-module/FlexGrid/Col/index.js +2 -0
- package/lib-module/FlexGrid/FlexGrid.js +147 -0
- package/lib-module/FlexGrid/Row/Row.js +177 -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 +171 -0
- package/lib-module/HorizontalScroll/HorizontalScrollButton.js +102 -0
- package/lib-module/HorizontalScroll/ScrollViewEnd.js +47 -0
- package/lib-module/HorizontalScroll/ScrollViewEnd.native.js +24 -0
- package/lib-module/HorizontalScroll/dictionary.js +11 -0
- package/lib-module/HorizontalScroll/index.js +11 -0
- package/lib-module/HorizontalScroll/itemPositions.js +106 -0
- package/lib-module/Icon/Icon.js +61 -0
- package/lib-module/Icon/IconText.js +81 -0
- package/lib-module/Icon/index.js +4 -0
- package/lib-module/IconButton/IconButton.js +115 -0
- package/lib-module/IconButton/index.js +2 -0
- package/lib-module/InputLabel/InputLabel.js +131 -0
- package/lib-module/InputLabel/LabelContent.js +24 -0
- package/lib-module/InputLabel/LabelContent.native.js +16 -0
- package/lib-module/InputLabel/index.js +2 -0
- package/lib-module/InputSupports/InputSupports.js +88 -0
- package/lib-module/InputSupports/index.js +2 -0
- package/lib-module/InputSupports/useInputSupports.js +31 -0
- package/lib-module/Link/ChevronLink.js +51 -0
- package/lib-module/Link/InlinePressable.js +37 -0
- package/lib-module/Link/InlinePressable.native.js +85 -0
- package/lib-module/Link/Link.js +27 -0
- package/lib-module/Link/LinkBase.js +210 -0
- package/lib-module/Link/TextButton.js +43 -0
- package/lib-module/Link/index.js +5 -0
- package/lib-module/List/List.js +55 -0
- package/lib-module/List/ListItem.js +213 -0
- package/lib-module/List/index.js +5 -0
- package/lib-module/Modal/Modal.js +208 -0
- package/lib-module/Modal/dictionary.js +9 -0
- package/lib-module/Modal/index.js +2 -0
- package/lib-module/Notification/Notification.js +196 -0
- package/lib-module/Notification/dictionary.js +8 -0
- package/lib-module/Notification/index.js +2 -0
- package/lib-module/Pagination/PageButton.js +65 -0
- package/lib-module/Pagination/Pagination.js +140 -0
- package/lib-module/Pagination/SideButton.js +103 -0
- package/lib-module/Pagination/dictionary.js +18 -0
- package/lib-module/Pagination/index.js +2 -0
- package/lib-module/Pagination/usePagination.js +72 -0
- package/lib-module/Progress/Progress.js +85 -0
- package/lib-module/Progress/ProgressBar.js +134 -0
- package/lib-module/Progress/ProgressBarBackground.js +41 -0
- package/lib-module/Progress/index.js +4 -0
- package/lib-module/Radio/Radio.js +263 -0
- package/lib-module/Radio/RadioButton.js +128 -0
- package/lib-module/Radio/RadioGroup.js +225 -0
- package/lib-module/Radio/RadioInput.js +60 -0
- package/lib-module/Radio/RadioInput.native.js +6 -0
- package/lib-module/Radio/index.js +3 -0
- package/lib-module/RadioCard/RadioCard.js +218 -0
- package/lib-module/RadioCard/RadioCardGroup.js +232 -0
- package/lib-module/RadioCard/index.js +3 -0
- package/lib-module/Search/Search.js +233 -0
- package/lib-module/Search/dictionary.js +12 -0
- package/lib-module/Search/index.js +2 -0
- package/lib-module/Select/Group.js +20 -0
- package/lib-module/Select/Group.native.js +14 -0
- package/lib-module/Select/Item.js +17 -0
- package/lib-module/Select/Item.native.js +9 -0
- package/lib-module/Select/Picker.js +67 -0
- package/lib-module/Select/Picker.native.js +110 -0
- package/lib-module/Select/Select.js +317 -0
- package/lib-module/Select/index.js +6 -0
- package/lib-module/SideNav/Item.js +139 -0
- package/lib-module/SideNav/ItemContent.js +45 -0
- package/lib-module/SideNav/ItemsGroup.js +115 -0
- package/lib-module/SideNav/SideNav.js +133 -0
- package/lib-module/SideNav/index.js +1 -0
- package/lib-module/Skeleton/Skeleton.js +117 -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 +97 -0
- package/lib-module/Spacer/index.js +2 -0
- package/lib-module/StackView/StackView.js +124 -0
- package/lib-module/StackView/StackWrap.js +48 -0
- package/lib-module/StackView/StackWrap.native.js +3 -0
- package/lib-module/StackView/StackWrapBox.js +114 -0
- package/lib-module/StackView/StackWrapGap.js +58 -0
- package/lib-module/StackView/common.js +32 -0
- package/lib-module/StackView/getStackedContent.js +123 -0
- package/lib-module/StackView/index.js +5 -0
- package/lib-module/StepTracker/Step.js +229 -0
- package/lib-module/StepTracker/StepTracker.js +175 -0
- package/lib-module/StepTracker/dictionary.js +10 -0
- package/lib-module/StepTracker/index.js +2 -0
- package/lib-module/Tabs/Tabs.js +113 -0
- package/lib-module/Tabs/TabsItem.js +215 -0
- package/lib-module/Tabs/index.js +2 -0
- package/lib-module/Tags/Tags.js +238 -0
- package/lib-module/Tags/index.js +2 -0
- package/lib-module/TextInput/TextArea.js +88 -0
- package/lib-module/TextInput/TextInput.js +60 -0
- package/lib-module/TextInput/TextInputBase.js +233 -0
- package/lib-module/TextInput/index.js +3 -0
- package/lib-module/TextInput/propTypes.js +31 -0
- package/lib-module/ThemeProvider/ThemeProvider.js +35 -0
- package/lib-module/ThemeProvider/index.js +6 -0
- package/lib-module/ThemeProvider/useSetTheme.js +22 -0
- package/lib-module/ThemeProvider/useTheme.js +14 -0
- package/lib-module/ThemeProvider/useThemeTokens.js +105 -0
- package/lib-module/ThemeProvider/utils/index.js +2 -0
- package/lib-module/ThemeProvider/utils/styles.js +174 -0
- package/lib-module/ThemeProvider/utils/theme-tokens.js +151 -0
- package/lib-module/ToggleSwitch/ToggleSwitch.js +224 -0
- package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +202 -0
- package/lib-module/ToggleSwitch/index.js +3 -0
- package/lib-module/Tooltip/Backdrop.js +52 -0
- package/lib-module/Tooltip/Backdrop.native.js +43 -0
- package/lib-module/Tooltip/Tooltip.js +332 -0
- package/lib-module/Tooltip/dictionary.js +8 -0
- package/lib-module/Tooltip/getTooltipPosition.js +164 -0
- package/lib-module/Tooltip/index.js +2 -0
- package/lib-module/TooltipButton/TooltipButton.js +71 -0
- package/lib-module/TooltipButton/index.js +2 -0
- package/lib-module/Typography/Typography.js +118 -0
- package/lib-module/Typography/index.js +2 -0
- package/lib-module/ViewportProvider/ViewportProvider.js +28 -0
- package/lib-module/ViewportProvider/index.js +3 -0
- package/lib-module/ViewportProvider/useViewport.js +3 -0
- package/lib-module/ViewportProvider/useViewportListener.js +43 -0
- package/lib-module/index.js +48 -0
- package/lib-module/utils/a11y/index.js +2 -0
- package/lib-module/utils/a11y/semantics.js +154 -0
- package/lib-module/utils/a11y/textSize.js +34 -0
- package/lib-module/utils/animation/index.js +2 -0
- package/lib-module/utils/animation/useVerticalExpandAnimation.js +49 -0
- package/lib-module/utils/children.js +118 -0
- package/lib-module/utils/index.js +15 -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 +180 -0
- package/lib-module/utils/pressability.js +97 -0
- package/lib-module/utils/props/a11yProps.js +140 -0
- package/lib-module/utils/props/clickProps.js +25 -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 +6 -0
- package/lib-module/utils/props/hrefAttrsProp.js +30 -0
- package/lib-module/utils/props/index.js +16 -0
- package/lib-module/utils/props/inputSupportsProps.js +54 -0
- package/lib-module/utils/props/linkProps.js +47 -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/tokens.js +120 -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 +35 -0
- package/lib-module/utils/useCopy.js +42 -0
- package/lib-module/utils/useHash.js +44 -0
- package/lib-module/utils/useHash.native.js +7 -0
- package/lib-module/utils/useResponsiveProp.js +47 -0
- package/lib-module/utils/useSpacingScale.js +123 -0
- package/lib-module/utils/useUniqueId.js +12 -0
- package/lib-module/utils/withLinkRouter.js +82 -0
- package/package.json +9 -5
- package/src/A11yText/index.jsx +7 -3
- package/src/ActivityIndicator/Spinner.jsx +56 -44
- package/src/ActivityIndicator/Spinner.native.jsx +20 -12
- package/src/Box/Box.jsx +10 -9
- package/src/Button/ButtonBase.jsx +9 -8
- package/src/Card/Card.jsx +7 -4
- package/src/Card/PressableCardBase.jsx +12 -12
- package/src/Checkbox/Checkbox.jsx +12 -5
- package/src/Divider/Divider.jsx +17 -10
- package/src/ExpandCollapse/Control.jsx +12 -7
- package/src/ExpandCollapse/ExpandCollapse.jsx +13 -3
- package/src/ExpandCollapse/Panel.jsx +15 -5
- package/src/Feedback/Feedback.jsx +13 -3
- package/src/Fieldset/Fieldset.jsx +1 -1
- package/src/HorizontalScroll/HorizontalScroll.jsx +12 -5
- package/src/IconButton/IconButton.jsx +12 -8
- package/src/InputLabel/InputLabel.jsx +16 -2
- package/src/InputSupports/InputSupports.jsx +1 -1
- package/src/Link/LinkBase.jsx +10 -9
- package/src/List/List.jsx +12 -5
- package/src/List/ListItem.jsx +16 -2
- package/src/Modal/Modal.jsx +63 -50
- package/src/Notification/Notification.jsx +17 -3
- package/src/Pagination/Pagination.jsx +10 -3
- package/src/Progress/Progress.jsx +5 -3
- package/src/Progress/ProgressBar.jsx +8 -6
- package/src/Radio/Radio.jsx +13 -5
- package/src/Radio/RadioButton.jsx +13 -3
- package/src/Radio/RadioGroup.jsx +14 -2
- package/src/RadioCard/RadioCard.jsx +9 -6
- package/src/RadioCard/RadioCardGroup.jsx +16 -4
- package/src/Search/Search.jsx +15 -3
- package/src/Select/Select.jsx +21 -7
- package/src/SideNav/Item.jsx +15 -7
- package/src/SideNav/SideNav.jsx +13 -2
- package/src/Skeleton/Skeleton.jsx +55 -43
- package/src/Spacer/Spacer.jsx +8 -16
- package/src/StackView/StackView.jsx +13 -12
- package/src/StackView/StackWrapBox.jsx +12 -12
- package/src/StackView/StackWrapGap.jsx +9 -7
- package/src/StepTracker/Step.jsx +7 -4
- package/src/StepTracker/StepTracker.jsx +8 -8
- package/src/Tabs/Tabs.jsx +16 -3
- package/src/Tabs/TabsItem.jsx +13 -9
- package/src/Tags/Tags.jsx +20 -5
- package/src/TextInput/TextArea.jsx +20 -8
- package/src/TextInput/TextInput.jsx +20 -8
- package/src/TextInput/TextInputBase.jsx +13 -3
- package/src/ToggleSwitch/ToggleSwitch.jsx +16 -5
- package/src/ToggleSwitch/ToggleSwitchGroup.jsx +14 -6
- package/src/Tooltip/Tooltip.jsx +13 -3
- package/src/TooltipButton/TooltipButton.jsx +6 -4
- package/src/Typography/Typography.jsx +10 -6
- package/src/index.js +1 -1
- package/src/utils/children.jsx +2 -1
- package/src/utils/index.js +1 -0
- package/src/utils/props/index.js +1 -0
- package/src/{InputSupports/propTypes.js → utils/props/inputSupportsProps.js} +2 -4
- package/src/utils/ssr.js +35 -0
- package/release-context.json +0 -7
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
4
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
5
|
+
import View from "react-native-web/dist/exports/View";
|
|
6
|
+
import InputLabel from '../InputLabel';
|
|
7
|
+
import ButtonBase from '../Button/ButtonBase';
|
|
8
|
+
import StackView from '../StackView';
|
|
9
|
+
import { useThemeTokensCallback, applyShadowToken } from '../ThemeProvider';
|
|
10
|
+
import { a11yProps, getTokensPropType, selectTokens, pressProps, selectSystemProps, useUniqueId, variantProp, viewProps } from '../utils';
|
|
11
|
+
import { useInputValue } from '../utils/input';
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, pressProps, viewProps]);
|
|
15
|
+
|
|
16
|
+
const selectButtonTokens = tokens => selectTokens('Button', { ...tokens,
|
|
17
|
+
// Width tokens are applied to our inner track. Disable Button width token so it wraps our track width.
|
|
18
|
+
width: null
|
|
19
|
+
}); // Map and rename icon-specific tokens to name used within Icon
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const selectIconTokens = ({
|
|
23
|
+
iconSize,
|
|
24
|
+
iconColor
|
|
25
|
+
}) => ({
|
|
26
|
+
size: iconSize,
|
|
27
|
+
color: iconColor
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const selectTrackStyles = ({
|
|
31
|
+
trackBorderWidth,
|
|
32
|
+
trackBorderColor,
|
|
33
|
+
trackBorderRadius,
|
|
34
|
+
width
|
|
35
|
+
}) => ({
|
|
36
|
+
borderWidth: trackBorderWidth,
|
|
37
|
+
borderColor: trackBorderColor,
|
|
38
|
+
borderRadius: trackBorderRadius,
|
|
39
|
+
width
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const selectSwitchStyles = ({
|
|
43
|
+
switchSize,
|
|
44
|
+
switchColor,
|
|
45
|
+
switchBorderWidth,
|
|
46
|
+
switchBorderColor,
|
|
47
|
+
switchBorderRadius,
|
|
48
|
+
switchShadow
|
|
49
|
+
}) => ({
|
|
50
|
+
width: switchSize,
|
|
51
|
+
height: switchSize,
|
|
52
|
+
backgroundColor: switchColor,
|
|
53
|
+
borderWidth: switchBorderWidth,
|
|
54
|
+
borderColor: switchBorderColor,
|
|
55
|
+
borderRadius: switchBorderRadius,
|
|
56
|
+
...applyShadowToken(switchShadow),
|
|
57
|
+
...Platform.select({
|
|
58
|
+
// TODO: https://github.com/telus/universal-design-system/issues/487
|
|
59
|
+
web: {
|
|
60
|
+
transition: 'transform 200ms'
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const selectLabelStyles = ({
|
|
66
|
+
labelMarginLeft
|
|
67
|
+
}) => ({
|
|
68
|
+
marginLeft: labelMarginLeft
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const selectLabelTokens = ({
|
|
72
|
+
labelColor,
|
|
73
|
+
labelFontName,
|
|
74
|
+
labelFontSize,
|
|
75
|
+
labelFontWeight,
|
|
76
|
+
labelLineHeight
|
|
77
|
+
}) => ({
|
|
78
|
+
color: labelColor,
|
|
79
|
+
fontName: labelFontName,
|
|
80
|
+
fontWeight: labelFontWeight,
|
|
81
|
+
fontSize: labelFontSize,
|
|
82
|
+
lineHeight: labelLineHeight
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const ToggleSwitch = /*#__PURE__*/forwardRef(({
|
|
86
|
+
value,
|
|
87
|
+
initialValue,
|
|
88
|
+
onChange,
|
|
89
|
+
id,
|
|
90
|
+
label,
|
|
91
|
+
inactive,
|
|
92
|
+
tokens,
|
|
93
|
+
tooltip,
|
|
94
|
+
variant,
|
|
95
|
+
accessibilityRole = 'switch',
|
|
96
|
+
accessibilityLabel = label,
|
|
97
|
+
...rest
|
|
98
|
+
}, ref) => {
|
|
99
|
+
const getTokens = useThemeTokensCallback('ToggleSwitch', tokens, variant);
|
|
100
|
+
const themeTokens = getTokens();
|
|
101
|
+
const {
|
|
102
|
+
currentValue,
|
|
103
|
+
setValue
|
|
104
|
+
} = useInputValue({
|
|
105
|
+
value,
|
|
106
|
+
initialValue,
|
|
107
|
+
onChange
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const handlePress = event => setValue(!currentValue, event);
|
|
111
|
+
|
|
112
|
+
const getButtonTokens = buttonState => selectButtonTokens(getTokens(buttonState));
|
|
113
|
+
|
|
114
|
+
const uniqueId = useUniqueId('toggleSwitch');
|
|
115
|
+
const inputId = id ?? uniqueId;
|
|
116
|
+
return /*#__PURE__*/_jsxs(StackView, {
|
|
117
|
+
space: 2,
|
|
118
|
+
direction: "row",
|
|
119
|
+
children: [Boolean(label) && /*#__PURE__*/_jsx(View, {
|
|
120
|
+
style: selectLabelStyles(themeTokens),
|
|
121
|
+
children: /*#__PURE__*/_jsx(InputLabel, {
|
|
122
|
+
forId: inputId,
|
|
123
|
+
label: label,
|
|
124
|
+
tokens: selectLabelTokens(themeTokens),
|
|
125
|
+
tooltip: tooltip
|
|
126
|
+
})
|
|
127
|
+
}), /*#__PURE__*/_jsx(ButtonBase, {
|
|
128
|
+
id: id,
|
|
129
|
+
ref: ref,
|
|
130
|
+
selected: currentValue,
|
|
131
|
+
inactive: inactive,
|
|
132
|
+
tokens: getButtonTokens,
|
|
133
|
+
accessibilityLabel: accessibilityLabel,
|
|
134
|
+
accessibilityRole: accessibilityRole,
|
|
135
|
+
accessibilityState: {
|
|
136
|
+
checked: currentValue
|
|
137
|
+
},
|
|
138
|
+
onPress: handlePress,
|
|
139
|
+
...selectProps(rest),
|
|
140
|
+
children: buttonState => {
|
|
141
|
+
const stateTokens = getTokens(buttonState);
|
|
142
|
+
const IconComponent = stateTokens.icon;
|
|
143
|
+
const switchStyles = selectSwitchStyles(stateTokens);
|
|
144
|
+
const trackStyles = selectTrackStyles(stateTokens);
|
|
145
|
+
const iconTokens = selectIconTokens(stateTokens); // If drag-slide support is needed, use a PanResponder and apply these to an Animated value.
|
|
146
|
+
// Use translate transforms for smoothest non-thread-blocking animations and to allow drag.
|
|
147
|
+
|
|
148
|
+
const slideStart = 0;
|
|
149
|
+
const slideEnd = stateTokens.width - stateTokens.switchSize - stateTokens.trackBorderWidth * 2;
|
|
150
|
+
const switchOffset = buttonState.selected ? slideEnd : slideStart;
|
|
151
|
+
const switchPositionStyle = {
|
|
152
|
+
transform: [{
|
|
153
|
+
translateX: switchOffset
|
|
154
|
+
}]
|
|
155
|
+
};
|
|
156
|
+
return /*#__PURE__*/_jsx(View, {
|
|
157
|
+
style: [staticStyles.track, trackStyles],
|
|
158
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
159
|
+
style: [staticStyles.switch, switchStyles, switchPositionStyle],
|
|
160
|
+
children: IconComponent && /*#__PURE__*/_jsx(IconComponent, { ...iconTokens
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
})]
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
ToggleSwitch.displayName = 'ToggleSwitch';
|
|
169
|
+
ToggleSwitch.propTypes = { ...selectedSystemPropTypes,
|
|
170
|
+
tokens: getTokensPropType('ToggleSwitch'),
|
|
171
|
+
variant: variantProp.propType,
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* If this is a "controlled" component and a parent handles its selected state,
|
|
175
|
+
* tells the switch if it is on (true) or off (false).
|
|
176
|
+
*/
|
|
177
|
+
value: PropTypes.bool,
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* If this is an "uncontrolled" component that handles its own selected state,
|
|
181
|
+
* optionally tells the switch if it should default to on (true) or off (false).
|
|
182
|
+
*/
|
|
183
|
+
initialValue: PropTypes.bool,
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Function called when the switch is toggled, with one boolean argument that is the
|
|
187
|
+
* new position of the switch, on (true) or off (false). For "controlled" components,
|
|
188
|
+
* this should always be passed and used to control the state of the switch.
|
|
189
|
+
*/
|
|
190
|
+
onChange: PropTypes.func,
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Input ID.
|
|
194
|
+
*/
|
|
195
|
+
id: PropTypes.string,
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* An optional label.
|
|
199
|
+
*/
|
|
200
|
+
label: PropTypes.string,
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* If passed, the switch does not respond to user input and may recieve different
|
|
204
|
+
* theme tokens if the theme supports inactive appearance.
|
|
205
|
+
*/
|
|
206
|
+
inactive: PropTypes.bool,
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Content of an optional Tooltip. If set, a tooltip button will be shown next to the label.
|
|
210
|
+
*/
|
|
211
|
+
tooltip: PropTypes.string
|
|
212
|
+
};
|
|
213
|
+
const staticStyles = StyleSheet.create({
|
|
214
|
+
track: {
|
|
215
|
+
flexGrow: 1,
|
|
216
|
+
alignSelf: 'stretch',
|
|
217
|
+
flexDirection: 'row'
|
|
218
|
+
},
|
|
219
|
+
switch: {
|
|
220
|
+
alignItems: 'center',
|
|
221
|
+
justifyContent: 'center'
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
export default ToggleSwitch;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import ABBPropTypes from 'airbnb-prop-types';
|
|
4
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
5
|
+
import ToggleSwitch from './ToggleSwitch';
|
|
6
|
+
import Fieldset from '../Fieldset';
|
|
7
|
+
import { getStackedContent } from '../StackView';
|
|
8
|
+
import { useViewport } from '../ViewportProvider';
|
|
9
|
+
import { useThemeTokens } from '../ThemeProvider';
|
|
10
|
+
import { a11yProps, getTokensPropType, pressProps, selectSystemProps, variantProp, viewProps } from '../utils/props';
|
|
11
|
+
import { useMultipleInputValues } from '../utils/input';
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, pressProps, viewProps]);
|
|
14
|
+
const ToggleSwitchGroup = /*#__PURE__*/forwardRef(({
|
|
15
|
+
variant,
|
|
16
|
+
tokens,
|
|
17
|
+
items = [],
|
|
18
|
+
values,
|
|
19
|
+
initialValues,
|
|
20
|
+
maxValues = 1,
|
|
21
|
+
onChange,
|
|
22
|
+
readOnly = false,
|
|
23
|
+
inactive = false,
|
|
24
|
+
feedback,
|
|
25
|
+
hint,
|
|
26
|
+
tooltip,
|
|
27
|
+
legend,
|
|
28
|
+
name: inputGroupName,
|
|
29
|
+
accessibilityRole = maxValues === 1 ? 'radiogroup' // radiogroup is cross-platform; only web aria has generic groups
|
|
30
|
+
: Platform.select({
|
|
31
|
+
web: 'group',
|
|
32
|
+
default: 'none'
|
|
33
|
+
}),
|
|
34
|
+
toggleSwitchTokens,
|
|
35
|
+
validation,
|
|
36
|
+
...rest
|
|
37
|
+
}, ref) => {
|
|
38
|
+
const viewport = useViewport();
|
|
39
|
+
const {
|
|
40
|
+
space,
|
|
41
|
+
fieldSpace
|
|
42
|
+
} = useThemeTokens('ToggleSwitchGroup', tokens, variant, {
|
|
43
|
+
viewport
|
|
44
|
+
});
|
|
45
|
+
const {
|
|
46
|
+
currentValues,
|
|
47
|
+
toggleOneValue
|
|
48
|
+
} = useMultipleInputValues({
|
|
49
|
+
initialValues,
|
|
50
|
+
values,
|
|
51
|
+
maxValues,
|
|
52
|
+
onChange,
|
|
53
|
+
readOnly
|
|
54
|
+
});
|
|
55
|
+
const selectedProps = selectProps({
|
|
56
|
+
accessibilityRole,
|
|
57
|
+
...rest
|
|
58
|
+
});
|
|
59
|
+
const itemA11yRole = selectedProps.accessibilityRole === 'radiogroup' ? 'radio' : 'switch';
|
|
60
|
+
const toggleSwitches = items.map(({
|
|
61
|
+
label,
|
|
62
|
+
id = label,
|
|
63
|
+
accessibilityLabel = label,
|
|
64
|
+
onChange: itemOnChange,
|
|
65
|
+
ref: itemRef,
|
|
66
|
+
tooltip: itemTooltip
|
|
67
|
+
}, index) => {
|
|
68
|
+
const isSelected = currentValues.includes(id);
|
|
69
|
+
|
|
70
|
+
const handleChange = (newCheckedState, event) => {
|
|
71
|
+
if (typeof itemOnChange === 'function') itemOnChange(newCheckedState, event);
|
|
72
|
+
toggleOneValue(id, event);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const itemA11y = {
|
|
76
|
+
accessibilityState: {
|
|
77
|
+
checked: isSelected
|
|
78
|
+
},
|
|
79
|
+
accessibilityRole: itemA11yRole,
|
|
80
|
+
accessibilityLabel,
|
|
81
|
+
...a11yProps.getPositionInSet(items.length, index)
|
|
82
|
+
};
|
|
83
|
+
return /*#__PURE__*/_jsx(ToggleSwitch, {
|
|
84
|
+
id: id,
|
|
85
|
+
ref: itemRef,
|
|
86
|
+
onChange: handleChange,
|
|
87
|
+
tokens: toggleSwitchTokens,
|
|
88
|
+
value: isSelected,
|
|
89
|
+
inactive: inactive,
|
|
90
|
+
label: label,
|
|
91
|
+
tooltip: itemTooltip,
|
|
92
|
+
...itemA11y
|
|
93
|
+
}, id);
|
|
94
|
+
});
|
|
95
|
+
return /*#__PURE__*/_jsx(Fieldset, {
|
|
96
|
+
ref: ref,
|
|
97
|
+
name: inputGroupName,
|
|
98
|
+
legend: legend,
|
|
99
|
+
tooltip: tooltip,
|
|
100
|
+
hint: hint,
|
|
101
|
+
space: fieldSpace,
|
|
102
|
+
feedback: feedback,
|
|
103
|
+
inactive: inactive,
|
|
104
|
+
validation: validation,
|
|
105
|
+
...selectedProps,
|
|
106
|
+
children: getStackedContent(toggleSwitches, {
|
|
107
|
+
space,
|
|
108
|
+
direction: 'column'
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
ToggleSwitchGroup.displayName = 'ToggleSwitchGroup';
|
|
113
|
+
ToggleSwitchGroup.propTypes = { ...selectedSystemPropTypes,
|
|
114
|
+
tokens: getTokensPropType('ToggleSwitchGroup'),
|
|
115
|
+
variant: variantProp.propType,
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The maximum number of items a user may select at once. Defaults to 1 and behaves
|
|
119
|
+
* like radio buttons. To have no limit and allow any number of selections, pass `null`.
|
|
120
|
+
*/
|
|
121
|
+
maxValues: PropTypes.number,
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The options a user may select
|
|
125
|
+
*/
|
|
126
|
+
items: PropTypes.arrayOf(PropTypes.shape({
|
|
127
|
+
/**
|
|
128
|
+
* The text displayed to the user on the label.
|
|
129
|
+
*/
|
|
130
|
+
label: PropTypes.string.isRequired,
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* An optional accessibility label may be passed to each ToggleSwitch
|
|
134
|
+
* and will be applied as normal for a React Native accessibilityLabel prop.
|
|
135
|
+
*/
|
|
136
|
+
accessibilityLabel: PropTypes.string,
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* An optional unique string may be provided to identify this option,
|
|
140
|
+
* which will be used in code and passed to any onChange function.
|
|
141
|
+
* If not provided, the label is used.
|
|
142
|
+
*/
|
|
143
|
+
id: PropTypes.string,
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* An optional ref for one individual ToggleSwitch in the ToggleSwitchGroup
|
|
147
|
+
*/
|
|
148
|
+
ref: ABBPropTypes.ref()
|
|
149
|
+
})),
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* If provided, this function is called when the current selection is changed
|
|
153
|
+
* and is passed an array of the `id`s of all currently selected `items`.
|
|
154
|
+
*/
|
|
155
|
+
onChange: PropTypes.func,
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* If the selected item(s) in the toggle switch group are to be controlled externally by
|
|
159
|
+
* a parent component, pass an array of strings as well as an `onChange` handler.
|
|
160
|
+
* Passing an array for "values" makes the ToggleSwitchGroup a "controlled" component that
|
|
161
|
+
* expects its state to be handled via `onChange` and so doesn't handle it itself.
|
|
162
|
+
*/
|
|
163
|
+
values: PropTypes.arrayOf(PropTypes.string),
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* If `values` is not passed, making the ToggleSwitchGroup an "uncontrolled" component
|
|
167
|
+
* managing its own selected state, a default set of selections may be provided.
|
|
168
|
+
* Changing the `initialValues` does not change the user's selections.
|
|
169
|
+
*/
|
|
170
|
+
initialValues: PropTypes.arrayOf(PropTypes.string),
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Optional additional text giving more detail to help a user make a choice.
|
|
174
|
+
*/
|
|
175
|
+
hint: PropTypes.string,
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Optional tooltip text content to include alongside the legend and hint.
|
|
179
|
+
*/
|
|
180
|
+
tooltip: PropTypes.string,
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* If provided, a Feedback element is rendered containing this text.
|
|
184
|
+
*/
|
|
185
|
+
feedback: PropTypes.string,
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Main text used to describe this group, used in Fieldset's Legend element.
|
|
189
|
+
*/
|
|
190
|
+
legend: PropTypes.string,
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Toggle switch token overrides.
|
|
194
|
+
*/
|
|
195
|
+
toggleSwitchTokens: getTokensPropType('ToggleSwitch'),
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Current validation status of the group, passed to the feedback element if there is one.
|
|
199
|
+
*/
|
|
200
|
+
validation: PropTypes.oneOf(['error', 'success'])
|
|
201
|
+
};
|
|
202
|
+
export default ToggleSwitchGroup;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
function createPortalNode(nodeId) {
|
|
6
|
+
const node = document.createElement('div');
|
|
7
|
+
node.id = nodeId; // we're mimicking React Native's Modal component, except for using an `absolute` position
|
|
8
|
+
// this way the backdrop stays in place when scrolling the window - that's why we need to
|
|
9
|
+
// position it at the scroll position when rendering
|
|
10
|
+
|
|
11
|
+
node.style.cssText = `
|
|
12
|
+
position: absolute;
|
|
13
|
+
top: ${window.scrollY}px;
|
|
14
|
+
left: ${window.scrollX}px;
|
|
15
|
+
right: 0;
|
|
16
|
+
bottom: 0;
|
|
17
|
+
z-index: 9999;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
`;
|
|
20
|
+
document.body.appendChild(node);
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function removePortalNode(nodeId) {
|
|
25
|
+
const node = document.getElementById(nodeId);
|
|
26
|
+
node.parentElement.removeChild(node);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The Web version of Backdrop utilizes React Portal for overlaying page content, so it is
|
|
30
|
+
* dependent on ReactDOM. Tooltip's closing is handled by the onBlur callback of the control.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function Backdrop({
|
|
35
|
+
children
|
|
36
|
+
}) {
|
|
37
|
+
const [portalNode, setPortalNode] = useState();
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const nodeId = `tooltip-backdrop-${Date.now()}`;
|
|
40
|
+
const node = createPortalNode(nodeId);
|
|
41
|
+
setPortalNode(node);
|
|
42
|
+
return () => {
|
|
43
|
+
removePortalNode(nodeId);
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
return portalNode ? /*#__PURE__*/ReactDOM.createPortal(children, portalNode) : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Backdrop.propTypes = {
|
|
50
|
+
children: PropTypes.node
|
|
51
|
+
};
|
|
52
|
+
export default Backdrop;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import TouchableWithoutFeedback from "react-native-web/dist/exports/TouchableWithoutFeedback";
|
|
3
|
+
import Modal from "react-native-web/dist/exports/Modal";
|
|
4
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
5
|
+
import View from "react-native-web/dist/exports/View";
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
/**
|
|
8
|
+
* The Native version of Backdrop utilizes React Native's Modal component for overlaying
|
|
9
|
+
* the app's content, since this is the only reliable to do it. The only drawback of this
|
|
10
|
+
* approach is that a press on the Backdrop will actually stop the press event from propagating,
|
|
11
|
+
* i.e. anything rendered beneath the Backdrop can't be pressed until the Backdrop is closed.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
|
|
16
|
+
function Backdrop({
|
|
17
|
+
onPress,
|
|
18
|
+
children
|
|
19
|
+
}) {
|
|
20
|
+
return /*#__PURE__*/_jsx(Modal, {
|
|
21
|
+
transparent: true,
|
|
22
|
+
children: /*#__PURE__*/_jsx(TouchableWithoutFeedback, {
|
|
23
|
+
onPress: onPress,
|
|
24
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
25
|
+
style: staticStyles.backdrop,
|
|
26
|
+
children: children
|
|
27
|
+
})
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default Backdrop;
|
|
33
|
+
Backdrop.propTypes = {
|
|
34
|
+
onPress: PropTypes.func,
|
|
35
|
+
children: PropTypes.node
|
|
36
|
+
};
|
|
37
|
+
const staticStyles = StyleSheet.create({
|
|
38
|
+
backdrop: {
|
|
39
|
+
flexBasis: '100%',
|
|
40
|
+
backgroundColor: 'rgba(255, 255, 255, 0.5)' // to visually mark that the content beneath is not pressable
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
});
|