@telus-uds/components-base 1.60.0 → 1.62.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/CHANGELOG.md +19 -2
  2. package/component-docs.json +306 -116
  3. package/lib/Autocomplete/Autocomplete.js +483 -0
  4. package/lib/Autocomplete/Loading.js +51 -0
  5. package/lib/Autocomplete/Suggestions.js +85 -0
  6. package/lib/Autocomplete/constants.js +14 -0
  7. package/lib/Autocomplete/dictionary.js +19 -0
  8. package/lib/Autocomplete/index.js +13 -0
  9. package/lib/IconButton/IconButton.js +28 -9
  10. package/lib/Listbox/GroupControl.js +121 -0
  11. package/lib/Listbox/Listbox.js +198 -0
  12. package/lib/Listbox/ListboxGroup.js +142 -0
  13. package/lib/Listbox/ListboxItem.js +97 -0
  14. package/lib/Listbox/ListboxOverlay.js +106 -0
  15. package/lib/Listbox/PressableItem.js +0 -2
  16. package/lib/Listbox/index.js +5 -24
  17. package/lib/SideNav/Item.js +7 -15
  18. package/lib/TextInput/TextInputBase.js +8 -1
  19. package/lib/Tooltip/Tooltip.js +5 -1
  20. package/lib/Tooltip/Tooltip.native.js +5 -1
  21. package/lib/Tooltip/shared.js +5 -0
  22. package/lib/index.js +17 -13
  23. package/lib/utils/useOverlaidPosition.js +6 -4
  24. package/lib-module/Autocomplete/Autocomplete.js +448 -0
  25. package/lib-module/Autocomplete/Loading.js +36 -0
  26. package/lib-module/Autocomplete/Suggestions.js +66 -0
  27. package/lib-module/Autocomplete/constants.js +4 -0
  28. package/lib-module/Autocomplete/dictionary.js +12 -0
  29. package/lib-module/Autocomplete/index.js +2 -0
  30. package/lib-module/IconButton/IconButton.js +30 -10
  31. package/lib-module/Listbox/GroupControl.js +102 -0
  32. package/lib-module/Listbox/Listbox.js +172 -0
  33. package/lib-module/Listbox/ListboxGroup.js +117 -0
  34. package/lib-module/Listbox/ListboxItem.js +71 -0
  35. package/lib-module/Listbox/ListboxOverlay.js +80 -0
  36. package/lib-module/Listbox/PressableItem.js +0 -2
  37. package/lib-module/Listbox/index.js +2 -2
  38. package/lib-module/SideNav/Item.js +7 -15
  39. package/lib-module/TextInput/TextInputBase.js +8 -1
  40. package/lib-module/Tooltip/Tooltip.js +5 -1
  41. package/lib-module/Tooltip/Tooltip.native.js +5 -1
  42. package/lib-module/Tooltip/shared.js +5 -0
  43. package/lib-module/index.js +2 -1
  44. package/lib-module/utils/useOverlaidPosition.js +5 -4
  45. package/package.json +4 -2
  46. package/src/Autocomplete/Autocomplete.jsx +411 -0
  47. package/src/Autocomplete/Loading.jsx +18 -0
  48. package/src/Autocomplete/Suggestions.jsx +54 -0
  49. package/src/Autocomplete/constants.js +4 -0
  50. package/src/Autocomplete/dictionary.js +12 -0
  51. package/src/Autocomplete/index.js +3 -0
  52. package/src/IconButton/IconButton.jsx +62 -35
  53. package/src/Listbox/GroupControl.jsx +93 -0
  54. package/src/Listbox/Listbox.jsx +165 -0
  55. package/src/Listbox/ListboxGroup.jsx +120 -0
  56. package/src/Listbox/ListboxItem.jsx +76 -0
  57. package/src/Listbox/ListboxOverlay.jsx +82 -0
  58. package/src/Listbox/PressableItem.jsx +0 -2
  59. package/src/Listbox/index.js +3 -2
  60. package/src/SideNav/Item.jsx +7 -13
  61. package/src/TextInput/TextInputBase.jsx +4 -1
  62. package/src/Tooltip/Tooltip.jsx +15 -2
  63. package/src/Tooltip/Tooltip.native.jsx +15 -2
  64. package/src/Tooltip/shared.js +4 -0
  65. package/src/index.js +2 -1
  66. package/src/utils/useOverlaidPosition.js +6 -5
@@ -111,12 +111,12 @@ Item.propTypes = {
111
111
  */
112
112
  children: PropTypes.node.isRequired,
113
113
  /**
114
- *
114
+ * @ignore
115
115
  * Set internally in `SideNav` render function - used to keep track of active item.
116
116
  */
117
117
  itemId: PropTypes.string,
118
118
  /**
119
- *
119
+ * @ignore
120
120
  * Set internally in `SideNav` render function - used to keep track of expanded items groups.
121
121
  */
122
122
  groupId: PropTypes.string,
@@ -128,25 +128,19 @@ Item.propTypes = {
128
128
  */
129
129
  hrefAttrs: PropTypes.shape(hrefAttrsProp.types),
130
130
  /**
131
- *
131
+ * @ignore
132
132
  * Set internally in `SideNav` render function.
133
133
  */
134
134
  isActive: PropTypes.bool,
135
135
  /**
136
- *
136
+ * @ignore
137
137
  * Set internally in `SideNav.ItemsGroup` render function. Used to mark expanded `ItemsGroup` parent.
138
138
  */
139
139
  isExpanded: PropTypes.bool,
140
- tokens: getTokensPropType('SideNavItem'),
141
- variant: variantProp.propType,
142
- /**
143
- * Accesibility Role
144
- */
145
140
  accessibilityRole: PropTypes.string,
146
- /**
147
- * test ID
148
- */
149
- testID: PropTypes.number
141
+ testID: PropTypes.number,
142
+ tokens: getTokensPropType('SideNavItem'),
143
+ variant: variantProp.propType
150
144
  }
151
145
 
152
146
  export default Item
@@ -253,7 +253,8 @@ const TextInputBase = forwardRef(
253
253
  icon={!showPassword ? passwordShowButtonIcon : passwordHideButtonIcon}
254
254
  key={!showPassword ? 'hide' : 'show'}
255
255
  onPress={handleShowOrHide}
256
- variant={{ compact: true, password: true, inactive: !!variant.inactive }}
256
+ variant={{ compact: true, password: true, inactive: variant.inactive, size: 'large' }}
257
+ tokens={{ width: 40, height: 40 }}
257
258
  />
258
259
  )
259
260
  }
@@ -341,6 +342,8 @@ export default TextInputBase
341
342
  const staticStyles = StyleSheet.create({
342
343
  buttonsContainer: {
343
344
  position: 'absolute',
345
+ flexDirection: 'row',
346
+ alignItems: 'center',
344
347
  right: 0,
345
348
  top: 0,
346
349
  bottom: 0,
@@ -83,7 +83,17 @@ const defaultControl = (pressableState, variant) => (
83
83
  */
84
84
  const Tooltip = forwardRef(
85
85
  (
86
- { children, content, position = 'auto', copy = 'en', tokens, variant, inline = false, ...rest },
86
+ {
87
+ children,
88
+ content,
89
+ position = 'auto',
90
+ copy = 'en',
91
+ onPress = () => {},
92
+ tokens,
93
+ variant,
94
+ inline = false,
95
+ ...rest
96
+ },
87
97
  ref
88
98
  ) => {
89
99
  const [isOpen, setIsOpen] = useState(false)
@@ -118,7 +128,10 @@ const Tooltip = forwardRef(
118
128
  const getCopy = useCopy({ dictionary, copy })
119
129
  const themeTokens = useThemeTokens('Tooltip', tokens, variant)
120
130
 
121
- const toggleIsOpen = () => setIsOpen(!isOpen)
131
+ const toggleIsOpen = () => {
132
+ onPress()
133
+ setIsOpen(!isOpen)
134
+ }
122
135
  const close = () => setIsOpen(false)
123
136
 
124
137
  const getPressableState = ({ pressed, hovered, focused }) => ({
@@ -109,7 +109,17 @@ const defaultControl = (pressableState, variant) => (
109
109
  */
110
110
  const Tooltip = forwardRef(
111
111
  (
112
- { children, content, position = 'auto', copy = 'en', tokens, variant, inline = false, ...rest },
112
+ {
113
+ children,
114
+ content,
115
+ position = 'auto',
116
+ copy = 'en',
117
+ onPress = () => {},
118
+ tokens,
119
+ variant,
120
+ inline = false,
121
+ ...rest
122
+ },
113
123
  ref
114
124
  ) => {
115
125
  const [isOpen, setIsOpen] = useState(false)
@@ -133,7 +143,10 @@ const Tooltip = forwardRef(
133
143
  return () => subscription?.remove()
134
144
  })
135
145
 
136
- const toggleIsOpen = () => setIsOpen(!isOpen)
146
+ const toggleIsOpen = () => {
147
+ onPress()
148
+ setIsOpen(!isOpen)
149
+ }
137
150
  const close = () => setIsOpen(false)
138
151
 
139
152
  const getPressableState = ({ pressed, hovered, focused }) => ({
@@ -24,6 +24,10 @@ const propTypes = {
24
24
  * Display tooltip icon button as an inline element.
25
25
  */
26
26
  inline: PropTypes.bool,
27
+ /**
28
+ * Callback function triggered when the tooltip is pressed.
29
+ */
30
+ onPress: PropTypes.func,
27
31
  tokens: getTokensPropType('Tooltip'),
28
32
  variant: variantProp.propType
29
33
  }
package/src/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  export { default as A11yText } from './A11yText'
2
2
  export { default as ActivityIndicator } from './ActivityIndicator'
3
+ export { default as Autocomplete } from './Autocomplete'
3
4
  export { default as Box } from './Box'
4
5
  export * from './Button'
5
6
  export { default as Card, PressableCardBase } from './Card'
6
7
  export * from './Carousel'
7
- export * from './Listbox'
8
+ export { default as Listbox } from './Listbox'
8
9
  export { default as Checkbox } from './Checkbox'
9
10
  export * from './Checkbox'
10
11
  export { default as Divider } from './Divider'
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect, useRef, useState } from 'react'
2
- import { Dimensions } from 'react-native'
2
+ import { Dimensions, Platform } from 'react-native'
3
3
 
4
4
  const adjustHorizontalToFit = (initialOffset, windowWidth, sourceWidth) => {
5
5
  const offset = Math.max(0, initialOffset)
@@ -169,8 +169,9 @@ const useOverlaidPosition = ({
169
169
  const readyToShow = Boolean(isShown && sourceRef.current)
170
170
  useEffect(() => {
171
171
  const handleDimensionsChange = ({ window }) => {
172
- sourceRef.current?.measureInWindow((x, y, width, height) => {
173
- // Could add a debouncer here if there's too many rerenders during gradual resizes
172
+ const measurementFunction = Platform.OS === 'web' ? 'measureInWindow' : 'measure'
173
+
174
+ sourceRef.current?.[measurementFunction]((x, y, width, height) => {
174
175
  setWindowDimensions(window)
175
176
  setSourceLayout({ x, y, width, height })
176
177
  })
@@ -181,9 +182,9 @@ const useOverlaidPosition = ({
181
182
  if (typeof subscription?.remove === 'function') {
182
183
  // React Native >=0.65.0
183
184
  subscription.remove()
184
- } else if (typeof Dimensions.removeEventListener === 'function') {
185
+ } else if (typeof Dimensions.remove === 'function') {
185
186
  // React Native <0.65.0
186
- Dimensions.removeEventListener('change', handleDimensionsChange)
187
+ Dimensions.remove('change', handleDimensionsChange)
187
188
  }
188
189
  setSourceLayout(null)
189
190
  setTargetDimensions(null)