@telus-uds/components-base 1.7.1 → 1.8.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 (66) hide show
  1. package/.storybook/main.js +7 -0
  2. package/.turbo/turbo-build.log +3 -3
  3. package/.turbo/turbo-lint.log +3 -13
  4. package/CHANGELOG.json +62 -1
  5. package/CHANGELOG.md +19 -2
  6. package/__fixtures__/Accessible.js +1 -2
  7. package/__fixtures__/Accessible.native.js +1 -2
  8. package/__tests__/FlexGrid/Col.test.jsx +5 -0
  9. package/__tests__/InputLabel/InputLabel.test.jsx +28 -0
  10. package/__tests__/InputLabel/__snapshots__/InputLabel.test.jsx.snap +3 -0
  11. package/__tests__/InputSupports/InputSupports.test.jsx +10 -0
  12. package/component-docs.json +264 -18
  13. package/lib/Button/ButtonGroup.js +118 -45
  14. package/lib/Checkbox/CheckboxGroup.js +3 -3
  15. package/lib/ExpandCollapse/Panel.js +2 -1
  16. package/lib/Fieldset/Fieldset.js +7 -0
  17. package/lib/InputLabel/InputLabel.js +8 -1
  18. package/lib/InputSupports/InputSupports.js +7 -0
  19. package/lib/Notification/Notification.js +1 -1
  20. package/lib/Radio/RadioGroup.js +12 -5
  21. package/lib/RadioCard/RadioCardGroup.js +7 -0
  22. package/lib/Search/Search.js +1 -1
  23. package/lib/Skeleton/Skeleton.js +48 -2
  24. package/lib/ToggleSwitch/ToggleSwitch.js +7 -0
  25. package/lib/ToggleSwitch/ToggleSwitchGroup.js +7 -0
  26. package/lib/Tooltip/Tooltip.js +1 -1
  27. package/lib/utils/animation/useVerticalExpandAnimation.js +26 -13
  28. package/lib/utils/props/inputSupportsProps.js +7 -0
  29. package/lib-module/Button/ButtonGroup.js +117 -45
  30. package/lib-module/Checkbox/CheckboxGroup.js +3 -3
  31. package/lib-module/ExpandCollapse/Panel.js +2 -1
  32. package/lib-module/Fieldset/Fieldset.js +7 -0
  33. package/lib-module/InputLabel/InputLabel.js +8 -1
  34. package/lib-module/InputSupports/InputSupports.js +7 -0
  35. package/lib-module/Notification/Notification.js +1 -1
  36. package/lib-module/Radio/RadioGroup.js +12 -5
  37. package/lib-module/RadioCard/RadioCardGroup.js +7 -0
  38. package/lib-module/Search/Search.js +1 -1
  39. package/lib-module/Skeleton/Skeleton.js +49 -3
  40. package/lib-module/ToggleSwitch/ToggleSwitch.js +7 -0
  41. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +7 -0
  42. package/lib-module/Tooltip/Tooltip.js +1 -1
  43. package/lib-module/utils/animation/useVerticalExpandAnimation.js +26 -14
  44. package/lib-module/utils/props/inputSupportsProps.js +7 -0
  45. package/package.json +9 -4
  46. package/src/Button/ButtonGroup.jsx +106 -41
  47. package/src/Checkbox/Checkbox.jsx +7 -4
  48. package/src/Checkbox/CheckboxGroup.jsx +3 -3
  49. package/src/ExpandCollapse/Panel.jsx +3 -1
  50. package/src/Fieldset/Fieldset.jsx +6 -0
  51. package/src/InputLabel/InputLabel.jsx +17 -2
  52. package/src/InputSupports/InputSupports.jsx +9 -1
  53. package/src/Notification/Notification.jsx +1 -1
  54. package/src/Radio/Radio.jsx +5 -1
  55. package/src/Radio/RadioGroup.jsx +11 -5
  56. package/src/RadioCard/RadioCard.jsx +5 -1
  57. package/src/RadioCard/RadioCardGroup.jsx +6 -0
  58. package/src/Search/Search.jsx +1 -1
  59. package/src/Skeleton/Skeleton.jsx +56 -3
  60. package/src/ToggleSwitch/ToggleSwitch.jsx +6 -0
  61. package/src/ToggleSwitch/ToggleSwitchGroup.jsx +6 -0
  62. package/src/Tooltip/Tooltip.jsx +1 -1
  63. package/src/utils/animation/useVerticalExpandAnimation.js +25 -12
  64. package/src/utils/props/inputSupportsProps.js +6 -1
  65. package/src/utils/props/tokens.js +21 -19
  66. package/stories/Tabs/Tabs.stories.jsx +4 -3
@@ -1,16 +1,30 @@
1
- import { useEffect, useRef } from 'react'
1
+ import { useEffect, useRef, useState } from 'react'
2
2
  import { Animated, Easing, Platform } from 'react-native'
3
3
 
4
4
  // TODO: systematise animations
5
5
  // https://github.com/telus/universal-design-system/issues/487
6
6
  function useVerticalExpandAnimation({ containerHeight, isExpanded, tokens }) {
7
+ const [isAnimating, setIsAnimating] = useState(false)
8
+
7
9
  const expandAnimatedValue = useRef(new Animated.Value(0)).current
10
+ const elementRef = useRef(null)
8
11
 
9
12
  const { expandDuration, collapseDuration } = tokens
10
13
 
14
+ // Treat as animating from when expanded state changes, until animation completes
15
+ useEffect(() => setIsAnimating(true), [isExpanded])
16
+
11
17
  useEffect(() => {
18
+ const onComplete = () => !isExpanded && setIsAnimating(false)
19
+
12
20
  if (Platform.OS === 'web') {
13
- return
21
+ if (!elementRef.current) return () => {}
22
+
23
+ // React Native Web does not pass `onTransitionEnd` through, must attach manually.
24
+ // https://github.com/necolas/react-native-web/pull/1713
25
+ const element = elementRef.current
26
+ element.addEventListener('transitionend', onComplete)
27
+ return () => element.removeEventListener('transitionend', onComplete)
14
28
  }
15
29
 
16
30
  const animationConfig = {
@@ -20,28 +34,27 @@ function useVerticalExpandAnimation({ containerHeight, isExpanded, tokens }) {
20
34
  useNativeDriver: false
21
35
  }
22
36
 
23
- Animated.timing(expandAnimatedValue, animationConfig).start()
37
+ const animation = Animated.timing(expandAnimatedValue, animationConfig)
38
+ animation.start(onComplete)
39
+ return () => animation.stop()
24
40
  }, [isExpanded, expandAnimatedValue, containerHeight, expandDuration, collapseDuration])
25
41
 
26
- let containerStyles
42
+ // Without `visibility: 'hidden', descendents are focusable on web even when collapsed
43
+ const containerStyles = !isExpanded && !isAnimating ? { visibility: 'hidden' } : {}
27
44
 
28
45
  // don't visually collapse the container until we have it measured
29
46
  if (containerHeight !== null) {
30
47
  if (Platform.OS === 'web') {
31
48
  const transitionDuration = isExpanded ? expandDuration : collapseDuration
49
+ containerStyles.transition = `height ${transitionDuration}ms ease-in-out`
32
50
 
33
- containerStyles = {
34
- transition: `height ${transitionDuration}ms ease-in-out`,
35
- height: isExpanded ? containerHeight : 0
36
- }
51
+ containerStyles.height = isExpanded ? containerHeight : 0
37
52
  } else {
38
- containerStyles = {
39
- height: expandAnimatedValue
40
- }
53
+ containerStyles.height = expandAnimatedValue
41
54
  }
42
55
  }
43
56
 
44
- return containerStyles
57
+ return [containerStyles, elementRef]
45
58
  }
46
59
 
47
60
  export default useVerticalExpandAnimation
@@ -2,6 +2,10 @@ import PropTypes from 'prop-types'
2
2
 
3
3
  export default {
4
4
  types: {
5
+ /**
6
+ * Whether the English or French copy will be used (e.g. for accessibility labels).
7
+ */
8
+ copy: PropTypes.oneOf(['en', 'fr']),
5
9
  /**
6
10
  * The input label.
7
11
  */
@@ -28,8 +32,9 @@ export default {
28
32
  */
29
33
  validation: PropTypes.oneOf(['error', 'success'])
30
34
  },
31
- select: ({ label, hint, hintPosition, feedback, tooltip, validation }) => ({
35
+ select: ({ copy, label, hint, hintPosition, feedback, tooltip, validation }) => ({
32
36
  supportsProps: {
37
+ copy,
33
38
  label,
34
39
  hint,
35
40
  hintPosition,
@@ -86,33 +86,35 @@ export const selectTokens = (specifier, tokens, prefix) => {
86
86
  * tokens: getTokensPropType('Component1', 'Component2')
87
87
  * }
88
88
  */
89
- export const getTokensPropType = (...componentsNames) => (props, propName, componentName) => {
90
- PropTypes.checkPropTypes(
91
- {
92
- [propName]: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
93
- },
94
- props,
95
- propName,
96
- componentName
97
- )
98
-
99
- if (typeof props[propName] !== 'function') {
89
+ export const getTokensPropType =
90
+ (...componentsNames) =>
91
+ (props, propName, componentName) => {
100
92
  PropTypes.checkPropTypes(
101
93
  {
102
- [propName]: PropTypes.exact(
103
- Object.fromEntries(
104
- componentsNames.flatMap((component) =>
105
- getTokenNames(component).map((key) => [key, tokenValueType])
106
- )
107
- )
108
- )
94
+ [propName]: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
109
95
  },
110
96
  props,
111
97
  propName,
112
98
  componentName
113
99
  )
100
+
101
+ if (typeof props[propName] !== 'function') {
102
+ PropTypes.checkPropTypes(
103
+ {
104
+ [propName]: PropTypes.exact(
105
+ Object.fromEntries(
106
+ componentsNames.flatMap((component) =>
107
+ getTokenNames(component).map((key) => [key, tokenValueType])
108
+ )
109
+ )
110
+ )
111
+ },
112
+ props,
113
+ propName,
114
+ componentName
115
+ )
116
+ }
114
117
  }
115
- }
116
118
 
117
119
  /**
118
120
  * Get a proptypes validator for a set of tokens that is not based on a component in the theme schema.
@@ -40,9 +40,10 @@ TabsWithHref.args = {
40
40
  ]
41
41
  }
42
42
 
43
- const loremIpsumArray = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. '
44
- .repeat(5)
45
- .split('. ')
43
+ const loremIpsumArray =
44
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. '
45
+ .repeat(5)
46
+ .split('. ')
46
47
 
47
48
  export const TabsControlled = (args) => {
48
49
  const [page, setPage] = useState('1')