@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,85 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import React, { forwardRef, useState } from 'react';
|
|
3
|
+
import Text from "react-native-web/dist/exports/Text";
|
|
4
|
+
import TouchableWithoutFeedback from "react-native-web/dist/exports/TouchableWithoutFeedback";
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('react-native').PressableProps} PressableProps
|
|
7
|
+
*/
|
|
8
|
+
// TouchableWithoutFeedback and Pressable have similar but not identical props APIs
|
|
9
|
+
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
|
|
12
|
+
const pressablePropsToTouchable = ({
|
|
13
|
+
unstable_pressDelay,
|
|
14
|
+
android_disableSound,
|
|
15
|
+
android_ripple,
|
|
16
|
+
// Unsupported, discard it
|
|
17
|
+
...props
|
|
18
|
+
}) => ({ ...props,
|
|
19
|
+
touchSoundDisabled: android_disableSound,
|
|
20
|
+
delayPressIn: unstable_pressDelay
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* InlinePressable is an alternative to React Native's Pressable that works better when nested
|
|
24
|
+
* inline inside Text. It accepts the same props as React Native's Pressable.
|
|
25
|
+
*
|
|
26
|
+
* There are a lot of React Native bugs around Views/Pressables nested in Text, e.g.:
|
|
27
|
+
*
|
|
28
|
+
* - https://github.com/facebook/react-native/issues/23601#issuecomment-468069822
|
|
29
|
+
* - https://github.com/facebook/react-native/issues/30375
|
|
30
|
+
* - https://github.com/facebook/react-native/issues/31955
|
|
31
|
+
*
|
|
32
|
+
* On Native, these can be avoided using a `Text` wrapped in a `TouchableWithoutFeedback`; the latter
|
|
33
|
+
* injects additional handlers such as onPressIn to `Text`, resulting in a tree that is purely `Text`.
|
|
34
|
+
*
|
|
35
|
+
* Note that this should only be used on Native, not Web, because React Navigation's Web navigation
|
|
36
|
+
* functions don't work in Touchables (but do work in Pressable) due to different event handling.
|
|
37
|
+
*
|
|
38
|
+
* @param {PressableProps} PressableProps
|
|
39
|
+
*/
|
|
40
|
+
// React Native exports prop Types but not propTypes, use JSDoc types here rather than duplicate RN
|
|
41
|
+
// eslint-disable-next-line react/prop-types
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
const InlinePressable = /*#__PURE__*/forwardRef(({
|
|
45
|
+
onPress,
|
|
46
|
+
children,
|
|
47
|
+
style,
|
|
48
|
+
...rest
|
|
49
|
+
}, ref) => {
|
|
50
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
51
|
+
|
|
52
|
+
const handleFocus = () => setIsFocused(true);
|
|
53
|
+
|
|
54
|
+
const handleBlur = () => setIsFocused(false);
|
|
55
|
+
|
|
56
|
+
const [isPressed, setIsPressed] = useState(false);
|
|
57
|
+
|
|
58
|
+
const handlePressIn = () => setIsPressed(true);
|
|
59
|
+
|
|
60
|
+
const handlePressOut = () => setIsPressed(false);
|
|
61
|
+
|
|
62
|
+
const pressState = {
|
|
63
|
+
pressed: isPressed,
|
|
64
|
+
focus: isFocused,
|
|
65
|
+
// limited support on native
|
|
66
|
+
hover: false // not yet supported on native
|
|
67
|
+
|
|
68
|
+
};
|
|
69
|
+
const currentStyle = typeof style === 'function' ? style(pressState) : style;
|
|
70
|
+
return /*#__PURE__*/_jsx(TouchableWithoutFeedback, {
|
|
71
|
+
onPress: onPress,
|
|
72
|
+
onPressIn: handlePressIn,
|
|
73
|
+
onPressOut: handlePressOut,
|
|
74
|
+
onFocus: handleFocus,
|
|
75
|
+
onBlur: handleBlur,
|
|
76
|
+
ref: ref,
|
|
77
|
+
...pressablePropsToTouchable(rest),
|
|
78
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
79
|
+
style: currentStyle,
|
|
80
|
+
children: typeof children === 'function' ? children(pressState) : children
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
InlinePressable.displayName = 'InlinePressable';
|
|
85
|
+
export default InlinePressable;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { useThemeTokensCallback } from '../ThemeProvider';
|
|
3
|
+
import LinkBase from './LinkBase';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
const Link = /*#__PURE__*/forwardRef(({
|
|
6
|
+
href,
|
|
7
|
+
children,
|
|
8
|
+
accessibilityRole = 'link',
|
|
9
|
+
variant = {},
|
|
10
|
+
tokens,
|
|
11
|
+
dataSet,
|
|
12
|
+
...linkProps
|
|
13
|
+
}, ref) => {
|
|
14
|
+
const getTokens = useThemeTokensCallback('Link', tokens, variant);
|
|
15
|
+
return /*#__PURE__*/_jsx(LinkBase, {
|
|
16
|
+
href: href,
|
|
17
|
+
accessibilityRole: accessibilityRole,
|
|
18
|
+
tokens: getTokens,
|
|
19
|
+
ref: ref,
|
|
20
|
+
dataSet: dataSet,
|
|
21
|
+
...linkProps,
|
|
22
|
+
children: children
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
Link.displayName = 'Link';
|
|
26
|
+
Link.propTypes = LinkBase.propTypes;
|
|
27
|
+
export default Link;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import Text from "react-native-web/dist/exports/Text";
|
|
4
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
5
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
6
|
+
import { a11yProps, clickProps, getTokensPropType, hrefAttrsProp, linkProps, selectSystemProps, variantProp, viewProps } from '../utils/props';
|
|
7
|
+
import { resolvePressableTokens } from '../utils/pressability';
|
|
8
|
+
import { withLinkRouter } from '../utils';
|
|
9
|
+
import InlinePressable from './InlinePressable';
|
|
10
|
+
import { applyTextStyles, applyOuterBorder } from '../ThemeProvider';
|
|
11
|
+
import { IconText, iconComponentPropTypes } from '../Icon';
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, linkProps, viewProps]);
|
|
14
|
+
|
|
15
|
+
const selectOuterBorderStyles = ({
|
|
16
|
+
outerBorderColor,
|
|
17
|
+
outerBorderWidth,
|
|
18
|
+
outerBorderGap,
|
|
19
|
+
borderRadius,
|
|
20
|
+
outerBorderOutline
|
|
21
|
+
}) => // A view wrapper with a border on native messes up inline text alignment
|
|
22
|
+
// so for now make focus styles strictly web-only
|
|
23
|
+
Platform.OS === 'web' ? {
|
|
24
|
+
// Allow theme to define outline, or, turn off outline and use border if rounded corners required
|
|
25
|
+
outline: outerBorderOutline,
|
|
26
|
+
...applyOuterBorder({
|
|
27
|
+
outerBorderColor,
|
|
28
|
+
outerBorderWidth,
|
|
29
|
+
outerBorderGap,
|
|
30
|
+
borderRadius
|
|
31
|
+
}),
|
|
32
|
+
// Stops focus ring stretching horizontally if parent has display: block
|
|
33
|
+
// width: fit-content isn't supported on Firefox; can't cascade props like CSS `width: fit-content; width: --moz-fit-content;`
|
|
34
|
+
display: 'inline-flex'
|
|
35
|
+
} : {};
|
|
36
|
+
|
|
37
|
+
const selectTextStyles = ({
|
|
38
|
+
color,
|
|
39
|
+
textLine,
|
|
40
|
+
textLineStyle
|
|
41
|
+
}) => ({
|
|
42
|
+
color,
|
|
43
|
+
textDecorationLine: textLine,
|
|
44
|
+
textDecorationStyle: textLineStyle,
|
|
45
|
+
...Platform.select({
|
|
46
|
+
web: {
|
|
47
|
+
// TODO: https://github.com/telus/universal-design-system/issues/487
|
|
48
|
+
transition: 'color 200ms'
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const selectBlockStyles = ({
|
|
54
|
+
blockFontWeight,
|
|
55
|
+
blockFontSize,
|
|
56
|
+
blockLineHeight,
|
|
57
|
+
blockFontName
|
|
58
|
+
}) => applyTextStyles({
|
|
59
|
+
fontWeight: blockFontWeight,
|
|
60
|
+
fontSize: blockFontSize,
|
|
61
|
+
lineHeight: blockLineHeight,
|
|
62
|
+
fontName: blockFontName
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const selectIconTokens = ({
|
|
66
|
+
color,
|
|
67
|
+
iconSize,
|
|
68
|
+
iconTranslateX,
|
|
69
|
+
iconTranslateY
|
|
70
|
+
}) => ({
|
|
71
|
+
color,
|
|
72
|
+
translateX: iconTranslateX,
|
|
73
|
+
translateY: iconTranslateY,
|
|
74
|
+
size: iconSize
|
|
75
|
+
});
|
|
76
|
+
/**
|
|
77
|
+
* Renders a pressable text link, with optional icon. This is rendered as a block element
|
|
78
|
+
* only (see 'Current Limitations'). On Web, renders an `<a>` anchor tag if `href` is provided.
|
|
79
|
+
*
|
|
80
|
+
* ## Current limitations
|
|
81
|
+
*
|
|
82
|
+
* - Not yet integrated with widely-used Telus navigation packages. This will probably
|
|
83
|
+
* require adding a `navigate` prop that aliases onPress so this can be passed to
|
|
84
|
+
* router's Link components' `Component` or `as` props but this needs testing
|
|
85
|
+
* as part of https://github.com/telus/universal-design-system/issues/24
|
|
86
|
+
*
|
|
87
|
+
* - Doesn't work inline e.g. in paragraphs. Support for inline links in native and
|
|
88
|
+
* web was implemented in https://github.com/telus/universal-design-system/pull/233
|
|
89
|
+
* but removed and will need to be restored at some point. When inline link support
|
|
90
|
+
* is restored, icons in inline links on Android will be slightly off-centre
|
|
91
|
+
* vertically (see )
|
|
92
|
+
*
|
|
93
|
+
* - Doesn't support :visited styles on web. Support for :visited styles was
|
|
94
|
+
* implemented in https://github.com/telus/universal-design-system/pull/234 but
|
|
95
|
+
* dropped in favour of investigating if a full-featured CSS-in-JS package could or
|
|
96
|
+
* should be used more widely (e.g. styled components)
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
const LinkBase = /*#__PURE__*/forwardRef(({
|
|
101
|
+
href,
|
|
102
|
+
icon,
|
|
103
|
+
iconPosition = icon ? 'left' : undefined,
|
|
104
|
+
iconProps,
|
|
105
|
+
variant,
|
|
106
|
+
tokens = {},
|
|
107
|
+
children,
|
|
108
|
+
accessibilityRole = 'link',
|
|
109
|
+
...rawRest
|
|
110
|
+
}, ref) => {
|
|
111
|
+
const {
|
|
112
|
+
onPress,
|
|
113
|
+
...props
|
|
114
|
+
} = clickProps.toPressProps(rawRest);
|
|
115
|
+
const {
|
|
116
|
+
hrefAttrs,
|
|
117
|
+
rest
|
|
118
|
+
} = hrefAttrsProp.bundle(props);
|
|
119
|
+
const selectedProps = selectProps({
|
|
120
|
+
accessibilityRole,
|
|
121
|
+
href,
|
|
122
|
+
onPress: linkProps.handleHref({
|
|
123
|
+
href,
|
|
124
|
+
onPress
|
|
125
|
+
}),
|
|
126
|
+
hrefAttrs,
|
|
127
|
+
...rest
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const resolveLinkTokens = pressState => resolvePressableTokens(tokens, pressState, {
|
|
131
|
+
iconPosition
|
|
132
|
+
}); // On web, this makes focus rings wrap only the link, not the entire block
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
const blockLeftStyle = Platform.OS === 'web' && staticStyles.blockLeft;
|
|
136
|
+
return /*#__PURE__*/_jsx(InlinePressable, { ...selectedProps,
|
|
137
|
+
ref: ref,
|
|
138
|
+
style: linkState => {
|
|
139
|
+
const themeTokens = resolveLinkTokens(linkState);
|
|
140
|
+
const outerBorderStyles = selectOuterBorderStyles(themeTokens);
|
|
141
|
+
const hasIcon = Boolean(icon || themeTokens.icon);
|
|
142
|
+
return [outerBorderStyles, blockLeftStyle, hasIcon && staticStyles.rowContainer];
|
|
143
|
+
},
|
|
144
|
+
children: linkState => {
|
|
145
|
+
const themeTokens = resolveLinkTokens(linkState);
|
|
146
|
+
const textStyles = selectTextStyles(themeTokens);
|
|
147
|
+
const iconTokens = selectIconTokens(themeTokens); // TODO: may need to apply some smarter text inheritance here if inline to avoid native
|
|
148
|
+
// issues like double-application of line heights breaking align-items: baseline
|
|
149
|
+
|
|
150
|
+
const blockTextStyles = selectBlockStyles(themeTokens);
|
|
151
|
+
const IconComponent = icon || themeTokens.icon;
|
|
152
|
+
const {
|
|
153
|
+
iconSpace
|
|
154
|
+
} = themeTokens;
|
|
155
|
+
return /*#__PURE__*/_jsx(IconText, {
|
|
156
|
+
icon: IconComponent,
|
|
157
|
+
iconPosition: iconPosition,
|
|
158
|
+
space: iconSpace,
|
|
159
|
+
iconProps: { ...iconProps,
|
|
160
|
+
tokens: iconTokens
|
|
161
|
+
},
|
|
162
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
163
|
+
style: [textStyles, blockTextStyles, staticStyles.baseline],
|
|
164
|
+
children: children
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
LinkBase.displayName = 'LinkBase';
|
|
171
|
+
LinkBase.propTypes = { ...selectedSystemPropTypes,
|
|
172
|
+
tokens: getTokensPropType('Link'),
|
|
173
|
+
variant: variantProp.propType,
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Optional variant that may be passed down to the link's icon if there is one
|
|
177
|
+
*/
|
|
178
|
+
iconProps: PropTypes.exact(iconComponentPropTypes),
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A function component for an SVG icon to render inside the link. Inherits size and color from
|
|
182
|
+
* the link and any Typography the link is nested inside.
|
|
183
|
+
*/
|
|
184
|
+
icon: PropTypes.func,
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* When `icon` is provided, use `iconPosition` to place the Icon to the left or right side of Link.
|
|
188
|
+
*/
|
|
189
|
+
iconPosition: PropTypes.oneOf(['left', 'right']),
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* On Web if href is passed, React Native Web maps this object's props to
|
|
193
|
+
* `rel`, `target` and `download` attrs.
|
|
194
|
+
*/
|
|
195
|
+
hrefAttrs: PropTypes.shape(hrefAttrsProp.types)
|
|
196
|
+
};
|
|
197
|
+
const staticStyles = StyleSheet.create({
|
|
198
|
+
blockLeft: {
|
|
199
|
+
alignSelf: 'flex-start'
|
|
200
|
+
},
|
|
201
|
+
rowContainer: {
|
|
202
|
+
flexDirection: 'row',
|
|
203
|
+
alignItems: 'center',
|
|
204
|
+
justifyContent: 'flex-start'
|
|
205
|
+
},
|
|
206
|
+
baseline: {
|
|
207
|
+
alignSelf: 'baseline'
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
export default withLinkRouter(LinkBase);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var _TextButton$propTypes;
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { useThemeTokensCallback } from '../ThemeProvider';
|
|
6
|
+
import LinkBase from './LinkBase';
|
|
7
|
+
/**
|
|
8
|
+
* `TextButton` is a button that looks like a Link. It uses the same theming and variants as
|
|
9
|
+
* Link but has the accessibility role of a `Button`. It should be used for actions that
|
|
10
|
+
* take place on the current page, or for navigation within an app.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
const TextButton = /*#__PURE__*/forwardRef(({
|
|
15
|
+
onPress,
|
|
16
|
+
children,
|
|
17
|
+
variant,
|
|
18
|
+
tokens,
|
|
19
|
+
// TODO: this may need to use `link` role on Web in the case of being passed both `href` and
|
|
20
|
+
// `onPress` in an omniplatform app that uses React Navigation's useLinkProps for internal nav.
|
|
21
|
+
accessibilityRole = 'button',
|
|
22
|
+
...linkProps
|
|
23
|
+
}, ref) => {
|
|
24
|
+
const getTokens = useThemeTokensCallback('Link', tokens, variant);
|
|
25
|
+
return /*#__PURE__*/_jsx(LinkBase, {
|
|
26
|
+
onPress: onPress,
|
|
27
|
+
accessibilityRole: accessibilityRole,
|
|
28
|
+
tokens: getTokens,
|
|
29
|
+
ref: ref,
|
|
30
|
+
...linkProps,
|
|
31
|
+
children: children
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
TextButton.displayName = 'TextButton';
|
|
35
|
+
TextButton.propTypes = { ...LinkBase.propTypes,
|
|
36
|
+
onPress: PropTypes.func.isRequired
|
|
37
|
+
}; // Remove incompatible Link prop (if this build includes propTypes)
|
|
38
|
+
// TODO: test if this works with web navigation in omniplatform React Navigation
|
|
39
|
+
// https://github.com/telus/universal-design-system/issues/665
|
|
40
|
+
// eslint-disable-next-line react/forbid-foreign-prop-types
|
|
41
|
+
|
|
42
|
+
if ((_TextButton$propTypes = TextButton.propTypes) !== null && _TextButton$propTypes !== void 0 && _TextButton$propTypes.href) delete TextButton.propTypes.href;
|
|
43
|
+
export default TextButton;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { cloneElement, forwardRef, Children } from 'react';
|
|
2
|
+
import View from "react-native-web/dist/exports/View";
|
|
3
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { a11yProps, componentPropType, getTokensPropType, selectSystemProps, variantProp, viewProps } from '../utils';
|
|
6
|
+
import ListItem from './ListItem';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
9
|
+
/**
|
|
10
|
+
* An unordered List component has a child a ListItem that
|
|
11
|
+
* allows icon, dividers and customized typography
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const List = /*#__PURE__*/forwardRef(({
|
|
15
|
+
children,
|
|
16
|
+
showDivider,
|
|
17
|
+
tokens,
|
|
18
|
+
variant,
|
|
19
|
+
...rest
|
|
20
|
+
}, ref) => {
|
|
21
|
+
const accessibilityRole = Platform.select({
|
|
22
|
+
web: 'list',
|
|
23
|
+
default: 'none'
|
|
24
|
+
});
|
|
25
|
+
const items = Children.map(children, (child, index) => {
|
|
26
|
+
if (child.type.name === ListItem.name) {
|
|
27
|
+
return /*#__PURE__*/cloneElement(child, {
|
|
28
|
+
showDivider,
|
|
29
|
+
isLastItem: index + 1 === Children.count(children),
|
|
30
|
+
tokens,
|
|
31
|
+
variant
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return child;
|
|
36
|
+
});
|
|
37
|
+
return /*#__PURE__*/_jsx(View, {
|
|
38
|
+
ref: ref,
|
|
39
|
+
accessibilityRole: accessibilityRole,
|
|
40
|
+
...selectProps(rest),
|
|
41
|
+
children: items
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
List.displayName = 'List';
|
|
45
|
+
List.propTypes = { ...selectedSystemPropTypes,
|
|
46
|
+
tokens: getTokensPropType('List'),
|
|
47
|
+
variant: variantProp.propType,
|
|
48
|
+
children: componentPropType('ListItem'),
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* In case it is not the last item allow display divider
|
|
52
|
+
*/
|
|
53
|
+
showDivider: PropTypes.bool
|
|
54
|
+
};
|
|
55
|
+
export default List;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import View from "react-native-web/dist/exports/View";
|
|
3
|
+
import Platform from "react-native-web/dist/exports/Platform";
|
|
4
|
+
import StyleSheet from "react-native-web/dist/exports/StyleSheet";
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import { useThemeTokens, applyTextStyles } from '../ThemeProvider';
|
|
7
|
+
import { a11yProps, getTokensPropType, selectSystemProps, variantProp, viewProps, wrapStringsInText } from '../utils';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
|
|
12
|
+
|
|
13
|
+
const selectBulletStyles = ({
|
|
14
|
+
itemBulletWidth,
|
|
15
|
+
itemBulletHeight,
|
|
16
|
+
itemBulletColor
|
|
17
|
+
}) => ({
|
|
18
|
+
width: itemBulletWidth,
|
|
19
|
+
height: itemBulletHeight,
|
|
20
|
+
borderRadius: itemBulletHeight / 2,
|
|
21
|
+
backgroundColor: itemBulletColor
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const selectBulletContainerStyles = ({
|
|
25
|
+
itemBulletContainerWidth,
|
|
26
|
+
itemBulletContainerAlign
|
|
27
|
+
}) => ({
|
|
28
|
+
width: itemBulletContainerWidth,
|
|
29
|
+
alignItems: itemBulletContainerAlign,
|
|
30
|
+
justifyContent: itemBulletContainerAlign
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const selectItemIconTokens = ({
|
|
34
|
+
itemIconSize,
|
|
35
|
+
itemIconColor
|
|
36
|
+
}) => ({
|
|
37
|
+
size: itemIconSize,
|
|
38
|
+
color: itemIconColor
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const selectCommonIconStyles = ({
|
|
42
|
+
iconMarginTop
|
|
43
|
+
}) => ({
|
|
44
|
+
marginTop: iconMarginTop
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const selectSideItemContainerStyles = ({
|
|
48
|
+
listGutter
|
|
49
|
+
}) => ({
|
|
50
|
+
marginRight: listGutter
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const selectItemStyles = ({
|
|
54
|
+
itemFontWeight,
|
|
55
|
+
itemFontSize,
|
|
56
|
+
itemLineHeight,
|
|
57
|
+
itemFontName
|
|
58
|
+
}) => applyTextStyles({
|
|
59
|
+
fontWeight: itemFontWeight,
|
|
60
|
+
fontSize: itemFontSize,
|
|
61
|
+
lineHeight: itemLineHeight,
|
|
62
|
+
fontName: itemFontName
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const selectItemBlockStyles = ({
|
|
66
|
+
interItemMargin
|
|
67
|
+
}) => ({
|
|
68
|
+
marginBottom: interItemMargin
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const selectDividerStyles = ({
|
|
72
|
+
dividerColor,
|
|
73
|
+
dividerSize,
|
|
74
|
+
interItemMarginWithDivider
|
|
75
|
+
}) => ({
|
|
76
|
+
borderBottomWidth: dividerSize,
|
|
77
|
+
borderColor: dividerColor,
|
|
78
|
+
marginBottom: interItemMarginWithDivider,
|
|
79
|
+
paddingBottom: interItemMarginWithDivider
|
|
80
|
+
});
|
|
81
|
+
/**
|
|
82
|
+
* ListItem is responsible for rendering icon or a bullet as side item
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
const ListItem = /*#__PURE__*/forwardRef(({
|
|
87
|
+
tokens,
|
|
88
|
+
variant,
|
|
89
|
+
icon,
|
|
90
|
+
iconColor,
|
|
91
|
+
iconSize,
|
|
92
|
+
showDivider,
|
|
93
|
+
children,
|
|
94
|
+
isLastItem,
|
|
95
|
+
...rest
|
|
96
|
+
}, ref) => {
|
|
97
|
+
const themeTokens = useThemeTokens('List', tokens, variant);
|
|
98
|
+
const itemStyles = selectItemStyles(themeTokens);
|
|
99
|
+
const itemBlockStyles = selectItemBlockStyles(themeTokens);
|
|
100
|
+
const dividerStyles = selectDividerStyles(themeTokens);
|
|
101
|
+
const itemBulletContainerStyles = selectBulletContainerStyles(themeTokens);
|
|
102
|
+
const itemBulletStyles = selectBulletStyles(themeTokens);
|
|
103
|
+
const iconTokens = selectItemIconTokens(themeTokens);
|
|
104
|
+
const commonIconStyles = selectCommonIconStyles(themeTokens);
|
|
105
|
+
const sideItemContainerStyles = selectSideItemContainerStyles(themeTokens);
|
|
106
|
+
const accessibilityRole = Platform.select({
|
|
107
|
+
web: 'listitem',
|
|
108
|
+
default: 'item'
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const renderItem = () => /*#__PURE__*/_jsx(View, {
|
|
112
|
+
style: staticStyles.wrap,
|
|
113
|
+
children: wrapStringsInText(children, {
|
|
114
|
+
style: itemStyles
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* Function responsible returning styling, in case the item is the last shouldn't
|
|
119
|
+
* add extra margin on the bottom, if "showDivider" is true it should add a divider
|
|
120
|
+
* and custom margin and padding, otherwise just adds a margin to the bottom
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
const getContainerStyle = () => {
|
|
125
|
+
if (isLastItem) {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (showDivider) {
|
|
130
|
+
return dividerStyles;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return itemBlockStyles;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Renders item bullet or Icon in case it's defined
|
|
137
|
+
* in case children are string the icon is centered otherwise
|
|
138
|
+
* it will align itself at start of the container
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
const renderMarker = () => {
|
|
143
|
+
const IconComponent = icon || /*#__PURE__*/_jsx(_Fragment, {});
|
|
144
|
+
|
|
145
|
+
if (icon) {
|
|
146
|
+
return /*#__PURE__*/_jsx(View, {
|
|
147
|
+
style: [sideItemContainerStyles, commonIconStyles],
|
|
148
|
+
children: /*#__PURE__*/_jsx(IconComponent, {
|
|
149
|
+
size: iconSize || iconTokens.size,
|
|
150
|
+
color: iconColor || iconTokens.color
|
|
151
|
+
})
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return /*#__PURE__*/_jsx(View, {
|
|
156
|
+
style: [sideItemContainerStyles, itemBulletContainerStyles],
|
|
157
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
158
|
+
style: itemBulletStyles,
|
|
159
|
+
testID: "unordered-item-bullet"
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
165
|
+
ref: ref,
|
|
166
|
+
style: [staticStyles.itemContainer, getContainerStyle()],
|
|
167
|
+
accessibilityRole: accessibilityRole,
|
|
168
|
+
...selectProps(rest),
|
|
169
|
+
children: [renderMarker(), renderItem()]
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
ListItem.displayName = 'ListItem';
|
|
173
|
+
const staticStyles = StyleSheet.create({
|
|
174
|
+
itemContainer: {
|
|
175
|
+
flexDirection: 'row'
|
|
176
|
+
},
|
|
177
|
+
wrap: {
|
|
178
|
+
flex: 1
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
ListItem.propTypes = { ...selectedSystemPropTypes,
|
|
182
|
+
tokens: getTokensPropType('List'),
|
|
183
|
+
variant: variantProp.propType,
|
|
184
|
+
children: PropTypes.node.isRequired,
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Renders side item icon
|
|
188
|
+
*/
|
|
189
|
+
icon: PropTypes.func,
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Will set display icon color
|
|
193
|
+
*/
|
|
194
|
+
iconColor: PropTypes.string,
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Allow the user define the icon size if not defined the theme's file
|
|
198
|
+
*/
|
|
199
|
+
iconSize: PropTypes.number,
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @ignore
|
|
203
|
+
* Defined by parent if it's last item on the list
|
|
204
|
+
*/
|
|
205
|
+
isLastItem: PropTypes.bool,
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @ignore
|
|
209
|
+
* In case it is not the last item allow display divider
|
|
210
|
+
*/
|
|
211
|
+
showDivider: PropTypes.bool
|
|
212
|
+
};
|
|
213
|
+
export default ListItem;
|