@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.
Files changed (155) hide show
  1. package/.ultra.cache.json +1 -1
  2. package/CHANGELOG.md +20 -0
  3. package/__fixtures__/testTheme.js +424 -37
  4. package/__tests__/Button/ButtonBase.test.jsx +2 -31
  5. package/__tests__/Checkbox/Checkbox.test.jsx +94 -0
  6. package/__tests__/InputSupports/InputSupports.test.jsx +50 -0
  7. package/__tests__/List/List.test.jsx +60 -0
  8. package/__tests__/Radio/Radio.test.jsx +87 -0
  9. package/__tests__/Select/Select.test.jsx +93 -0
  10. package/__tests__/Skeleton/Skeleton.test.jsx +61 -0
  11. package/__tests__/Tags/Tags.test.jsx +328 -0
  12. package/__tests__/TextInput/TextArea.test.jsx +34 -0
  13. package/__tests__/TextInput/{TextInput.test.jsx → TextInputBase.test.jsx} +20 -46
  14. package/jest.config.js +3 -1
  15. package/lib/Button/Button.js +10 -3
  16. package/lib/Button/ButtonBase.js +73 -59
  17. package/lib/Button/ButtonGroup.js +11 -27
  18. package/lib/Button/ButtonLink.js +5 -0
  19. package/lib/Checkbox/Checkbox.js +308 -0
  20. package/lib/Checkbox/CheckboxInput.native.js +6 -0
  21. package/lib/Checkbox/CheckboxInput.web.js +57 -0
  22. package/lib/Checkbox/index.js +2 -0
  23. package/lib/Feedback/Feedback.js +20 -3
  24. package/lib/Icon/Icon.js +8 -5
  25. package/lib/Icon/IconText.js +72 -0
  26. package/lib/Icon/index.js +2 -1
  27. package/lib/InputSupports/InputSupports.js +90 -0
  28. package/lib/InputSupports/index.js +2 -0
  29. package/lib/InputSupports/propTypes.js +55 -0
  30. package/lib/Link/ChevronLink.js +23 -20
  31. package/lib/Link/InlinePressable.native.js +78 -0
  32. package/lib/Link/InlinePressable.web.js +32 -0
  33. package/lib/Link/Link.js +11 -10
  34. package/lib/Link/LinkBase.js +62 -123
  35. package/lib/Link/TextButton.js +20 -9
  36. package/lib/Link/index.js +2 -1
  37. package/lib/List/List.js +52 -0
  38. package/lib/List/ListItem.js +207 -0
  39. package/lib/List/index.js +2 -0
  40. package/lib/Pagination/PageButton.js +2 -25
  41. package/lib/Pagination/SideButton.js +27 -37
  42. package/lib/Radio/Radio.js +291 -0
  43. package/lib/Radio/RadioInput.native.js +6 -0
  44. package/lib/Radio/RadioInput.web.js +59 -0
  45. package/lib/Radio/index.js +2 -0
  46. package/lib/Select/Group.native.js +14 -0
  47. package/lib/Select/Group.web.js +18 -0
  48. package/lib/Select/Item.native.js +9 -0
  49. package/lib/Select/Item.web.js +15 -0
  50. package/lib/Select/Picker.native.js +87 -0
  51. package/lib/Select/Picker.web.js +63 -0
  52. package/lib/Select/Select.js +272 -0
  53. package/lib/Select/index.js +6 -0
  54. package/lib/Skeleton/Skeleton.js +119 -0
  55. package/lib/Skeleton/index.js +2 -0
  56. package/lib/Tags/Tags.js +217 -0
  57. package/lib/Tags/index.js +2 -0
  58. package/lib/TextInput/TextArea.js +82 -0
  59. package/lib/TextInput/TextInput.js +23 -304
  60. package/lib/TextInput/TextInputBase.js +229 -0
  61. package/lib/TextInput/index.js +2 -1
  62. package/lib/TextInput/propTypes.js +31 -0
  63. package/lib/ThemeProvider/useThemeTokens.js +54 -3
  64. package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
  65. package/lib/Typography/Typography.js +4 -19
  66. package/lib/index.js +8 -1
  67. package/lib/utils/a11y/index.js +1 -0
  68. package/lib/utils/a11y/textSize.js +33 -0
  69. package/lib/utils/index.js +3 -0
  70. package/lib/utils/info/index.js +7 -0
  71. package/lib/utils/info/platform/index.js +11 -0
  72. package/lib/utils/info/platform/platform.android.js +1 -0
  73. package/lib/utils/info/platform/platform.ios.js +1 -0
  74. package/lib/utils/info/platform/platform.native.js +4 -0
  75. package/lib/utils/info/platform/platform.web.js +1 -0
  76. package/lib/utils/info/versions.js +5 -0
  77. package/lib/utils/pressability.js +92 -0
  78. package/lib/utils/propTypes.js +78 -17
  79. package/package.json +5 -4
  80. package/release-context.json +4 -4
  81. package/src/Button/Button.jsx +6 -3
  82. package/src/Button/ButtonBase.jsx +66 -57
  83. package/src/Button/ButtonGroup.jsx +9 -22
  84. package/src/Button/ButtonLink.jsx +11 -2
  85. package/src/Checkbox/Checkbox.jsx +275 -0
  86. package/src/Checkbox/CheckboxInput.native.jsx +6 -0
  87. package/src/Checkbox/CheckboxInput.web.jsx +55 -0
  88. package/src/Checkbox/index.js +3 -0
  89. package/src/Feedback/Feedback.jsx +13 -4
  90. package/src/Icon/Icon.jsx +9 -5
  91. package/src/Icon/IconText.jsx +63 -0
  92. package/src/Icon/index.js +2 -1
  93. package/src/InputSupports/InputSupports.jsx +86 -0
  94. package/src/InputSupports/index.js +3 -0
  95. package/src/InputSupports/propTypes.js +44 -0
  96. package/src/Link/ChevronLink.jsx +20 -17
  97. package/src/Link/InlinePressable.native.jsx +73 -0
  98. package/src/Link/InlinePressable.web.jsx +37 -0
  99. package/src/Link/Link.jsx +17 -13
  100. package/src/Link/LinkBase.jsx +57 -140
  101. package/src/Link/TextButton.jsx +25 -11
  102. package/src/Link/index.js +2 -1
  103. package/src/List/List.jsx +47 -0
  104. package/src/List/ListItem.jsx +187 -0
  105. package/src/List/index.js +3 -0
  106. package/src/Pagination/PageButton.jsx +2 -16
  107. package/src/Pagination/SideButton.jsx +23 -34
  108. package/src/Radio/Radio.jsx +270 -0
  109. package/src/Radio/RadioInput.native.jsx +6 -0
  110. package/src/Radio/RadioInput.web.jsx +57 -0
  111. package/src/Radio/index.js +3 -0
  112. package/src/Select/Group.native.jsx +14 -0
  113. package/src/Select/Group.web.jsx +15 -0
  114. package/src/Select/Item.native.jsx +10 -0
  115. package/src/Select/Item.web.jsx +11 -0
  116. package/src/Select/Picker.native.jsx +95 -0
  117. package/src/Select/Picker.web.jsx +67 -0
  118. package/src/Select/Select.jsx +265 -0
  119. package/src/Select/index.js +8 -0
  120. package/src/Skeleton/Skeleton.jsx +101 -0
  121. package/src/Skeleton/index.js +3 -0
  122. package/src/Tags/Tags.jsx +206 -0
  123. package/src/Tags/index.js +3 -0
  124. package/src/TextInput/TextArea.jsx +78 -0
  125. package/src/TextInput/TextInput.jsx +17 -284
  126. package/src/TextInput/TextInputBase.jsx +220 -0
  127. package/src/TextInput/index.js +2 -1
  128. package/src/TextInput/propTypes.js +29 -0
  129. package/src/ThemeProvider/useThemeTokens.js +54 -3
  130. package/src/ToggleSwitch/ToggleSwitch.jsx +1 -1
  131. package/src/Typography/Typography.jsx +4 -15
  132. package/src/index.js +8 -1
  133. package/src/utils/a11y/index.js +1 -0
  134. package/src/utils/a11y/textSize.js +30 -0
  135. package/src/utils/index.js +3 -0
  136. package/src/utils/info/index.js +8 -0
  137. package/src/utils/info/platform/index.js +11 -0
  138. package/src/utils/info/platform/platform.android.js +1 -0
  139. package/src/utils/info/platform/platform.ios.js +1 -0
  140. package/src/utils/info/platform/platform.native.js +4 -0
  141. package/src/utils/info/platform/platform.web.js +1 -0
  142. package/src/utils/info/versions.js +6 -0
  143. package/src/utils/pressability.js +92 -0
  144. package/src/utils/propTypes.js +97 -22
  145. package/stories/Button/Button.stories.jsx +5 -0
  146. package/stories/Checkbox/Checkbox.stories.jsx +71 -0
  147. package/stories/Feedback/Feedback.stories.jsx +5 -6
  148. package/stories/Link/Link.stories.jsx +15 -1
  149. package/stories/List/List.stories.jsx +117 -0
  150. package/stories/Radio/Radio.stories.jsx +113 -0
  151. package/stories/Select/Select.stories.jsx +55 -0
  152. package/stories/Skeleton/Skeleton.stories.jsx +36 -0
  153. package/stories/Tags/Tags.stories.jsx +69 -0
  154. package/stories/TextInput/TextArea.stories.jsx +100 -0
  155. 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(rest)
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/propTypes'
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={themeTokens.size} color={themeTokens.color} />
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: https://github.com/telus/universal-design-system/issues/487
19
- transition: 'transform 200ms',
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
@@ -1,4 +1,5 @@
1
1
  import Icon, { iconComponentPropTypes, iconSvgPropTypes } from './Icon'
2
+ import IconText from './IconText'
2
3
 
3
4
  export default Icon
4
- export { iconComponentPropTypes, iconSvgPropTypes }
5
+ export { iconComponentPropTypes, iconSvgPropTypes, IconText }
@@ -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,3 @@
1
+ import InputSupports from './InputSupports'
2
+
3
+ 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
@@ -1,34 +1,37 @@
1
1
  import React from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
 
4
- import { useThemeTokens } from '../ThemeProvider'
5
- import Link from './Link'
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. If you have a use case outside of the above you are better off constructing theme variants of `Link`.
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 { iconDisplace, leftIcon, rightIcon } = useThemeTokens('ChevronLink', {}, {})
16
- const icon = direction === 'right' ? rightIcon : leftIcon
17
- const tokensCallback = (linkState) => ({
18
- ...(typeof tokens === 'function' ? tokens(linkState) : tokens),
19
- iconGapBefore: 0,
20
- iconGapAfter: 0,
21
- iconTranslateX: linkState.hover ? iconDisplace * (direction === 'right' ? 1 : -1) : 0
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
- <Link iconPosition={direction} icon={icon} {...linkProps} tokens={tokensCallback}>
27
+ <LinkBase {...linkProps} iconPosition={direction} tokens={getTokens}>
25
28
  {children}
26
- </Link>
29
+ </LinkBase>
27
30
  )
28
31
  }
29
-
30
32
  ChevronLink.propTypes = {
31
- ...Link.propTypes,
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 = ({ href, children, accessibilityRole = 'link', variant = {}, ...linkProps }) => (
6
- <LinkBase
7
- href={href}
8
- accessibilityRole={accessibilityRole}
9
- variant={{ component: 'Link', ...variant }}
10
- {...linkProps}
11
- >
12
- {children}
13
- </LinkBase>
14
- )
15
-
16
- Link.propTypes = {
17
- ...LinkBase.propTypes
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