@telus-uds/components-base 3.29.0 → 3.30.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.
Files changed (105) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/jest.config.cjs +1 -0
  3. package/lib/cjs/ActionCard/ActionCard.js +4 -4
  4. package/lib/cjs/ActivityIndicator/Dots.native.js +1 -2
  5. package/lib/cjs/ActivityIndicator/Spinner.native.js +1 -2
  6. package/lib/cjs/Box/Box.js +1 -2
  7. package/lib/cjs/Button/Button.js +1 -2
  8. package/lib/cjs/Button/ButtonBase.js +8 -8
  9. package/lib/cjs/Button/ButtonDropdown.js +1 -2
  10. package/lib/cjs/Button/ButtonGroup.js +1 -2
  11. package/lib/cjs/Button/ButtonLink.js +1 -2
  12. package/lib/cjs/Card/Card.js +1 -2
  13. package/lib/cjs/Card/PressableCardBase.js +1 -2
  14. package/lib/cjs/Card/index.js +1 -2
  15. package/lib/cjs/CardGroup/CardGroup.js +1 -2
  16. package/lib/cjs/Carousel/Carousel.js +12 -7
  17. package/lib/cjs/Carousel/CarouselThumbnail.js +123 -31
  18. package/lib/cjs/Carousel/CarouselThumbnailNavigation.js +8 -1
  19. package/lib/cjs/CheckboxCard/CheckboxCard.js +1 -2
  20. package/lib/cjs/CheckboxCardGroup/CheckboxCardGroup.js +1 -2
  21. package/lib/cjs/Footnote/FootnoteLink.js +18 -17
  22. package/lib/cjs/HorizontalScroll/index.js +1 -2
  23. package/lib/cjs/Icon/IconText.js +1 -2
  24. package/lib/cjs/Icon/index.js +1 -2
  25. package/lib/cjs/InputSupports/InputSupports.js +1 -2
  26. package/lib/cjs/InputSupports/useInputSupports.js +1 -3
  27. package/lib/cjs/Link/MobileIconTextContent.js +1 -2
  28. package/lib/cjs/Listbox/Listbox.js +1 -2
  29. package/lib/cjs/Modal/Modal.js +1 -1
  30. package/lib/cjs/Pagination/PageButton.js +1 -2
  31. package/lib/cjs/Pagination/Pagination.js +1 -2
  32. package/lib/cjs/Progress/Progress.js +30 -5
  33. package/lib/cjs/QuickLinks/QuickLinks.js +7 -0
  34. package/lib/cjs/Radio/Radio.js +1 -2
  35. package/lib/cjs/RadioCard/RadioCard.js +1 -2
  36. package/lib/cjs/RadioCard/RadioCardGroup.js +1 -2
  37. package/lib/cjs/Scroll/Scroll.js +466 -0
  38. package/lib/cjs/Scroll/ScrollContext.js +55 -0
  39. package/lib/cjs/Scroll/ScrollItem.js +103 -0
  40. package/lib/cjs/Scroll/ScrollProgress.js +99 -0
  41. package/lib/cjs/Scroll/dictionary.js +18 -0
  42. package/lib/cjs/Scroll/index.js +29 -0
  43. package/lib/cjs/Shortcuts/Shortcuts.js +1 -2
  44. package/lib/cjs/SideNav/SideNav.js +1 -2
  45. package/lib/cjs/StackView/StackWrapBox.js +9 -1
  46. package/lib/cjs/StackView/StackWrapGap.js +3 -1
  47. package/lib/cjs/StackView/getStackedContent.js +21 -12
  48. package/lib/cjs/Tabs/Tabs.js +1 -2
  49. package/lib/cjs/Tooltip/Tooltip.native.js +2 -2
  50. package/lib/cjs/index.js +16 -2
  51. package/lib/cjs/utils/animation/index.js +7 -0
  52. package/lib/cjs/utils/animation/useAnimatedValue.js +46 -0
  53. package/lib/cjs/utils/children.js +2 -1
  54. package/lib/cjs/utils/index.js +1 -2
  55. package/lib/esm/ActionCard/ActionCard.js +4 -4
  56. package/lib/esm/Button/ButtonBase.js +8 -8
  57. package/lib/esm/Carousel/Carousel.js +12 -7
  58. package/lib/esm/Carousel/CarouselThumbnail.js +124 -32
  59. package/lib/esm/Carousel/CarouselThumbnailNavigation.js +8 -1
  60. package/lib/esm/Footnote/FootnoteLink.js +18 -17
  61. package/lib/esm/InputSupports/InputSupports.js +1 -2
  62. package/lib/esm/InputSupports/useInputSupports.js +1 -3
  63. package/lib/esm/Modal/Modal.js +1 -1
  64. package/lib/esm/Progress/Progress.js +30 -5
  65. package/lib/esm/QuickLinks/QuickLinks.js +7 -0
  66. package/lib/esm/Scroll/Scroll.js +459 -0
  67. package/lib/esm/Scroll/ScrollContext.js +47 -0
  68. package/lib/esm/Scroll/ScrollItem.js +96 -0
  69. package/lib/esm/Scroll/ScrollProgress.js +92 -0
  70. package/lib/esm/Scroll/dictionary.js +12 -0
  71. package/lib/esm/Scroll/index.js +4 -0
  72. package/lib/esm/StackView/StackWrapBox.js +9 -1
  73. package/lib/esm/StackView/StackWrapGap.js +3 -1
  74. package/lib/esm/StackView/getStackedContent.js +20 -10
  75. package/lib/esm/Tooltip/Tooltip.native.js +2 -2
  76. package/lib/esm/index.js +1 -0
  77. package/lib/esm/utils/animation/index.js +1 -1
  78. package/lib/esm/utils/animation/useAnimatedValue.js +39 -0
  79. package/lib/esm/utils/children.js +2 -1
  80. package/lib/package.json +2 -2
  81. package/package.json +2 -2
  82. package/src/Carousel/Carousel.jsx +6 -1
  83. package/src/Carousel/CarouselThumbnail.jsx +153 -64
  84. package/src/Carousel/CarouselThumbnailNavigation.jsx +8 -2
  85. package/src/Footnote/FootnoteLink.jsx +17 -12
  86. package/src/InputSupports/InputSupports.jsx +1 -6
  87. package/src/InputSupports/useInputSupports.js +1 -1
  88. package/src/Modal/Modal.jsx +1 -1
  89. package/src/Progress/Progress.jsx +22 -3
  90. package/src/QuickLinks/QuickLinks.jsx +8 -0
  91. package/src/Scroll/Scroll.jsx +488 -0
  92. package/src/Scroll/ScrollContext.jsx +41 -0
  93. package/src/Scroll/ScrollItem.jsx +89 -0
  94. package/src/Scroll/ScrollProgress.jsx +75 -0
  95. package/src/Scroll/dictionary.js +12 -0
  96. package/src/Scroll/index.js +5 -0
  97. package/src/StackView/StackWrapBox.jsx +13 -1
  98. package/src/StackView/StackWrapGap.jsx +2 -1
  99. package/src/StackView/getStackedContent.jsx +22 -8
  100. package/src/index.js +1 -0
  101. package/src/utils/animation/index.js +1 -1
  102. package/src/utils/animation/useAnimatedValue.js +37 -0
  103. package/src/utils/children.jsx +4 -1
  104. package/types/Scroll.d.ts +66 -0
  105. package/types/index.d.ts +9 -0
@@ -0,0 +1,75 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import { View } from 'react-native'
4
+
5
+ import { resolvePressableState, useAnimatedValue } from '../utils'
6
+ import Progress from '../Progress'
7
+
8
+ const MAX_PERCENTAGE = 100
9
+ const BORDER_RADIUS_DIVISOR = 2
10
+
11
+ const staticProgressTokens = {
12
+ borderWidth: 0,
13
+ borderColor: 'transparent'
14
+ }
15
+
16
+ const staticProgressBarTokens = {
17
+ gradient: null,
18
+ outlineWidth: 0
19
+ }
20
+
21
+ const selectProgressTokens = ({ progressTrackHeight, progressBarHeight, progressTrackColor }) => ({
22
+ height: progressTrackHeight,
23
+ barHeight: progressBarHeight,
24
+ backgroundColor: progressTrackColor,
25
+ borderRadius: progressTrackHeight / BORDER_RADIUS_DIVISOR
26
+ })
27
+
28
+ const selectBarTokens = ({ progressBarColor, progressBarHeight }) => ({
29
+ backgroundColor: progressBarColor,
30
+ borderRadius: progressBarHeight / BORDER_RADIUS_DIVISOR
31
+ })
32
+
33
+ const ScrollProgress = React.forwardRef(
34
+ ({ pressableState, getTokens, thumbWrapperStyle, getCopy }, ref) => {
35
+ const state = resolvePressableState(pressableState)
36
+ const themeTokens = getTokens(state)
37
+ const animatedBarHeight = useAnimatedValue(themeTokens.progressBarHeight)
38
+ const animatedTokens = { ...themeTokens, progressBarHeight: animatedBarHeight }
39
+
40
+ return (
41
+ <Progress tokens={{ ...staticProgressTokens, ...selectProgressTokens(animatedTokens) }}>
42
+ <View ref={ref} style={thumbWrapperStyle}>
43
+ <Progress.Bar
44
+ percentage={MAX_PERCENTAGE}
45
+ tokens={{ ...staticProgressBarTokens, ...selectBarTokens(animatedTokens) }}
46
+ accessibilityLabel={getCopy('progressBarLabel')}
47
+ />
48
+ </View>
49
+ </Progress>
50
+ )
51
+ }
52
+ )
53
+
54
+ ScrollProgress.displayName = 'ScrollProgress'
55
+
56
+ ScrollProgress.propTypes = {
57
+ /**
58
+ * State object from Pressable's render callback containing hovered, pressed, and focused states
59
+ */
60
+ pressableState: PropTypes.object.isRequired,
61
+ /**
62
+ * Theme token resolver callback from useThemeTokensCallback that accepts appearance state
63
+ */
64
+ getTokens: PropTypes.func.isRequired,
65
+ /**
66
+ * Style array for the thumb wrapper containing static and dynamic position styles
67
+ */
68
+ thumbWrapperStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]).isRequired,
69
+ /**
70
+ * Copy resolver function from useCopy for retrieving localized strings
71
+ */
72
+ getCopy: PropTypes.func.isRequired
73
+ }
74
+
75
+ export default ScrollProgress
@@ -0,0 +1,12 @@
1
+ export default {
2
+ en: {
3
+ accessibilityLabel: 'Scrollable content',
4
+ instructionText: 'Use Tab, arrow keys, or space bar to navigate',
5
+ progressBarLabel: 'Scroll position'
6
+ },
7
+ fr: {
8
+ accessibilityLabel: 'Contenu défilable',
9
+ instructionText: "Utilisez Tab, les touches fléchées ou la barre d'espace pour naviguer",
10
+ progressBarLabel: 'Position de défilement'
11
+ }
12
+ }
@@ -0,0 +1,5 @@
1
+ import Scroll from './Scroll'
2
+
3
+ export default Scroll
4
+ export { default as ScrollItem } from './ScrollItem'
5
+ export { ScrollProvider, useScroll } from './ScrollContext'
@@ -58,6 +58,7 @@ const StackWrapBox = React.forwardRef(
58
58
  variant,
59
59
  tag,
60
60
  accessibilityRole,
61
+ itemAccessibilityRole,
61
62
  ...rest
62
63
  },
63
64
  ref
@@ -76,7 +77,12 @@ const StackWrapBox = React.forwardRef(
76
77
  const gapSize = useSpacingScale(gap)
77
78
  const offsetStyle = { [offsetSides[direction]]: -1 * gapSize }
78
79
  const boxProps = { [gapSides[direction]]: gap, [spaceSides[direction]]: space }
79
- const content = getStackedContent(children, { direction, space: 0, box: boxProps })
80
+ const content = getStackedContent(children, {
81
+ direction,
82
+ space: 0,
83
+ box: boxProps,
84
+ itemAccessibilityRole
85
+ })
80
86
 
81
87
  return (
82
88
  <View
@@ -119,6 +125,12 @@ StackWrapBox.propTypes = {
119
125
  * is not defined, the accessibilityRole will default to "heading".
120
126
  */
121
127
  tag: PropTypes.oneOf(layoutTags),
128
+ /**
129
+ * Optional accessibility role to apply to each item in the stack.
130
+ * On web, items are wrapped (or cloned) with this role, enabling correct list semantics
131
+ * when the container tag is "ul" or "ol".
132
+ */
133
+ itemAccessibilityRole: PropTypes.string,
122
134
  /**
123
135
  * A StackWrap may take any children, but will have no effect if it is only passed one child or is passed children
124
136
  * wrapped in a component. If necessary, children may be wrapped in one React Fragment.
@@ -37,6 +37,7 @@ const StackWrapGap = React.forwardRef(
37
37
  children,
38
38
  tag,
39
39
  accessibilityRole,
40
+ itemAccessibilityRole,
40
41
  ...rest
41
42
  },
42
43
  ref
@@ -54,7 +55,7 @@ const StackWrapGap = React.forwardRef(
54
55
  const size = useSpacingScale(space)
55
56
  const gapStyle = { gap: size }
56
57
 
57
- const content = getStackedContent(children, { direction, space: 0 })
58
+ const content = getStackedContent(children, { direction, space: 0, itemAccessibilityRole })
58
59
 
59
60
  return (
60
61
  <View
@@ -32,7 +32,7 @@ import Spacer from '../Spacer'
32
32
  */
33
33
  const getStackedContent = (
34
34
  children,
35
- { divider, space, direction = 'column', box, preserveFragments = false }
35
+ { divider, space, direction = 'column', box, preserveFragments = false, itemAccessibilityRole }
36
36
  ) => {
37
37
  const boxProps = box && typeof box === 'object' ? box : { space }
38
38
  const dividerProps = divider && typeof divider === 'object' ? divider : {}
@@ -42,15 +42,29 @@ const getStackedContent = (
42
42
  const validChildren = React.Children.toArray(topLevelChildren).filter(Boolean)
43
43
  const content = validChildren.reduce((newChildren, child, index) => {
44
44
  const boxID = `Stack-Box-${index}`
45
- const item = box ? (
45
+
46
+ let item
47
+ if (box) {
46
48
  // If wrapped in Box, that Box needs a key.
47
49
  // If possible, use an existing content key; use an index-based key only if necessary.
48
- <Box {...boxProps} key={child.key || boxID} testID={boxID}>
49
- {child}
50
- </Box>
51
- ) : (
52
- child
53
- )
50
+ item = (
51
+ <Box
52
+ {...boxProps}
53
+ accessibilityRole={itemAccessibilityRole}
54
+ key={child.key || boxID}
55
+ testID={boxID}
56
+ >
57
+ {child}
58
+ </Box>
59
+ )
60
+ } else if (itemAccessibilityRole) {
61
+ item = React.cloneElement(child, {
62
+ accessibilityRole: itemAccessibilityRole,
63
+ key: child.key || boxID
64
+ })
65
+ } else {
66
+ item = child
67
+ }
54
68
  if (!index || (!space && !divider)) return [...newChildren, item]
55
69
 
56
70
  const testID = `Stack-${divider ? 'Divider' : 'Spacer'}-${index}`
package/src/index.js CHANGED
@@ -49,6 +49,7 @@ export { default as QuickLinksFeature } from './QuickLinksFeature'
49
49
  export { default as Radio, RadioGroup } from './Radio'
50
50
  export { default as RadioCard, RadioCardGroup } from './RadioCard'
51
51
  export { default as Responsive } from './Responsive'
52
+ export { default as Scroll, ScrollItem } from './Scroll'
52
53
  export { default as Search } from './Search'
53
54
  export { default as Select } from './Select'
54
55
  export { default as Shortcuts, ShortcutsItem } from './Shortcuts'
@@ -1,2 +1,2 @@
1
- /* eslint-disable import/prefer-default-export */
1
+ export { default as useAnimatedValue } from './useAnimatedValue'
2
2
  export { default as useVerticalExpandAnimation } from './useVerticalExpandAnimation'
@@ -0,0 +1,37 @@
1
+ import React from 'react'
2
+ import { Animated, Easing } from 'react-native'
3
+
4
+ const ANIMATION_DURATION = 200
5
+
6
+ /**
7
+ * Smoothly animates a numeric value to a new target using a quadratic ease-in-out
8
+ * curve. Returns the current interpolated value as a plain number so
9
+ * consumers can use it in non-Animated style props.
10
+ *
11
+ * @param {number} targetValue - The value to animate towards.
12
+ * @param {number} [duration=ANIMATION_DURATION] - Animation duration in ms.
13
+ */
14
+ const useAnimatedValue = (targetValue, duration = ANIMATION_DURATION) => {
15
+ const [currentValue, setCurrentValue] = React.useState(targetValue)
16
+ const animatedValue = React.useRef(new Animated.Value(targetValue)).current
17
+
18
+ React.useEffect(() => {
19
+ const id = animatedValue.addListener(({ value }) => setCurrentValue(value))
20
+ return () => animatedValue.removeListener(id)
21
+ }, [animatedValue])
22
+
23
+ React.useEffect(() => {
24
+ const animation = Animated.timing(animatedValue, {
25
+ toValue: targetValue,
26
+ duration,
27
+ easing: Easing.inOut(Easing.quad),
28
+ useNativeDriver: false
29
+ })
30
+ animation.start()
31
+ return () => animation.stop()
32
+ }, [targetValue, animatedValue, duration])
33
+
34
+ return currentValue
35
+ }
36
+
37
+ export default useAnimatedValue
@@ -47,8 +47,11 @@ export const unpackFragment = (child) => {
47
47
 
48
48
  const isStringOrNumber = (child) => typeof child === 'string' || typeof child === 'number'
49
49
  // Wrap an A11yText with neighouring text strings so it doesn't split them into multiple <Text>s
50
+ // Check displayName first as it is explicitly set and reliable regardless of export style (named vs default)
50
51
  const isWrapable = (child) =>
51
- isStringOrNumber(child) || child.type === A11yText || child.type?.name === 'FootnoteLink'
52
+ isStringOrNumber(child) ||
53
+ child.type === A11yText ||
54
+ child.type?.__UDS_COMPONENT_NAME__ === 'FootnoteLink'
52
55
  const combineKeys = (childrenArray) =>
53
56
  childrenArray.reduce((newKey, child) => `${newKey}${child.key || ''}`, '')
54
57
 
@@ -0,0 +1,66 @@
1
+ import type { ComponentType, ReactNode } from 'react'
2
+ import type { SemanticTag } from './Common'
3
+
4
+ export interface ScrollDictionary {
5
+ accessibilityLabel: string
6
+ instructionText: string
7
+ progressBarLabel: string
8
+ }
9
+
10
+ export interface ScrollProps {
11
+ /**
12
+ * Scroll items to display. Should be `ScrollItem` components.
13
+ */
14
+ children: ReactNode
15
+ /**
16
+ * Theme tokens for customizing the Scroll appearance.
17
+ */
18
+ tokens?: ScrollTokens
19
+ /**
20
+ * Variant for the Scroll component.
21
+ */
22
+ variant?: ScrollVariant
23
+ /**
24
+ * Select English or French copy for accessible labels.
25
+ */
26
+ copy?: 'en' | 'fr'
27
+ /**
28
+ * Override the default dictionary by passing the complete dictionary object for `en` and `fr`.
29
+ */
30
+ dictionary?: {
31
+ en: ScrollDictionary
32
+ fr: ScrollDictionary
33
+ }
34
+ /**
35
+ * Accessibility label for the scrollable region.
36
+ */
37
+ accessibilityLabel?: string
38
+ }
39
+
40
+ export type ScrollVariant = {}
41
+
42
+ export interface ScrollTokens {
43
+ itemGap?: number
44
+ progressBarColor?: string
45
+ progressBarHeight?: number
46
+ progressHitAreaHeight?: number
47
+ progressSpacing?: number
48
+ progressTrackColor?: string
49
+ progressTrackHeight?: number
50
+ }
51
+
52
+ export interface ScrollItemProps {
53
+ /**
54
+ * Content of the scroll item.
55
+ */
56
+ children: ReactNode
57
+ /**
58
+ * Sets the HTML tag of the outer container. Defaults to `'li'`.
59
+ */
60
+ tag?: SemanticTag
61
+ }
62
+
63
+ declare const Scroll: ComponentType<ScrollProps>
64
+ export declare const ScrollItem: ComponentType<ScrollItemProps>
65
+
66
+ export default Scroll
package/types/index.d.ts CHANGED
@@ -45,6 +45,15 @@ export { LinkProps, LinkSize, LinkAndTextButtonVariants, LinkTokens } from './Li
45
45
  export { default as List } from './List'
46
46
  export { ListVariants, ListTokens, ListProps, ListItemProps, ListItemTokens } from './List'
47
47
 
48
+ export { default as Scroll, ScrollItem } from './Scroll'
49
+ export type {
50
+ ScrollProps,
51
+ ScrollTokens,
52
+ ScrollVariant,
53
+ ScrollItemProps,
54
+ ScrollDictionary
55
+ } from './Scroll'
56
+
48
57
  export { default as Search } from './Search'
49
58
  export { SearchTokens, SearchProps } from './Search'
50
59