@telus-uds/components-base 0.0.2-prerelease.6 → 0.0.2-prerelease.7
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 +20 -0
- package/__fixtures__/testTheme.js +424 -37
- package/__tests__/Button/ButtonBase.test.jsx +2 -31
- package/__tests__/Checkbox/Checkbox.test.jsx +94 -0
- package/__tests__/InputSupports/InputSupports.test.jsx +50 -0
- package/__tests__/List/List.test.jsx +60 -0
- package/__tests__/Radio/Radio.test.jsx +87 -0
- package/__tests__/Select/Select.test.jsx +93 -0
- package/__tests__/Skeleton/Skeleton.test.jsx +61 -0
- package/__tests__/Tags/Tags.test.jsx +328 -0
- package/__tests__/TextInput/TextArea.test.jsx +34 -0
- package/__tests__/TextInput/{TextInput.test.jsx → TextInputBase.test.jsx} +20 -46
- package/jest.config.js +3 -1
- package/lib/Button/Button.js +10 -3
- package/lib/Button/ButtonBase.js +73 -59
- package/lib/Button/ButtonGroup.js +11 -27
- package/lib/Button/ButtonLink.js +5 -0
- package/lib/Checkbox/Checkbox.js +308 -0
- package/lib/Checkbox/CheckboxInput.native.js +6 -0
- package/lib/Checkbox/CheckboxInput.web.js +57 -0
- package/lib/Checkbox/index.js +2 -0
- package/lib/Feedback/Feedback.js +20 -3
- package/lib/Icon/Icon.js +8 -5
- package/lib/Icon/IconText.js +72 -0
- package/lib/Icon/index.js +2 -1
- package/lib/InputSupports/InputSupports.js +90 -0
- package/lib/InputSupports/index.js +2 -0
- package/lib/InputSupports/propTypes.js +55 -0
- package/lib/Link/ChevronLink.js +23 -20
- package/lib/Link/InlinePressable.native.js +78 -0
- package/lib/Link/InlinePressable.web.js +32 -0
- package/lib/Link/Link.js +11 -10
- package/lib/Link/LinkBase.js +62 -123
- package/lib/Link/TextButton.js +20 -9
- package/lib/Link/index.js +2 -1
- package/lib/List/List.js +52 -0
- package/lib/List/ListItem.js +207 -0
- package/lib/List/index.js +2 -0
- package/lib/Pagination/PageButton.js +2 -25
- package/lib/Pagination/SideButton.js +27 -37
- package/lib/Radio/Radio.js +291 -0
- package/lib/Radio/RadioInput.native.js +6 -0
- package/lib/Radio/RadioInput.web.js +59 -0
- package/lib/Radio/index.js +2 -0
- package/lib/Select/Group.native.js +14 -0
- package/lib/Select/Group.web.js +18 -0
- package/lib/Select/Item.native.js +9 -0
- package/lib/Select/Item.web.js +15 -0
- package/lib/Select/Picker.native.js +87 -0
- package/lib/Select/Picker.web.js +63 -0
- package/lib/Select/Select.js +272 -0
- package/lib/Select/index.js +6 -0
- package/lib/Skeleton/Skeleton.js +119 -0
- package/lib/Skeleton/index.js +2 -0
- package/lib/Tags/Tags.js +217 -0
- package/lib/Tags/index.js +2 -0
- package/lib/TextInput/TextArea.js +82 -0
- package/lib/TextInput/TextInput.js +23 -304
- package/lib/TextInput/TextInputBase.js +229 -0
- package/lib/TextInput/index.js +2 -1
- package/lib/TextInput/propTypes.js +31 -0
- package/lib/ThemeProvider/useThemeTokens.js +54 -3
- package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
- package/lib/Typography/Typography.js +4 -19
- package/lib/index.js +8 -1
- package/lib/utils/a11y/index.js +1 -0
- package/lib/utils/a11y/textSize.js +33 -0
- package/lib/utils/index.js +3 -0
- package/lib/utils/info/index.js +7 -0
- package/lib/utils/info/platform/index.js +11 -0
- package/lib/utils/info/platform/platform.android.js +1 -0
- package/lib/utils/info/platform/platform.ios.js +1 -0
- package/lib/utils/info/platform/platform.native.js +4 -0
- package/lib/utils/info/platform/platform.web.js +1 -0
- package/lib/utils/info/versions.js +5 -0
- package/lib/utils/pressability.js +92 -0
- package/lib/utils/propTypes.js +78 -17
- package/package.json +5 -4
- package/release-context.json +4 -4
- package/src/Button/Button.jsx +6 -3
- package/src/Button/ButtonBase.jsx +66 -57
- package/src/Button/ButtonGroup.jsx +9 -22
- package/src/Button/ButtonLink.jsx +11 -2
- package/src/Checkbox/Checkbox.jsx +275 -0
- package/src/Checkbox/CheckboxInput.native.jsx +6 -0
- package/src/Checkbox/CheckboxInput.web.jsx +55 -0
- package/src/Checkbox/index.js +3 -0
- package/src/Feedback/Feedback.jsx +13 -4
- package/src/Icon/Icon.jsx +9 -5
- package/src/Icon/IconText.jsx +63 -0
- package/src/Icon/index.js +2 -1
- package/src/InputSupports/InputSupports.jsx +86 -0
- package/src/InputSupports/index.js +3 -0
- package/src/InputSupports/propTypes.js +44 -0
- package/src/Link/ChevronLink.jsx +20 -17
- package/src/Link/InlinePressable.native.jsx +73 -0
- package/src/Link/InlinePressable.web.jsx +37 -0
- package/src/Link/Link.jsx +17 -13
- package/src/Link/LinkBase.jsx +57 -140
- package/src/Link/TextButton.jsx +25 -11
- package/src/Link/index.js +2 -1
- package/src/List/List.jsx +47 -0
- package/src/List/ListItem.jsx +187 -0
- package/src/List/index.js +3 -0
- package/src/Pagination/PageButton.jsx +2 -16
- package/src/Pagination/SideButton.jsx +23 -34
- package/src/Radio/Radio.jsx +270 -0
- package/src/Radio/RadioInput.native.jsx +6 -0
- package/src/Radio/RadioInput.web.jsx +57 -0
- package/src/Radio/index.js +3 -0
- package/src/Select/Group.native.jsx +14 -0
- package/src/Select/Group.web.jsx +15 -0
- package/src/Select/Item.native.jsx +10 -0
- package/src/Select/Item.web.jsx +11 -0
- package/src/Select/Picker.native.jsx +95 -0
- package/src/Select/Picker.web.jsx +67 -0
- package/src/Select/Select.jsx +265 -0
- package/src/Select/index.js +8 -0
- package/src/Skeleton/Skeleton.jsx +101 -0
- package/src/Skeleton/index.js +3 -0
- package/src/Tags/Tags.jsx +206 -0
- package/src/Tags/index.js +3 -0
- package/src/TextInput/TextArea.jsx +78 -0
- package/src/TextInput/TextInput.jsx +17 -284
- package/src/TextInput/TextInputBase.jsx +220 -0
- package/src/TextInput/index.js +2 -1
- package/src/TextInput/propTypes.js +29 -0
- package/src/ThemeProvider/useThemeTokens.js +54 -3
- package/src/ToggleSwitch/ToggleSwitch.jsx +1 -1
- package/src/Typography/Typography.jsx +4 -15
- package/src/index.js +8 -1
- package/src/utils/a11y/index.js +1 -0
- package/src/utils/a11y/textSize.js +30 -0
- package/src/utils/index.js +3 -0
- package/src/utils/info/index.js +8 -0
- package/src/utils/info/platform/index.js +11 -0
- package/src/utils/info/platform/platform.android.js +1 -0
- package/src/utils/info/platform/platform.ios.js +1 -0
- package/src/utils/info/platform/platform.native.js +4 -0
- package/src/utils/info/platform/platform.web.js +1 -0
- package/src/utils/info/versions.js +6 -0
- package/src/utils/pressability.js +92 -0
- package/src/utils/propTypes.js +97 -22
- package/stories/Button/Button.stories.jsx +5 -0
- package/stories/Checkbox/Checkbox.stories.jsx +71 -0
- package/stories/Feedback/Feedback.stories.jsx +5 -6
- package/stories/Link/Link.stories.jsx +15 -1
- package/stories/List/List.stories.jsx +117 -0
- package/stories/Radio/Radio.stories.jsx +113 -0
- package/stories/Select/Select.stories.jsx +55 -0
- package/stories/Skeleton/Skeleton.stories.jsx +36 -0
- package/stories/Tags/Tags.stories.jsx +69 -0
- package/stories/TextInput/TextArea.stories.jsx +100 -0
- package/stories/supports.jsx +1 -1
|
@@ -40,8 +40,8 @@ const selectIconContainerStyles = ({ iconGap }) => ({
|
|
|
40
40
|
* ### Accessibility
|
|
41
41
|
* All accessibility props set on this component will be applied to the outer container.
|
|
42
42
|
*/
|
|
43
|
-
const Feedback = ({ title, children, tokens, variant, ...rest }) => {
|
|
44
|
-
const themeTokens = useThemeTokens('Feedback', tokens, variant)
|
|
43
|
+
const Feedback = ({ title, children, id, validation, tokens, variant, ...rest }) => {
|
|
44
|
+
const themeTokens = useThemeTokens('Feedback', tokens, { ...variant, validation })
|
|
45
45
|
const { space } = themeTokens
|
|
46
46
|
|
|
47
47
|
const { icon: IconComponent } = themeTokens
|
|
@@ -52,10 +52,13 @@ const Feedback = ({ title, children, tokens, variant, ...rest }) => {
|
|
|
52
52
|
const content =
|
|
53
53
|
typeof children === 'string' ? <Text style={contentTextStyles}>{children}</Text> : children
|
|
54
54
|
|
|
55
|
-
const accessibilityProps = a11yProps.select(
|
|
55
|
+
const accessibilityProps = a11yProps.select({
|
|
56
|
+
accessibilityRole: validation === 'error' ? 'alert' : undefined,
|
|
57
|
+
...rest
|
|
58
|
+
})
|
|
56
59
|
|
|
57
60
|
return (
|
|
58
|
-
<View style={selectStyles(themeTokens)} {...accessibilityProps}>
|
|
61
|
+
<View style={selectStyles(themeTokens)} {...accessibilityProps} nativeID={id}>
|
|
59
62
|
<StackView space={space}>
|
|
60
63
|
{title !== undefined && (
|
|
61
64
|
<View style={staticStyles.title}>
|
|
@@ -84,6 +87,12 @@ Feedback.propTypes = {
|
|
|
84
87
|
* Feedback content rendered below the title. A render function `({textStyles, variant}) => {}` is supported.
|
|
85
88
|
*/
|
|
86
89
|
children: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.func]),
|
|
90
|
+
/**
|
|
91
|
+
* Use to visually mark the Feedback as valid or invalid.
|
|
92
|
+
*/
|
|
93
|
+
validation: PropTypes.oneOf(['error', 'success']),
|
|
94
|
+
/** @ignore */
|
|
95
|
+
id: PropTypes.string,
|
|
87
96
|
tokens: getTokensPropType('Feedback'),
|
|
88
97
|
variant: variantProp.propType
|
|
89
98
|
}
|
package/src/Icon/Icon.jsx
CHANGED
|
@@ -3,20 +3,24 @@ import { Platform, View } from 'react-native'
|
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
4
|
|
|
5
5
|
import { useThemeTokens } from '../ThemeProvider'
|
|
6
|
-
import { getTokensPropType, variantProp } from '../utils
|
|
6
|
+
import { getTokensPropType, scaleWithText, variantProp } from '../utils'
|
|
7
7
|
|
|
8
|
-
const Icon = ({ IconSvg, variant, label, titleId, tokens =
|
|
8
|
+
const Icon = ({ IconSvg, variant, label, titleId, tokens, scalesWithText = false }) => {
|
|
9
9
|
const themeTokens = useThemeTokens('Icon', tokens, variant)
|
|
10
|
+
|
|
11
|
+
const size = scalesWithText ? scaleWithText(themeTokens.size) : themeTokens.size
|
|
12
|
+
|
|
10
13
|
const iconContent = (
|
|
11
|
-
<IconSvg title={label} titleId={titleId} size={
|
|
14
|
+
<IconSvg title={label} titleId={titleId} size={size} color={themeTokens.color} />
|
|
12
15
|
)
|
|
13
16
|
|
|
14
17
|
return Platform.OS === 'web' ? (
|
|
15
18
|
<View
|
|
16
19
|
// eslint-disable-next-line react-native/no-inline-styles
|
|
17
20
|
style={{
|
|
18
|
-
// TODO:
|
|
19
|
-
|
|
21
|
+
// TODO: systematise animations.
|
|
22
|
+
// https://github.com/telus/universal-design-system/issues/487
|
|
23
|
+
transition: 'transform 200ms, color 200ms',
|
|
20
24
|
transform: [
|
|
21
25
|
themeTokens.scale ? `scale(${themeTokens.scale})` : '',
|
|
22
26
|
themeTokens.translateX ? `translateX(${themeTokens.translateX}px)` : '',
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { Platform, View } from 'react-native'
|
|
4
|
+
|
|
5
|
+
import { iconComponentPropTypes } from './Icon'
|
|
6
|
+
import { getStackedContent } from '../StackView'
|
|
7
|
+
import { spacingProps } from '../utils'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns an icon and some text with a sized gap between them. This is a utility component
|
|
11
|
+
* intended for use when creating components, not intended for use in applications on its own.
|
|
12
|
+
*
|
|
13
|
+
* IconText does not wrap its children, so should be used either:
|
|
14
|
+
* - inline within a <Text> element
|
|
15
|
+
* - within a container with `flexDirection: 'row'`
|
|
16
|
+
*/
|
|
17
|
+
const IconText = ({ space, iconPosition = 'left', icon: IconComponent, iconProps, children }) => {
|
|
18
|
+
const iconContent = IconComponent && <IconComponent scalesWithText {...iconProps} />
|
|
19
|
+
|
|
20
|
+
// Inline images on Android are always baseline-aligned which makes them look misaligned - offset it.
|
|
21
|
+
// See abandoned issue https://github.com/facebook/react-native/issues/6529
|
|
22
|
+
const size = iconProps?.tokens?.size
|
|
23
|
+
const iconAdjusted =
|
|
24
|
+
Platform.OS === 'android' && iconContent && size ? (
|
|
25
|
+
<View style={{ transform: [{ translateY: size * 0.2 }] }}>{iconContent}</View>
|
|
26
|
+
) : (
|
|
27
|
+
iconContent
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
return getStackedContent(
|
|
31
|
+
iconPosition === 'left' ? [iconAdjusted, children] : [children, iconAdjusted],
|
|
32
|
+
{ space, direction: 'row' }
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
IconText.propTypes = {
|
|
37
|
+
/**
|
|
38
|
+
* Amount of space to separate the text content and icon. Uses the themes's spacing scale
|
|
39
|
+
* (see useSpacingScale for more info).
|
|
40
|
+
*/
|
|
41
|
+
space: spacingProps.types.spacingValue,
|
|
42
|
+
/**
|
|
43
|
+
* Whether the icon should be to the left of the content or the right of the content.
|
|
44
|
+
*/
|
|
45
|
+
iconPosition: PropTypes.oneOf(['left', 'right']),
|
|
46
|
+
/**
|
|
47
|
+
* A valid UDS icon component imported from a UDS palette.
|
|
48
|
+
*/
|
|
49
|
+
icon: PropTypes.func,
|
|
50
|
+
/**
|
|
51
|
+
* Props that will be passed to the icon component. By default the icon's `scalesWithText`
|
|
52
|
+
* prop will be set as "true" so that the icon continues to match the size of the text
|
|
53
|
+
* if users use accessibility settings to increase text size.
|
|
54
|
+
*/
|
|
55
|
+
iconProps: PropTypes.exact(iconComponentPropTypes),
|
|
56
|
+
/**
|
|
57
|
+
* Content to be rendered alongside the Icon component. Usually this should be a
|
|
58
|
+
* `<Typography>` component, or a component that renders `<Text>`.
|
|
59
|
+
*/
|
|
60
|
+
children: PropTypes.node
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default IconText
|
package/src/Icon/index.js
CHANGED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import InputLabel from '../InputLabel'
|
|
5
|
+
import Feedback from '../Feedback'
|
|
6
|
+
import StackView from '../StackView'
|
|
7
|
+
import { useThemeTokens } from '../ThemeProvider'
|
|
8
|
+
import useUniqueId from '../utils/useUniqueId'
|
|
9
|
+
|
|
10
|
+
const joinDefined = (array) => array.filter((item) => item !== undefined).join(' ')
|
|
11
|
+
|
|
12
|
+
function InputSupports({
|
|
13
|
+
children,
|
|
14
|
+
label,
|
|
15
|
+
hint,
|
|
16
|
+
hintPosition = 'inline',
|
|
17
|
+
feedback,
|
|
18
|
+
tooltip,
|
|
19
|
+
validation
|
|
20
|
+
}) {
|
|
21
|
+
const { space } = useThemeTokens('InputSupports')
|
|
22
|
+
|
|
23
|
+
const hasValidationError = validation === 'error'
|
|
24
|
+
|
|
25
|
+
const inputId = useUniqueId('input')
|
|
26
|
+
const hintId = useUniqueId('input-hint')
|
|
27
|
+
const feedbackId = useUniqueId('input-feedback')
|
|
28
|
+
|
|
29
|
+
const a11yProps = {
|
|
30
|
+
accessibilityLabel: label,
|
|
31
|
+
accessibilityHint: joinDefined([!hasValidationError && feedback, hint]), // native only -> replaced with describedBy on web
|
|
32
|
+
accessibilityDescribedBy: joinDefined([
|
|
33
|
+
!hasValidationError && feedback && feedbackId, // feedback receives a11yRole=alert on error, so there's no need to include it here
|
|
34
|
+
hint && hintId
|
|
35
|
+
]), // introduced in RNW 0.15.0
|
|
36
|
+
accessibilityInvalid: hasValidationError // introduced in RNW 0.15.0
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<StackView space={space}>
|
|
41
|
+
{label && (
|
|
42
|
+
<InputLabel
|
|
43
|
+
label={label}
|
|
44
|
+
hint={hint}
|
|
45
|
+
hintPosition={hintPosition}
|
|
46
|
+
hintId={hintId}
|
|
47
|
+
tooltip={tooltip}
|
|
48
|
+
forId={inputId}
|
|
49
|
+
/>
|
|
50
|
+
)}
|
|
51
|
+
{typeof children === 'function' ? children({ a11yProps, inputId }) : children}
|
|
52
|
+
{feedback && <Feedback id={feedbackId} title={feedback} validation={validation} />}
|
|
53
|
+
</StackView>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
InputSupports.propTypes = {
|
|
58
|
+
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
|
|
59
|
+
/**
|
|
60
|
+
* The input label.
|
|
61
|
+
*/
|
|
62
|
+
label: PropTypes.string,
|
|
63
|
+
/**
|
|
64
|
+
* A short description of the expected input.
|
|
65
|
+
*/
|
|
66
|
+
hint: PropTypes.string,
|
|
67
|
+
/**
|
|
68
|
+
* Position of the hint relative to label.
|
|
69
|
+
*/
|
|
70
|
+
hintPosition: PropTypes.oneOf(['inline', 'below']),
|
|
71
|
+
/**
|
|
72
|
+
* A detailed description of validation error/success or additional instructions.
|
|
73
|
+
* Visual variant is determined based on the `validation` prop.
|
|
74
|
+
*/
|
|
75
|
+
feedback: PropTypes.string,
|
|
76
|
+
/**
|
|
77
|
+
* Content of an optional `Tooltip`. If set, a tooltip button will be shown next to the label.
|
|
78
|
+
*/
|
|
79
|
+
tooltip: PropTypes.string,
|
|
80
|
+
/**
|
|
81
|
+
* Use to visually mark an input as valid or invalid.
|
|
82
|
+
*/
|
|
83
|
+
validation: PropTypes.oneOf(['error', 'success'])
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default InputSupports
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
|
|
3
|
+
const inputSupportProps = {
|
|
4
|
+
types: {
|
|
5
|
+
/**
|
|
6
|
+
* The input label.
|
|
7
|
+
*/
|
|
8
|
+
label: PropTypes.string,
|
|
9
|
+
/**
|
|
10
|
+
* A short description of the expected input.
|
|
11
|
+
*/
|
|
12
|
+
hint: PropTypes.string,
|
|
13
|
+
/**
|
|
14
|
+
* Position of the hint relative to label. Use `below` to display a larger hint below the label.
|
|
15
|
+
*/
|
|
16
|
+
hintPosition: PropTypes.oneOf(['inline', 'below']),
|
|
17
|
+
/**
|
|
18
|
+
* A detailed description of validation error/success or additional instructions.
|
|
19
|
+
* Visual variant is determined based on the `validation` prop.
|
|
20
|
+
*/
|
|
21
|
+
feedback: PropTypes.string,
|
|
22
|
+
/**
|
|
23
|
+
* Content of an optional `Tooltip`. If set, a tooltip button will be shown next to the label.
|
|
24
|
+
*/
|
|
25
|
+
tooltip: PropTypes.string,
|
|
26
|
+
/**
|
|
27
|
+
* Use to visually mark an input as valid or invalid.
|
|
28
|
+
*/
|
|
29
|
+
validation: PropTypes.oneOf(['error', 'success'])
|
|
30
|
+
},
|
|
31
|
+
select: ({ label, hint, hintPosition, feedback, tooltip, validation, ...rest }) => ({
|
|
32
|
+
props: {
|
|
33
|
+
label,
|
|
34
|
+
hint,
|
|
35
|
+
hintPosition,
|
|
36
|
+
feedback,
|
|
37
|
+
tooltip,
|
|
38
|
+
validation
|
|
39
|
+
},
|
|
40
|
+
rest
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default inputSupportProps
|
package/src/Link/ChevronLink.jsx
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { useThemeTokensCallback } from '../ThemeProvider'
|
|
5
|
+
import { selectTokens, getTokensPropType } from '../utils'
|
|
6
|
+
import LinkBase from './LinkBase'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* `ChevronLink` is a convenience wrapper around the `Link` component to enable "directional" links.
|
|
9
10
|
* It effectively pre-binds left and right icons, and a directional translation of the icon on hover.
|
|
10
11
|
*
|
|
11
|
-
* ChevronLink is not intended to be deeply themable
|
|
12
|
-
* In that vein, note that the `tokens` and `variant` system props for `ChevronLink` are passed directly to the underlying `Link` component: ChevronLink itself does not support further customisation using these system props.
|
|
12
|
+
* ChevronLink is not intended to be deeply themable; variants passed to ChevronLink are forwarded to Link.
|
|
13
13
|
*/
|
|
14
|
-
const ChevronLink = ({ direction = 'right', children, tokens, ...linkProps }) => {
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
const ChevronLink = ({ direction = 'right', children, tokens, variant, ...linkProps }) => {
|
|
15
|
+
const getChevronTokens = useThemeTokensCallback('ChevronLink', tokens, variant)
|
|
16
|
+
const applyChevronTokens = (linkState) => {
|
|
17
|
+
const { leftIcon, rightIcon, iconDisplace, ...otherTokens } = getChevronTokens(linkState)
|
|
18
|
+
return {
|
|
19
|
+
...selectTokens('Link', otherTokens),
|
|
20
|
+
icon: direction === 'right' ? rightIcon : leftIcon,
|
|
21
|
+
iconTranslateX: iconDisplace * (direction === 'right' ? 1 : -1) || 0
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const getTokens = useThemeTokensCallback('Link', applyChevronTokens, variant)
|
|
23
26
|
return (
|
|
24
|
-
<
|
|
27
|
+
<LinkBase {...linkProps} iconPosition={direction} tokens={getTokens}>
|
|
25
28
|
{children}
|
|
26
|
-
</
|
|
29
|
+
</LinkBase>
|
|
27
30
|
)
|
|
28
31
|
}
|
|
29
|
-
|
|
30
32
|
ChevronLink.propTypes = {
|
|
31
|
-
...
|
|
33
|
+
...LinkBase.propTypes,
|
|
34
|
+
tokens: getTokensPropType('ChevronLink', 'Link'),
|
|
32
35
|
direction: PropTypes.oneOf(['left', 'right'])
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
2
|
+
import React, { useState } from 'react'
|
|
3
|
+
import { Text, TouchableWithoutFeedback } from 'react-native'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('react-native').PressableProps} PressableProps
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// TouchableWithoutFeedback and Pressable have similar but not identical props APIs
|
|
10
|
+
const pressablePropsToTouchable = ({
|
|
11
|
+
unstable_pressDelay,
|
|
12
|
+
android_disableSound,
|
|
13
|
+
android_ripple, // Unsupported, discard it
|
|
14
|
+
...props
|
|
15
|
+
}) => ({
|
|
16
|
+
...props,
|
|
17
|
+
touchSoundDisabled: android_disableSound,
|
|
18
|
+
delayPressIn: unstable_pressDelay
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* InlinePressable is an alternative to React Native's Pressable that works better when nested
|
|
23
|
+
* inline inside Text. It accepts the same props as React Native's Pressable.
|
|
24
|
+
*
|
|
25
|
+
* There are a lot of React Native bugs around Views/Pressables nested in Text, e.g.:
|
|
26
|
+
*
|
|
27
|
+
* - https://github.com/facebook/react-native/issues/23601#issuecomment-468069822
|
|
28
|
+
* - https://github.com/facebook/react-native/issues/30375
|
|
29
|
+
* - https://github.com/facebook/react-native/issues/31955
|
|
30
|
+
*
|
|
31
|
+
* On Native, these can be avoided using a `Text` wrapped in a `TouchableWithoutFeedback`; the latter
|
|
32
|
+
* injects additional handlers such as onPressIn to `Text`, resulting in a tree that is purely `Text`.
|
|
33
|
+
*
|
|
34
|
+
* Note that this should only be used on Native, not Web, because React Navigation's Web navigation
|
|
35
|
+
* functions don't work in Touchables (but do work in Pressable) due to different event handling.
|
|
36
|
+
*
|
|
37
|
+
* @param {PressableProps} PressableProps
|
|
38
|
+
*/
|
|
39
|
+
// React Native exports prop Types but not propTypes, use JSDoc types here rather than duplicate RN
|
|
40
|
+
// eslint-disable-next-line react/prop-types
|
|
41
|
+
const InlinePressable = ({ onPress, children, style, ...rest }) => {
|
|
42
|
+
const [isFocused, setIsFocused] = useState(false)
|
|
43
|
+
const handleFocus = () => setIsFocused(true)
|
|
44
|
+
const handleBlur = () => setIsFocused(false)
|
|
45
|
+
|
|
46
|
+
const [isPressed, setIsPressed] = useState(false)
|
|
47
|
+
const handlePressIn = () => setIsPressed(true)
|
|
48
|
+
const handlePressOut = () => setIsPressed(false)
|
|
49
|
+
|
|
50
|
+
const pressState = {
|
|
51
|
+
pressed: isPressed,
|
|
52
|
+
focus: isFocused, // limited support on native
|
|
53
|
+
hover: false // not yet supported on native
|
|
54
|
+
}
|
|
55
|
+
const currentStyle = typeof style === 'function' ? style(pressState) : style
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<TouchableWithoutFeedback
|
|
59
|
+
onPress={onPress}
|
|
60
|
+
onPressIn={handlePressIn}
|
|
61
|
+
onPressOut={handlePressOut}
|
|
62
|
+
onFocus={handleFocus}
|
|
63
|
+
onBlur={handleBlur}
|
|
64
|
+
{...pressablePropsToTouchable(rest)}
|
|
65
|
+
>
|
|
66
|
+
<Text style={currentStyle}>
|
|
67
|
+
{typeof children === 'function' ? children(pressState) : children}
|
|
68
|
+
</Text>
|
|
69
|
+
</TouchableWithoutFeedback>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default InlinePressable
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Pressable, StyleSheet } from 'react-native'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('react-native').PressableProps} PressableProps
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* InlinePressable is an alternative to React Native's Pressable that works better when nested
|
|
10
|
+
* inline inside Text. It accepts the same props as React Native's Pressable.
|
|
11
|
+
*
|
|
12
|
+
* On Web it simply passes its props to Pressable and defaults to `inline-flex` instead of `flex`.
|
|
13
|
+
*
|
|
14
|
+
* @param {PressableProps} PressableProps
|
|
15
|
+
*/
|
|
16
|
+
// React Native exports prop Types but not propTypes, use JSDoc types here rather than duplicate RN
|
|
17
|
+
// eslint-disable-next-line react/prop-types
|
|
18
|
+
const InlinePressable = ({ children, style, ...props }) => (
|
|
19
|
+
<Pressable
|
|
20
|
+
style={(pressState) => [
|
|
21
|
+
staticStyles.inline,
|
|
22
|
+
typeof style === 'function' ? style(pressState) : style
|
|
23
|
+
]}
|
|
24
|
+
{...props}
|
|
25
|
+
>
|
|
26
|
+
{(pressState) => (typeof children === 'function' ? children(pressState) : children)}
|
|
27
|
+
</Pressable>
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
const staticStyles = StyleSheet.create({
|
|
31
|
+
inline: {
|
|
32
|
+
// Stop Pressable defaulting to (block) flex
|
|
33
|
+
display: 'inline-flex'
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export default InlinePressable
|
package/src/Link/Link.jsx
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
|
|
3
|
+
import { useThemeTokensCallback } from '../ThemeProvider'
|
|
3
4
|
import LinkBase from './LinkBase'
|
|
4
5
|
|
|
5
|
-
const Link = ({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
const Link = ({
|
|
7
|
+
href,
|
|
8
|
+
children,
|
|
9
|
+
accessibilityRole = 'link',
|
|
10
|
+
variant = {},
|
|
11
|
+
tokens,
|
|
12
|
+
...linkProps
|
|
13
|
+
}) => {
|
|
14
|
+
const getTokens = useThemeTokensCallback('Link', tokens, variant)
|
|
15
|
+
return (
|
|
16
|
+
<LinkBase href={href} accessibilityRole={accessibilityRole} tokens={getTokens} {...linkProps}>
|
|
17
|
+
{children}
|
|
18
|
+
</LinkBase>
|
|
19
|
+
)
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
Link.propTypes = LinkBase.propTypes
|
|
23
|
+
|
|
20
24
|
export default Link
|