@telus-uds/components-base 1.8.3 → 1.8.4

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 (269) hide show
  1. package/CHANGELOG.md +14 -2
  2. package/component-docs.json +1 -1
  3. package/lib/ActivityIndicator/Spinner.js +7 -7
  4. package/lib/ActivityIndicator/Spinner.native.js +2 -2
  5. package/lib/Button/ButtonBase.js +2 -2
  6. package/lib/Button/ButtonGroup.js +1 -1
  7. package/lib/Checkbox/Checkbox.js +1 -1
  8. package/lib/Checkbox/CheckboxGroup.js +2 -2
  9. package/lib/Divider/Divider.js +2 -2
  10. package/lib/ExpandCollapse/Panel.js +2 -17
  11. package/lib/FlexGrid/Col/Col.js +1 -1
  12. package/lib/Icon/Icon.js +1 -1
  13. package/lib/List/List.js +8 -2
  14. package/lib/Pagination/PageButton.js +2 -2
  15. package/lib/Pagination/Pagination.js +5 -3
  16. package/lib/Pagination/usePagination.js +2 -2
  17. package/lib/Progress/ProgressBar.js +3 -3
  18. package/lib/Progress/ProgressBarBackground.js +3 -3
  19. package/lib/Radio/Radio.js +2 -2
  20. package/lib/Radio/RadioGroup.js +2 -2
  21. package/lib/RadioCard/RadioCard.js +1 -1
  22. package/lib/RadioCard/RadioCardGroup.js +2 -2
  23. package/lib/Search/Search.js +1 -1
  24. package/lib/SideNav/SideNav.js +2 -2
  25. package/lib/Skeleton/Skeleton.js +1 -1
  26. package/lib/Skeleton/skeletonWebAnimation.js +1 -1
  27. package/lib/StackView/StackWrap.js +3 -1
  28. package/lib/StackView/getStackedContent.js +2 -2
  29. package/lib/Tabs/Tabs.js +28 -3
  30. package/lib/Tabs/TabsItem.js +5 -6
  31. package/lib/Tags/Tags.js +1 -1
  32. package/lib/ThemeProvider/utils/styles.js +2 -2
  33. package/lib/ThemeProvider/utils/theme-tokens.js +7 -9
  34. package/lib/ToggleSwitch/ToggleSwitch.js +1 -1
  35. package/lib/ToggleSwitch/ToggleSwitchGroup.js +1 -1
  36. package/lib/Tooltip/Backdrop.js +2 -10
  37. package/lib/utils/animation/useVerticalExpandAnimation.js +40 -14
  38. package/lib/utils/children.js +2 -2
  39. package/lib/utils/input.js +6 -12
  40. package/lib/utils/props/componentPropType.js +3 -3
  41. package/lib/utils/props/selectSystemProps.js +2 -2
  42. package/lib/utils/props/tokens.js +2 -2
  43. package/lib/utils/useSpacingScale.js +3 -1
  44. package/lib/utils/useUniqueId.js +1 -1
  45. package/lib-module/A11yInfoProvider/index.js +63 -0
  46. package/lib-module/A11yText/index.js +56 -0
  47. package/lib-module/ActivityIndicator/Spinner.js +77 -0
  48. package/lib-module/ActivityIndicator/Spinner.native.js +144 -0
  49. package/lib-module/ActivityIndicator/index.js +41 -0
  50. package/lib-module/ActivityIndicator/shared.js +12 -0
  51. package/lib-module/BaseProvider/index.js +29 -0
  52. package/lib-module/Box/Box.js +244 -0
  53. package/lib-module/Box/index.js +2 -0
  54. package/lib-module/Button/Button.js +26 -0
  55. package/lib-module/Button/ButtonBase.js +271 -0
  56. package/lib-module/Button/ButtonGroup.js +247 -0
  57. package/lib-module/Button/ButtonLink.js +40 -0
  58. package/lib-module/Button/index.js +4 -0
  59. package/lib-module/Button/propTypes.js +36 -0
  60. package/lib-module/Card/Card.js +84 -0
  61. package/lib-module/Card/CardBase.js +66 -0
  62. package/lib-module/Card/PressableCardBase.js +114 -0
  63. package/lib-module/Card/index.js +4 -0
  64. package/lib-module/Checkbox/Checkbox.js +346 -0
  65. package/lib-module/Checkbox/CheckboxGroup.js +233 -0
  66. package/lib-module/Checkbox/CheckboxInput.js +60 -0
  67. package/lib-module/Checkbox/CheckboxInput.native.js +6 -0
  68. package/lib-module/Checkbox/index.js +3 -0
  69. package/lib-module/Divider/Divider.js +124 -0
  70. package/lib-module/Divider/index.js +2 -0
  71. package/lib-module/ExpandCollapse/Accordion.js +15 -0
  72. package/lib-module/ExpandCollapse/Control.js +136 -0
  73. package/lib-module/ExpandCollapse/ExpandCollapse.js +95 -0
  74. package/lib-module/ExpandCollapse/Panel.js +151 -0
  75. package/lib-module/ExpandCollapse/index.js +7 -0
  76. package/lib-module/Feedback/Feedback.js +157 -0
  77. package/lib-module/Feedback/index.js +2 -0
  78. package/lib-module/Fieldset/Fieldset.js +153 -0
  79. package/lib-module/Fieldset/FieldsetContainer.js +32 -0
  80. package/lib-module/Fieldset/FieldsetContainer.native.js +23 -0
  81. package/lib-module/Fieldset/Legend.js +24 -0
  82. package/lib-module/Fieldset/Legend.native.js +31 -0
  83. package/lib-module/Fieldset/cssReset.js +14 -0
  84. package/lib-module/Fieldset/index.js +2 -0
  85. package/lib-module/FlexGrid/Col/Col.js +276 -0
  86. package/lib-module/FlexGrid/Col/index.js +2 -0
  87. package/lib-module/FlexGrid/FlexGrid.js +148 -0
  88. package/lib-module/FlexGrid/Row/Row.js +184 -0
  89. package/lib-module/FlexGrid/Row/index.js +2 -0
  90. package/lib-module/FlexGrid/helpers/index.js +18 -0
  91. package/lib-module/FlexGrid/index.js +2 -0
  92. package/lib-module/FlexGrid/providers/GutterContext.js +3 -0
  93. package/lib-module/HorizontalScroll/HorizontalScroll.js +175 -0
  94. package/lib-module/HorizontalScroll/HorizontalScrollButton.js +81 -0
  95. package/lib-module/HorizontalScroll/ScrollViewEnd.js +48 -0
  96. package/lib-module/HorizontalScroll/ScrollViewEnd.native.js +27 -0
  97. package/lib-module/HorizontalScroll/dictionary.js +11 -0
  98. package/lib-module/HorizontalScroll/index.js +11 -0
  99. package/lib-module/HorizontalScroll/itemPositions.js +112 -0
  100. package/lib-module/Icon/Icon.js +62 -0
  101. package/lib-module/Icon/IconText.js +83 -0
  102. package/lib-module/Icon/index.js +4 -0
  103. package/lib-module/IconButton/IconButton.js +122 -0
  104. package/lib-module/IconButton/index.js +2 -0
  105. package/lib-module/InputLabel/InputLabel.js +148 -0
  106. package/lib-module/InputLabel/LabelContent.js +27 -0
  107. package/lib-module/InputLabel/LabelContent.native.js +19 -0
  108. package/lib-module/InputLabel/index.js +2 -0
  109. package/lib-module/InputSupports/InputSupports.js +96 -0
  110. package/lib-module/InputSupports/index.js +2 -0
  111. package/lib-module/InputSupports/useInputSupports.js +32 -0
  112. package/lib-module/Link/ChevronLink.js +52 -0
  113. package/lib-module/Link/InlinePressable.js +40 -0
  114. package/lib-module/Link/InlinePressable.native.js +89 -0
  115. package/lib-module/Link/Link.js +28 -0
  116. package/lib-module/Link/LinkBase.js +240 -0
  117. package/lib-module/Link/TextButton.js +35 -0
  118. package/lib-module/Link/index.js +5 -0
  119. package/lib-module/List/List.js +62 -0
  120. package/lib-module/List/ListItem.js +248 -0
  121. package/lib-module/List/index.js +5 -0
  122. package/lib-module/Modal/Modal.js +222 -0
  123. package/lib-module/Modal/dictionary.js +9 -0
  124. package/lib-module/Modal/index.js +2 -0
  125. package/lib-module/Notification/Notification.js +209 -0
  126. package/lib-module/Notification/dictionary.js +8 -0
  127. package/lib-module/Notification/index.js +2 -0
  128. package/lib-module/Pagination/PageButton.js +66 -0
  129. package/lib-module/Pagination/Pagination.js +153 -0
  130. package/lib-module/Pagination/SideButton.js +106 -0
  131. package/lib-module/Pagination/dictionary.js +18 -0
  132. package/lib-module/Pagination/index.js +2 -0
  133. package/lib-module/Pagination/usePagination.js +73 -0
  134. package/lib-module/Progress/Progress.js +89 -0
  135. package/lib-module/Progress/ProgressBar.js +138 -0
  136. package/lib-module/Progress/ProgressBarBackground.js +42 -0
  137. package/lib-module/Progress/index.js +4 -0
  138. package/lib-module/Radio/Radio.js +285 -0
  139. package/lib-module/Radio/RadioButton.js +138 -0
  140. package/lib-module/Radio/RadioGroup.js +243 -0
  141. package/lib-module/Radio/RadioInput.js +62 -0
  142. package/lib-module/Radio/RadioInput.native.js +6 -0
  143. package/lib-module/Radio/index.js +3 -0
  144. package/lib-module/RadioCard/RadioCard.js +219 -0
  145. package/lib-module/RadioCard/RadioCardGroup.js +250 -0
  146. package/lib-module/RadioCard/index.js +3 -0
  147. package/lib-module/Search/Search.js +261 -0
  148. package/lib-module/Search/dictionary.js +12 -0
  149. package/lib-module/Search/index.js +2 -0
  150. package/lib-module/Select/Group.js +21 -0
  151. package/lib-module/Select/Group.native.js +15 -0
  152. package/lib-module/Select/Item.js +20 -0
  153. package/lib-module/Select/Item.native.js +3 -0
  154. package/lib-module/Select/Picker.js +68 -0
  155. package/lib-module/Select/Picker.native.js +120 -0
  156. package/lib-module/Select/Select.js +337 -0
  157. package/lib-module/Select/index.js +6 -0
  158. package/lib-module/SideNav/Item.js +145 -0
  159. package/lib-module/SideNav/ItemContent.js +48 -0
  160. package/lib-module/SideNav/ItemsGroup.js +117 -0
  161. package/lib-module/SideNav/SideNav.js +136 -0
  162. package/lib-module/SideNav/index.js +1 -0
  163. package/lib-module/Skeleton/Skeleton.js +179 -0
  164. package/lib-module/Skeleton/index.js +2 -0
  165. package/lib-module/Skeleton/skeleton.constant.js +3 -0
  166. package/lib-module/Skeleton/skeletonWebAnimation.js +18 -0
  167. package/lib-module/Skeleton/useSkeletonNativeAnimation.js +24 -0
  168. package/lib-module/Spacer/Spacer.js +98 -0
  169. package/lib-module/Spacer/index.js +2 -0
  170. package/lib-module/StackView/StackView.js +125 -0
  171. package/lib-module/StackView/StackWrap.js +50 -0
  172. package/lib-module/StackView/StackWrap.native.js +3 -0
  173. package/lib-module/StackView/StackWrapBox.js +115 -0
  174. package/lib-module/StackView/StackWrapGap.js +59 -0
  175. package/lib-module/StackView/common.js +35 -0
  176. package/lib-module/StackView/getStackedContent.js +124 -0
  177. package/lib-module/StackView/index.js +5 -0
  178. package/lib-module/StepTracker/Step.js +248 -0
  179. package/lib-module/StepTracker/StepTracker.js +185 -0
  180. package/lib-module/StepTracker/dictionary.js +10 -0
  181. package/lib-module/StepTracker/index.js +2 -0
  182. package/lib-module/Tabs/Tabs.js +143 -0
  183. package/lib-module/Tabs/TabsItem.js +224 -0
  184. package/lib-module/Tabs/index.js +2 -0
  185. package/lib-module/Tags/Tags.js +251 -0
  186. package/lib-module/Tags/index.js +2 -0
  187. package/lib-module/TextInput/TextArea.js +94 -0
  188. package/lib-module/TextInput/TextInput.js +72 -0
  189. package/lib-module/TextInput/TextInputBase.js +245 -0
  190. package/lib-module/TextInput/index.js +3 -0
  191. package/lib-module/TextInput/propTypes.js +37 -0
  192. package/lib-module/ThemeProvider/ThemeProvider.js +36 -0
  193. package/lib-module/ThemeProvider/index.js +6 -0
  194. package/lib-module/ThemeProvider/useSetTheme.js +25 -0
  195. package/lib-module/ThemeProvider/useTheme.js +14 -0
  196. package/lib-module/ThemeProvider/useThemeTokens.js +110 -0
  197. package/lib-module/ThemeProvider/utils/index.js +2 -0
  198. package/lib-module/ThemeProvider/utils/styles.js +181 -0
  199. package/lib-module/ThemeProvider/utils/theme-tokens.js +163 -0
  200. package/lib-module/ToggleSwitch/ToggleSwitch.js +250 -0
  201. package/lib-module/ToggleSwitch/ToggleSwitchGroup.js +220 -0
  202. package/lib-module/ToggleSwitch/index.js +3 -0
  203. package/lib-module/Tooltip/Backdrop.js +45 -0
  204. package/lib-module/Tooltip/Backdrop.native.js +44 -0
  205. package/lib-module/Tooltip/Tooltip.js +348 -0
  206. package/lib-module/Tooltip/dictionary.js +8 -0
  207. package/lib-module/Tooltip/getTooltipPosition.js +175 -0
  208. package/lib-module/Tooltip/index.js +2 -0
  209. package/lib-module/TooltipButton/TooltipButton.js +78 -0
  210. package/lib-module/TooltipButton/index.js +2 -0
  211. package/lib-module/Typography/Typography.js +124 -0
  212. package/lib-module/Typography/index.js +2 -0
  213. package/lib-module/ViewportProvider/ViewportProvider.js +29 -0
  214. package/lib-module/ViewportProvider/index.js +3 -0
  215. package/lib-module/ViewportProvider/useViewport.js +3 -0
  216. package/lib-module/ViewportProvider/useViewportListener.js +46 -0
  217. package/lib-module/index.js +48 -0
  218. package/lib-module/utils/a11y/index.js +2 -0
  219. package/lib-module/utils/a11y/semantics.js +157 -0
  220. package/lib-module/utils/a11y/textSize.js +36 -0
  221. package/lib-module/utils/animation/index.js +2 -0
  222. package/lib-module/utils/animation/useVerticalExpandAnimation.js +88 -0
  223. package/lib-module/utils/children.js +119 -0
  224. package/lib-module/utils/containUniqueFields.js +26 -0
  225. package/lib-module/utils/index.js +16 -0
  226. package/lib-module/utils/info/index.js +7 -0
  227. package/lib-module/utils/info/platform/index.js +11 -0
  228. package/lib-module/utils/info/platform/platform.android.js +1 -0
  229. package/lib-module/utils/info/platform/platform.ios.js +1 -0
  230. package/lib-module/utils/info/platform/platform.js +1 -0
  231. package/lib-module/utils/info/platform/platform.native.js +4 -0
  232. package/lib-module/utils/info/versions.js +5 -0
  233. package/lib-module/utils/input.js +179 -0
  234. package/lib-module/utils/pressability.js +111 -0
  235. package/lib-module/utils/props/a11yProps.js +140 -0
  236. package/lib-module/utils/props/clickProps.js +26 -0
  237. package/lib-module/utils/props/componentPropType.js +63 -0
  238. package/lib-module/utils/props/copyPropTypes.js +2 -0
  239. package/lib-module/utils/props/getPropSelector.js +9 -0
  240. package/lib-module/utils/props/handlerProps.js +65 -0
  241. package/lib-module/utils/props/hrefAttrsProp.js +33 -0
  242. package/lib-module/utils/props/index.js +19 -0
  243. package/lib-module/utils/props/inputSupportsProps.js +62 -0
  244. package/lib-module/utils/props/linkProps.js +44 -0
  245. package/lib-module/utils/props/paddingProp.js +9 -0
  246. package/lib-module/utils/props/pressProps.js +42 -0
  247. package/lib-module/utils/props/rectProp.js +9 -0
  248. package/lib-module/utils/props/responsiveProps.js +30 -0
  249. package/lib-module/utils/props/selectSystemProps.js +24 -0
  250. package/lib-module/utils/props/spacingProps.js +56 -0
  251. package/lib-module/utils/props/textInputProps.js +194 -0
  252. package/lib-module/utils/props/textProps.js +59 -0
  253. package/lib-module/utils/props/tokens.js +133 -0
  254. package/lib-module/utils/props/variantProp.js +18 -0
  255. package/lib-module/utils/props/viewProps.js +22 -0
  256. package/lib-module/utils/ssr.js +38 -0
  257. package/lib-module/utils/useCopy.js +44 -0
  258. package/lib-module/utils/useHash.js +45 -0
  259. package/lib-module/utils/useHash.native.js +7 -0
  260. package/lib-module/utils/useResponsiveProp.js +47 -0
  261. package/lib-module/utils/useSpacingScale.js +125 -0
  262. package/lib-module/utils/useUniqueId.js +13 -0
  263. package/lib-module/utils/withLinkRouter.js +83 -0
  264. package/package.json +2 -2
  265. package/src/ExpandCollapse/Panel.jsx +2 -19
  266. package/src/List/List.jsx +6 -2
  267. package/src/Tabs/Tabs.jsx +24 -2
  268. package/src/Tabs/TabsItem.jsx +6 -5
  269. package/src/utils/animation/useVerticalExpandAnimation.js +47 -13
@@ -0,0 +1,348 @@
1
+ import React, { forwardRef, useEffect, useRef, useState } from 'react';
2
+ import Dimensions from "react-native-web/dist/exports/Dimensions";
3
+ import Platform from "react-native-web/dist/exports/Platform";
4
+ import Pressable from "react-native-web/dist/exports/Pressable";
5
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
6
+ import Text from "react-native-web/dist/exports/Text";
7
+ import View from "react-native-web/dist/exports/View";
8
+ import PropTypes from 'prop-types';
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';
13
+ import TooltipButton from '../TooltipButton';
14
+ import useCopy from '../utils/useCopy';
15
+ import dictionary from './dictionary';
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ import { jsxs as _jsxs } from "react/jsx-runtime";
18
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
19
+
20
+ const selectTooltipStyles = _ref => {
21
+ let {
22
+ backgroundColor,
23
+ paddingTop,
24
+ paddingBottom,
25
+ paddingLeft,
26
+ paddingRight,
27
+ borderRadius
28
+ } = _ref;
29
+ return {
30
+ backgroundColor,
31
+ paddingTop,
32
+ paddingBottom,
33
+ paddingLeft,
34
+ paddingRight,
35
+ borderRadius
36
+ };
37
+ };
38
+
39
+ const selectTooltipShadowStyles = _ref2 => {
40
+ let {
41
+ shadow,
42
+ borderRadius
43
+ } = _ref2;
44
+ return {
45
+ borderRadius,
46
+ ...applyShadowToken(shadow)
47
+ };
48
+ };
49
+
50
+ const selectTooltipPositionStyles = _ref3 => {
51
+ let {
52
+ top,
53
+ left,
54
+ width
55
+ } = _ref3;
56
+ return {
57
+ top,
58
+ left,
59
+ width
60
+ };
61
+ };
62
+
63
+ const selectArrowStyles = (_ref4, _ref5) => {
64
+ let {
65
+ backgroundColor,
66
+ arrowWidth,
67
+ arrowBorderRadius,
68
+ shadow
69
+ } = _ref4;
70
+ let {
71
+ position,
72
+ width: tooltipWidth,
73
+ height: tooltipHeight
74
+ } = _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
+ };
113
+ return {
114
+ backgroundColor,
115
+ width: rectangleSide,
116
+ height: rectangleSide,
117
+ borderBottomRightRadius: arrowBorderRadius,
118
+ // this corner will be the arrow tip after rotation
119
+ ...applyShadowToken(shadow),
120
+ ...directionalStyles[position]
121
+ };
122
+ };
123
+
124
+ const selectTextStyles = tokens => applyTextStyles(selectTokens('Typography', tokens));
125
+
126
+ const defaultControl = (pressableState, variant) => /*#__PURE__*/_jsx(TooltipButton, {
127
+ pressableState: pressableState,
128
+ variant: variant
129
+ });
130
+ /**
131
+ * Tooltip provides a descriptive and detailed explanation or instructions. It can be used next to an input label
132
+ * to help a user fill it in, or as a standalone component.
133
+ *
134
+ * By default the TooltipButton component will be used as a control for triggering the tooltip, but you may attach
135
+ * a tooltip to any other component. A render function can be used to adjust the control's styling on state changes (hover, focus, etc.).
136
+ *
137
+ * ### Positioning
138
+ * By default a Tooltip will be automatically positioned in a way that ensures it fits within the viewport.
139
+ * You may suggest a position with a prop - it will be used, unless the tooltip would end up outside the viewport.
140
+ *
141
+ * ### Usage criteria
142
+ * - You may use one when the information is useful only to a small percentage of users (ie. tech savvy people wouldn't need this info).
143
+ * - Tooltips may also be useful when vertical space is an issue.
144
+ */
145
+
146
+
147
+ const Tooltip = /*#__PURE__*/forwardRef((_ref6, ref) => {
148
+ let {
149
+ children,
150
+ content,
151
+ position = 'auto',
152
+ copy = 'en',
153
+ tokens,
154
+ variant,
155
+ ...rest
156
+ } = _ref6;
157
+ const [isOpen, setIsOpen] = useState(false);
158
+ const controlRef = useRef();
159
+ const [controlLayout, setControlLayout] = useState(null);
160
+ const [tooltipDimensions, setTooltipDimensions] = useState(null);
161
+ const [windowDimensions, setWindowDimensions] = useState(Dimensions.get('window'));
162
+ const [tooltipPosition, setTooltipPosition] = useState(null);
163
+ const getCopy = useCopy({
164
+ dictionary,
165
+ copy
166
+ });
167
+ 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
+
182
+ const toggleIsOpen = () => setIsOpen(!isOpen);
183
+
184
+ const close = () => setIsOpen(false);
185
+
186
+ const getPressableState = _ref8 => {
187
+ let {
188
+ pressed,
189
+ hovered,
190
+ focused
191
+ } = _ref8;
192
+ return {
193
+ pressed,
194
+ hover: hovered,
195
+ focus: focused
196
+ };
197
+ };
198
+
199
+ const onTooltipLayout = _ref9 => {
200
+ let {
201
+ nativeEvent: {
202
+ layout: {
203
+ width,
204
+ height
205
+ }
206
+ }
207
+ } = _ref9;
208
+
209
+ if (tooltipDimensions === null || tooltipDimensions.width !== width || tooltipDimensions.height !== height) {
210
+ setTooltipDimensions({
211
+ width: Platform.select({
212
+ web: width + 0.3,
213
+ // avoids often unnecessary line breaks due to subpixel rendering of fonts
214
+ native: width
215
+ }),
216
+ height
217
+ });
218
+ }
219
+ };
220
+
221
+ 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);
233
+ setTooltipDimensions(null);
234
+ setTooltipPosition(null);
235
+ }
236
+ }, [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
+ const control = children !== undefined ? children : defaultControl;
260
+ const pressableStyles = control === defaultControl ? Platform.select({
261
+ web: {
262
+ outline: 'none'
263
+ }
264
+ }) : undefined;
265
+ const pressableHitSlop = control === defaultControl ? {
266
+ top: 10,
267
+ bottom: 10,
268
+ left: 10,
269
+ right: 10
270
+ } : undefined;
271
+ return /*#__PURE__*/_jsxs(View, {
272
+ style: staticStyles.container,
273
+ ...selectProps(rest),
274
+ children: [/*#__PURE__*/_jsx(Pressable, {
275
+ onPress: toggleIsOpen,
276
+ ref: controlRef,
277
+ onBlur: close,
278
+ style: pressableStyles,
279
+ hitSlop: pressableHitSlop,
280
+ accessibilityLabel: getCopy('a11yText'),
281
+ accessibilityRole: "button",
282
+ 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
+ })
302
+ })]
303
+ });
304
+ });
305
+ Tooltip.displayName = 'Tooltip';
306
+ 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
330
+ };
331
+ export default Tooltip;
332
+ const staticStyles = StyleSheet.create({
333
+ container: {
334
+ alignItems: 'flex-start'
335
+ },
336
+ tooltip: {
337
+ position: 'absolute',
338
+ maxWidth: 240,
339
+ top: 0,
340
+ left: 0
341
+ },
342
+ tooltipHidden: {
343
+ opacity: 0
344
+ },
345
+ arrow: {
346
+ position: 'absolute'
347
+ }
348
+ });
@@ -0,0 +1,8 @@
1
+ export default {
2
+ en: {
3
+ a11yText: 'Reveal additional information.'
4
+ },
5
+ fr: {
6
+ a11yText: 'Afficher des renseignements supplémentaires.'
7
+ }
8
+ };
@@ -0,0 +1,175 @@
1
+ function normalizePosition(position) {
2
+ const {
3
+ left,
4
+ right,
5
+ bottom,
6
+ top,
7
+ width,
8
+ ...rest
9
+ } = position; // adjust the coordinates so that it fits within the window
10
+
11
+ const normalized = {
12
+ left: Math.max(0, left),
13
+ right: Math.max(0, right),
14
+ top: Math.max(0, top),
15
+ bottom // since it's ok the make the document grow downwards - no need to normalize here
16
+
17
+ };
18
+
19
+ const getAbsoluteDiff = (value1, value2) => Math.abs(Math.abs(value1) - Math.abs(value2)); // adjust the width by whatever has been subtracted from left or right
20
+
21
+
22
+ normalized.width = width - Math.abs(getAbsoluteDiff(left, normalized.left) - getAbsoluteDiff(right, normalized.right));
23
+
24
+ if (normalized.top !== top) {
25
+ normalized.bottom += normalized.top - top;
26
+ }
27
+
28
+ const isNormalized = normalized.right !== right || normalized.left !== left || normalized.top !== top;
29
+ return { ...normalized,
30
+ ...rest,
31
+ isNormalized
32
+ };
33
+ }
34
+
35
+ function invertPosition(position) {
36
+ switch (position) {
37
+ case 'above':
38
+ return 'below';
39
+
40
+ case 'below':
41
+ return 'above';
42
+
43
+ case 'left':
44
+ return 'right';
45
+
46
+ default:
47
+ return 'left';
48
+ }
49
+ }
50
+
51
+ function findRectByPosition(position, rectsArray) {
52
+ return rectsArray.find(_ref => {
53
+ let {
54
+ position: rectPosition
55
+ } = _ref;
56
+ return rectPosition === position;
57
+ });
58
+ }
59
+ /**
60
+ * Used for absolute positioning of the tooltip. Since the tooltip is always centered relatively
61
+ * to the control (button) and we have a limited set of positions, an easy and consistent way
62
+ * of positioning it is to check all of the possible positions and pick one that will be rendered
63
+ * within the window bounds. This way we can also rely on the tooltip being actually rendered
64
+ * before it is shown, which makes it account for the width being limiting in styles, custom font
65
+ * rendering, etc.
66
+ */
67
+
68
+
69
+ function getTooltipPosition(position, _ref2) {
70
+ let {
71
+ controlLayout,
72
+ tooltipDimensions,
73
+ windowDimensions,
74
+ arrowWidth = 0,
75
+ arrowOffset = 0
76
+ } = _ref2;
77
+ const {
78
+ width: controlWidth,
79
+ height: controlHeight,
80
+ x: controlX,
81
+ y: controlY
82
+ } = controlLayout;
83
+ const {
84
+ width: tooltipWidth,
85
+ height: tooltipHeight
86
+ } = tooltipDimensions;
87
+ const {
88
+ width: windowWidth,
89
+ height: windowHeight
90
+ } = windowDimensions;
91
+ const arrowSize = arrowWidth / 2 + arrowOffset;
92
+ const horizontalBounds = {
93
+ left: controlX + controlWidth / 2 - tooltipWidth / 2,
94
+ right: windowWidth - (controlX + controlWidth / 2 + tooltipWidth / 2)
95
+ };
96
+ const verticalBounds = {
97
+ top: controlY + controlHeight / 2 - tooltipHeight / 2,
98
+ bottom: windowHeight - (controlY + controlHeight / 2 + tooltipHeight / 2)
99
+ }; // calculate absolute coordinates for each of the potential positions (relative to window)
100
+
101
+ const boundingRects = [{
102
+ position: 'above',
103
+ ...horizontalBounds,
104
+ top: controlY - tooltipHeight - arrowSize,
105
+ bottom: windowHeight - (controlY - arrowSize)
106
+ }, {
107
+ position: 'right',
108
+ ...verticalBounds,
109
+ left: controlX + controlWidth + arrowSize,
110
+ right: windowWidth - (controlX + controlWidth + tooltipWidth + arrowSize)
111
+ }, {
112
+ position: 'below',
113
+ ...horizontalBounds,
114
+ top: controlY + controlHeight + arrowSize,
115
+ bottom: windowHeight - (controlY + controlHeight + tooltipHeight + arrowSize)
116
+ }, {
117
+ position: 'left',
118
+ ...verticalBounds,
119
+ left: controlX - tooltipWidth - arrowSize,
120
+ right: windowWidth - (controlX - arrowSize)
121
+ }].map(rect => {
122
+ // an absolute value representing how much of the tooltip is overflowing the window on each side
123
+ const windowOverflow = Math.abs(Math.min(rect.top, 0) - Math.min(rect.left, 0) - Math.min(rect.right, 0) - Math.min(rect.bottom, 0));
124
+ return { ...rect,
125
+ ...tooltipDimensions,
126
+ overflow: windowOverflow,
127
+ isNormalized: false
128
+ };
129
+ }); // the 'position' prop overrides the automatic positioning
130
+
131
+ if (position !== 'auto') {
132
+ let rect = findRectByPosition(position, boundingRects); // check if the suggested 'position' fits in window
133
+
134
+ if (rect.overflow === 0) {
135
+ return rect;
136
+ } // otherwise try the inverted position (e.g. left -> right)
137
+
138
+
139
+ rect = findRectByPosition(invertPosition(position), boundingRects);
140
+
141
+ if (rect.overflow === 0) {
142
+ return rect;
143
+ }
144
+ }
145
+
146
+ const inWindow = boundingRects.filter(_ref3 => {
147
+ let {
148
+ overflow
149
+ } = _ref3;
150
+ return overflow === 0;
151
+ }); // pick the first position that fits in window
152
+ // (these are sorted clockwise which makes them show where one would expect them to be)
153
+
154
+ if (inWindow.length > 0) {
155
+ return inWindow[0];
156
+ } // if all positions would end up being out of window bounds, let's pick the one that is
157
+ // the least overflowing and normalize its position to fit within window bounds
158
+
159
+
160
+ boundingRects.sort((_ref4, _ref5) => {
161
+ let {
162
+ overflow: overflowA
163
+ } = _ref4;
164
+ let {
165
+ overflow: overflowB
166
+ } = _ref5;
167
+ return overflowA - overflowB;
168
+ });
169
+ const leastOverflowing = boundingRects[0]; // prefer 'below' over 'above', since we can always expand the document downwards,
170
+ // and 'above' might cause issues on small viewports with large tooltips
171
+
172
+ return normalizePosition(leastOverflowing.position === 'above' ? findRectByPosition('below', boundingRects) : leastOverflowing);
173
+ }
174
+
175
+ export default getTooltipPosition;
@@ -0,0 +1,2 @@
1
+ import Tooltip from './Tooltip';
2
+ export default Tooltip;
@@ -0,0 +1,78 @@
1
+ import React from 'react';
2
+ import View from "react-native-web/dist/exports/View";
3
+ import PropTypes from 'prop-types';
4
+ import { useThemeTokens, applyOuterBorder } from '../ThemeProvider';
5
+ import { a11yProps, getTokensPropType, selectSystemProps, variantProp, viewProps } from '../utils';
6
+ import Icon from '../Icon';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
9
+
10
+ const selectInnerContainerStyles = _ref => {
11
+ let {
12
+ borderRadius,
13
+ width
14
+ } = _ref;
15
+ return {
16
+ borderRadius,
17
+ width
18
+ };
19
+ };
20
+
21
+ const selectIconTokens = _ref2 => {
22
+ let {
23
+ iconSize,
24
+ iconColor
25
+ /* iconScale = 1 */
26
+
27
+ } = _ref2;
28
+ return {
29
+ size: iconSize,
30
+ color: iconColor // scale: iconScale TODO re-enable with icon component
31
+
32
+ };
33
+ };
34
+ /**
35
+ * `TooltipButton` is a helper component used as a default control for the `Tooltip` component.
36
+ * In fact though, it isn't actually a pressable - it's meant to be used as pressable's content.
37
+ * Due to this any interaction states (e.g. pressed, hover, etc.) has to be passed down to it as a prop.
38
+ */
39
+
40
+
41
+ const TooltipButton = _ref3 => {
42
+ let {
43
+ pressableState,
44
+ tokens,
45
+ variant,
46
+ ...rest
47
+ } = _ref3;
48
+ const themeTokens = useThemeTokens('TooltipButton', tokens, variant, pressableState);
49
+ const {
50
+ icon: IconComponent
51
+ } = themeTokens;
52
+ return /*#__PURE__*/_jsx(View, {
53
+ style: applyOuterBorder(themeTokens),
54
+ ...selectProps(rest),
55
+ children: /*#__PURE__*/_jsx(View, {
56
+ style: selectInnerContainerStyles(themeTokens),
57
+ children: IconComponent && /*#__PURE__*/_jsx(Icon, {
58
+ icon: IconComponent,
59
+ tokens: selectIconTokens(themeTokens)
60
+ })
61
+ })
62
+ });
63
+ };
64
+
65
+ TooltipButton.propTypes = { ...selectedSystemPropTypes,
66
+
67
+ /**
68
+ * Used as appearances when resolving theme tokens.
69
+ */
70
+ pressableState: PropTypes.shape({
71
+ pressed: PropTypes.bool,
72
+ hover: PropTypes.bool,
73
+ focus: PropTypes.bool
74
+ }),
75
+ tokens: getTokensPropType('TooltipButton'),
76
+ variant: variantProp.propType
77
+ };
78
+ export default TooltipButton;
@@ -0,0 +1,2 @@
1
+ import TooltipButton from './TooltipButton';
2
+ export default TooltipButton;