@telus-uds/components-base 1.24.0 → 1.24.2

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 (63) hide show
  1. package/CHANGELOG.md +21 -2
  2. package/component-docs.json +0 -11
  3. package/lib/Box/Box.js +3 -1
  4. package/lib/Divider/Divider.js +3 -0
  5. package/lib/Feedback/Feedback.js +2 -5
  6. package/lib/Fieldset/Fieldset.js +3 -1
  7. package/lib/FlexGrid/FlexGrid.js +3 -1
  8. package/lib/Link/InlinePressable.js +8 -1
  9. package/lib/Link/LinkBase.js +6 -8
  10. package/lib/List/ListItem.js +10 -2
  11. package/lib/Radio/RadioGroup.js +1 -1
  12. package/lib/StackView/StackView.js +3 -1
  13. package/lib/StackView/StackWrapBox.js +3 -1
  14. package/lib/StackView/StackWrapGap.js +3 -1
  15. package/lib/ThemeProvider/utils/styles.js +1 -3
  16. package/lib/Tooltip/Tooltip.js +85 -158
  17. package/lib/Tooltip/Tooltip.native.js +357 -0
  18. package/lib/Tooltip/index.js +6 -1
  19. package/lib/Tooltip/shared.js +39 -0
  20. package/lib/Typography/Typography.js +3 -1
  21. package/lib/utils/floating-ui/index.js +43 -0
  22. package/lib/utils/floating-ui/index.native.js +43 -0
  23. package/lib-module/Box/Box.js +3 -1
  24. package/lib-module/Divider/Divider.js +3 -0
  25. package/lib-module/Feedback/Feedback.js +2 -5
  26. package/lib-module/Fieldset/Fieldset.js +3 -1
  27. package/lib-module/FlexGrid/FlexGrid.js +3 -1
  28. package/lib-module/Link/InlinePressable.js +8 -1
  29. package/lib-module/Link/LinkBase.js +6 -8
  30. package/lib-module/List/ListItem.js +10 -2
  31. package/lib-module/Radio/RadioGroup.js +1 -1
  32. package/lib-module/StackView/StackView.js +3 -1
  33. package/lib-module/StackView/StackWrapBox.js +3 -1
  34. package/lib-module/StackView/StackWrapGap.js +3 -1
  35. package/lib-module/ThemeProvider/utils/styles.js +1 -3
  36. package/lib-module/Tooltip/Tooltip.js +85 -155
  37. package/lib-module/Tooltip/Tooltip.native.js +326 -0
  38. package/lib-module/Tooltip/index.js +4 -1
  39. package/lib-module/Tooltip/shared.js +27 -0
  40. package/lib-module/Typography/Typography.js +3 -1
  41. package/lib-module/utils/floating-ui/index.js +1 -0
  42. package/lib-module/utils/floating-ui/index.native.js +1 -0
  43. package/package.json +4 -2
  44. package/src/Box/Box.jsx +1 -0
  45. package/src/Divider/Divider.jsx +3 -0
  46. package/src/Feedback/Feedback.jsx +3 -8
  47. package/src/Fieldset/Fieldset.jsx +1 -1
  48. package/src/FlexGrid/FlexGrid.jsx +1 -0
  49. package/src/Link/InlinePressable.jsx +9 -3
  50. package/src/Link/LinkBase.jsx +17 -10
  51. package/src/List/ListItem.jsx +3 -1
  52. package/src/Radio/RadioGroup.jsx +1 -1
  53. package/src/StackView/StackView.jsx +1 -0
  54. package/src/StackView/StackWrapBox.jsx +1 -0
  55. package/src/StackView/StackWrapGap.jsx +1 -0
  56. package/src/ThemeProvider/utils/styles.js +1 -3
  57. package/src/Tooltip/Tooltip.jsx +79 -156
  58. package/src/Tooltip/Tooltip.native.jsx +283 -0
  59. package/src/Tooltip/index.js +5 -1
  60. package/src/Tooltip/shared.js +27 -0
  61. package/src/Typography/Typography.jsx +1 -0
  62. package/src/utils/floating-ui/index.js +1 -0
  63. package/src/utils/floating-ui/index.native.js +1 -0
@@ -1,5 +1,6 @@
1
1
  import React, { forwardRef } from 'react';
2
2
  import ListItemBase from './ListItemBase';
3
+ import Typography from '../Typography';
3
4
  import { useThemeTokens } from '../ThemeProvider';
4
5
  import { variantProp } from '../utils';
5
6
  /**
@@ -7,19 +8,26 @@ import { variantProp } from '../utils';
7
8
  */
8
9
 
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
10
12
  const ListItem = /*#__PURE__*/forwardRef((_ref, ref) => {
11
13
  let {
12
14
  tokens,
13
15
  variant,
14
16
  children,
17
+ title,
15
18
  ...listItemProps
16
19
  } = _ref;
17
20
  const themeTokens = useThemeTokens('List', tokens, variant);
18
- return /*#__PURE__*/_jsx(ListItemBase, {
21
+ return /*#__PURE__*/_jsxs(ListItemBase, {
19
22
  tokens: themeTokens,
20
23
  ref: ref,
21
24
  ...listItemProps,
22
- children: children
25
+ children: [Boolean(title) && /*#__PURE__*/_jsx(Typography, {
26
+ variant: {
27
+ size: 'h4'
28
+ },
29
+ children: title
30
+ }), children]
23
31
  });
24
32
  });
25
33
  ListItem.displayName = 'ListItem';
@@ -145,8 +145,8 @@ const RadioGroup = /*#__PURE__*/forwardRef((_ref, ref) => {
145
145
  feedback: feedback,
146
146
  inactive: inactive,
147
147
  validation: validation,
148
- showIcon: true,
149
148
  showErrorBorder: true,
149
+ showIcon: true,
150
150
  accessibilityRole: "radiogroup",
151
151
  ...selectProps(rest),
152
152
  children: getStackedContent(radios, {
@@ -66,7 +66,9 @@ const StackView = /*#__PURE__*/forwardRef((_ref, ref) => {
66
66
  } = _ref;
67
67
  const viewport = useViewport();
68
68
  const direction = useResponsiveProp(directionProp, 'column');
69
- const selectedProps = selectProps({ ...getA11yPropsFromHtmlTag(tag, accessibilityRole),
69
+ const selectedProps = selectProps({
70
+ accessibilityRole,
71
+ ...getA11yPropsFromHtmlTag(tag, accessibilityRole),
70
72
  ...rest
71
73
  });
72
74
  const content = getStackedContent(children, {
@@ -51,7 +51,9 @@ const StackWrapBox = /*#__PURE__*/forwardRef((_ref, ref) => {
51
51
  viewport
52
52
  });
53
53
  const flexStyles = selectFlexStyles(themeTokens);
54
- const selectedProps = selectProps({ ...getA11yPropsFromHtmlTag(tag, accessibilityRole),
54
+ const selectedProps = selectProps({
55
+ accessibilityRole,
56
+ ...getA11yPropsFromHtmlTag(tag, accessibilityRole),
55
57
  ...rest
56
58
  }); // Mimic CSS `gap` using box spacing on the side after a wrapped row then offsetting it on the last row.
57
59
 
@@ -36,7 +36,9 @@ const StackWrapGap = /*#__PURE__*/forwardRef((_ref, ref) => {
36
36
  viewport
37
37
  });
38
38
  const flexStyles = selectFlexStyles(themeTokens);
39
- const selectedProps = selectProps({ ...getA11yPropsFromHtmlTag(tag, accessibilityRole),
39
+ const selectedProps = selectProps({
40
+ accessibilityRole,
41
+ ...getA11yPropsFromHtmlTag(tag, accessibilityRole),
40
42
  ...rest
41
43
  });
42
44
  const size = useSpacingScale(space);
@@ -45,9 +45,7 @@ export function applyTextStyles(_ref) {
45
45
  // Don't set undefined font families. May need some validation here that the font is available.
46
46
  // Android doesn't recognise font weights natively so apply custom font weights via `fontFamily`.
47
47
  styles.fontFamily = "".concat(fontName).concat(fontWeight).concat(fontStyle);
48
- }
49
-
50
- if (fontWeight) {
48
+ } else if (fontWeight) {
51
49
  // If using system default font, apply the font weight directly.
52
50
  // Font weight support in Android is limited to 'bold' or anything else === 'normal'.
53
51
  styles.fontWeight = Platform.OS === 'android' && Number(fontWeight) > 400 ? 'bold' : fontWeight;
@@ -1,15 +1,13 @@
1
1
  import React, { forwardRef, useEffect, useRef, useState } from 'react';
2
- import Dimensions from "react-native-web/dist/exports/Dimensions";
3
2
  import Platform from "react-native-web/dist/exports/Platform";
4
3
  import Pressable from "react-native-web/dist/exports/Pressable";
5
4
  import StyleSheet from "react-native-web/dist/exports/StyleSheet";
6
5
  import Text from "react-native-web/dist/exports/Text";
7
6
  import View from "react-native-web/dist/exports/View";
8
- import PropTypes from 'prop-types';
7
+ import propTypes from './shared';
8
+ import { useFloating, arrow, offset, shift, flip, autoPlacement } from '../utils/floating-ui';
9
9
  import { applyShadowToken, applyTextStyles, useThemeTokens } from '../ThemeProvider';
10
- import { a11yProps, getTokensPropType, selectSystemProps, selectTokens, variantProp, viewProps } from '../utils';
11
- import Backdrop from './Backdrop';
12
- import getTooltipPosition from './getTooltipPosition';
10
+ import { a11yProps, selectSystemProps, selectTokens, viewProps } from '../utils';
13
11
  import TooltipButton from '../TooltipButton';
14
12
  import useCopy from '../utils/useCopy';
15
13
  import dictionary from './dictionary';
@@ -47,20 +45,20 @@ const selectTooltipShadowStyles = _ref2 => {
47
45
  };
48
46
  };
49
47
 
50
- const selectTooltipPositionStyles = _ref3 => {
48
+ const selectMobileTooltipPositionStyles = _ref3 => {
51
49
  let {
52
50
  top,
53
51
  left,
54
- width
52
+ position
55
53
  } = _ref3;
56
54
  return {
57
55
  top,
58
56
  left,
59
- width
57
+ position
60
58
  };
61
59
  };
62
60
 
63
- const selectArrowStyles = (_ref4, _ref5) => {
61
+ const selectMobileArrowStyles = (_ref4, _ref5) => {
64
62
  let {
65
63
  backgroundColor,
66
64
  arrowWidth,
@@ -68,56 +66,31 @@ const selectArrowStyles = (_ref4, _ref5) => {
68
66
  shadow
69
67
  } = _ref4;
70
68
  let {
71
- position,
72
- width: tooltipWidth,
73
- height: tooltipHeight
69
+ placement,
70
+ x: arrowX,
71
+ y: arrowY
74
72
  } = _ref5;
75
- // the arrow width is actually a diagonal of the rectangle that we'll use as a tip
76
- const rectangleSide = Math.sqrt(arrowWidth * arrowWidth / 2); // position the arrow at the side and center of the tooltip - this happens before rotation
77
- // so we use the rectangle size as basis
78
-
79
- const verticalOffset = -1 * rectangleSide / 2;
80
- const horizontalOffset = rectangleSide / 2; // percentage-based absolute positioning doesn't act well on native, so we have to
81
- // calculate the pixel values
82
-
83
- const directionalStyles = {
84
- above: {
85
- bottom: verticalOffset,
86
- left: tooltipWidth / 2 - horizontalOffset,
87
- transform: [{
88
- rotateZ: '45deg'
89
- }]
90
- },
91
- below: {
92
- top: verticalOffset,
93
- left: tooltipWidth / 2 - horizontalOffset,
94
- transform: [{
95
- rotateZ: '-135deg'
96
- }]
97
- },
98
- left: {
99
- right: verticalOffset,
100
- top: tooltipHeight / 2 - horizontalOffset,
101
- transform: [{
102
- rotateZ: '-45deg'
103
- }]
104
- },
105
- right: {
106
- left: verticalOffset,
107
- top: tooltipHeight / 2 - horizontalOffset,
108
- transform: [{
109
- rotateZ: '135deg'
110
- }]
111
- }
112
- };
73
+ const staticSide = {
74
+ top: 'bottom',
75
+ right: 'left',
76
+ bottom: 'top',
77
+ left: 'right'
78
+ }[placement.split('-')[0]];
113
79
  return {
114
80
  backgroundColor,
115
- width: rectangleSide,
116
- height: rectangleSide,
81
+ width: arrowWidth,
82
+ height: arrowWidth,
117
83
  borderBottomRightRadius: arrowBorderRadius,
118
84
  // this corner will be the arrow tip after rotation
85
+ transform: [{
86
+ rotateZ: '45deg'
87
+ }],
119
88
  ...applyShadowToken(shadow),
120
- ...directionalStyles[position]
89
+ left: arrowX != null && arrowX,
90
+ top: arrowY != null && arrowY,
91
+ right: '',
92
+ bottom: '',
93
+ [staticSide]: '-4px'
121
94
  };
122
95
  };
123
96
 
@@ -155,40 +128,50 @@ const Tooltip = /*#__PURE__*/forwardRef((_ref6, ref) => {
155
128
  ...rest
156
129
  } = _ref6;
157
130
  const [isOpen, setIsOpen] = useState(false);
158
- const controlRef = useRef();
159
- const [controlLayout, setControlLayout] = useState(null);
131
+ const arrowRef = useRef();
160
132
  const [tooltipDimensions, setTooltipDimensions] = useState(null);
161
- const [windowDimensions, setWindowDimensions] = useState(Dimensions.get('window'));
162
- const [tooltipPosition, setTooltipPosition] = useState(null);
133
+ const positions = {
134
+ auto: undefined,
135
+ // Auto needs to specifically bet set to undefined
136
+ above: 'top',
137
+ right: 'right',
138
+ below: 'bottom',
139
+ left: 'left'
140
+ }; // "AutoPlacement" can't be used with "flip"
141
+
142
+ const additionalMiddleware = position !== 'auto' ? autoPlacement : flip;
143
+ const {
144
+ x,
145
+ y,
146
+ reference,
147
+ floating,
148
+ strategy,
149
+ placement,
150
+ middlewareData: {
151
+ arrow: arrowData = {}
152
+ }
153
+ } = useFloating({
154
+ placement: positions[position],
155
+ middleware: [shift(), additionalMiddleware(), offset(15), arrow({
156
+ element: arrowRef
157
+ })]
158
+ });
163
159
  const getCopy = useCopy({
164
160
  dictionary,
165
161
  copy
166
162
  });
167
163
  const themeTokens = useThemeTokens('Tooltip', tokens, variant);
168
- const {
169
- arrowWidth,
170
- arrowOffset
171
- } = themeTokens;
172
- useEffect(() => {
173
- const subscription = Dimensions.addEventListener('change', _ref7 => {
174
- let {
175
- window
176
- } = _ref7;
177
- setWindowDimensions(window);
178
- });
179
- return () => subscription === null || subscription === void 0 ? void 0 : subscription.remove();
180
- });
181
164
 
182
165
  const toggleIsOpen = () => setIsOpen(!isOpen);
183
166
 
184
167
  const close = () => setIsOpen(false);
185
168
 
186
- const getPressableState = _ref8 => {
169
+ const getPressableState = _ref7 => {
187
170
  let {
188
171
  pressed,
189
172
  hovered,
190
173
  focused
191
- } = _ref8;
174
+ } = _ref7;
192
175
  return {
193
176
  pressed,
194
177
  hover: hovered,
@@ -196,7 +179,7 @@ const Tooltip = /*#__PURE__*/forwardRef((_ref6, ref) => {
196
179
  };
197
180
  };
198
181
 
199
- const onTooltipLayout = _ref9 => {
182
+ const onTooltipLayout = _ref8 => {
200
183
  let {
201
184
  nativeEvent: {
202
185
  layout: {
@@ -204,7 +187,7 @@ const Tooltip = /*#__PURE__*/forwardRef((_ref6, ref) => {
204
187
  height
205
188
  }
206
189
  }
207
- } = _ref9;
190
+ } = _ref8;
208
191
 
209
192
  if (tooltipDimensions === null || tooltipDimensions.width !== width || tooltipDimensions.height !== height) {
210
193
  setTooltipDimensions({
@@ -219,43 +202,10 @@ const Tooltip = /*#__PURE__*/forwardRef((_ref6, ref) => {
219
202
  };
220
203
 
221
204
  useEffect(() => {
222
- if (isOpen) {
223
- controlRef.current.measureInWindow((x, y, width, height) => {
224
- setControlLayout({
225
- x,
226
- y,
227
- width,
228
- height
229
- });
230
- });
231
- } else {
232
- setControlLayout(null);
205
+ if (!isOpen) {
233
206
  setTooltipDimensions(null);
234
- setTooltipPosition(null);
235
207
  }
236
208
  }, [isOpen]);
237
- useEffect(() => {
238
- setIsOpen(false);
239
- }, [windowDimensions]);
240
- useEffect(() => {
241
- if (tooltipPosition !== null && !(tooltipPosition !== null && tooltipPosition !== void 0 && tooltipPosition.isNormalized) || !isOpen || controlLayout === null || tooltipDimensions == null) {
242
- return;
243
- }
244
-
245
- const updatedPosition = getTooltipPosition(position, {
246
- controlLayout,
247
- tooltipDimensions,
248
- windowDimensions,
249
- arrowWidth,
250
- arrowOffset
251
- }); // avoid ending up in an infinite normalization loop
252
-
253
- if (tooltipPosition !== null && tooltipPosition !== void 0 && tooltipPosition.isNormalized && updatedPosition.isNormalized) {
254
- return;
255
- }
256
-
257
- setTooltipPosition(updatedPosition);
258
- }, [isOpen, position, tooltipDimensions, controlLayout, windowDimensions, arrowWidth, arrowOffset, tooltipPosition]);
259
209
  const control = children !== undefined ? children : defaultControl;
260
210
  const pressableStyles = control === defaultControl ? Platform.select({
261
211
  web: {
@@ -271,67 +221,50 @@ const Tooltip = /*#__PURE__*/forwardRef((_ref6, ref) => {
271
221
  return /*#__PURE__*/_jsxs(View, {
272
222
  style: staticStyles.container,
273
223
  ...selectProps(rest),
224
+ ref: ref,
274
225
  children: [/*#__PURE__*/_jsx(Pressable, {
275
226
  onPress: toggleIsOpen,
276
- ref: controlRef,
227
+ ref: reference,
277
228
  onBlur: close,
278
229
  style: pressableStyles,
279
230
  hitSlop: pressableHitSlop,
280
231
  accessibilityLabel: getCopy('a11yText'),
281
232
  accessibilityRole: "button",
282
233
  children: typeof control === 'function' ? pressableState => control(getPressableState(pressableState), variant) : control
283
- }), isOpen && /*#__PURE__*/_jsx(Backdrop, {
284
- onPress: close,
285
- children: /*#__PURE__*/_jsxs(View, {
286
- ref: ref,
287
- style: [staticStyles.tooltip, selectTooltipShadowStyles(themeTokens), // applied separately so that it doesn't cover the arrow
288
- tooltipPosition && selectTooltipPositionStyles(tooltipPosition), (tooltipPosition === null || (tooltipPosition === null || tooltipPosition === void 0 ? void 0 : tooltipPosition.isNormalized)) && staticStyles.tooltipHidden // visually hide the tooltip until we have a final measurement
289
- ],
290
- onLayout: onTooltipLayout,
291
- accessibilityRole: "alert",
292
- children: [/*#__PURE__*/_jsx(View, {
293
- style: [staticStyles.arrow, tooltipPosition && selectArrowStyles(themeTokens, tooltipPosition)]
294
- }), /*#__PURE__*/_jsx(View, {
295
- style: selectTooltipStyles(themeTokens),
296
- children: /*#__PURE__*/_jsx(Text, {
297
- style: selectTextStyles(themeTokens),
298
- children: content
299
- })
300
- })]
301
- })
234
+ }), isOpen && /*#__PURE__*/_jsxs(View, {
235
+ ref: floating,
236
+ style: [selectTooltipShadowStyles(themeTokens), staticStyles.tooltip, // applied separately so that it doesn't cover the arrow
237
+ selectMobileTooltipPositionStyles({
238
+ position: strategy,
239
+ top: y !== null && y !== void 0 ? y : 0,
240
+ left: x !== null && x !== void 0 ? x : 0
241
+ })],
242
+ onLayout: onTooltipLayout,
243
+ accessibilityRole: "alert",
244
+ children: [/*#__PURE__*/_jsx(View, {
245
+ style: [staticStyles.arrow, selectMobileArrowStyles(themeTokens, { ...arrowData,
246
+ placement
247
+ })],
248
+ ref: arrowRef
249
+ }), /*#__PURE__*/_jsx(View, {
250
+ style: selectTooltipStyles(themeTokens),
251
+ children: /*#__PURE__*/_jsx(Text, {
252
+ style: selectTextStyles(themeTokens),
253
+ children: content
254
+ })
255
+ })]
302
256
  })]
303
257
  });
304
258
  });
305
259
  Tooltip.displayName = 'Tooltip';
306
260
  Tooltip.propTypes = { ...selectedSystemPropTypes,
307
-
308
- /**
309
- * Used to render the control (i.e. tooltip trigger). If a render function is used it will receive the
310
- * pressable state and tooltip variant as an argument.
311
- */
312
- children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
313
-
314
- /**
315
- * The message. Can be raw text or text components.
316
- */
317
- content: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
318
-
319
- /**
320
- * Select English or French copy for the accessible label.
321
- */
322
- copy: PropTypes.oneOf(['en', 'fr']),
323
-
324
- /**
325
- * Use to place the tooltip in a specific location (only if it fits within viewport).
326
- */
327
- position: PropTypes.oneOf(['auto', 'above', 'right', 'below', 'left']),
328
- tokens: getTokensPropType('Tooltip'),
329
- variant: variantProp.propType
261
+ ...propTypes
330
262
  };
331
263
  export default Tooltip;
332
264
  const staticStyles = StyleSheet.create({
333
265
  container: {
334
- alignItems: 'flex-start'
266
+ alignItems: 'flex-start',
267
+ position: 'absolute'
335
268
  },
336
269
  tooltip: {
337
270
  position: 'absolute',
@@ -339,9 +272,6 @@ const staticStyles = StyleSheet.create({
339
272
  top: 0,
340
273
  left: 0
341
274
  },
342
- tooltipHidden: {
343
- opacity: 0
344
- },
345
275
  arrow: {
346
276
  position: 'absolute'
347
277
  }