@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,113 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Pressable from "react-native-web/dist/exports/Pressable";
|
|
4
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
5
|
+
import { useViewport } from '../ViewportProvider';
|
|
6
|
+
import { applyOuterBorder, validateThemeTokens } from '../ThemeProvider';
|
|
7
|
+
import { a11yProps, clickProps, getTokenNames, getTokensSetPropType, linkProps, resolvePressableState, resolvePressableTokens, selectSystemProps, selectTokens, variantProp, viewProps, withLinkRouter } from '../utils';
|
|
8
|
+
import CardBase from './CardBase';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
11
|
+
const tokenKeys = [...getTokenNames('Card'), // Outer border tokens. TODO: centralise common token sets like these as part of
|
|
12
|
+
// https://github.com/telus/universal-design-system/issues/782
|
|
13
|
+
'outerBorderColor', 'outerBorderWidth', 'outerBorderGap'];
|
|
14
|
+
export const selectPressableCardTokens = tokens => Object.fromEntries(tokenKeys.map(key => [key, tokens[key]]));
|
|
15
|
+
/**
|
|
16
|
+
* A pressable themeless base component that handles pressable states and passes tokens
|
|
17
|
+
* based on these to an outer border and a base Card component. Not intended to be used in
|
|
18
|
+
* apps or sites directly: build themed components on top of this.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const PressableCardBase = /*#__PURE__*/forwardRef(({
|
|
22
|
+
children,
|
|
23
|
+
tokens,
|
|
24
|
+
checked,
|
|
25
|
+
validation,
|
|
26
|
+
inactive,
|
|
27
|
+
href,
|
|
28
|
+
hrefAttrs,
|
|
29
|
+
accessibilityRole = href ? 'link' : undefined,
|
|
30
|
+
...rawRest
|
|
31
|
+
}, ref) => {
|
|
32
|
+
const {
|
|
33
|
+
onPress,
|
|
34
|
+
...rest
|
|
35
|
+
} = clickProps.toPressProps(rawRest);
|
|
36
|
+
const viewport = useViewport();
|
|
37
|
+
const additionalState = {
|
|
38
|
+
checked,
|
|
39
|
+
validation,
|
|
40
|
+
inactive,
|
|
41
|
+
viewport
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const getCardState = pressableState => resolvePressableState(pressableState, additionalState);
|
|
45
|
+
|
|
46
|
+
const getTokens = pressableState => validateThemeTokens(resolvePressableTokens(tokens, pressableState, additionalState), getTokensSetPropType(tokenKeys, {
|
|
47
|
+
requireAll: true
|
|
48
|
+
}), 'PressableCard');
|
|
49
|
+
|
|
50
|
+
const getCardTokens = pressableState => selectTokens('Card', getTokens(pressableState));
|
|
51
|
+
|
|
52
|
+
const getOuterBorderStyle = pressableState => {
|
|
53
|
+
const {
|
|
54
|
+
flex,
|
|
55
|
+
minWidth,
|
|
56
|
+
outerBorderColor,
|
|
57
|
+
outerBorderGap = 0,
|
|
58
|
+
outerBorderWidth = 0,
|
|
59
|
+
borderRadius
|
|
60
|
+
} = getTokens(pressableState);
|
|
61
|
+
return {
|
|
62
|
+
flex,
|
|
63
|
+
minWidth: minWidth + outerBorderGap + outerBorderWidth,
|
|
64
|
+
...applyOuterBorder({
|
|
65
|
+
outerBorderColor,
|
|
66
|
+
outerBorderGap,
|
|
67
|
+
outerBorderWidth,
|
|
68
|
+
borderRadius
|
|
69
|
+
}),
|
|
70
|
+
...Platform.select({
|
|
71
|
+
web: {
|
|
72
|
+
outline: 'none'
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const handleChange = linkProps.handleHref({
|
|
79
|
+
href,
|
|
80
|
+
onPress
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const handleKeyDown = event => {
|
|
84
|
+
// The expected keyboard shortcut for selecting a focused item is the Space key
|
|
85
|
+
if ((event === null || event === void 0 ? void 0 : event.key) === ' ') handleChange(event);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
89
|
+
ref: ref,
|
|
90
|
+
href: href,
|
|
91
|
+
onPress: handleChange,
|
|
92
|
+
onKeyDown: handleKeyDown,
|
|
93
|
+
hrefAttrs: hrefAttrs,
|
|
94
|
+
style: getOuterBorderStyle,
|
|
95
|
+
...selectProps({ ...rest,
|
|
96
|
+
accessibilityRole
|
|
97
|
+
}),
|
|
98
|
+
children: pressableState => /*#__PURE__*/_jsx(CardBase, {
|
|
99
|
+
tokens: getCardTokens(pressableState),
|
|
100
|
+
children: typeof children === 'function' ? children(getCardState(pressableState)) : children
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
PressableCardBase.displayName = 'PressableCardBase';
|
|
105
|
+
PressableCardBase.propTypes = { ...selectedSystemPropTypes,
|
|
106
|
+
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
|
|
107
|
+
tokens: getTokensSetPropType(tokenKeys, {
|
|
108
|
+
requireAll: true,
|
|
109
|
+
allowFunction: true
|
|
110
|
+
}),
|
|
111
|
+
variant: variantProp.propType
|
|
112
|
+
};
|
|
113
|
+
export default withLinkRouter(PressableCardBase);
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
4
|
+
import Pressable from "react-native-web/dist/exports/Pressable";
|
|
5
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
6
|
+
import Text from "react-native-web/dist/exports/Text";
|
|
7
|
+
import View from "react-native-web/dist/exports/View";
|
|
8
|
+
import CheckboxInput from './CheckboxInput';
|
|
9
|
+
import CheckboxLabel from '../InputLabel/LabelContent';
|
|
10
|
+
import Feedback from '../Feedback';
|
|
11
|
+
import StackView from '../StackView';
|
|
12
|
+
import { applyShadowToken, applyTextStyles, useThemeTokensCallback } from '../ThemeProvider';
|
|
13
|
+
import { a11yProps, getTokensPropType, selectSystemProps, useInputValue, variantProp, viewProps } from '../utils';
|
|
14
|
+
import useUniqueId from '../utils/useUniqueId';
|
|
15
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
18
|
+
|
|
19
|
+
const selectInputStyles = ({
|
|
20
|
+
iconBackgroundColor,
|
|
21
|
+
inputBorderColor,
|
|
22
|
+
inputBorderRadius,
|
|
23
|
+
inputBorderWidth,
|
|
24
|
+
inputBackgroundColor,
|
|
25
|
+
inputHeight,
|
|
26
|
+
inputOutlineColor,
|
|
27
|
+
inputOutlineWidth,
|
|
28
|
+
inputShadow,
|
|
29
|
+
inputWidth
|
|
30
|
+
}, isChecked) => ({
|
|
31
|
+
borderColor: inputBorderColor,
|
|
32
|
+
borderWidth: inputBorderWidth,
|
|
33
|
+
borderRadius: inputBorderRadius,
|
|
34
|
+
backgroundColor: isChecked ? iconBackgroundColor : inputBackgroundColor,
|
|
35
|
+
height: inputHeight,
|
|
36
|
+
width: inputWidth,
|
|
37
|
+
...applyShadowToken(inputShadow),
|
|
38
|
+
...Platform.select({
|
|
39
|
+
web: {
|
|
40
|
+
outlineStyle: 'solid',
|
|
41
|
+
outlineColor: inputOutlineColor,
|
|
42
|
+
outlineWidth: inputOutlineWidth
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const selectLabelStyles = ({
|
|
48
|
+
labelColor,
|
|
49
|
+
labelFontName,
|
|
50
|
+
labelFontSize,
|
|
51
|
+
labelFontWeight,
|
|
52
|
+
labelMarginLeft,
|
|
53
|
+
labelLineHeight
|
|
54
|
+
}) => ({
|
|
55
|
+
marginLeft: labelMarginLeft,
|
|
56
|
+
...applyTextStyles({
|
|
57
|
+
color: labelColor,
|
|
58
|
+
fontName: labelFontName,
|
|
59
|
+
fontWeight: labelFontWeight,
|
|
60
|
+
fontSize: labelFontSize,
|
|
61
|
+
lineHeight: labelLineHeight
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const selectIconTokens = ({
|
|
66
|
+
icon,
|
|
67
|
+
iconColor,
|
|
68
|
+
iconSize
|
|
69
|
+
}) => ({
|
|
70
|
+
icon,
|
|
71
|
+
color: iconColor,
|
|
72
|
+
size: iconSize
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const selectFeedbackTokens = ({
|
|
76
|
+
feedbackMarginBottom,
|
|
77
|
+
feedbackMarginTop,
|
|
78
|
+
feedbackPosition
|
|
79
|
+
}) => ({
|
|
80
|
+
feedbackPosition,
|
|
81
|
+
feedbackMarginBottom,
|
|
82
|
+
feedbackMarginTop
|
|
83
|
+
});
|
|
84
|
+
/**
|
|
85
|
+
* Basic Checkbox component.
|
|
86
|
+
*
|
|
87
|
+
* ## Component API
|
|
88
|
+
*
|
|
89
|
+
* Use `label` prop to provide a label for the checkbox.
|
|
90
|
+
* For a disabled `Checkbox` set the `inactive` prop to `true`.
|
|
91
|
+
*
|
|
92
|
+
* ### Controlled version
|
|
93
|
+
*
|
|
94
|
+
* If the checkbox is controlled from outside, it needs to receive `checked` and `onChange` props.
|
|
95
|
+
*
|
|
96
|
+
* ### Uncontrolled version
|
|
97
|
+
*
|
|
98
|
+
* In case of uncontrolled checkbox you can use `defaultChecked` prop to provide the initial value.
|
|
99
|
+
* Whenever the checkbox gets toggled, it calls the `onChange` callback with the new value (boolean).
|
|
100
|
+
*
|
|
101
|
+
* ### Using within forms
|
|
102
|
+
*
|
|
103
|
+
* You can pass `name` and `value` props if you need a particular checkbox to be a part of a group of
|
|
104
|
+
* checkboxes on a form.
|
|
105
|
+
*
|
|
106
|
+
* ### Validation and feedback
|
|
107
|
+
*
|
|
108
|
+
* You can use the `feedback` prop to provide a comment related to the checkbox element. If the comment
|
|
109
|
+
* is related to a validation error, the checkbox and the feedback can be styled accordingly by setting
|
|
110
|
+
* the `error` prop to `true` (can also be done without feedback).
|
|
111
|
+
*
|
|
112
|
+
* ## A11y guidelines
|
|
113
|
+
*
|
|
114
|
+
* Checkbox component accepts all the common accessibility props, but also sets some defaults, including
|
|
115
|
+
* accessibility role `'checkbox'` and accessibility state that depends on the other props (`checked`, `inactive`)
|
|
116
|
+
* or the internal state in case of uncontrolled checkbox.
|
|
117
|
+
*
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
const Checkbox = /*#__PURE__*/forwardRef(({
|
|
122
|
+
checked,
|
|
123
|
+
defaultChecked,
|
|
124
|
+
error = false,
|
|
125
|
+
feedback,
|
|
126
|
+
id,
|
|
127
|
+
inactive,
|
|
128
|
+
label,
|
|
129
|
+
name,
|
|
130
|
+
onChange,
|
|
131
|
+
tokens,
|
|
132
|
+
value,
|
|
133
|
+
variant,
|
|
134
|
+
...rest
|
|
135
|
+
}, ref) => {
|
|
136
|
+
const {
|
|
137
|
+
currentValue: isChecked,
|
|
138
|
+
setValue: setIsChecked,
|
|
139
|
+
isControlled
|
|
140
|
+
} = useInputValue({
|
|
141
|
+
value: checked,
|
|
142
|
+
initialValue: defaultChecked,
|
|
143
|
+
onChange
|
|
144
|
+
}, 'useCheckboxValue');
|
|
145
|
+
const getTokens = useThemeTokensCallback('Checkbox', tokens, {
|
|
146
|
+
checked: isChecked,
|
|
147
|
+
inactive,
|
|
148
|
+
error,
|
|
149
|
+
...variant
|
|
150
|
+
});
|
|
151
|
+
const defaultTokens = getTokens();
|
|
152
|
+
const {
|
|
153
|
+
feedbackMarginBottom,
|
|
154
|
+
feedbackMarginTop,
|
|
155
|
+
feedbackPosition
|
|
156
|
+
} = selectFeedbackTokens(defaultTokens);
|
|
157
|
+
const styles = StyleSheet.create({
|
|
158
|
+
feedbackContainer: {
|
|
159
|
+
marginTop: feedbackMarginTop,
|
|
160
|
+
marginBottom: feedbackMarginBottom
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const handleChange = event => {
|
|
165
|
+
if (!inactive) {
|
|
166
|
+
setIsChecked(!isChecked, event);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const handleKeyDown = event => {
|
|
171
|
+
// The expected keyboard shortcut for activating a checkbox is the Space key
|
|
172
|
+
if ((event === null || event === void 0 ? void 0 : event.key) === ' ') handleChange(event);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const uniqueId = useUniqueId('checkbox');
|
|
176
|
+
const inputId = id ?? uniqueId;
|
|
177
|
+
return /*#__PURE__*/_jsx(View, {
|
|
178
|
+
style: staticStyles.wrapper,
|
|
179
|
+
ref: ref,
|
|
180
|
+
children: /*#__PURE__*/_jsxs(StackView, {
|
|
181
|
+
direction: feedbackPosition === 'top' ? 'column-reverse' : 'column',
|
|
182
|
+
space: 0,
|
|
183
|
+
children: [/*#__PURE__*/_jsx(Pressable, {
|
|
184
|
+
disabled: inactive,
|
|
185
|
+
onKeyDown: handleKeyDown,
|
|
186
|
+
onPress: handleChange,
|
|
187
|
+
accessibilityRole: "checkbox",
|
|
188
|
+
accessibilityState: {
|
|
189
|
+
checked: isChecked,
|
|
190
|
+
disabled: inactive
|
|
191
|
+
},
|
|
192
|
+
...selectProps(rest),
|
|
193
|
+
children: ({
|
|
194
|
+
focused: focus,
|
|
195
|
+
hovered: hover,
|
|
196
|
+
pressed
|
|
197
|
+
}) => {
|
|
198
|
+
const {
|
|
199
|
+
icon: IconComponent,
|
|
200
|
+
...stateTokens
|
|
201
|
+
} = getTokens({
|
|
202
|
+
focus,
|
|
203
|
+
hover,
|
|
204
|
+
pressed
|
|
205
|
+
});
|
|
206
|
+
const iconTokens = selectIconTokens(stateTokens);
|
|
207
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
208
|
+
style: staticStyles.container,
|
|
209
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
210
|
+
style: StyleSheet.flatten([staticStyles.defaultInputStyles, selectInputStyles(stateTokens, isChecked)]),
|
|
211
|
+
testID: "Checkbox-Input",
|
|
212
|
+
children: [/*#__PURE__*/_jsx(CheckboxInput, {
|
|
213
|
+
checked: isChecked,
|
|
214
|
+
defaultChecked: defaultChecked,
|
|
215
|
+
disabled: inactive,
|
|
216
|
+
id: inputId,
|
|
217
|
+
isControlled: isControlled,
|
|
218
|
+
name: name,
|
|
219
|
+
value: value
|
|
220
|
+
}), isChecked && IconComponent && /*#__PURE__*/_jsx(IconComponent, { ...iconTokens,
|
|
221
|
+
testID: "Checkbox-Icon"
|
|
222
|
+
})]
|
|
223
|
+
}), Boolean(label) && /*#__PURE__*/_jsx(Text, {
|
|
224
|
+
style: selectLabelStyles(stateTokens),
|
|
225
|
+
children: /*#__PURE__*/_jsx(CheckboxLabel, {
|
|
226
|
+
forId: inputId,
|
|
227
|
+
children: label
|
|
228
|
+
})
|
|
229
|
+
})]
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}), Boolean(feedback) && /*#__PURE__*/_jsx(View, {
|
|
233
|
+
style: styles.feedbackContainer,
|
|
234
|
+
children: /*#__PURE__*/_jsx(Feedback, {
|
|
235
|
+
title: feedback,
|
|
236
|
+
variant: {
|
|
237
|
+
icon: error === true
|
|
238
|
+
},
|
|
239
|
+
validation: error === true ? 'error' : undefined
|
|
240
|
+
})
|
|
241
|
+
})]
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
Checkbox.displayName = 'Checkbox';
|
|
246
|
+
Checkbox.propTypes = { ...selectedSystemPropTypes,
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Use `checked` for controlled Checkbox. For uncontrolled Checkbox, use the `defaultChecked` prop.
|
|
250
|
+
*/
|
|
251
|
+
checked: PropTypes.bool,
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Use `defaultChecked` to provide the initial value for an uncontrolled Checkbox.
|
|
255
|
+
*/
|
|
256
|
+
defaultChecked: PropTypes.bool,
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* A detailed description of related validation error or additional instructions (depending on the `error` prop).
|
|
260
|
+
*/
|
|
261
|
+
feedback: PropTypes.string,
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Checkbox ID.
|
|
265
|
+
*/
|
|
266
|
+
id: PropTypes.string,
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Whether the corresponding input is disabled or active.
|
|
270
|
+
*/
|
|
271
|
+
inactive: PropTypes.bool,
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* The label.
|
|
275
|
+
*/
|
|
276
|
+
label: PropTypes.string,
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Associate this checkbox with a group (set as the name attribute).
|
|
280
|
+
*/
|
|
281
|
+
name: PropTypes.string,
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Whether the underlying input triggered a validation error or not.
|
|
285
|
+
*/
|
|
286
|
+
error: PropTypes.bool,
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* The value. Must be unique within the group.
|
|
290
|
+
*/
|
|
291
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.bool]),
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Callback called when a controlled checkbox gets interacted with.
|
|
295
|
+
*/
|
|
296
|
+
onChange: PropTypes.func,
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Checkbox tokens.
|
|
300
|
+
*/
|
|
301
|
+
tokens: getTokensPropType('Checkbox'),
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Checkbox variant.
|
|
305
|
+
*/
|
|
306
|
+
variant: variantProp.propType
|
|
307
|
+
};
|
|
308
|
+
export default Checkbox;
|
|
309
|
+
const staticStyles = StyleSheet.create({
|
|
310
|
+
wrapper: {
|
|
311
|
+
backgroundColor: 'transparent'
|
|
312
|
+
},
|
|
313
|
+
container: {
|
|
314
|
+
flexDirection: 'row',
|
|
315
|
+
alignItems: 'center'
|
|
316
|
+
},
|
|
317
|
+
defaultInputStyles: {
|
|
318
|
+
alignItems: 'center',
|
|
319
|
+
justifyContent: 'center'
|
|
320
|
+
}
|
|
321
|
+
});
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import ABBPropTypes from 'airbnb-prop-types';
|
|
4
|
+
import { useViewport } from '../ViewportProvider';
|
|
5
|
+
import { useThemeTokens } from '../ThemeProvider';
|
|
6
|
+
import { getTokensPropType, useMultipleInputValues, variantProp } from '../utils';
|
|
7
|
+
import { getStackedContent } from '../StackView';
|
|
8
|
+
import Checkbox from './Checkbox';
|
|
9
|
+
import Fieldset from '../Fieldset';
|
|
10
|
+
/**
|
|
11
|
+
* A group of Checkboxs that behave as a fieldset. Use when users select any number of choices from options.
|
|
12
|
+
*
|
|
13
|
+
* ## Component API
|
|
14
|
+
*
|
|
15
|
+
* Use the `items` prop to pass an array of objects describing each Checkbox in the group:
|
|
16
|
+
*
|
|
17
|
+
* - `label`: main text passed to CheckboxGroup's `label` prop
|
|
18
|
+
* - `id`: identifier used to store which CheckboxGroup is selected (uses `label` if undefinded)
|
|
19
|
+
* - `onChange`: optional function called on selection, in addition to updating the group's selection state
|
|
20
|
+
*
|
|
21
|
+
* ### Controlled version
|
|
22
|
+
*
|
|
23
|
+
* If the selection state is controlled from outside, it needs to receive `checkedId` and `onChange` props.
|
|
24
|
+
*
|
|
25
|
+
* ### Uncontrolled version
|
|
26
|
+
*
|
|
27
|
+
* If the CheckboxGroup manages its own state, you can use `initialCheckedId` prop to provide the initial value.
|
|
28
|
+
* Whenever the radio card gets toggled, it calls the `onChange` callback with the new value (string).
|
|
29
|
+
*
|
|
30
|
+
* ### Use in forms
|
|
31
|
+
*
|
|
32
|
+
* For web forms, the `name` prop may be used to define the name of the group's `fieldset` and input elements.
|
|
33
|
+
*
|
|
34
|
+
* ### Validation
|
|
35
|
+
*
|
|
36
|
+
* Validation state may be set by passing 'error' or 'success' to the `validation` prop.
|
|
37
|
+
*
|
|
38
|
+
* ## A11y guidelines
|
|
39
|
+
*
|
|
40
|
+
* CheckboxGroup accepts all the common accessibility props, and controls the accessibility state
|
|
41
|
+
* of children like Checkbox and Feedback based on current state.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```jsx
|
|
45
|
+
* <CheckboxGroup
|
|
46
|
+
* initialCheckedId="check1"
|
|
47
|
+
* items={[
|
|
48
|
+
* { label: 'Checkbox 1', id: 'check1' },
|
|
49
|
+
* { label: 'Checkbox 2', id: 'check2' },
|
|
50
|
+
* { label: 'Checkbox 3', id: 'check3' }
|
|
51
|
+
* ]}
|
|
52
|
+
* legend="Checkboxes"
|
|
53
|
+
* hint="Choose from these options"
|
|
54
|
+
* />
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
59
|
+
const CheckboxGroup = /*#__PURE__*/forwardRef(({
|
|
60
|
+
tokens,
|
|
61
|
+
radioTokens,
|
|
62
|
+
variant,
|
|
63
|
+
items = [],
|
|
64
|
+
legend,
|
|
65
|
+
tooltip,
|
|
66
|
+
hint,
|
|
67
|
+
validation,
|
|
68
|
+
feedback,
|
|
69
|
+
initialCheckedIds,
|
|
70
|
+
checkedIds,
|
|
71
|
+
onChange,
|
|
72
|
+
readOnly,
|
|
73
|
+
name: inputGroupName,
|
|
74
|
+
inactive
|
|
75
|
+
}, ref) => {
|
|
76
|
+
const viewport = useViewport();
|
|
77
|
+
const {
|
|
78
|
+
space,
|
|
79
|
+
fieldSpace
|
|
80
|
+
} = useThemeTokens('CheckboxGroup', tokens, variant, {
|
|
81
|
+
viewport
|
|
82
|
+
});
|
|
83
|
+
const {
|
|
84
|
+
currentValues,
|
|
85
|
+
toggleOneValue
|
|
86
|
+
} = useMultipleInputValues({
|
|
87
|
+
values: checkedIds,
|
|
88
|
+
initialValues: initialCheckedIds,
|
|
89
|
+
onChange,
|
|
90
|
+
readOnly: readOnly || inactive
|
|
91
|
+
});
|
|
92
|
+
const checkboxes = items.map(({
|
|
93
|
+
label,
|
|
94
|
+
id,
|
|
95
|
+
onChange: itemOnChange,
|
|
96
|
+
ref: itemRef
|
|
97
|
+
}, index) => {
|
|
98
|
+
const checkboxId = id || `Checkbox[${index}]`;
|
|
99
|
+
|
|
100
|
+
const handleChange = (newCheckedState, event) => {
|
|
101
|
+
if (typeof itemOnChange === 'function') itemOnChange(newCheckedState, event);
|
|
102
|
+
toggleOneValue(checkboxId, event);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return /*#__PURE__*/_jsx(Checkbox, {
|
|
106
|
+
ref: itemRef,
|
|
107
|
+
id: checkboxId,
|
|
108
|
+
checked: currentValues.includes(checkboxId),
|
|
109
|
+
onChange: handleChange,
|
|
110
|
+
inactive: inactive,
|
|
111
|
+
label: label,
|
|
112
|
+
name: inputGroupName,
|
|
113
|
+
tokens: radioTokens,
|
|
114
|
+
variant: variant
|
|
115
|
+
}, checkboxId);
|
|
116
|
+
});
|
|
117
|
+
return /*#__PURE__*/_jsx(Fieldset, {
|
|
118
|
+
ref: ref,
|
|
119
|
+
name: inputGroupName,
|
|
120
|
+
legend: legend,
|
|
121
|
+
tooltip: tooltip,
|
|
122
|
+
hint: hint,
|
|
123
|
+
space: fieldSpace,
|
|
124
|
+
feedback: feedback,
|
|
125
|
+
inactive: inactive,
|
|
126
|
+
validation: validation,
|
|
127
|
+
children: getStackedContent(checkboxes, {
|
|
128
|
+
space,
|
|
129
|
+
direction: 'column'
|
|
130
|
+
})
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
CheckboxGroup.displayName = 'CheckboxGroup';
|
|
134
|
+
CheckboxGroup.propTypes = {
|
|
135
|
+
/**
|
|
136
|
+
* Optional theme token overrides for the outer CheckboxGroup component
|
|
137
|
+
*/
|
|
138
|
+
tokens: getTokensPropType('CheckboxGroup'),
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Optional theme token overrides for each inner Checkbox component
|
|
142
|
+
*/
|
|
143
|
+
radioTokens: getTokensPropType('Checkbox'),
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Theme variants, shared between both CheckboxGroup and Checkbox
|
|
147
|
+
*/
|
|
148
|
+
variant: variantProp.propType,
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Array of objects containing specifics for each Checkbox to be rendered in the group.
|
|
152
|
+
*/
|
|
153
|
+
items: PropTypes.arrayOf(PropTypes.exact({
|
|
154
|
+
label: PropTypes.string,
|
|
155
|
+
id: PropTypes.string,
|
|
156
|
+
onChange: PropTypes.func,
|
|
157
|
+
ref: ABBPropTypes.ref()
|
|
158
|
+
})),
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Main text used to describe this group, used in Fieldset's Legend element.
|
|
162
|
+
*/
|
|
163
|
+
legend: PropTypes.string,
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Optional additional text giving more detail to help a user make a choice.
|
|
167
|
+
*/
|
|
168
|
+
hint: PropTypes.string,
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Optional tooltip text content to include alongside the legend and hint.
|
|
172
|
+
*/
|
|
173
|
+
tooltip: PropTypes.string,
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Current validation status of the group, passed to the feedback element if there is one.
|
|
177
|
+
*/
|
|
178
|
+
validation: PropTypes.oneOf(['error', 'success']),
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* If provided, a Feedback element is rendered containing this text.
|
|
182
|
+
*/
|
|
183
|
+
feedback: PropTypes.string,
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* If provided, the checkboxed with this ids are selected on first render.
|
|
187
|
+
*/
|
|
188
|
+
initialCheckedIds: PropTypes.arrayOf(PropTypes.string),
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* If not undefined, the checkboxes with these ids is selected, and the
|
|
192
|
+
* element's selection state will be controlled by its parent using the `onChange` function.
|
|
193
|
+
*/
|
|
194
|
+
checkedIds: PropTypes.arrayOf(PropTypes.string),
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Function to call on change in selection state. Is required if the selection state is controlled
|
|
198
|
+
* by a parent using checkedId and the input is not readOnly.
|
|
199
|
+
*/
|
|
200
|
+
onChange: PropTypes.func,
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* If true, the radio cards cannot be selected by the user and simply show their current state.
|
|
204
|
+
*/
|
|
205
|
+
readOnly: PropTypes.bool,
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* If true, the checkbox cannot be interacted with, elements are set as `disabled` and if the
|
|
209
|
+
* theme supports `inactive` appearances rules, these are applied.
|
|
210
|
+
*/
|
|
211
|
+
inactive: PropTypes.bool,
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* On Web, this is passed to the `name` attribute of the fieldset and each radio input.
|
|
215
|
+
*/
|
|
216
|
+
name: PropTypes.string
|
|
217
|
+
};
|
|
218
|
+
export default CheckboxGroup;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
/**
|
|
4
|
+
* On Web we need to include an actual input but hide it.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const CheckboxInput = /*#__PURE__*/forwardRef(({
|
|
9
|
+
checked,
|
|
10
|
+
defaultChecked,
|
|
11
|
+
disabled,
|
|
12
|
+
id,
|
|
13
|
+
isControlled,
|
|
14
|
+
name,
|
|
15
|
+
onChange,
|
|
16
|
+
value
|
|
17
|
+
}, ref) => {
|
|
18
|
+
const handleClick = event => {
|
|
19
|
+
// Cancel the click dispatched via the label tag, since it's already wrapped
|
|
20
|
+
// in <Pressable>
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
event.stopPropagation();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return /*#__PURE__*/_jsx("input", {
|
|
26
|
+
checked: isControlled ? checked : undefined,
|
|
27
|
+
defaultChecked: isControlled ? undefined : defaultChecked,
|
|
28
|
+
disabled: disabled,
|
|
29
|
+
hidden: true,
|
|
30
|
+
id: id,
|
|
31
|
+
name: name,
|
|
32
|
+
onChange: onChange,
|
|
33
|
+
onClick: handleClick,
|
|
34
|
+
ref: ref,
|
|
35
|
+
type: "checkbox",
|
|
36
|
+
value: value
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
CheckboxInput.displayName = 'CheckboxInput';
|
|
40
|
+
CheckboxInput.propTypes = {
|
|
41
|
+
checked: PropTypes.bool,
|
|
42
|
+
defaultChecked: PropTypes.bool,
|
|
43
|
+
disabled: PropTypes.bool,
|
|
44
|
+
id: PropTypes.string.isRequired,
|
|
45
|
+
isControlled: PropTypes.bool.isRequired,
|
|
46
|
+
name: PropTypes.string,
|
|
47
|
+
onChange: PropTypes.func,
|
|
48
|
+
value: PropTypes.string
|
|
49
|
+
};
|
|
50
|
+
CheckboxInput.defaultProps = {
|
|
51
|
+
checked: undefined,
|
|
52
|
+
defaultChecked: undefined,
|
|
53
|
+
disabled: false,
|
|
54
|
+
name: undefined,
|
|
55
|
+
onChange: () => {},
|
|
56
|
+
value: undefined
|
|
57
|
+
};
|
|
58
|
+
export default CheckboxInput;
|