@telus-uds/components-base 1.1.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 +8 -0
- package/CHANGELOG.json +38 -0
- package/CHANGELOG.md +35 -2
- package/__fixtures__/Accessible.js +4 -2
- package/__fixtures__/Accessible.native.js +5 -2
- package/__fixtures__/testTheme.js +9 -0
- package/__tests__/ActivityIndicator/ActivityIndicator.test.jsx +35 -0
- package/__tests__/ActivityIndicator/__snapshots__/ActivityIndicator.test.jsx.snap +287 -0
- package/__tests__/FlexGrid/Col.test.jsx +6 -10
- package/__tests__/HorizontalScroll/HorizontalScroll.test.jsx +1 -0
- package/__tests__/ToggleSwitch/ToggleSwitch.test.jsx +10 -0
- package/__tests__/ToggleSwitch/ToggleSwitchGroup.test.jsx +192 -0
- package/__tests__/utils/props.test.js +36 -0
- package/__tests__/utils/semantics.test.jsx +1 -10
- package/babel.config.js +27 -5
- package/component-docs.json +638 -1145
- package/generate-component-docs.js +3 -0
- package/lib/A11yText/index.js +6 -5
- package/lib/ActivityIndicator/Spinner.js +46 -37
- package/lib/ActivityIndicator/Spinner.native.js +26 -15
- package/lib/ActivityIndicator/index.js +3 -3
- package/lib/Box/Box.js +8 -8
- package/lib/Button/Button.js +2 -2
- package/lib/Button/ButtonBase.js +25 -12
- package/lib/Button/ButtonGroup.js +10 -12
- package/lib/Button/ButtonLink.js +4 -4
- package/lib/Button/propTypes.js +4 -2
- package/lib/Card/Card.js +6 -5
- package/lib/Card/CardBase.js +6 -9
- package/lib/Card/PressableCardBase.js +15 -14
- package/lib/Checkbox/Checkbox.js +4 -8
- package/lib/Divider/Divider.js +14 -13
- 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/FlexGrid/FlexGrid.js +4 -4
- package/lib/FlexGrid/helpers/index.js +1 -4
- package/lib/HorizontalScroll/HorizontalScroll.js +5 -6
- package/lib/IconButton/IconButton.js +14 -9
- package/lib/InputLabel/InputLabel.js +7 -2
- package/lib/InputSupports/InputSupports.js +2 -2
- package/lib/Link/LinkBase.js +21 -15
- 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/PageButton.js +3 -1
- package/lib/Pagination/Pagination.js +22 -5
- package/lib/Pagination/SideButton.js +3 -1
- package/lib/Progress/Progress.js +5 -4
- package/lib/Progress/ProgressBar.js +8 -7
- package/lib/Radio/Radio.js +4 -8
- 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 +9 -20
- package/lib/StackView/StackView.js +7 -7
- package/lib/StackView/StackWrapBox.js +6 -7
- package/lib/StackView/StackWrapGap.js +6 -5
- package/lib/StackView/getStackedContent.js +1 -1
- package/lib/StepTracker/Step.js +7 -3
- package/lib/StepTracker/StepTracker.js +7 -7
- package/lib/Tabs/Tabs.js +16 -4
- package/lib/Tabs/TabsItem.js +18 -11
- package/lib/Tags/Tags.js +11 -12
- package/lib/TextInput/TextArea.js +13 -14
- package/lib/TextInput/TextInput.js +13 -14
- package/lib/TextInput/TextInputBase.js +5 -3
- package/lib/ThemeProvider/useThemeTokens.js +3 -3
- package/lib/ThemeProvider/utils/theme-tokens.js +3 -3
- package/lib/ToggleSwitch/ToggleSwitch.js +106 -43
- package/lib/ToggleSwitch/ToggleSwitchGroup.js +228 -0
- package/lib/ToggleSwitch/index.js +14 -4
- 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 +20 -8
- package/lib/utils/a11y/semantics.js +4 -3
- package/lib/utils/children.js +5 -1
- package/lib/utils/index.js +28 -5
- package/lib/utils/pressability.js +2 -2
- package/lib/utils/props/a11yProps.js +153 -0
- package/lib/utils/props/clickProps.js +36 -0
- package/lib/utils/props/componentPropType.js +70 -0
- package/lib/utils/props/copyPropTypes.js +14 -0
- package/lib/utils/props/getPropSelector.js +13 -0
- package/lib/utils/props/hrefAttrsProp.js +41 -0
- package/lib/utils/props/index.js +158 -0
- package/lib/{InputSupports/propTypes.js → utils/props/inputSupportsProps.js} +2 -3
- package/lib/utils/props/linkProps.js +64 -0
- package/lib/utils/props/paddingProp.js +20 -0
- package/lib/utils/props/pressProps.js +57 -0
- package/lib/utils/props/rectProp.js +20 -0
- package/lib/utils/props/responsiveProps.js +40 -0
- package/lib/utils/props/selectSystemProps.js +31 -0
- package/lib/utils/props/spacingProps.js +71 -0
- package/lib/utils/props/tokens.js +145 -0
- package/lib/utils/props/variantProp.js +28 -0
- package/lib/utils/props/viewProps.js +34 -0
- package/lib/utils/ssr.js +51 -0
- package/lib/utils/useResponsiveProp.js +1 -1
- package/lib/utils/useSpacingScale.js +4 -4
- package/lib/utils/withLinkRouter.js +98 -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/ActivityIndicator/index.jsx +1 -1
- package/src/Box/Box.jsx +15 -13
- package/src/Button/Button.jsx +1 -1
- package/src/Button/ButtonBase.jsx +20 -12
- package/src/Button/ButtonGroup.jsx +17 -8
- package/src/Button/ButtonLink.jsx +1 -1
- package/src/Button/propTypes.js +2 -1
- package/src/Card/Card.jsx +7 -4
- package/src/Card/CardBase.jsx +6 -5
- package/src/Card/PressableCardBase.jsx +16 -14
- package/src/Checkbox/Checkbox.jsx +12 -7
- package/src/Divider/Divider.jsx +19 -12
- 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/FlexGrid/FlexGrid.jsx +11 -5
- package/src/FlexGrid/helpers/index.js +1 -3
- package/src/HorizontalScroll/HorizontalScroll.jsx +12 -5
- package/src/IconButton/IconButton.jsx +18 -12
- package/src/InputLabel/InputLabel.jsx +16 -2
- package/src/InputSupports/InputSupports.jsx +1 -1
- package/src/Link/LinkBase.jsx +15 -12
- 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/PageButton.jsx +3 -2
- package/src/Pagination/Pagination.jsx +38 -4
- package/src/Pagination/SideButton.jsx +2 -2
- package/src/Progress/Progress.jsx +5 -3
- package/src/Progress/ProgressBar.jsx +8 -6
- package/src/Radio/Radio.jsx +13 -7
- 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 +10 -18
- package/src/StackView/StackView.jsx +13 -12
- package/src/StackView/StackWrapBox.jsx +12 -12
- package/src/StackView/StackWrapGap.jsx +9 -7
- package/src/StackView/getStackedContent.jsx +1 -1
- package/src/StepTracker/Step.jsx +7 -4
- package/src/StepTracker/StepTracker.jsx +8 -8
- package/src/Tabs/Tabs.jsx +63 -23
- package/src/Tabs/TabsItem.jsx +22 -14
- package/src/Tags/Tags.jsx +16 -7
- package/src/TextInput/TextArea.jsx +20 -8
- package/src/TextInput/TextInput.jsx +20 -8
- package/src/TextInput/TextInputBase.jsx +13 -3
- package/src/ThemeProvider/useThemeTokens.js +3 -3
- package/src/ThemeProvider/utils/theme-tokens.js +3 -3
- package/src/ToggleSwitch/ToggleSwitch.jsx +104 -41
- package/src/ToggleSwitch/ToggleSwitchGroup.jsx +211 -0
- package/src/ToggleSwitch/index.js +2 -1
- 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 +2 -2
- package/src/utils/a11y/semantics.js +3 -2
- package/src/utils/children.jsx +2 -1
- package/src/utils/index.js +3 -1
- package/src/utils/pressability.js +1 -1
- package/src/utils/props/a11yProps.js +151 -0
- package/src/utils/props/clickProps.js +31 -0
- package/src/utils/props/componentPropType.js +67 -0
- package/src/utils/props/copyPropTypes.js +3 -0
- package/src/utils/props/getPropSelector.js +14 -0
- package/src/utils/props/hrefAttrsProp.js +25 -0
- package/src/utils/props/index.js +16 -0
- package/src/{InputSupports/propTypes.js → utils/props/inputSupportsProps.js} +2 -4
- package/src/utils/props/linkProps.js +43 -0
- package/src/utils/props/paddingProp.js +10 -0
- package/src/utils/props/pressProps.js +45 -0
- package/src/utils/props/rectProp.js +10 -0
- package/src/utils/props/responsiveProps.js +30 -0
- package/src/utils/props/selectSystemProps.js +25 -0
- package/src/utils/props/spacingProps.js +58 -0
- package/src/utils/props/tokens.js +150 -0
- package/src/utils/props/variantProp.js +20 -0
- package/src/utils/props/viewProps.js +23 -0
- package/src/utils/ssr.js +35 -0
- package/src/utils/useResponsiveProp.js +1 -1
- package/src/utils/useSpacingScale.js +4 -4
- package/src/utils/withLinkRouter.jsx +68 -0
- package/stories/TextInput/TextArea.stories.jsx +1 -0
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +5 -1
- package/stories/ToggleSwitch/ToggleSwitchGroup.stories.jsx +81 -0
- package/.ultra.cache.json +0 -1
- package/lib/utils/a11y/propTypes.js +0 -61
- package/lib/utils/a11y/propTypes.native.js +0 -47
- package/lib/utils/propTypes.js +0 -541
- package/release-context.json +0 -7
- package/src/utils/a11y/propTypes.js +0 -61
- package/src/utils/a11y/propTypes.native.js +0 -39
- package/src/utils/propTypes.js +0 -531
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import { Platform } from 'react-native'
|
|
3
|
+
import getPropSelector from './getPropSelector'
|
|
4
|
+
|
|
5
|
+
// React Native exports a11y prop definitions as TypeScript Interfaces, but no longer exports PropTypes
|
|
6
|
+
// so we have to define them ourselves.
|
|
7
|
+
const nativeA11yPropTypes = {
|
|
8
|
+
accessible: PropTypes.bool,
|
|
9
|
+
focusable: PropTypes.bool,
|
|
10
|
+
|
|
11
|
+
accessibilityElementsHidden: PropTypes.bool,
|
|
12
|
+
accessibilityHint: PropTypes.string, // react-native-web ignores `accessibilityHint`
|
|
13
|
+
accessibilityIgnoresInvertColors: PropTypes.bool,
|
|
14
|
+
accessibilityLabel: PropTypes.string,
|
|
15
|
+
accessibilityRole: PropTypes.string,
|
|
16
|
+
accessibilityActions: PropTypes.arrayOf(
|
|
17
|
+
PropTypes.shape({
|
|
18
|
+
name: PropTypes.string.isRequired,
|
|
19
|
+
label: PropTypes.string
|
|
20
|
+
})
|
|
21
|
+
),
|
|
22
|
+
accessibilityLiveRegion: PropTypes.oneOf(['none', 'polite', 'assertive']),
|
|
23
|
+
accessibilityState: PropTypes.shape({
|
|
24
|
+
disabled: PropTypes.bool,
|
|
25
|
+
selected: PropTypes.bool,
|
|
26
|
+
checked: PropTypes.oneOf([true, false, 'mixed']),
|
|
27
|
+
busy: PropTypes.bool,
|
|
28
|
+
expanded: PropTypes.bool
|
|
29
|
+
}),
|
|
30
|
+
accessibilityValue: PropTypes.shape({
|
|
31
|
+
min: PropTypes.number,
|
|
32
|
+
max: PropTypes.number,
|
|
33
|
+
now: PropTypes.number,
|
|
34
|
+
text: PropTypes.string
|
|
35
|
+
}),
|
|
36
|
+
accessibilityViewIsModal: PropTypes.bool,
|
|
37
|
+
importantForAccessibility: PropTypes.oneOf(['auto', 'yes', 'no', 'no-hide-descendants']),
|
|
38
|
+
onAccessibilityAction: PropTypes.func,
|
|
39
|
+
onAccessibilityEscape: PropTypes.func,
|
|
40
|
+
onAccessibilityTap: PropTypes.func
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const a11yPropTypes = {
|
|
44
|
+
...nativeA11yPropTypes,
|
|
45
|
+
// React Native Web adds many a11y props that alias aria-* attributes
|
|
46
|
+
// Types based on https://necolas.github.io/react-native-web/docs/accessibility/
|
|
47
|
+
accessibilityActiveDescendant: PropTypes.string,
|
|
48
|
+
accessibilityAtomic: PropTypes.bool,
|
|
49
|
+
accessibilityAutoComplete: PropTypes.string,
|
|
50
|
+
accessibilityBusy: PropTypes.bool,
|
|
51
|
+
accessibilityChecked: PropTypes.oneOf([true, false, 'mixed']),
|
|
52
|
+
accessibilityColumnCount: PropTypes.number,
|
|
53
|
+
accessibilityColumnIndex: PropTypes.number,
|
|
54
|
+
accessibilityColumnSpan: PropTypes.number,
|
|
55
|
+
accessibilityControls: PropTypes.oneOfType([
|
|
56
|
+
PropTypes.string,
|
|
57
|
+
PropTypes.arrayOf(PropTypes.string)
|
|
58
|
+
]),
|
|
59
|
+
accessibilityCurrent: PropTypes.oneOf([true, false, 'page', 'step', 'location', 'date', 'time']),
|
|
60
|
+
accessibilityDescribedBy: PropTypes.oneOfType([
|
|
61
|
+
PropTypes.string,
|
|
62
|
+
PropTypes.arrayOf(PropTypes.string)
|
|
63
|
+
]),
|
|
64
|
+
accessibilityDetails: PropTypes.string,
|
|
65
|
+
accessibilityDisabled: PropTypes.bool,
|
|
66
|
+
accessibilityErrorMessage: PropTypes.string,
|
|
67
|
+
accessibilityExpanded: PropTypes.bool,
|
|
68
|
+
accessibilityFlowTo: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
69
|
+
accessibilityHasPopup: PropTypes.string,
|
|
70
|
+
accessibilityHidden: PropTypes.bool,
|
|
71
|
+
accessibilityInvalid: PropTypes.bool,
|
|
72
|
+
accessibilityKeyShortcuts: PropTypes.string,
|
|
73
|
+
accessibilityLabelledBy: PropTypes.oneOfType([
|
|
74
|
+
PropTypes.string,
|
|
75
|
+
PropTypes.arrayOf(PropTypes.string)
|
|
76
|
+
]),
|
|
77
|
+
accessibilityLevel: PropTypes.number,
|
|
78
|
+
accessibilityModal: PropTypes.bool,
|
|
79
|
+
accessibilityMultiline: PropTypes.bool,
|
|
80
|
+
accessibilityMultiSelectable: PropTypes.bool,
|
|
81
|
+
accessibilityOrientation: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
82
|
+
accessibilityOwns: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
|
|
83
|
+
accessibilityPlaceholder: PropTypes.string,
|
|
84
|
+
accessibilityPosInSet: PropTypes.number,
|
|
85
|
+
accessibilityPressed: PropTypes.bool,
|
|
86
|
+
accessibilityReadOnly: PropTypes.bool,
|
|
87
|
+
accessibilityRequired: PropTypes.bool,
|
|
88
|
+
accessibilityRoleDescription: PropTypes.string,
|
|
89
|
+
accessibilityRowCount: PropTypes.number,
|
|
90
|
+
accessibilityRowIndex: PropTypes.number,
|
|
91
|
+
accessibilityRowSpan: PropTypes.number,
|
|
92
|
+
accessibilitySelected: PropTypes.bool,
|
|
93
|
+
accessibilitySetSize: PropTypes.number,
|
|
94
|
+
accessibilitySort: PropTypes.oneOf(['ascending', 'descending', 'none', 'other']),
|
|
95
|
+
accessibilityValueMax: PropTypes.number,
|
|
96
|
+
accessibilityValueMin: PropTypes.number,
|
|
97
|
+
accessibilityValueNow: PropTypes.number,
|
|
98
|
+
accessibilityValueText: PropTypes.string
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default {
|
|
102
|
+
/**
|
|
103
|
+
* Proptypes for recognised React Native accessiblity (a11y) props.
|
|
104
|
+
* Spread this in the propTypes of components that accept React Native a11y props.
|
|
105
|
+
*/
|
|
106
|
+
types: a11yPropTypes,
|
|
107
|
+
/**
|
|
108
|
+
* Filters a props object, returning only recognised React Native accessiblity (a11y) props.
|
|
109
|
+
*
|
|
110
|
+
* Where components accept React Native a11y props, pass { ...rest } from its props to this,
|
|
111
|
+
* then spread the returned object into the component's props (usually its outer container).
|
|
112
|
+
*/
|
|
113
|
+
select: getPropSelector(a11yPropTypes, /^aria-/),
|
|
114
|
+
/**
|
|
115
|
+
* Use this to disable focus for elements which are visually hidden but still rendered.
|
|
116
|
+
*/
|
|
117
|
+
nonFocusableProps: {
|
|
118
|
+
focusable: false, // for android, and for keyboard nav in web
|
|
119
|
+
...Platform.select({
|
|
120
|
+
web: {
|
|
121
|
+
accessibilityHidden: true // web screenreaders
|
|
122
|
+
},
|
|
123
|
+
android: {
|
|
124
|
+
importantForAccessibility: 'no-hide-descendants'
|
|
125
|
+
},
|
|
126
|
+
ios: {
|
|
127
|
+
accessibilityElementsHidden: true
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
},
|
|
131
|
+
/**
|
|
132
|
+
* Generates an object of platform-appropriate a11y props describing an item that has an
|
|
133
|
+
* ordered position in a set. Examples of usage by accessibility tools includes screenreaders
|
|
134
|
+
* saying "Item X of Y" when this item is select.
|
|
135
|
+
*
|
|
136
|
+
* @param {number} itemsCount - the number of items in the set
|
|
137
|
+
* @param {number} index - the current item's index in the set
|
|
138
|
+
* @returns {object} - platform-applicable a11y props describing this position (if available)
|
|
139
|
+
*/
|
|
140
|
+
getPositionInSet: (itemsCount, index) =>
|
|
141
|
+
Platform.select({
|
|
142
|
+
web: {
|
|
143
|
+
// accessibilityPosInSet etc exists in React Native Web main branch
|
|
144
|
+
// but not in a release compatible with Expo etc; just use `aria-*`
|
|
145
|
+
'aria-setsize': itemsCount,
|
|
146
|
+
'aria-posinset': index + 1
|
|
147
|
+
},
|
|
148
|
+
// No equivalents exist on the native side
|
|
149
|
+
default: {}
|
|
150
|
+
})
|
|
151
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
|
|
3
|
+
const clickHandlerMapping = {
|
|
4
|
+
onClick: 'onPress',
|
|
5
|
+
mouseDown: 'onPressIn',
|
|
6
|
+
mouseUp: 'onPressOut'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
/**
|
|
11
|
+
* Web-oriented HTML click handlers that may be mapped to React Native press handlers
|
|
12
|
+
*/
|
|
13
|
+
types: Object.fromEntries(
|
|
14
|
+
Object.keys(clickHandlerMapping).map((mouseName) => [mouseName, PropTypes.func])
|
|
15
|
+
),
|
|
16
|
+
/**
|
|
17
|
+
* Takes a set of props and converts HTML mouse click oriented event handlers to closest
|
|
18
|
+
* equivalent React Native press event handler.
|
|
19
|
+
*
|
|
20
|
+
* Use this when a component that expects press-oriented props may need to support third-party
|
|
21
|
+
* web-oriented tooling that injects web-oriented event handlers directly. For example, for
|
|
22
|
+
* to support use with NextJS's 'next/link' component, which injects `onClick` prop into its child.
|
|
23
|
+
*/
|
|
24
|
+
toPressProps: (props) =>
|
|
25
|
+
Object.fromEntries(
|
|
26
|
+
Object.entries(props).map(([originalName, value]) => {
|
|
27
|
+
const translatedName = clickHandlerMapping[originalName]
|
|
28
|
+
return translatedName ? [translatedName, value] : [originalName, value]
|
|
29
|
+
})
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a prop type validator which checks whether a prop is either a component or an array of
|
|
3
|
+
* components of a given type, based on their `name` or `displayName` properties.
|
|
4
|
+
* Use an array of strings for `passedName` to accept more than one component type.
|
|
5
|
+
* For an array the validation fails on the first occurrence of an invalid element.
|
|
6
|
+
*
|
|
7
|
+
* @param {string|string[]} passedName
|
|
8
|
+
* @return {function}
|
|
9
|
+
*/
|
|
10
|
+
export default function componentPropType(passedName) {
|
|
11
|
+
const passedNames = typeof passedName === 'string' ? [passedName] : passedName
|
|
12
|
+
|
|
13
|
+
const checkProp = (props, propName, componentName) => {
|
|
14
|
+
if (props[propName] === undefined || props[propName] === null) {
|
|
15
|
+
return undefined
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (Array.isArray(props[propName])) {
|
|
19
|
+
// Iterates through every child and try to find the first element that does not match the passed name
|
|
20
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
21
|
+
return props[propName]
|
|
22
|
+
.map((_, index) => checkProp(props[propName], index, componentName))
|
|
23
|
+
.find(Boolean)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const nameInProp = props[propName].type?.displayName || props[propName].type?.name
|
|
27
|
+
if (!nameInProp || !passedNames.includes(nameInProp)) {
|
|
28
|
+
const propDescription = nameInProp ? `Component ${nameInProp}` : typeof props[propName]
|
|
29
|
+
return new Error(
|
|
30
|
+
`${componentName}: ${propDescription} was passed to \`${propName}\` prop; should be ${passedNames.join(
|
|
31
|
+
' or '
|
|
32
|
+
)}`
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
return undefined
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const checkRequired = (props, propName, componentName) => {
|
|
39
|
+
if (props[propName] === undefined) {
|
|
40
|
+
return new Error(
|
|
41
|
+
`The prop \`${propName}\` is marked as required in \`${componentName}\`, but its value is ${props[propName]}.`
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
return undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const createValidate = (isRequired) => {
|
|
48
|
+
if (isRequired) {
|
|
49
|
+
return (props, propName, componentName) => {
|
|
50
|
+
const checkForError = checkProp(props, propName, componentName)
|
|
51
|
+
|
|
52
|
+
if (checkForError) {
|
|
53
|
+
return checkForError
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return checkRequired(props, propName, componentName)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return checkProp
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const validate = createValidate()
|
|
64
|
+
validate.isRequired = createValidate(true)
|
|
65
|
+
|
|
66
|
+
return validate
|
|
67
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default function getPropSelector(propTypes, regexp) {
|
|
2
|
+
const keys = Object.keys(propTypes)
|
|
3
|
+
return (props) =>
|
|
4
|
+
Object.entries(props).reduce(
|
|
5
|
+
(items, [key, value]) =>
|
|
6
|
+
keys.includes(key) || (regexp && regexp.test(key))
|
|
7
|
+
? {
|
|
8
|
+
...items,
|
|
9
|
+
[key]: value
|
|
10
|
+
}
|
|
11
|
+
: items,
|
|
12
|
+
{}
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
|
|
3
|
+
// Props related to HTML <a> anchor link attributes.
|
|
4
|
+
const targetValues = ['_self', '_blank', '_parent', '_top']
|
|
5
|
+
export default {
|
|
6
|
+
types: {
|
|
7
|
+
// React Native Web >= 0.15.0 supports hrefAttrs prop with only these properties
|
|
8
|
+
// and passes them to <a> if an element has a href prop or accessibilityRole "link"
|
|
9
|
+
download: PropTypes.string,
|
|
10
|
+
rel: PropTypes.string,
|
|
11
|
+
target: PropTypes.oneOf(targetValues)
|
|
12
|
+
},
|
|
13
|
+
/**
|
|
14
|
+
* Takes a props object, bundles any hrefAttrs props present into one object
|
|
15
|
+
* and returns that keyed as `hrefAttrs` and non-hrefAttrs props keyed as `rest`
|
|
16
|
+
*/
|
|
17
|
+
bundle: ({ download, rel, target, ...rest }) => ({
|
|
18
|
+
hrefAttrs: {
|
|
19
|
+
download,
|
|
20
|
+
rel,
|
|
21
|
+
target
|
|
22
|
+
},
|
|
23
|
+
rest
|
|
24
|
+
})
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './tokens'
|
|
2
|
+
export { default as a11yProps } from './a11yProps'
|
|
3
|
+
export { default as clickProps } from './clickProps'
|
|
4
|
+
export { default as copyPropTypes } from './copyPropTypes'
|
|
5
|
+
export { default as componentPropType } from './componentPropType'
|
|
6
|
+
export { default as hrefAttrsProp } from './hrefAttrsProp'
|
|
7
|
+
export { default as inputSupportsProps } from './inputSupportsProps'
|
|
8
|
+
export { default as linkProps } from './linkProps'
|
|
9
|
+
export { default as pressProps } from './pressProps'
|
|
10
|
+
export { default as paddingProp } from './paddingProp'
|
|
11
|
+
export { default as rectProp } from './rectProp'
|
|
12
|
+
export { default as responsiveProps } from './responsiveProps'
|
|
13
|
+
export { default as spacingProps } from './spacingProps'
|
|
14
|
+
export { default as selectSystemProps } from './selectSystemProps'
|
|
15
|
+
export { default as variantProp } from './variantProp'
|
|
16
|
+
export { default as viewProps } from './viewProps'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import PropTypes from 'prop-types'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default {
|
|
4
4
|
types: {
|
|
5
5
|
/**
|
|
6
6
|
* The input label.
|
|
@@ -37,8 +37,6 @@ const inputSupportProps = {
|
|
|
37
37
|
tooltip,
|
|
38
38
|
validation
|
|
39
39
|
},
|
|
40
|
-
rest
|
|
40
|
+
...rest
|
|
41
41
|
})
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
export default inputSupportProps
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Linking, Platform } from 'react-native'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { pressPropTypes } from './pressProps'
|
|
4
|
+
import a11yProps from './a11yProps'
|
|
5
|
+
import hrefAttrsProp from './hrefAttrsProp'
|
|
6
|
+
import getPropSelector from './getPropSelector'
|
|
7
|
+
|
|
8
|
+
const linkPropTypes = {
|
|
9
|
+
...pressPropTypes,
|
|
10
|
+
href: PropTypes.string,
|
|
11
|
+
hrefAttrs: PropTypes.shape(hrefAttrsProp.types),
|
|
12
|
+
...a11yProps.types
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
/**
|
|
17
|
+
* Proptypes for components that, on Web, can output <a href="..."> link elements
|
|
18
|
+
*/
|
|
19
|
+
types: linkPropTypes,
|
|
20
|
+
/**
|
|
21
|
+
* Filters a props object, returning only the platform-relevant link props defined above
|
|
22
|
+
*/
|
|
23
|
+
select: getPropSelector(linkPropTypes),
|
|
24
|
+
/**
|
|
25
|
+
* Turn hrefs into press handlers on Native and throw if not given `onPress` or `href`.
|
|
26
|
+
*
|
|
27
|
+
* @param {({ onPress?: () => void, href?: string })}
|
|
28
|
+
* @returns {(() => void)|undefined} Returns a press handler, or undefined on web if href
|
|
29
|
+
* string is provided. Expects calling component to use href string on web (e.g. in `<a>`).
|
|
30
|
+
*/
|
|
31
|
+
handleHref: ({ onPress, href }) => {
|
|
32
|
+
if (!href && !onPress) {
|
|
33
|
+
throw new Error('handleHref requires either href or onPress')
|
|
34
|
+
}
|
|
35
|
+
return Platform.select({
|
|
36
|
+
web: onPress,
|
|
37
|
+
default: (...args) => {
|
|
38
|
+
if (onPress) onPress(...args)
|
|
39
|
+
if (href) Linking.openURL(href)
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Platform } from 'react-native'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import rectProp from './rectProp'
|
|
4
|
+
import getPropSelector from './getPropSelector'
|
|
5
|
+
|
|
6
|
+
const pressHandlerPropTypes = {
|
|
7
|
+
onPress: PropTypes.func,
|
|
8
|
+
onPressIn: PropTypes.func,
|
|
9
|
+
onPressOut: PropTypes.func,
|
|
10
|
+
...Platform.select({
|
|
11
|
+
web: {
|
|
12
|
+
onMouseEnter: PropTypes.func,
|
|
13
|
+
onMouseLeave: PropTypes.func,
|
|
14
|
+
onFocus: PropTypes.func,
|
|
15
|
+
onBlur: PropTypes.func
|
|
16
|
+
},
|
|
17
|
+
default: {
|
|
18
|
+
onLongPress: PropTypes.func
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const pressPropTypes = {
|
|
24
|
+
...pressHandlerPropTypes,
|
|
25
|
+
disabled: PropTypes.bool,
|
|
26
|
+
...Platform.select({
|
|
27
|
+
web: {},
|
|
28
|
+
default: {
|
|
29
|
+
hitSlop: PropTypes.number,
|
|
30
|
+
pressRetentionOffset: PropTypes.oneOfType([PropTypes.number, rectProp.propType])
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default {
|
|
36
|
+
/**
|
|
37
|
+
* Proptypes for clickable or pressable components, including web-only props
|
|
38
|
+
*/
|
|
39
|
+
types: pressPropTypes,
|
|
40
|
+
/**
|
|
41
|
+
* Filters a props object, returning only the platform-relevant press props defined above
|
|
42
|
+
*/
|
|
43
|
+
select: getPropSelector(pressPropTypes),
|
|
44
|
+
selectHandlers: getPropSelector(pressHandlerPropTypes)
|
|
45
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
|
|
3
|
+
const getByViewport = (propType) => ({
|
|
4
|
+
xs: propType,
|
|
5
|
+
sm: propType,
|
|
6
|
+
md: propType,
|
|
7
|
+
lg: propType,
|
|
8
|
+
xl: propType
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Utilities for props that allow different values to be applied at different viewports.
|
|
13
|
+
*
|
|
14
|
+
* These should apply viewport inheritance such that if a viewport is undefined, the value is
|
|
15
|
+
* taken from the next smallest viewport for which a value is available. For example, a
|
|
16
|
+
* responsive prop { xs: 2, lg: 3 } should apply 2 at sizes sm and md, and 3 at size xl.
|
|
17
|
+
*
|
|
18
|
+
* @property {Function} getByViewport - returns an object where each each viewport has a key
|
|
19
|
+
* containing the provided argument.
|
|
20
|
+
* @property {Function} getTypeByViewport - returns a PropTypes shape validator for an object where
|
|
21
|
+
* each viewport has a key containing the provided proptype.
|
|
22
|
+
* @property {Function} getTypeOptionallyByViewport - returns a PropTypes validator that accepts
|
|
23
|
+
* either the provided proptype on its own, or the output of getTypeByViewport
|
|
24
|
+
*/
|
|
25
|
+
export default {
|
|
26
|
+
getByViewport,
|
|
27
|
+
getTypeByViewport: (propType) => PropTypes.shape(getByViewport(propType)),
|
|
28
|
+
getTypeOptionallyByViewport: (propType) =>
|
|
29
|
+
PropTypes.oneOfType([propType, PropTypes.shape(getByViewport(propType))])
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Returns a selector for requested prop kinds as well as the propTypes for
|
|
2
|
+
// those props merged into one object
|
|
3
|
+
export default function selectSystemProps(systemPropHelpers) {
|
|
4
|
+
const selectProps = (props) =>
|
|
5
|
+
systemPropHelpers.reduce((acc, propHelper) => {
|
|
6
|
+
if (typeof propHelper?.select !== 'function') {
|
|
7
|
+
throw new Error(
|
|
8
|
+
`An invalid system prop helper has been passed to 'selectSystemProps': prop selector ('.select') is missing in ${propHelper}`
|
|
9
|
+
)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return { ...acc, ...propHelper.select(props) }
|
|
13
|
+
}, {})
|
|
14
|
+
const selectedPropTypes = systemPropHelpers.reduce((acc, propHelper) => {
|
|
15
|
+
if (!propHelper?.types) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
`An invalid system prop helper has been passed to 'selectSystemProps': types selector ('.types') is missing in ${propHelper}`
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return { ...acc, ...propHelper.types }
|
|
22
|
+
}, {})
|
|
23
|
+
|
|
24
|
+
return [selectProps, selectedPropTypes]
|
|
25
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import responsiveProps from './responsiveProps'
|
|
3
|
+
import variantProp from './variantProp'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {0|1|2|3|4|5|6|7|8|9|10|11} SpacingIndex - value used to select a size on the spacing scale
|
|
7
|
+
*
|
|
8
|
+
* @typedef SpacingOptions
|
|
9
|
+
* @property {VariantProp} [SpacingOptions.variant] - optional theme scale variants e.g. compact, wide
|
|
10
|
+
* @property {number} [SpacingOptions.size] - optional override to force a particular pixel size
|
|
11
|
+
* @property {number} [SpacingOptions.subtract] - optional number to subtract from final pixel size
|
|
12
|
+
*
|
|
13
|
+
* @typedef SpacingObject
|
|
14
|
+
* @property {SpacingIndex} [SpacingObject.xs] - space scale index to use above xs viewport
|
|
15
|
+
* @property {SpacingIndex} [SpacingObject.sm] - space scale index to use above sm viewport
|
|
16
|
+
* @property {SpacingIndex} [SpacingObject.md] - space scale index to use above md viewport
|
|
17
|
+
* @property {SpacingIndex} [SpacingObject.lg] - space scale index to use above lg viewport
|
|
18
|
+
* @property {SpacingIndex} [SpacingObject.xl] - space scale index to use above xl viewport
|
|
19
|
+
* @property {SpacingIndex} [SpacingObject.space] - space scale index to use at all viewports
|
|
20
|
+
* @property {SpacingOptions} [SpacingObject.options] - optional options for this spacing
|
|
21
|
+
*
|
|
22
|
+
* @typedef {SpacingIndex|SpacingObject} SpacingValue
|
|
23
|
+
*/
|
|
24
|
+
const spacingScale = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
|
|
25
|
+
const spacingIndexPropType = PropTypes.oneOf(spacingScale)
|
|
26
|
+
const spacingObjectPropType = PropTypes.shape({
|
|
27
|
+
...responsiveProps.getByViewport(spacingIndexPropType),
|
|
28
|
+
space: spacingIndexPropType,
|
|
29
|
+
options: PropTypes.shape({
|
|
30
|
+
variant: variantProp.propType,
|
|
31
|
+
size: PropTypes.number
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Components and utilities that assign fixed space between components use a theme-defined spacing scale.
|
|
37
|
+
*
|
|
38
|
+
* They typically take one or more props of the {@link SpacingValue} type and turn it into a pixel size value
|
|
39
|
+
* using the hook `useSpacingScale`, which resolves any options or responsive behaviour and returns the
|
|
40
|
+
* appropriate value from the theme spacing scale.
|
|
41
|
+
*
|
|
42
|
+
* - see /ADRs/inter-component-spacing/README.md - ADR on this structure
|
|
43
|
+
* - see /src/utils/spacing/useSpacingScale.js - hook that processes spacing values
|
|
44
|
+
* - @see {@link SpacingIndex} - themes provide spacing scales of up to 12 sizes with optional theme rules.
|
|
45
|
+
* - @see {@link SpacingValue} - either a simple number referencing an index position on the spacing
|
|
46
|
+
* scale, or an object with an optional `options` key and one or more spacing indexes keyed either by
|
|
47
|
+
* viewports or `space` to apply at all viewports.
|
|
48
|
+
*/
|
|
49
|
+
export default {
|
|
50
|
+
scale: spacingScale,
|
|
51
|
+
types: {
|
|
52
|
+
spacingIndex: spacingIndexPropType,
|
|
53
|
+
spacingObject: spacingObjectPropType,
|
|
54
|
+
|
|
55
|
+
// Most spacing components and utilities take this prop / arg type:
|
|
56
|
+
spacingValue: PropTypes.oneOfType([spacingIndexPropType, spacingObjectPropType])
|
|
57
|
+
}
|
|
58
|
+
}
|