@telus-uds/components-base 0.0.2-prerelease.9 → 1.0.0
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/.eslintrc.js +9 -0
- package/.ultra.cache.json +1 -1
- package/CHANGELOG.md +32 -0
- package/README.md +4 -2
- package/__fixtures__/test-utils.js +25 -0
- package/__fixtures__/testTheme.js +4 -2
- package/__tests__/Button/ButtonGroup.test.jsx +4 -5
- package/__tests__/Checkbox/Checkbox.test.jsx +2 -2
- package/__tests__/Checkbox/CheckboxGroup.test.jsx +4 -5
- package/__tests__/ExpandCollapse/ExpandCollapse.test.jsx +2 -2
- package/__tests__/HorizontalScroll/HorizontalScroll.test.jsx +164 -0
- package/__tests__/Link/LinkBase.test.jsx +0 -14
- package/__tests__/Radio/Radio.test.jsx +2 -2
- package/__tests__/Radio/RadioGroup.test.jsx +4 -5
- package/__tests__/RadioCard/RadioCard.test.jsx +2 -2
- package/__tests__/RadioCard/RadioCardGroup.test.jsx +4 -5
- package/__tests__/Search/Search.test.jsx +9 -8
- package/__tests__/Select/Select.test.jsx +3 -2
- package/__tests__/Tabs/Tabs.test.jsx +1 -161
- package/__tests__/Tags/Tags.test.jsx +4 -5
- package/__tests__/TextInput/TextArea.test.jsx +3 -2
- package/__tests__/TextInput/TextInputBase.test.jsx +10 -5
- package/__tests__/ThemeProvider/ThemeProvider.test.jsx +77 -0
- package/__tests__/ThemeProvider/useThemeTokens.test.jsx +9 -5
- package/__tests__/ThemeProvider/utils/theme-tokens.test.js +41 -0
- package/__tests__/ToggleSwitch/ToggleSwitch.test.jsx +3 -2
- package/__tests__/utils/children.test.jsx +128 -0
- package/__tests__/utils/input.test.js +1 -1
- package/__tests__/utils/semantics.test.jsx +43 -0
- package/lib/A11yText/index.js +10 -5
- package/lib/ActivityIndicator/Spinner.js +16 -13
- package/lib/ActivityIndicator/Spinner.native.js +12 -8
- package/lib/Box/Box.js +102 -8
- package/lib/Button/Button.js +9 -8
- package/lib/Button/ButtonBase.js +14 -7
- package/lib/Button/ButtonGroup.js +25 -10
- package/lib/Button/ButtonLink.js +10 -7
- package/lib/Card/Card.js +2 -0
- package/lib/Card/CardBase.js +12 -5
- package/lib/Card/PressableCardBase.js +12 -8
- package/lib/Checkbox/Checkbox.js +25 -14
- package/lib/Checkbox/CheckboxGroup.js +22 -12
- package/lib/Divider/Divider.js +12 -7
- package/lib/ExpandCollapse/Accordion.js +10 -4
- package/lib/ExpandCollapse/Control.js +12 -6
- package/lib/ExpandCollapse/ExpandCollapse.js +10 -5
- package/lib/ExpandCollapse/Panel.js +8 -7
- package/lib/Feedback/Feedback.js +10 -5
- package/lib/Fieldset/Fieldset.js +10 -5
- package/lib/Fieldset/FieldsetContainer.js +10 -5
- package/lib/Fieldset/FieldsetContainer.native.js +10 -5
- package/lib/Fieldset/Legend.js +10 -5
- package/lib/Fieldset/Legend.native.js +10 -5
- package/lib/FlexGrid/Col/Col.js +8 -5
- package/lib/FlexGrid/FlexGrid.js +31 -6
- package/lib/FlexGrid/Row/Row.js +12 -5
- package/lib/{Tabs → HorizontalScroll}/HorizontalScroll.js +5 -4
- package/lib/{Tabs/TabsScrollButton.js → HorizontalScroll/HorizontalScrollButton.js} +14 -8
- package/lib/{Tabs → HorizontalScroll}/ScrollViewEnd.js +0 -0
- package/lib/{Tabs → HorizontalScroll}/ScrollViewEnd.native.js +0 -0
- package/lib/{Tabs → HorizontalScroll}/dictionary.js +0 -0
- package/lib/HorizontalScroll/index.js +35 -0
- package/lib/{Tabs → HorizontalScroll}/itemPositions.js +0 -0
- package/lib/Icon/Icon.js +16 -9
- package/lib/Icon/IconText.js +8 -7
- package/lib/IconButton/IconButton.js +10 -5
- package/lib/InputLabel/InputLabel.js +33 -5
- package/lib/InputLabel/LabelContent.js +22 -12
- package/lib/InputLabel/LabelContent.native.js +23 -5
- package/lib/InputSupports/InputSupports.js +10 -5
- package/lib/Link/ChevronLink.js +12 -5
- package/lib/Link/InlinePressable.js +10 -4
- package/lib/Link/InlinePressable.native.js +5 -4
- package/lib/Link/Link.js +12 -5
- package/lib/Link/LinkBase.js +12 -5
- package/lib/Link/TextButton.js +10 -5
- package/lib/List/List.js +5 -4
- package/lib/List/ListItem.js +16 -8
- package/lib/Modal/Modal.js +10 -5
- package/lib/Notification/Notification.js +21 -5
- package/lib/Pagination/PageButton.js +21 -10
- package/lib/Pagination/Pagination.js +12 -7
- package/lib/Pagination/SideButton.js +12 -7
- package/lib/Pagination/usePagination.js +2 -2
- package/lib/Progress/Progress.js +10 -5
- package/lib/Progress/ProgressBar.js +21 -10
- package/lib/Progress/ProgressBarBackground.js +12 -8
- package/lib/Radio/Radio.js +14 -13
- package/lib/Radio/RadioButton.js +20 -9
- package/lib/Radio/RadioGroup.js +24 -13
- package/lib/RadioCard/RadioCard.js +14 -10
- package/lib/RadioCard/RadioCardGroup.js +13 -12
- package/lib/Search/Search.js +29 -18
- package/lib/Select/Picker.js +11 -6
- package/lib/Select/Picker.native.js +21 -6
- package/lib/Select/Select.js +46 -4
- package/lib/SideNav/Item.js +10 -5
- package/lib/SideNav/ItemsGroup.js +10 -5
- package/lib/SideNav/SideNav.js +11 -7
- package/lib/Skeleton/Skeleton.js +15 -15
- package/lib/Skeleton/skeletonWebAnimation.js +1 -1
- package/lib/Spacer/Spacer.js +19 -7
- package/lib/StackView/StackView.js +25 -7
- package/lib/StackView/StackWrap.js +16 -9
- package/lib/StackView/StackWrapBox.js +33 -8
- package/lib/StackView/StackWrapGap.js +16 -7
- package/lib/StackView/common.js +4 -2
- package/lib/StackView/getStackedContent.js +2 -2
- package/lib/StepTracker/StepTracker.js +10 -5
- package/lib/Tabs/Tabs.js +26 -19
- package/lib/Tabs/TabsItem.js +16 -12
- package/lib/Tags/Tags.js +27 -11
- package/lib/TextInput/TextArea.js +7 -5
- package/lib/TextInput/TextInput.js +12 -6
- package/lib/TextInput/TextInputBase.js +12 -8
- package/lib/ThemeProvider/ThemeProvider.js +14 -10
- package/lib/ThemeProvider/useSetTheme.js +6 -1
- package/lib/ThemeProvider/utils/styles.js +2 -2
- package/lib/ThemeProvider/utils/theme-tokens.js +39 -8
- package/lib/ToggleSwitch/ToggleSwitch.js +11 -6
- package/lib/Tooltip/Backdrop.js +10 -2
- package/lib/Tooltip/Tooltip.js +5 -4
- package/lib/Typography/Typography.js +40 -24
- package/lib/index.js +21 -0
- package/lib/utils/a11y/index.js +13 -0
- package/lib/utils/a11y/semantics.js +173 -0
- package/lib/utils/animation/useVerticalExpandAnimation.js +1 -1
- package/lib/utils/children.js +55 -8
- package/lib/utils/input.js +27 -17
- package/lib/utils/propTypes.js +82 -29
- package/lib/utils/useCopy.js +1 -1
- package/lib/utils/useHash.js +8 -4
- package/lib/utils/useSpacingScale.js +1 -3
- package/lib/utils/useUniqueId.js +1 -1
- package/package.json +9 -5
- package/release-context.json +4 -4
- package/src/A11yText/index.jsx +6 -4
- package/src/ActivityIndicator/Spinner.jsx +5 -3
- package/src/ActivityIndicator/Spinner.native.jsx +5 -3
- package/src/Box/Box.jsx +124 -39
- package/src/Button/Button.jsx +7 -4
- package/src/Button/ButtonBase.jsx +86 -77
- package/src/Button/ButtonGroup.jsx +81 -69
- package/src/Button/ButtonLink.jsx +18 -13
- package/src/Card/Card.jsx +2 -2
- package/src/Card/CardBase.jsx +5 -4
- package/src/Card/PressableCardBase.jsx +71 -64
- package/src/Checkbox/Checkbox.jsx +118 -108
- package/src/Checkbox/CheckboxGroup.jsx +72 -62
- package/src/Divider/Divider.jsx +7 -4
- package/src/ExpandCollapse/Accordion.jsx +3 -2
- package/src/ExpandCollapse/Control.jsx +40 -43
- package/src/ExpandCollapse/ExpandCollapse.jsx +26 -23
- package/src/ExpandCollapse/Panel.jsx +69 -63
- package/src/Feedback/Feedback.jsx +36 -33
- package/src/Fieldset/Fieldset.jsx +63 -56
- package/src/Fieldset/FieldsetContainer.jsx +14 -5
- package/src/Fieldset/FieldsetContainer.native.jsx +7 -4
- package/src/Fieldset/Legend.jsx +7 -2
- package/src/Fieldset/Legend.native.jsx +7 -2
- package/src/FlexGrid/Col/Col.jsx +139 -132
- package/src/FlexGrid/FlexGrid.jsx +79 -51
- package/src/FlexGrid/Row/Row.jsx +55 -48
- package/src/HorizontalScroll/HorizontalScroll.jsx +168 -0
- package/src/HorizontalScroll/HorizontalScrollButton.jsx +105 -0
- package/src/{Tabs → HorizontalScroll}/ScrollViewEnd.jsx +0 -0
- package/src/{Tabs → HorizontalScroll}/ScrollViewEnd.native.jsx +0 -0
- package/src/{Tabs → HorizontalScroll}/dictionary.js +0 -0
- package/src/HorizontalScroll/index.js +17 -0
- package/src/{Tabs → HorizontalScroll}/itemPositions.js +0 -0
- package/src/Icon/Icon.jsx +37 -35
- package/src/Icon/IconText.jsx +22 -17
- package/src/IconButton/IconButton.jsx +49 -42
- package/src/InputLabel/InputLabel.jsx +53 -38
- package/src/InputLabel/LabelContent.jsx +14 -6
- package/src/InputLabel/LabelContent.native.jsx +11 -2
- package/src/InputSupports/InputSupports.jsx +29 -34
- package/src/Link/ChevronLink.jsx +26 -16
- package/src/Link/InlinePressable.jsx +5 -3
- package/src/Link/InlinePressable.native.jsx +5 -3
- package/src/Link/Link.jsx +22 -16
- package/src/Link/LinkBase.jsx +67 -58
- package/src/Link/TextButton.jsx +30 -23
- package/src/List/List.jsx +5 -4
- package/src/List/ListItem.jsx +77 -82
- package/src/Modal/Modal.jsx +9 -4
- package/src/Notification/Notification.jsx +58 -43
- package/src/Pagination/PageButton.jsx +42 -35
- package/src/Pagination/Pagination.jsx +88 -92
- package/src/Pagination/SideButton.jsx +44 -41
- package/src/Progress/Progress.jsx +5 -4
- package/src/Progress/ProgressBar.jsx +42 -29
- package/src/Progress/ProgressBarBackground.jsx +5 -3
- package/src/Radio/Radio.jsx +85 -78
- package/src/Radio/RadioButton.jsx +54 -43
- package/src/Radio/RadioGroup.jsx +74 -63
- package/src/RadioCard/RadioCard.jsx +75 -68
- package/src/RadioCard/RadioCardGroup.jsx +82 -75
- package/src/Search/Search.jsx +127 -106
- package/src/Select/Picker.jsx +49 -42
- package/src/Select/Picker.native.jsx +56 -49
- package/src/Select/Select.jsx +115 -72
- package/src/SideNav/Item.jsx +53 -46
- package/src/SideNav/ItemsGroup.jsx +50 -43
- package/src/SideNav/SideNav.jsx +68 -60
- package/src/Skeleton/Skeleton.jsx +9 -13
- package/src/Spacer/Spacer.jsx +11 -4
- package/src/StackView/StackView.jsx +46 -23
- package/src/StackView/StackWrap.jsx +7 -6
- package/src/StackView/StackWrapBox.jsx +61 -28
- package/src/StackView/StackWrapGap.jsx +46 -24
- package/src/StackView/common.jsx +3 -2
- package/src/StepTracker/StepTracker.jsx +73 -62
- package/src/Tabs/Tabs.jsx +70 -62
- package/src/Tabs/TabsItem.jsx +111 -103
- package/src/Tags/Tags.jsx +114 -102
- package/src/TextInput/TextArea.jsx +5 -4
- package/src/TextInput/TextInput.jsx +5 -4
- package/src/TextInput/TextInputBase.jsx +84 -77
- package/src/ThemeProvider/ThemeProvider.jsx +11 -7
- package/src/ThemeProvider/useSetTheme.js +4 -0
- package/src/ThemeProvider/utils/theme-tokens.js +28 -0
- package/src/ToggleSwitch/ToggleSwitch.jsx +49 -50
- package/src/Tooltip/Tooltip.jsx +134 -130
- package/src/Typography/Typography.jsx +67 -44
- package/src/index.js +2 -0
- package/src/utils/a11y/index.js +1 -0
- package/src/utils/a11y/semantics.js +162 -0
- package/src/utils/children.jsx +60 -7
- package/src/utils/input.js +20 -17
- package/src/utils/propTypes.js +101 -39
- package/src/utils/useCopy.js +1 -1
- package/src/utils/useHash.js +8 -3
- package/stories/A11yText/A11yText.stories.jsx +2 -2
- package/stories/ActivityIndicator/ActivityIndicator.stories.jsx +1 -1
- package/stories/Box/Box.stories.jsx +1 -1
- package/stories/Button/Button.stories.jsx +2 -2
- package/stories/Button/ButtonGroup.stories.jsx +1 -1
- package/stories/Button/ButtonLink.stories.jsx +1 -1
- package/stories/Card/Card.stories.jsx +1 -1
- package/stories/Checkbox/Checkbox.stories.jsx +1 -1
- package/stories/Divider/Divider.stories.jsx +1 -1
- package/stories/ExpandCollapse/ExpandCollapse.stories.jsx +2 -2
- package/stories/Feedback/Feedback.stories.jsx +1 -1
- package/stories/FlexGrid/01 FlexGrid.stories.jsx +1 -1
- package/stories/FlexGrid/02 Row.stories.jsx +1 -1
- package/stories/FlexGrid/03 Col.stories.jsx +1 -1
- package/stories/Icon/Icon.stories.jsx +1 -1
- package/stories/IconButton/IconButton.stories.jsx +1 -1
- package/stories/InputLabel/InputLabel.stories.jsx +1 -1
- package/stories/Link/ChevronLink.stories.jsx +1 -1
- package/stories/Link/Link.stories.jsx +1 -1
- package/stories/Link/TextButton.stories.jsx +1 -1
- package/stories/List/List.stories.jsx +1 -1
- package/stories/Modal/Modal.stories.jsx +1 -1
- package/stories/Notification/Notification.stories.jsx +1 -1
- package/stories/Pagination/Pagination.stories.jsx +1 -1
- package/stories/Progress/Progress.stories.jsx +1 -1
- package/stories/Radio/Radio.stories.jsx +1 -1
- package/stories/RadioCard/RadioCard.stories.jsx +1 -1
- package/stories/Search/Search.stories.jsx +1 -1
- package/stories/Select/Select.stories.jsx +1 -1
- package/stories/SideNav/SideNav.stories.jsx +1 -1
- package/stories/SideNav/SideNavItem.stories.jsx +1 -1
- package/stories/SideNav/SideNavItemsGroup.stories.jsx +1 -1
- package/stories/Skeleton/Skeleton.stories.jsx +2 -2
- package/stories/Spacer/Spacer.stories.jsx +1 -1
- package/stories/StackView/StackView.stories.jsx +1 -1
- package/stories/StackView/StackWrap.stories.jsx +1 -1
- package/stories/StepTracker/StepTracker.stories.jsx +1 -1
- package/stories/Tabs/Tabs.stories.jsx +1 -1
- package/stories/Tags/Tags.stories.jsx +1 -1
- package/stories/TextInput/TextArea.stories.jsx +1 -1
- package/stories/TextInput/TextInput.stories.jsx +1 -1
- package/stories/ToggleSwitch/ToggleSwitch.stories.jsx +1 -1
- package/stories/Tooltip/Tooltip.stories.jsx +1 -1
- package/stories/TooltipButton/TooltipButton.stories.jsx +1 -1
- package/stories/Typography/Typography.stories.jsx +1 -1
- package/stories/platform-supports.jsx +1 -1
- package/stories/supports.jsx +2 -2
- package/src/Tabs/HorizontalScroll.jsx +0 -165
- package/src/Tabs/TabsScrollButton.jsx +0 -100
package/src/Tabs/TabsItem.jsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React, { useEffect } from 'react'
|
|
1
|
+
import React, { forwardRef, useEffect } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import { Platform, Pressable, StyleSheet, Text, View } from 'react-native'
|
|
4
|
-
import system from '@telus-uds/system-themes/src/tokens/rn'
|
|
5
4
|
|
|
6
5
|
import { applyTextStyles, useThemeTokensCallback } from '../ThemeProvider'
|
|
7
6
|
import {
|
|
@@ -13,7 +12,9 @@ import {
|
|
|
13
12
|
a11yProps
|
|
14
13
|
} from '../utils'
|
|
15
14
|
import Spacer from '../Spacer'
|
|
16
|
-
import {
|
|
15
|
+
import { horizontalScrollUtils } from '../HorizontalScroll'
|
|
16
|
+
|
|
17
|
+
const { itemPositionsPropType, getItemPositionLayoutHandler } = horizontalScrollUtils
|
|
17
18
|
|
|
18
19
|
const selectHighlightBarStyles = ({
|
|
19
20
|
highlightColor,
|
|
@@ -41,9 +42,9 @@ const selectHighlightTriangleStyles = ({ highlightColor, highlightTriangleSize }
|
|
|
41
42
|
width: 0,
|
|
42
43
|
borderWidth: highlightTriangleSize,
|
|
43
44
|
borderTopColor: highlightColor,
|
|
44
|
-
borderBottomColor:
|
|
45
|
-
borderLeftColor:
|
|
46
|
-
borderRightColor:
|
|
45
|
+
borderBottomColor: 'transparent',
|
|
46
|
+
borderLeftColor: 'transparent',
|
|
47
|
+
borderRightColor: 'transparent'
|
|
47
48
|
}
|
|
48
49
|
})
|
|
49
50
|
|
|
@@ -69,108 +70,115 @@ const selectContainerStyles = ({
|
|
|
69
70
|
*
|
|
70
71
|
* This is rendered automatically by `Tabs` and isn't intended be used directly.
|
|
71
72
|
*/
|
|
72
|
-
const TabsItem = (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
const TabsItem = forwardRef(
|
|
74
|
+
(
|
|
75
|
+
{
|
|
76
|
+
onPress,
|
|
77
|
+
href,
|
|
78
|
+
variant,
|
|
79
|
+
tokens,
|
|
80
|
+
selected,
|
|
81
|
+
itemPositions,
|
|
82
|
+
index,
|
|
83
|
+
children,
|
|
84
|
+
accessibilityRole = href ? 'link' : 'tab',
|
|
85
|
+
accessibilityState = Platform.OS === 'web' && accessibilityRole === 'link'
|
|
86
|
+
? // Web links can't be aria-selected but can be aria-current
|
|
87
|
+
{ current: selected ? 'page' : false }
|
|
88
|
+
: { selected },
|
|
89
|
+
...rest
|
|
90
|
+
},
|
|
91
|
+
ref
|
|
92
|
+
) => {
|
|
93
|
+
const getTokens = useThemeTokensCallback('TabsItem', tokens, variant)
|
|
94
|
+
const resolveTokens = (pressableState) =>
|
|
95
|
+
resolvePressableTokens(getTokens, pressableState, { selected })
|
|
96
|
+
|
|
97
|
+
const getPressableStyle = (pressableState) => {
|
|
98
|
+
const { maxWidth } = resolveTokens(pressableState)
|
|
99
|
+
return [{ maxWidth }, Platform.OS === 'web' && { outline: 'none' }]
|
|
100
|
+
}
|
|
96
101
|
|
|
97
|
-
|
|
102
|
+
const handleLayout = getItemPositionLayoutHandler(itemPositions.positions, index)
|
|
103
|
+
|
|
104
|
+
// On press, update the selection, call any press handler, and open any href in platform-appropriate way
|
|
105
|
+
const openHref = href && linkProps.handleHref({ href })
|
|
106
|
+
const handlePress =
|
|
107
|
+
onPress || openHref
|
|
108
|
+
? () => {
|
|
109
|
+
if (onPress) onPress()
|
|
110
|
+
if (openHref) openHref()
|
|
111
|
+
}
|
|
112
|
+
: undefined
|
|
113
|
+
|
|
114
|
+
const a11y = {
|
|
115
|
+
accessibilityRole,
|
|
116
|
+
accessibilityState,
|
|
117
|
+
...a11yProps.select(rest)
|
|
118
|
+
}
|
|
98
119
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
// If this is selected while off-screen, scroll it into view
|
|
122
|
+
if (selected) {
|
|
123
|
+
const position = itemPositions.positions[index]
|
|
124
|
+
const scrollEnd = itemPositions.scrollOffset + itemPositions.containerWidth
|
|
125
|
+
if (
|
|
126
|
+
// is off the right edge, or
|
|
127
|
+
(scrollEnd && position?.end > scrollEnd) ||
|
|
128
|
+
// is off the left edge
|
|
129
|
+
(typeof position?.start === 'number' && position.start < itemPositions.scrollOffset)
|
|
130
|
+
) {
|
|
131
|
+
itemPositions.scrollTo(position.start)
|
|
106
132
|
}
|
|
107
|
-
: undefined
|
|
108
|
-
|
|
109
|
-
const a11y = {
|
|
110
|
-
accessibilityRole,
|
|
111
|
-
accessibilityState,
|
|
112
|
-
...a11yProps.select(rest)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
useEffect(() => {
|
|
116
|
-
// If this is selected while off-screen, scroll it into view
|
|
117
|
-
if (selected) {
|
|
118
|
-
const position = itemPositions.positions[index]
|
|
119
|
-
const scrollEnd = itemPositions.scrollOffset + itemPositions.containerWidth
|
|
120
|
-
if (
|
|
121
|
-
// is off the right edge, or
|
|
122
|
-
(scrollEnd && position?.end > scrollEnd) ||
|
|
123
|
-
// is off the left edge
|
|
124
|
-
(typeof position?.start === 'number' && position.start < itemPositions.scrollOffset)
|
|
125
|
-
) {
|
|
126
|
-
itemPositions.scrollTo(position.start)
|
|
127
133
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
</View>
|
|
161
|
-
<Spacer space={space} />
|
|
162
|
-
{hasHighlightBar && <View style={[staticStyles.absolute, highlightBarStyle]} />}
|
|
163
|
-
{hasHighlightTriangle && (
|
|
164
|
-
<View style={[staticStyles.absolute, highlightTriangleStyle.container]}>
|
|
165
|
-
<View style={highlightTriangleStyle.triangle} />
|
|
134
|
+
// itemPositions is a ref object so this should only re-run when `selected` (or `index`) change
|
|
135
|
+
}, [selected, index, itemPositions])
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<Pressable
|
|
139
|
+
ref={ref}
|
|
140
|
+
onPress={handlePress}
|
|
141
|
+
href={href}
|
|
142
|
+
style={getPressableStyle}
|
|
143
|
+
onLayout={handleLayout}
|
|
144
|
+
{...a11y}
|
|
145
|
+
>
|
|
146
|
+
{(pressableState) => {
|
|
147
|
+
const { space, textAlign, ...themeTokens } = resolveTokens(pressableState)
|
|
148
|
+
|
|
149
|
+
const hasHighlightBar = Boolean(themeTokens.highlightBarHeight)
|
|
150
|
+
const highlightBarStyle = hasHighlightBar && selectHighlightBarStyles(themeTokens)
|
|
151
|
+
|
|
152
|
+
const hasHighlightTriangle = Boolean(themeTokens.highlightTriangleSize)
|
|
153
|
+
const highlightTriangleStyle =
|
|
154
|
+
hasHighlightTriangle && selectHighlightTriangleStyles(themeTokens)
|
|
155
|
+
|
|
156
|
+
const containerStyles = selectContainerStyles(themeTokens)
|
|
157
|
+
const textStyles = applyTextStyles({
|
|
158
|
+
...selectTokens('Typography', themeTokens),
|
|
159
|
+
textAlign
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<View style={staticStyles.container}>
|
|
164
|
+
<View style={containerStyles}>
|
|
165
|
+
<Text style={textStyles}>{children}</Text>
|
|
166
166
|
</View>
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
167
|
+
<Spacer space={space} />
|
|
168
|
+
{hasHighlightBar && <View style={[staticStyles.absolute, highlightBarStyle]} />}
|
|
169
|
+
{hasHighlightTriangle && (
|
|
170
|
+
<View style={[staticStyles.absolute, highlightTriangleStyle.container]}>
|
|
171
|
+
<View style={highlightTriangleStyle.triangle} />
|
|
172
|
+
</View>
|
|
173
|
+
)}
|
|
174
|
+
</View>
|
|
175
|
+
)
|
|
176
|
+
}}
|
|
177
|
+
</Pressable>
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
TabsItem.displayName = 'TabsItem'
|
|
174
182
|
|
|
175
183
|
TabsItem.propTypes = {
|
|
176
184
|
...a11yProps.propTypes,
|
package/src/Tags/Tags.jsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
|
+
import ABBPropTypes from 'airbnb-prop-types'
|
|
3
4
|
import { Platform, Text, View } from 'react-native'
|
|
4
5
|
|
|
5
6
|
import ButtonBase from '../Button/ButtonBase'
|
|
@@ -51,106 +52,113 @@ const selectIconTextTokens = ({
|
|
|
51
52
|
}
|
|
52
53
|
})
|
|
53
54
|
|
|
54
|
-
const Tags = (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
55
|
+
const Tags = forwardRef(
|
|
56
|
+
(
|
|
57
|
+
{
|
|
58
|
+
variant,
|
|
59
|
+
tokens,
|
|
60
|
+
items = [],
|
|
61
|
+
values,
|
|
62
|
+
initialValues,
|
|
63
|
+
maxValues,
|
|
64
|
+
onChange,
|
|
65
|
+
readOnly = false,
|
|
66
|
+
inactive = false,
|
|
67
|
+
accessibilityRole = Platform.select({ web: 'group', default: 'none' }),
|
|
68
|
+
...rest
|
|
69
|
+
},
|
|
70
|
+
ref
|
|
71
|
+
) => {
|
|
72
|
+
const viewport = useViewport()
|
|
73
|
+
const themeTokens = useThemeTokens('Tags', tokens, variant, { viewport })
|
|
74
|
+
const stackTokens = selectTokens('StackView', themeTokens)
|
|
75
|
+
const { direction, space } = themeTokens
|
|
76
|
+
|
|
77
|
+
const getItemTokens = useThemeTokensCallback('TagsItem', tokens, variant)
|
|
78
|
+
const getButtonTokens = (buttonState) => selectTokens('Button', getItemTokens(buttonState))
|
|
79
|
+
|
|
80
|
+
const { currentValues, toggleOneValue } = useMultipleInputValues({
|
|
81
|
+
initialValues,
|
|
82
|
+
values,
|
|
83
|
+
maxValues,
|
|
84
|
+
onChange,
|
|
85
|
+
readOnly
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const a11y = a11yProps.select({
|
|
89
|
+
accessibilityRole,
|
|
90
|
+
...rest
|
|
91
|
+
})
|
|
92
|
+
const itemA11yRole = 'checkbox'
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<StackWrap ref={ref} {...a11y} space={space} direction={direction} tokens={stackTokens}>
|
|
96
|
+
{items.map(({ label, id = label, accessibilityLabel, ref: itemRef }, index) => {
|
|
97
|
+
const isSelected = currentValues.includes(id)
|
|
98
|
+
|
|
99
|
+
// Pass an object of relevant component state as first argument for any passed-in press handlers
|
|
100
|
+
const pressHandlers = getPressHandlersWithArgs(rest, [{ id, label, currentValues }])
|
|
101
|
+
|
|
102
|
+
const handlePress = (event) => {
|
|
103
|
+
if (pressHandlers.onPress) pressHandlers.onPress()
|
|
104
|
+
toggleOneValue(id, event)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const itemA11y = {
|
|
108
|
+
accessibilityState: { checked: isSelected },
|
|
109
|
+
accessibilityRole: itemA11yRole,
|
|
110
|
+
accessibilityLabel,
|
|
111
|
+
...a11yProps.getPositionInSet(items.length, index)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<ButtonBase
|
|
116
|
+
ref={itemRef}
|
|
117
|
+
key={id}
|
|
118
|
+
{...pressHandlers}
|
|
119
|
+
onPress={handlePress}
|
|
120
|
+
tokens={getButtonTokens}
|
|
121
|
+
selected={isSelected}
|
|
122
|
+
inactive={inactive}
|
|
123
|
+
{...itemA11y}
|
|
124
|
+
>
|
|
125
|
+
{({ textStyles, ...buttonState }) => {
|
|
126
|
+
// TODO: once Icon/IconButton designs are stable, see if this sort of styling around
|
|
127
|
+
// an icon should go in Icon itself, or possibly via an IconText token set. Related issues:
|
|
128
|
+
// - Icon: https://github.com/telus/universal-design-system/issues/327
|
|
129
|
+
// - IconButton: https://github.com/telus/universal-design-system/issues/281
|
|
130
|
+
// - Token sets: https://github.com/telus/universal-design-system/issues/782
|
|
131
|
+
|
|
132
|
+
const itemTokens = getItemTokens(buttonState)
|
|
133
|
+
|
|
134
|
+
const {
|
|
135
|
+
iconTokens,
|
|
136
|
+
iconPosition,
|
|
137
|
+
iconSpace,
|
|
138
|
+
iconWrapperStyle,
|
|
139
|
+
icon: IconComponent
|
|
140
|
+
} = selectIconTextTokens(itemTokens)
|
|
141
|
+
|
|
142
|
+
const iconContent = IconComponent ? (
|
|
143
|
+
<View style={iconWrapperStyle}>
|
|
144
|
+
<Icon icon={IconComponent} tokens={iconTokens} />
|
|
145
|
+
</View>
|
|
146
|
+
) : null
|
|
147
|
+
const textContent = <Text style={textStyles}>{label}</Text>
|
|
148
|
+
|
|
149
|
+
return getStackedContent(
|
|
150
|
+
iconPosition === 'left' ? [iconContent, textContent] : [textContent, iconContent],
|
|
151
|
+
{ space: iconSpace, direction: 'row' }
|
|
152
|
+
)
|
|
153
|
+
}}
|
|
154
|
+
</ButtonBase>
|
|
155
|
+
)
|
|
156
|
+
})}
|
|
157
|
+
</StackWrap>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
Tags.displayName = 'Tags'
|
|
154
162
|
|
|
155
163
|
Tags.propTypes = {
|
|
156
164
|
...a11yProps.propTypes,
|
|
@@ -181,7 +189,11 @@ Tags.propTypes = {
|
|
|
181
189
|
* which will be used in code and passed to any onChange function.
|
|
182
190
|
* If not provided, the label is used.
|
|
183
191
|
*/
|
|
184
|
-
id: PropTypes.string
|
|
192
|
+
id: PropTypes.string,
|
|
193
|
+
/**
|
|
194
|
+
* An optional ref for one individual Tag button in the tags
|
|
195
|
+
*/
|
|
196
|
+
ref: ABBPropTypes.ref()
|
|
185
197
|
})
|
|
186
198
|
),
|
|
187
199
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState } from 'react'
|
|
1
|
+
import React, { forwardRef, useState } from 'react'
|
|
2
2
|
|
|
3
3
|
import { Platform } from 'react-native'
|
|
4
4
|
import { getTokensPropType, variantProp } from '../utils'
|
|
@@ -32,7 +32,7 @@ import textInputPropTypes from './propTypes'
|
|
|
32
32
|
* or an indicator that the field is optional.
|
|
33
33
|
* It is a more usable and accessible option than the HTML `placeholder` attribute.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
const TextArea = forwardRef(({ tokens, variant = {}, ...remainingProps }, ref) => {
|
|
36
36
|
const themeTokens = useThemeTokens('TextArea', tokens, variant)
|
|
37
37
|
const [inputHeight, setInputHeight] = useState()
|
|
38
38
|
|
|
@@ -62,11 +62,12 @@ function TextArea({ tokens, variant = {}, ...remainingProps }) {
|
|
|
62
62
|
return (
|
|
63
63
|
<InputSupports {...supportsProps}>
|
|
64
64
|
{({ a11yProps, inputId }) => (
|
|
65
|
-
<TextInputBase {...inputProps} {...a11yProps} nativeID={inputId} />
|
|
65
|
+
<TextInputBase ref={ref} {...inputProps} {...a11yProps} nativeID={inputId} />
|
|
66
66
|
)}
|
|
67
67
|
</InputSupports>
|
|
68
68
|
)
|
|
69
|
-
}
|
|
69
|
+
})
|
|
70
|
+
TextArea.displayName = 'TextArea'
|
|
70
71
|
|
|
71
72
|
TextArea.propTypes = {
|
|
72
73
|
...inputSupportProps.types,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
2
|
|
|
3
3
|
import { getTokensPropType, variantProp } from '../utils'
|
|
4
4
|
import InputSupports from '../InputSupports'
|
|
@@ -24,7 +24,7 @@ import textInputPropTypes from './propTypes'
|
|
|
24
24
|
* supported props and <a href="https://reactnative.dev/docs/textinput" target="_blank">React Native Web documentation</a> for
|
|
25
25
|
* their implementation on the web.
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
const TextInput = forwardRef(({ tokens, variant = {}, ...remainingProps }, ref) => {
|
|
28
28
|
const { props: supportsProps, rest } = inputSupportProps.select(remainingProps)
|
|
29
29
|
|
|
30
30
|
const inputProps = {
|
|
@@ -36,11 +36,12 @@ function TextInput({ tokens, variant = {}, ...remainingProps }) {
|
|
|
36
36
|
return (
|
|
37
37
|
<InputSupports {...supportsProps}>
|
|
38
38
|
{({ a11yProps, inputId }) => (
|
|
39
|
-
<TextInputBase {...inputProps} {...a11yProps} nativeID={inputId} />
|
|
39
|
+
<TextInputBase ref={ref} {...inputProps} {...a11yProps} nativeID={inputId} />
|
|
40
40
|
)}
|
|
41
41
|
</InputSupports>
|
|
42
42
|
)
|
|
43
|
-
}
|
|
43
|
+
})
|
|
44
|
+
TextInput.displayName = 'TextInput'
|
|
44
45
|
|
|
45
46
|
TextInput.propTypes = {
|
|
46
47
|
...inputSupportProps.types,
|