@telus-uds/components-base 0.0.2-prerelease.7 → 0.0.2-prerelease.8
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/.ultra.cache.json +1 -1
- package/CHANGELOG.md +27 -0
- package/__fixtures__/Accessible.js +33 -0
- package/__fixtures__/Accessible.native.js +32 -0
- package/__fixtures__/testTheme.js +429 -29
- package/__tests__/ActivityIndicator/ActivityIndicator.test.jsx +1 -1
- package/__tests__/Button/ButtonGroup.test.jsx +2 -2
- package/__tests__/Checkbox/CheckboxGroup.test.jsx +247 -0
- package/__tests__/Icon/Icon.test.jsx +3 -3
- package/__tests__/Modal/Modal.test.jsx +47 -0
- package/__tests__/Notification/Notification.test.jsx +20 -0
- package/__tests__/Pagination/Pagination.test.jsx +2 -2
- package/__tests__/Progress/Progress.test.jsx +79 -0
- package/__tests__/Radio/RadioGroup.test.jsx +221 -0
- package/__tests__/RadioCard/RadioCard.test.jsx +87 -0
- package/__tests__/RadioCard/RadioCardGroup.test.jsx +247 -0
- package/__tests__/Search/Search.test.jsx +72 -0
- package/__tests__/Skeleton/Skeleton.test.jsx +1 -1
- package/__tests__/StepTracker/StepTracker.test.jsx +94 -0
- package/__tests__/Tabs/Tabs.test.jsx +200 -0
- package/__tests__/Tags/Tags.test.jsx +1 -1
- package/__tests__/utils/input.test.js +58 -0
- package/__tests__/utils/useCopy.test.js +14 -3
- package/babel.config.js +20 -0
- package/jest.config.js +1 -1
- package/lib/A11yInfoProvider/index.js +54 -26
- package/lib/A11yText/index.js +37 -14
- package/lib/ActivityIndicator/Spinner.js +78 -0
- package/lib/ActivityIndicator/Spinner.native.js +121 -87
- package/lib/ActivityIndicator/index.js +28 -12
- package/lib/ActivityIndicator/shared.js +27 -12
- package/lib/BaseProvider/index.js +34 -11
- package/lib/Box/Box.js +54 -31
- package/lib/Box/index.js +13 -2
- package/lib/Button/Button.js +32 -11
- package/lib/Button/ButtonBase.js +85 -78
- package/lib/Button/ButtonGroup.js +94 -70
- package/lib/Button/ButtonLink.js +38 -15
- package/lib/Button/index.js +31 -4
- package/lib/Button/propTypes.js +32 -9
- package/lib/Card/Card.js +36 -41
- package/lib/Card/CardBase.js +78 -0
- package/lib/Card/PressableCardBase.js +137 -0
- package/lib/Card/index.js +40 -2
- package/lib/Checkbox/Checkbox.js +139 -103
- package/lib/Checkbox/CheckboxGroup.js +231 -0
- package/lib/Checkbox/CheckboxInput.js +74 -0
- package/lib/Checkbox/CheckboxInput.native.js +9 -1
- package/lib/Checkbox/index.js +21 -2
- package/lib/Divider/Divider.js +50 -24
- package/lib/Divider/index.js +13 -2
- package/lib/ExpandCollapse/Accordion.js +20 -7
- package/lib/ExpandCollapse/Control.js +50 -27
- package/lib/ExpandCollapse/ExpandCollapse.js +41 -24
- package/lib/ExpandCollapse/Panel.js +75 -37
- package/lib/ExpandCollapse/index.js +25 -7
- package/lib/Feedback/Feedback.js +69 -40
- package/lib/Feedback/index.js +13 -2
- package/lib/Fieldset/Fieldset.js +160 -0
- package/lib/Fieldset/FieldsetContainer.js +41 -0
- package/lib/Fieldset/FieldsetContainer.native.js +33 -0
- package/lib/Fieldset/Legend.js +33 -0
- package/lib/Fieldset/Legend.native.js +43 -0
- package/lib/Fieldset/cssReset.js +21 -0
- package/lib/Fieldset/index.js +13 -0
- package/lib/FlexGrid/Col/Col.js +67 -38
- package/lib/FlexGrid/Col/index.js +13 -2
- package/lib/FlexGrid/FlexGrid.js +70 -45
- package/lib/FlexGrid/Row/Row.js +48 -27
- package/lib/FlexGrid/Row/index.js +13 -2
- package/lib/FlexGrid/helpers/index.js +9 -1
- package/lib/FlexGrid/index.js +13 -2
- package/lib/FlexGrid/providers/GutterContext.js +15 -3
- package/lib/Icon/Icon.js +46 -44
- package/lib/Icon/IconText.js +49 -21
- package/lib/Icon/index.js +31 -4
- package/lib/InputLabel/InputLabel.js +70 -36
- package/lib/InputLabel/LabelContent.js +31 -0
- package/lib/InputLabel/LabelContent.native.js +9 -1
- package/lib/InputLabel/index.js +13 -2
- package/lib/InputSupports/InputSupports.js +62 -48
- package/lib/InputSupports/index.js +13 -2
- package/lib/InputSupports/propTypes.js +19 -8
- package/lib/InputSupports/useInputSupports.js +41 -0
- package/lib/Link/ChevronLink.js +33 -16
- package/lib/Link/InlinePressable.js +50 -0
- package/lib/Link/InlinePressable.native.js +34 -11
- package/lib/Link/Link.js +25 -9
- package/lib/Link/LinkBase.js +87 -57
- package/lib/Link/TextButton.js +32 -13
- package/lib/Link/index.js +39 -5
- package/lib/List/List.js +51 -23
- package/lib/List/ListItem.js +70 -40
- package/lib/List/index.js +13 -2
- package/lib/Modal/Modal.js +226 -0
- package/lib/Modal/dictionary.js +16 -0
- package/lib/Modal/index.js +13 -0
- package/lib/Notification/Notification.js +200 -0
- package/lib/Notification/dictionary.js +15 -0
- package/lib/Notification/index.js +13 -0
- package/lib/Pagination/PageButton.js +47 -25
- package/lib/Pagination/Pagination.js +70 -40
- package/lib/Pagination/SideButton.js +63 -37
- package/lib/Pagination/dictionary.js +9 -2
- package/lib/Pagination/index.js +13 -2
- package/lib/Pagination/usePagination.js +12 -2
- package/lib/Progress/Progress.js +99 -0
- package/lib/Progress/ProgressBar.js +146 -0
- package/lib/Progress/ProgressBarBackground.js +57 -0
- package/lib/Progress/index.js +16 -0
- package/lib/Radio/Radio.js +110 -109
- package/lib/Radio/RadioButton.js +141 -0
- package/lib/Radio/RadioGroup.js +233 -0
- package/lib/Radio/RadioInput.js +76 -0
- package/lib/Radio/RadioInput.native.js +9 -1
- package/lib/Radio/index.js +21 -2
- package/lib/RadioCard/RadioCard.js +240 -0
- package/lib/RadioCard/RadioCardGroup.js +251 -0
- package/lib/RadioCard/index.js +21 -0
- package/lib/Search/Search.js +243 -0
- package/lib/Search/dictionary.js +19 -0
- package/lib/Search/index.js +13 -0
- package/lib/Select/Group.js +33 -0
- package/lib/Select/Group.native.js +16 -5
- package/lib/Select/Item.js +29 -0
- package/lib/Select/Item.native.js +14 -4
- package/lib/Select/Picker.js +79 -0
- package/lib/Select/Picker.native.js +52 -24
- package/lib/Select/Select.js +110 -82
- package/lib/Select/index.js +19 -6
- package/lib/SideNav/Item.js +54 -33
- package/lib/SideNav/ItemContent.js +41 -15
- package/lib/SideNav/ItemsGroup.js +46 -27
- package/lib/SideNav/SideNav.js +92 -69
- package/lib/SideNav/index.js +15 -1
- package/lib/Skeleton/Skeleton.js +55 -37
- package/lib/Skeleton/index.js +13 -2
- package/lib/Skeleton/skeleton.constant.js +12 -0
- package/lib/Skeleton/skeletonWebAnimation.js +27 -0
- package/lib/Skeleton/useSkeletonNativeAnimation.js +37 -0
- package/lib/Spacer/Spacer.js +31 -12
- package/lib/Spacer/index.js +13 -2
- package/lib/StackView/StackView.js +49 -27
- package/lib/StackView/StackWrap.js +33 -10
- package/lib/StackView/StackWrap.native.js +13 -2
- package/lib/StackView/StackWrapBox.js +46 -24
- package/lib/StackView/StackWrapGap.js +43 -22
- package/lib/StackView/common.js +19 -4
- package/lib/StackView/getStackedContent.js +49 -19
- package/lib/StackView/index.js +29 -5
- package/lib/StepTracker/Step.js +245 -0
- package/lib/StepTracker/StepTracker.js +197 -0
- package/lib/StepTracker/dictionary.js +17 -0
- package/lib/StepTracker/index.js +13 -0
- package/lib/Tabs/HorizontalScroll.js +199 -0
- package/lib/Tabs/ScrollViewEnd.js +66 -0
- package/lib/Tabs/ScrollViewEnd.native.js +41 -0
- package/lib/Tabs/Tabs.js +117 -0
- package/lib/Tabs/TabsItem.js +234 -0
- package/lib/Tabs/TabsScrollButton.js +121 -0
- package/lib/Tabs/dictionary.js +18 -0
- package/lib/Tabs/index.js +13 -0
- package/lib/Tabs/itemPositions.js +128 -0
- package/lib/Tags/Tags.js +130 -97
- package/lib/Tags/index.js +13 -2
- package/lib/TextInput/TextArea.js +51 -24
- package/lib/TextInput/TextInput.js +40 -19
- package/lib/TextInput/TextInputBase.js +78 -55
- package/lib/TextInput/index.js +23 -3
- package/lib/TextInput/propTypes.js +18 -7
- package/lib/ThemeProvider/ThemeProvider.js +38 -14
- package/lib/ThemeProvider/index.js +61 -6
- package/lib/ThemeProvider/useSetTheme.js +14 -5
- package/lib/ThemeProvider/useTheme.js +13 -4
- package/lib/ThemeProvider/useThemeTokens.js +32 -16
- package/lib/ThemeProvider/utils/index.js +31 -2
- package/lib/ThemeProvider/utils/styles.js +52 -16
- package/lib/ThemeProvider/utils/theme-tokens.js +94 -16
- package/lib/ToggleSwitch/ToggleSwitch.js +75 -51
- package/lib/ToggleSwitch/index.js +13 -2
- package/lib/Tooltip/{Backdrop.web.js → Backdrop.js} +22 -18
- package/lib/Tooltip/Backdrop.native.js +39 -15
- package/lib/Tooltip/Tooltip.js +112 -70
- package/lib/Tooltip/dictionary.js +9 -2
- package/lib/Tooltip/getTooltipPosition.js +9 -1
- package/lib/Tooltip/index.js +13 -2
- package/lib/TooltipButton/TooltipButton.js +57 -38
- package/lib/TooltipButton/index.js +13 -2
- package/lib/Typography/Typography.js +57 -27
- package/lib/Typography/index.js +13 -2
- package/lib/ViewportProvider/ViewportProvider.js +34 -13
- package/lib/ViewportProvider/index.js +28 -3
- package/lib/ViewportProvider/useViewport.js +15 -3
- package/lib/ViewportProvider/useViewportListener.js +24 -10
- package/lib/index.js +509 -33
- package/lib/utils/a11y/index.js +18 -1
- package/lib/utils/a11y/textSize.js +23 -7
- package/lib/utils/animation/index.js +15 -2
- package/lib/utils/animation/useVerticalExpandAnimation.js +28 -11
- package/lib/utils/children.js +87 -0
- package/lib/utils/index.js +163 -10
- package/lib/utils/info/index.js +18 -6
- package/lib/utils/info/platform/index.js +19 -7
- package/lib/utils/info/platform/platform.android.js +8 -1
- package/lib/utils/info/platform/platform.ios.js +8 -1
- package/lib/utils/info/platform/platform.js +8 -0
- package/lib/utils/info/platform/platform.native.js +8 -1
- package/lib/utils/info/versions.js +15 -4
- package/lib/utils/input.js +51 -33
- package/lib/utils/pressability.js +38 -10
- package/lib/utils/propTypes.js +217 -125
- package/lib/utils/useCopy.js +40 -5
- package/lib/utils/useHash.js +48 -0
- package/lib/utils/useHash.native.js +15 -0
- package/lib/utils/useResponsiveProp.js +21 -9
- package/lib/utils/useSpacingScale.js +21 -9
- package/lib/utils/useUniqueId.js +13 -4
- package/package.json +7 -6
- package/release-context.json +4 -4
- package/src/ActivityIndicator/{Spinner.web.jsx → Spinner.jsx} +0 -0
- package/src/Box/Box.jsx +11 -4
- package/src/Button/Button.jsx +3 -2
- package/src/Button/ButtonBase.jsx +27 -36
- package/src/Button/ButtonGroup.jsx +2 -2
- package/src/Button/ButtonLink.jsx +3 -2
- package/src/Button/propTypes.js +12 -2
- package/src/Card/Card.jsx +4 -30
- package/src/Card/CardBase.jsx +57 -0
- package/src/Card/PressableCardBase.jsx +112 -0
- package/src/Card/index.js +3 -0
- package/src/Checkbox/Checkbox.jsx +10 -11
- package/src/Checkbox/CheckboxGroup.jsx +196 -0
- package/src/Checkbox/{CheckboxInput.web.jsx → CheckboxInput.jsx} +0 -0
- package/src/Checkbox/index.js +2 -0
- package/src/ExpandCollapse/Control.jsx +1 -1
- package/src/Feedback/Feedback.jsx +1 -1
- package/src/Fieldset/Fieldset.jsx +129 -0
- package/src/Fieldset/FieldsetContainer.jsx +22 -0
- package/src/Fieldset/FieldsetContainer.native.jsx +16 -0
- package/src/Fieldset/Legend.jsx +16 -0
- package/src/Fieldset/Legend.native.jsx +22 -0
- package/src/Fieldset/cssReset.js +14 -0
- package/src/Fieldset/index.js +3 -0
- package/src/Icon/Icon.jsx +14 -23
- package/src/Icon/IconText.jsx +2 -2
- package/src/Icon/index.js +2 -2
- package/src/InputLabel/InputLabel.jsx +9 -2
- package/src/InputLabel/{LabelContent.web.jsx → LabelContent.jsx} +0 -0
- package/src/InputSupports/InputSupports.jsx +7 -18
- package/src/InputSupports/useInputSupports.js +30 -0
- package/src/Link/{InlinePressable.web.jsx → InlinePressable.jsx} +0 -0
- package/src/Link/LinkBase.jsx +14 -12
- package/src/Modal/Modal.jsx +185 -0
- package/src/Modal/dictionary.js +9 -0
- package/src/Modal/index.js +3 -0
- package/src/Notification/Notification.jsx +149 -0
- package/src/Notification/dictionary.js +8 -0
- package/src/Notification/index.js +3 -0
- package/src/Progress/Progress.jsx +77 -0
- package/src/Progress/ProgressBar.jsx +110 -0
- package/src/Progress/ProgressBarBackground.jsx +34 -0
- package/src/Progress/index.js +6 -0
- package/src/Radio/Radio.jsx +19 -56
- package/src/Radio/RadioButton.jsx +131 -0
- package/src/Radio/RadioGroup.jsx +198 -0
- package/src/Radio/{RadioInput.web.jsx → RadioInput.jsx} +0 -0
- package/src/Radio/index.js +2 -0
- package/src/RadioCard/RadioCard.jsx +191 -0
- package/src/RadioCard/RadioCardGroup.jsx +211 -0
- package/src/RadioCard/index.js +5 -0
- package/src/Search/Search.jsx +204 -0
- package/src/Search/dictionary.js +12 -0
- package/src/Search/index.js +3 -0
- package/src/Select/{Group.web.jsx → Group.jsx} +0 -0
- package/src/Select/{Item.web.jsx → Item.jsx} +0 -0
- package/src/Select/{Picker.web.jsx → Picker.jsx} +0 -0
- package/src/Select/Select.jsx +12 -22
- package/src/SideNav/Item.jsx +2 -2
- package/src/Skeleton/Skeleton.jsx +17 -20
- package/src/Skeleton/skeleton.constant.js +3 -0
- package/src/Skeleton/skeletonWebAnimation.js +13 -0
- package/src/Skeleton/useSkeletonNativeAnimation.js +27 -0
- package/src/StackView/StackView.jsx +10 -3
- package/src/StackView/StackWrap.jsx +9 -1
- package/src/StackView/StackWrapBox.jsx +4 -3
- package/src/StackView/StackWrapGap.jsx +3 -3
- package/src/StackView/getStackedContent.jsx +8 -2
- package/src/StepTracker/Step.jsx +202 -0
- package/src/StepTracker/StepTracker.jsx +163 -0
- package/src/StepTracker/dictionary.js +10 -0
- package/src/StepTracker/index.js +3 -0
- package/src/Tabs/HorizontalScroll.jsx +165 -0
- package/src/Tabs/ScrollViewEnd.jsx +53 -0
- package/src/Tabs/ScrollViewEnd.native.jsx +24 -0
- package/src/Tabs/Tabs.jsx +89 -0
- package/src/Tabs/TabsItem.jsx +204 -0
- package/src/Tabs/TabsScrollButton.jsx +100 -0
- package/src/Tabs/dictionary.js +11 -0
- package/src/Tabs/index.js +3 -0
- package/src/Tabs/itemPositions.js +101 -0
- package/src/Tags/Tags.jsx +2 -1
- package/src/TextInput/TextInputBase.jsx +12 -22
- package/src/ThemeProvider/useThemeTokens.js +2 -2
- package/src/ThemeProvider/utils/styles.js +18 -5
- package/src/ThemeProvider/utils/theme-tokens.js +46 -5
- package/src/ToggleSwitch/ToggleSwitch.jsx +2 -3
- package/src/Tooltip/{Backdrop.web.jsx → Backdrop.jsx} +0 -0
- package/src/Tooltip/Tooltip.jsx +1 -1
- package/src/TooltipButton/TooltipButton.jsx +23 -27
- package/src/Typography/Typography.jsx +6 -5
- package/src/index.js +20 -2
- package/src/utils/children.jsx +66 -0
- package/src/utils/index.js +3 -0
- package/src/utils/info/platform/platform.js +1 -0
- package/src/utils/info/versions.js +2 -2
- package/src/utils/input.js +20 -12
- package/src/utils/pressability.js +4 -0
- package/src/utils/propTypes.js +98 -34
- package/src/utils/useCopy.js +30 -4
- package/src/utils/useHash.js +34 -0
- package/src/utils/useHash.native.js +6 -0
- package/stories/A11yText/A11yText.stories.jsx +4 -8
- package/stories/Checkbox/Checkbox.stories.jsx +24 -1
- package/stories/Icon/Icon.stories.jsx +6 -5
- package/stories/Modal/Modal.stories.jsx +29 -0
- package/stories/Notification/Notification.stories.jsx +82 -0
- package/stories/Progress/Progress.stories.jsx +93 -0
- package/stories/Radio/Radio.stories.jsx +23 -36
- package/stories/RadioCard/RadioCard.stories.jsx +98 -0
- package/stories/Search/Search.stories.jsx +16 -0
- package/stories/StepTracker/StepTracker.stories.jsx +71 -0
- package/stories/Tabs/Tabs.stories.jsx +97 -0
- package/stories/{platform-supports.web.jsx → platform-supports.jsx} +0 -0
- package/__fixtures__/accessible.icon.svg +0 -6
- package/babel.config.json +0 -8
- package/lib/ActivityIndicator/Spinner.web.js +0 -55
- package/lib/Checkbox/CheckboxInput.web.js +0 -57
- package/lib/InputLabel/LabelContent.web.js +0 -17
- package/lib/Link/InlinePressable.web.js +0 -32
- package/lib/Radio/RadioInput.web.js +0 -59
- package/lib/Select/Group.web.js +0 -18
- package/lib/Select/Item.web.js +0 -15
- package/lib/Select/Picker.web.js +0 -63
- package/lib/config/svgr-icons-web.js +0 -9
- package/lib/config/svgr-icons.js +0 -52
- package/lib/utils/info/platform/platform.web.js +0 -1
- package/src/config/svgr-icons-web.js +0 -11
- package/src/config/svgr-icons.js +0 -46
- package/src/utils/info/platform/platform.web.js +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useRef, useState } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
|
|
4
|
+
// Utilities to assist scrolling a parent so that it snaps neatly to an appropriate child.
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef ItemPositionPosition
|
|
8
|
+
* @property {number} [ItemPositionItem.start] - optional theme scale variants e.g. compact, wide
|
|
9
|
+
* @property {number} [ItemPositionItem.end] - optional override to force a particular pixel size
|
|
10
|
+
*
|
|
11
|
+
* @typedef {Object.<number, ItemPositionItem>} ItemPositionPositions - ref object of start/end coordinates
|
|
12
|
+
*
|
|
13
|
+
* @typedef ItemPositions
|
|
14
|
+
* @property {number} ItemPositions.contentWidth - current width of potentially-overflowing content inside scrollable
|
|
15
|
+
* @property {number} ItemPositions.containerWidth - current width of non-overflowing outer scroll container
|
|
16
|
+
* @property {number} ItemPositions.scrollOffset - current x position of the left edge of the visible section of the scrollable content
|
|
17
|
+
* @property {ItemPositionPositions} ItemPositions.positions - `{ start, end }` coordinates of each scrollable content item, by index
|
|
18
|
+
* @property {(targetX: number) => void)} ItemPositions.scrollTo - function to scroll to a co-ordinate, applying scrolling logic
|
|
19
|
+
* @property {() => void)} ItemPositions.setIsReady - function to call when layout has been calculated and itemPositions data is ready
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Takes a desired scroll target coordinate and returns a valid coordinate
|
|
24
|
+
* that, when not scrolling to one end or another, snaps to the start of an item,
|
|
25
|
+
* making sure any "scroll back" button doesn't overlap the first item.
|
|
26
|
+
*
|
|
27
|
+
* @param {number} x - the intended coordinate to scroll to
|
|
28
|
+
* @param {number} scrollMax - the highest posible coordinate to scroll to
|
|
29
|
+
* @param {ItemPositionPositions} positions - positions list from `useItemPositions` ref
|
|
30
|
+
* @param {number} [buttonClearance] - offset to allow space for a button
|
|
31
|
+
* @returns {number}
|
|
32
|
+
*/
|
|
33
|
+
export const getItemPositionScrollTarget = (x, scrollMax, positions, buttonClearance = 0) => {
|
|
34
|
+
if (x <= 0) return 0
|
|
35
|
+
if (x >= scrollMax) return scrollMax
|
|
36
|
+
|
|
37
|
+
// If not scrolling all the way to the start or end, stop
|
|
38
|
+
// where the first item is not coverred by the scroll previous button
|
|
39
|
+
const targetItem = Object.values(positions).find(({ start, end }) => start <= x && end > x)
|
|
40
|
+
|
|
41
|
+
// If there's no target item we're landing at a gap between items
|
|
42
|
+
const targetX = targetItem ? targetItem.start : x
|
|
43
|
+
return Math.max(0, targetX - buttonClearance)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Returns a handler for React Native's `onLayout` which updates the values of
|
|
48
|
+
* the ref object returned from `useItemPositions`.
|
|
49
|
+
*
|
|
50
|
+
* @param {ItemPositionPositions} positions
|
|
51
|
+
* @param {number} index
|
|
52
|
+
* @returns {function}
|
|
53
|
+
*/
|
|
54
|
+
export const getItemPositionLayoutHandler = (positions, index) => {
|
|
55
|
+
const handleLayout = ({
|
|
56
|
+
nativeEvent: {
|
|
57
|
+
layout: { width, x }
|
|
58
|
+
}
|
|
59
|
+
}) => {
|
|
60
|
+
/* eslint-disable-next-line no-param-reassign */
|
|
61
|
+
positions[index] = { start: x, end: x + width }
|
|
62
|
+
}
|
|
63
|
+
return handleLayout
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Wrapper for `useRef` which gives a mutable object in which item start/end coordinates,
|
|
68
|
+
* scrollTo method and content/container widths may be set and updated without causing a re-render.
|
|
69
|
+
*
|
|
70
|
+
* @returns {[ItemPositions, isReady: bool]} tuple array of:
|
|
71
|
+
* - current ref object `{ positions, contentWidth, containerWidth, scrollOffset, scrollTo, setIsReady }`
|
|
72
|
+
* - boolean that updates to `true` (causing a re-render) after the first time `setIsReady` is called
|
|
73
|
+
*/
|
|
74
|
+
export const useItemPositions = () => {
|
|
75
|
+
const [isReady, setIsReady] = useState(false)
|
|
76
|
+
return [
|
|
77
|
+
useRef({
|
|
78
|
+
positions: {},
|
|
79
|
+
scrollTo: () => {},
|
|
80
|
+
contentWidth: 0,
|
|
81
|
+
containerWidth: 0,
|
|
82
|
+
scrollOffset: 0,
|
|
83
|
+
setIsReady
|
|
84
|
+
}).current,
|
|
85
|
+
isReady
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* PropType for the ref object returned by `useItemPositions`
|
|
91
|
+
*/
|
|
92
|
+
export const itemPositionsPropType = PropTypes.exact({
|
|
93
|
+
positions: PropTypes.objectOf(
|
|
94
|
+
PropTypes.shape({ start: PropTypes.number, end: PropTypes.number })
|
|
95
|
+
),
|
|
96
|
+
scrollTo: PropTypes.func,
|
|
97
|
+
contentWidth: PropTypes.number,
|
|
98
|
+
containerWidth: PropTypes.number,
|
|
99
|
+
scrollOffset: PropTypes.number,
|
|
100
|
+
setIsReady: PropTypes.func
|
|
101
|
+
})
|
package/src/Tags/Tags.jsx
CHANGED
|
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
|
|
|
3
3
|
import { Platform, Text, View } from 'react-native'
|
|
4
4
|
|
|
5
5
|
import ButtonBase from '../Button/ButtonBase'
|
|
6
|
+
import Icon from '../Icon'
|
|
6
7
|
import { StackWrap, getStackedContent } from '../StackView'
|
|
7
8
|
import { useViewport } from '../ViewportProvider'
|
|
8
9
|
import { useThemeTokens, useThemeTokensCallback } from '../ThemeProvider'
|
|
@@ -134,7 +135,7 @@ const Tags = ({
|
|
|
134
135
|
|
|
135
136
|
const iconContent = IconComponent ? (
|
|
136
137
|
<View style={iconWrapperStyle}>
|
|
137
|
-
<IconComponent tokens={iconTokens} />
|
|
138
|
+
<Icon icon={IconComponent} tokens={iconTokens} />
|
|
138
139
|
</View>
|
|
139
140
|
) : null
|
|
140
141
|
const textContent = <Text style={textStyles}>{label}</Text>
|
|
@@ -2,7 +2,7 @@ import React, { useState } from 'react'
|
|
|
2
2
|
import { Platform, StyleSheet, TextInput as NativeTextInput, View } from 'react-native'
|
|
3
3
|
|
|
4
4
|
import PropTypes from 'prop-types'
|
|
5
|
-
import { applyTextStyles, useThemeTokens } from '../ThemeProvider'
|
|
5
|
+
import { applyTextStyles, useThemeTokens, applyOuterBorder } from '../ThemeProvider'
|
|
6
6
|
import { getTokensPropType, useInputValue, variantProp } from '../utils'
|
|
7
7
|
|
|
8
8
|
const selectInputStyles = (
|
|
@@ -76,27 +76,17 @@ const selectInputStyles = (
|
|
|
76
76
|
|
|
77
77
|
const selectOuterBorderStyles = ({
|
|
78
78
|
outerBackgroundColor,
|
|
79
|
-
outerBorderWidth
|
|
79
|
+
outerBorderWidth,
|
|
80
80
|
outerBorderColor,
|
|
81
|
-
|
|
82
|
-
}) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
background: outerBackgroundColor,
|
|
91
|
-
borderWidth: outerBorderWidth,
|
|
92
|
-
borderColor: outerBorderColor,
|
|
93
|
-
borderRadius,
|
|
94
|
-
marginTop: margin,
|
|
95
|
-
marginBottom: margin,
|
|
96
|
-
marginLeft: margin,
|
|
97
|
-
marginRight: margin
|
|
98
|
-
}
|
|
99
|
-
}
|
|
81
|
+
borderRadius
|
|
82
|
+
}) => ({
|
|
83
|
+
background: outerBackgroundColor,
|
|
84
|
+
...applyOuterBorder({
|
|
85
|
+
outerBorderColor,
|
|
86
|
+
outerBorderWidth,
|
|
87
|
+
borderRadius
|
|
88
|
+
})
|
|
89
|
+
})
|
|
100
90
|
|
|
101
91
|
const selectIconTokens = ({ iconSize, iconColor }) => ({
|
|
102
92
|
size: iconSize,
|
|
@@ -186,7 +176,7 @@ function TextInputBase({
|
|
|
186
176
|
pointerEvents="none" // avoid hijacking input press events
|
|
187
177
|
style={[staticStyles.iconContainer, selectIconContainerStyles(themeTokens)]}
|
|
188
178
|
>
|
|
189
|
-
<IconComponent
|
|
179
|
+
<IconComponent {...selectIconTokens(themeTokens)} />
|
|
190
180
|
</View>
|
|
191
181
|
)}
|
|
192
182
|
</View>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react'
|
|
2
2
|
import useTheme from './useTheme'
|
|
3
|
-
import { getComponentTheme, getThemeTokens,
|
|
3
|
+
import { getComponentTheme, getThemeTokens, resolveThemeTokens, mergeAppearances } from './utils'
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {import('../utils/propTypes.js').AppearanceSet} AppearanceSet
|
|
6
6
|
* @typedef {import('../utils/propTypes.js').TokensProp} TokensProp
|
|
@@ -98,7 +98,7 @@ export const useThemeTokensCallback = (componentName, tokens = {}, variants = {}
|
|
|
98
98
|
const getThemeTokensCallback = useCallback(
|
|
99
99
|
(states, tokenOverrides) => {
|
|
100
100
|
const appearances = mergeAppearances(variants, states)
|
|
101
|
-
const resolvedTokens =
|
|
101
|
+
const resolvedTokens = resolveThemeTokens(tokens, appearances, tokenOverrides)
|
|
102
102
|
return getThemeTokens(componentTheme, resolvedTokens, appearances)
|
|
103
103
|
},
|
|
104
104
|
[componentTheme, tokens, variants]
|
|
@@ -9,6 +9,7 @@ import { fontBasePixels } from '@telus-uds/system-constants'
|
|
|
9
9
|
// Make design tokens fit React Native's text styles' specific requirements and quirks
|
|
10
10
|
export function applyTextStyles({
|
|
11
11
|
fontSize,
|
|
12
|
+
fontScaleCap,
|
|
12
13
|
lineHeight,
|
|
13
14
|
letterSpacing,
|
|
14
15
|
fontWeight = '400',
|
|
@@ -27,7 +28,7 @@ export function applyTextStyles({
|
|
|
27
28
|
styles.lineHeight = lineHeight * (fontSize || fontBasePixels)
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
if (typeof letterSpacing === 'number') {
|
|
31
|
+
if (typeof letterSpacing === 'number' && letterSpacing) {
|
|
31
32
|
// Same as for line heights - React Native expects absolute letter spacing value
|
|
32
33
|
styles.letterSpacing = letterSpacing * (fontSize || fontBasePixels)
|
|
33
34
|
}
|
|
@@ -133,7 +134,19 @@ export function verticalAlignRow(verticalAlign, reverse = false) {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Use on an outer container to create an outer border with an optional gap around it
|
|
139
|
+
* that matches the border radius of any inner border.
|
|
140
|
+
*/
|
|
141
|
+
export const applyOuterBorder = ({
|
|
142
|
+
outerBorderColor,
|
|
143
|
+
outerBorderWidth = 0,
|
|
144
|
+
outerBorderGap = 0,
|
|
145
|
+
borderRadius = 0
|
|
146
|
+
}) => ({
|
|
147
|
+
margin: 0 - outerBorderWidth - outerBorderGap,
|
|
148
|
+
padding: outerBorderGap,
|
|
149
|
+
borderRadius: borderRadius + outerBorderGap + outerBorderWidth,
|
|
150
|
+
borderWidth: outerBorderWidth,
|
|
151
|
+
borderColor: outerBorderColor
|
|
152
|
+
})
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @typedef {import('../../utils/propTypes.js').AppearanceSet} AppearanceSet
|
|
3
5
|
* @typedef {import('../../utils/propTypes.js').TokensProp} TokensProp
|
|
@@ -37,15 +39,22 @@ export const doesThemeRuleApply = (rule, appearances) =>
|
|
|
37
39
|
Object.entries(rule.if).every((condition) => doesThemeConditionApply(condition, appearances))
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
|
-
* Turns a tokens prop
|
|
41
|
-
* into one tokens
|
|
42
|
+
* Turns a tokens prop (which may be either a tokens object or a tokens getter function)
|
|
43
|
+
* into one resolved tokens object, based on current appearances state.
|
|
44
|
+
*
|
|
45
|
+
* This is used inside `useThemeTokens` and `useThemeTokensCallback` for handling the `tokens`
|
|
46
|
+
* props of themed components. It may also be used directly in cases where a non-themed component
|
|
47
|
+
* needs to resolve a tokens prop that may be a tokens getter function or a resolved tokens object.
|
|
48
|
+
*
|
|
49
|
+
* A second tokens prop of tokens overrides may optionally be passed; it will be resolved to an object
|
|
50
|
+
* based on provided appearance state and then shallow-merged over the first set of tokens.
|
|
42
51
|
*
|
|
43
52
|
* @param {TokensProp} defaultTokens - a set of tokens or tokens getter function which may be overridden
|
|
44
|
-
* @param {TokensProp} [tokenOverrides] - optional set of tokens or tokens getter function to override the default
|
|
45
53
|
* @param {AppearanceSet} [appearances] - optional appearance set to pass to tokens getter functions
|
|
54
|
+
* @param {TokensProp} [tokenOverrides] - optional set of tokens or tokens getter function to override the default
|
|
46
55
|
* @returns {TokensSet} - object containing resolved tokens with overrides applied
|
|
47
56
|
*/
|
|
48
|
-
export const
|
|
57
|
+
export const resolveThemeTokens = (defaultTokens, appearances = {}, tokenOverrides) => {
|
|
49
58
|
const resolve = (tokens) => (typeof tokens === 'function' ? tokens(appearances) : tokens)
|
|
50
59
|
if (!tokenOverrides) return resolve(defaultTokens)
|
|
51
60
|
|
|
@@ -56,6 +65,27 @@ export const resolveTokens = (defaultTokens, tokenOverrides, appearances = {}) =
|
|
|
56
65
|
)
|
|
57
66
|
}
|
|
58
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Gives a prop types error if a set of resolved tokens doesn't match a provided prop
|
|
70
|
+
* types validator.
|
|
71
|
+
*
|
|
72
|
+
* In production, this is a no-op (PropTypes.checkPropTypes is automatically replaced
|
|
73
|
+
* with a no-op function).
|
|
74
|
+
*
|
|
75
|
+
* @param {TokensSet} themeTokens - object containing resolved theme tokens
|
|
76
|
+
* @param {function} validator - PropTypes validator function
|
|
77
|
+
* @param {string} componentName - identifier to display in PropType error messages
|
|
78
|
+
*/
|
|
79
|
+
export const validateThemeTokens = (themeTokens, validator, componentName) => {
|
|
80
|
+
PropTypes.checkPropTypes(
|
|
81
|
+
{ tokens: validator },
|
|
82
|
+
{ tokens: themeTokens },
|
|
83
|
+
'resolved token',
|
|
84
|
+
componentName
|
|
85
|
+
)
|
|
86
|
+
return themeTokens
|
|
87
|
+
}
|
|
88
|
+
|
|
59
89
|
/**
|
|
60
90
|
* Merges variants over states. Must be merged in that order to allow static showcases of a state,
|
|
61
91
|
* e.g. `<Button variant={{ pressed: true }} />` where button's pressed state is `false` by default.
|
|
@@ -68,6 +98,17 @@ export const resolveTokens = (defaultTokens, tokenOverrides, appearances = {}) =
|
|
|
68
98
|
export const mergeAppearances = (variants = {}, states) =>
|
|
69
99
|
states ? { ...states, ...variants } : variants
|
|
70
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Get a set of theme tokens by applying a theme's component rules based on a component's variants and state.
|
|
103
|
+
*
|
|
104
|
+
* This is used internally in `useThemeTokens` and `useThemeTokensCallback` and should not normally be called directly.
|
|
105
|
+
*
|
|
106
|
+
* @param {object} componentTheme - object containing a theme's `tokens` and `rules` for a component
|
|
107
|
+
* @param {object|function} [tokensProp] - UDS tokens prop containing theming overrides
|
|
108
|
+
* @param {object} [variants] - UDS variant prop containing the variant options for this component instance
|
|
109
|
+
* @param {object} [states] - object containing current state options for this component instance
|
|
110
|
+
* @returns {object} Set of resolved theme tokens
|
|
111
|
+
*/
|
|
71
112
|
export const getThemeTokens = (
|
|
72
113
|
{ rules = [], tokens: defaultThemeTokens = {} },
|
|
73
114
|
tokensProp,
|
|
@@ -88,7 +129,7 @@ export const getThemeTokens = (
|
|
|
88
129
|
: mergedTokens,
|
|
89
130
|
defaultThemeTokens
|
|
90
131
|
)
|
|
91
|
-
return
|
|
132
|
+
return resolveThemeTokens(themeTokens, appearances, tokensProp)
|
|
92
133
|
}
|
|
93
134
|
|
|
94
135
|
export const toArray = (strOrArr) => (Array.isArray(strOrArr) ? strOrArr : [strOrArr])
|
|
@@ -21,8 +21,7 @@ const selectButtonTokens = (tokens) =>
|
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
// Map and rename icon-specific tokens to name used within Icon
|
|
24
|
-
const selectIconTokens = ({ iconSize, iconColor
|
|
25
|
-
opacity: iconOpacity,
|
|
24
|
+
const selectIconTokens = ({ iconSize, iconColor }) => ({
|
|
26
25
|
size: iconSize,
|
|
27
26
|
color: iconColor
|
|
28
27
|
})
|
|
@@ -103,7 +102,7 @@ const ToggleSwitch = ({
|
|
|
103
102
|
return (
|
|
104
103
|
<View style={[staticStyles.track, trackStyles]}>
|
|
105
104
|
<View style={[staticStyles.switch, switchStyles, switchPositionStyle]}>
|
|
106
|
-
{IconComponent && <IconComponent
|
|
105
|
+
{IconComponent && <IconComponent {...iconTokens} />}
|
|
107
106
|
</View>
|
|
108
107
|
</View>
|
|
109
108
|
)
|
|
File without changes
|
package/src/Tooltip/Tooltip.jsx
CHANGED
|
@@ -81,7 +81,7 @@ const selectArrowStyles = (
|
|
|
81
81
|
|
|
82
82
|
const selectTextStyles = (tokens) => applyTextStyles(selectTokens('Typography', tokens))
|
|
83
83
|
const defaultControl = (pressableState, variant) => (
|
|
84
|
-
<TooltipButton
|
|
84
|
+
<TooltipButton pressableState={pressableState} variant={variant} />
|
|
85
85
|
)
|
|
86
86
|
|
|
87
87
|
/**
|
|
@@ -1,51 +1,47 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { View } from 'react-native'
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
5
|
+
import { useThemeTokens, applyOuterBorder } from '../ThemeProvider'
|
|
5
6
|
import { getTokensPropType, variantProp } from '../utils'
|
|
7
|
+
import Icon from '../Icon'
|
|
6
8
|
|
|
7
|
-
const selectOuterContainerStyles = ({
|
|
8
|
-
outerBorderColor,
|
|
9
|
-
outerBorderWidth = 0,
|
|
10
|
-
outerBorderGap = 0,
|
|
11
|
-
outerBorderRadius
|
|
12
|
-
}) => {
|
|
13
|
-
const outerBorderOffset = -1 * (outerBorderWidth + outerBorderGap)
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
marginTop: outerBorderOffset,
|
|
17
|
-
marginLeft: outerBorderOffset,
|
|
18
|
-
marginRight: outerBorderOffset,
|
|
19
|
-
marginBottom: outerBorderOffset,
|
|
20
|
-
borderColor: outerBorderColor,
|
|
21
|
-
borderWidth: outerBorderWidth,
|
|
22
|
-
padding: outerBorderGap,
|
|
23
|
-
borderRadius: outerBorderRadius
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
9
|
const selectInnerContainerStyles = ({ borderRadius, width }) => ({ borderRadius, width })
|
|
27
10
|
|
|
28
|
-
const selectIconTokens = ({ iconSize, iconColor
|
|
11
|
+
const selectIconTokens = ({ iconSize, iconColor /* iconScale = 1 */ }) => ({
|
|
29
12
|
size: iconSize,
|
|
30
|
-
color: iconColor
|
|
31
|
-
scale: iconScale
|
|
13
|
+
color: iconColor
|
|
14
|
+
// scale: iconScale TODO re-enable with icon component
|
|
32
15
|
})
|
|
33
16
|
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
/**
|
|
18
|
+
* `TooltipButton` is a helper component used as a default control for the `Tooltip` component.
|
|
19
|
+
* In fact though, it isn't actually a pressable - it's meant to be used as pressable's content.
|
|
20
|
+
* Due to this any interaction states (e.g. pressed, hover, etc.) has to be passed down to it as a prop.
|
|
21
|
+
*/
|
|
22
|
+
const TooltipButton = ({ pressableState, tokens, variant }) => {
|
|
23
|
+
const themeTokens = useThemeTokens('TooltipButton', tokens, variant, pressableState)
|
|
36
24
|
|
|
37
25
|
const { icon: IconComponent } = themeTokens
|
|
38
26
|
|
|
39
27
|
return (
|
|
40
|
-
<View style={
|
|
28
|
+
<View style={applyOuterBorder(themeTokens)}>
|
|
41
29
|
<View style={selectInnerContainerStyles(themeTokens)}>
|
|
42
|
-
{IconComponent && <IconComponent tokens={selectIconTokens(themeTokens)} />}
|
|
30
|
+
{IconComponent && <Icon icon={IconComponent} tokens={selectIconTokens(themeTokens)} />}
|
|
43
31
|
</View>
|
|
44
32
|
</View>
|
|
45
33
|
)
|
|
46
34
|
}
|
|
47
35
|
|
|
48
36
|
TooltipButton.propTypes = {
|
|
37
|
+
/**
|
|
38
|
+
* Used as appearances when resolving theme tokens.
|
|
39
|
+
*/
|
|
40
|
+
pressableState: PropTypes.shape({
|
|
41
|
+
pressed: PropTypes.bool,
|
|
42
|
+
hover: PropTypes.bool,
|
|
43
|
+
focus: PropTypes.bool
|
|
44
|
+
}),
|
|
49
45
|
tokens: getTokensPropType('TooltipButton'),
|
|
50
46
|
variant: variantProp.propType
|
|
51
47
|
}
|
|
@@ -23,7 +23,8 @@ const selectTextStyles = ({
|
|
|
23
23
|
lineHeight,
|
|
24
24
|
fontName,
|
|
25
25
|
textAlign,
|
|
26
|
-
textTransform
|
|
26
|
+
textTransform,
|
|
27
|
+
letterSpacing
|
|
27
28
|
}) =>
|
|
28
29
|
applyTextStyles({
|
|
29
30
|
fontWeight,
|
|
@@ -32,7 +33,8 @@ const selectTextStyles = ({
|
|
|
32
33
|
lineHeight,
|
|
33
34
|
fontName,
|
|
34
35
|
textAlign,
|
|
35
|
-
textTransform
|
|
36
|
+
textTransform,
|
|
37
|
+
letterSpacing
|
|
36
38
|
})
|
|
37
39
|
|
|
38
40
|
// General-purpose flexible theme-neutral base component for text
|
|
@@ -57,9 +59,8 @@ const Typography = ({
|
|
|
57
59
|
const a11y = {
|
|
58
60
|
...a11yProps.select(rest),
|
|
59
61
|
accessibilityRole,
|
|
60
|
-
// On React Native Web, `
|
|
61
|
-
|
|
62
|
-
[headingLevel && 'aria-level']: headingLevel
|
|
62
|
+
// On React Native Web, `accessibilityLevel` controls which heading tag (h1, h2 etc) is used.
|
|
63
|
+
...(headingLevel && { accessibilityLevel: headingLevel })
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
return block ? (
|
package/src/index.js
CHANGED
|
@@ -2,24 +2,36 @@ export { default as A11yText } from './A11yText'
|
|
|
2
2
|
export { default as ActivityIndicator } from './ActivityIndicator'
|
|
3
3
|
export { default as Box } from './Box'
|
|
4
4
|
export * from './Button'
|
|
5
|
-
export { default as Card } from './Card'
|
|
5
|
+
export { default as Card, PressableCardBase } from './Card'
|
|
6
6
|
export { default as Checkbox } from './Checkbox'
|
|
7
|
+
export * from './Checkbox'
|
|
7
8
|
export { default as Divider } from './Divider'
|
|
8
9
|
export { default as ExpandCollapse, Accordion } from './ExpandCollapse'
|
|
9
10
|
export { default as Feedback } from './Feedback'
|
|
11
|
+
export { default as Fieldset } from './Fieldset'
|
|
10
12
|
export { default as FlexGrid } from './FlexGrid'
|
|
11
13
|
export { default as Icon } from './Icon'
|
|
12
14
|
export * from './Icon'
|
|
15
|
+
export { default as InputLabel } from './InputLabel'
|
|
13
16
|
export * from './Link'
|
|
14
17
|
export { default as List } from './List'
|
|
18
|
+
export { default as Modal } from './Modal'
|
|
19
|
+
export { default as Notification } from './Notification'
|
|
15
20
|
export { default as Pagination } from './Pagination'
|
|
21
|
+
export { default as Progress } from './Progress'
|
|
16
22
|
export { default as Radio } from './Radio'
|
|
23
|
+
export * from './Radio'
|
|
24
|
+
export { default as RadioCard } from './RadioCard'
|
|
25
|
+
export * from './RadioCard'
|
|
26
|
+
export { default as Search } from './Search'
|
|
17
27
|
export { default as Select } from './Select'
|
|
18
28
|
export { default as SideNav } from './SideNav'
|
|
19
29
|
export { default as Skeleton } from './Skeleton'
|
|
20
30
|
export { default as Spacer } from './Spacer'
|
|
21
31
|
export { default as StackView } from './StackView'
|
|
22
32
|
export * from './StackView'
|
|
33
|
+
export { default as StepTracker } from './StepTracker'
|
|
34
|
+
export { default as Tabs } from './Tabs'
|
|
23
35
|
export { default as Tags } from './Tags'
|
|
24
36
|
export * from './TextInput'
|
|
25
37
|
export { default as ToggleSwitch } from './ToggleSwitch'
|
|
@@ -30,6 +42,12 @@ export { default as Typography } from './Typography'
|
|
|
30
42
|
export { default as A11yInfoProvider, useA11yInfo } from './A11yInfoProvider'
|
|
31
43
|
export { default as BaseProvider } from './BaseProvider'
|
|
32
44
|
export { default as ViewportProvider, useViewport } from './ViewportProvider'
|
|
33
|
-
export {
|
|
45
|
+
export {
|
|
46
|
+
default as ThemeProvider,
|
|
47
|
+
useTheme,
|
|
48
|
+
useSetTheme,
|
|
49
|
+
useThemeTokens,
|
|
50
|
+
getThemeTokens
|
|
51
|
+
} from './ThemeProvider'
|
|
34
52
|
|
|
35
53
|
export * from './utils'
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React, { Children, Fragment } from 'react'
|
|
2
|
+
import { Text } from 'react-native'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Unpacks top-level fragments, so that common compositional patterns such as the following examples
|
|
6
|
+
* can be iterated as flat siblings (as if they were `<Child1 /><Child2 /><Child3 />`):
|
|
7
|
+
*
|
|
8
|
+
* - Setting `children` as a property wrapped in a fragment:
|
|
9
|
+
*
|
|
10
|
+
* ```jsx
|
|
11
|
+
* args.children = <><Child1 /><Child2 /><Child3 /></>
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* - Defining `children` as a variable wrapped in a fragment:
|
|
15
|
+
*
|
|
16
|
+
* ```jsx
|
|
17
|
+
* const content = <><Child1 /><Child2 /><Child3 /></>
|
|
18
|
+
* if (someCondition) return <SomeWrapper>{content}</SomeWrapper>
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* - Using fragments at the top level of a JSX block for conditional rendering:
|
|
22
|
+
*
|
|
23
|
+
* ```jsx
|
|
24
|
+
* <Child1 />
|
|
25
|
+
* {someCondition && (
|
|
26
|
+
* <>
|
|
27
|
+
* <Child2 />
|
|
28
|
+
* <Child3 />
|
|
29
|
+
* </>
|
|
30
|
+
* )}
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param {ReactChildren} child
|
|
34
|
+
* @returns {ReactChildren}
|
|
35
|
+
*/
|
|
36
|
+
export const unpackFragment = (child) => {
|
|
37
|
+
// If this level is a set of top-level siblings rather than one child, check each in turn
|
|
38
|
+
if (Children.count(child) > 1) return Children.map(child, unpackFragment)
|
|
39
|
+
|
|
40
|
+
// When a fragment is found, unpack its children to the top level and check them
|
|
41
|
+
if (child?.type === Fragment) return unpackFragment(child.props?.children)
|
|
42
|
+
|
|
43
|
+
// Stop unpacking as soon as any non-fragment child is found
|
|
44
|
+
return child
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* React Native on Native crashes if text content is rendered outside `<Text>`, and on web,
|
|
49
|
+
* text style inheritance isn't as expected.
|
|
50
|
+
*
|
|
51
|
+
* Call this function on children that may contain text (strings or numbers) at the top level,
|
|
52
|
+
* and any that are found will be wrapped in a React Native `<Text>` element with supplied props.
|
|
53
|
+
*
|
|
54
|
+
* Note that this does not wrap strings that are nested children of the top level children:
|
|
55
|
+
* `wrapStringsInText(<View>Some text</View>)` will not wrap the inner text and will still crash,
|
|
56
|
+
* but `wrapStringsInText(<>{someString}{anotherString}</>)` will wrap the strings in the fragment.
|
|
57
|
+
*
|
|
58
|
+
* @param {ReactChildren} children
|
|
59
|
+
* @param {TextProps} props
|
|
60
|
+
* @returns {ReactChildren}
|
|
61
|
+
*/
|
|
62
|
+
export const wrapStringsInText = (children, props = {}) => {
|
|
63
|
+
return Children.map(unpackFragment(children), (child) =>
|
|
64
|
+
typeof child === 'string' || typeof child === 'number' ? <Text {...props}>{child}</Text> : child
|
|
65
|
+
)
|
|
66
|
+
}
|
package/src/utils/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export * from './a11y'
|
|
2
2
|
export * from './animation'
|
|
3
|
+
export * from './children'
|
|
3
4
|
export * from './input'
|
|
4
5
|
export * from './pressability'
|
|
5
6
|
export * from './propTypes'
|
|
6
7
|
|
|
7
8
|
export { default as info } from './info'
|
|
9
|
+
export { default as useCopy } from './useCopy'
|
|
10
|
+
export { default as useHash } from './useHash'
|
|
8
11
|
export { default as useSpacingScale } from './useSpacingScale'
|
|
9
12
|
export { default as useResponsiveProp } from './useResponsiveProp'
|
|
10
13
|
export * from './useResponsiveProp'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default '.web (default)'
|