@atlaskit/tooltip 20.11.1 → 20.13.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.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/internal/tooltip-manager.js +10 -2
- package/dist/cjs/tooltip.js +43 -20
- package/dist/cjs/utilities.js +43 -0
- package/dist/es2019/internal/tooltip-manager.js +10 -2
- package/dist/es2019/tooltip.js +43 -21
- package/dist/es2019/utilities.js +37 -0
- package/dist/esm/internal/tooltip-manager.js +10 -2
- package/dist/esm/tooltip.js +44 -21
- package/dist/esm/utilities.js +42 -0
- package/dist/types/internal/tooltip-manager.d.ts +8 -3
- package/dist/types/tooltip.d.ts +1 -1
- package/dist/types/types.d.ts +10 -2
- package/dist/types/utilities.d.ts +8 -0
- package/dist/types-ts4.5/internal/tooltip-manager.d.ts +8 -3
- package/dist/types-ts4.5/tooltip.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +10 -2
- package/dist/types-ts4.5/utilities.d.ts +8 -0
- package/package.json +13 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @atlaskit/tooltip
|
|
2
2
|
|
|
3
|
+
## 20.13.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`05a04a1bfd2f9`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/05a04a1bfd2f9) -
|
|
8
|
+
Adds the experimental `UNSAFE_shouldAlwaysFadeIn` prop behind the
|
|
9
|
+
`platform_dst_nav4_side_nav_resize_tooltip_feedback` feature gate. When used, the tooltip will
|
|
10
|
+
always use the fade in animation, and never use the show immediate behaviour, even when another
|
|
11
|
+
tooltip is already visible.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
17
|
+
## 20.12.0
|
|
18
|
+
|
|
19
|
+
### Minor Changes
|
|
20
|
+
|
|
21
|
+
- [`2e7328e8eff65`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2e7328e8eff65) -
|
|
22
|
+
Adds `mouse-x` and `mouse-y` positions for tooltips behind the
|
|
23
|
+
`platform_dst_nav4_side_nav_resize_tooltip_feedback` gate. These positions only use the mouse
|
|
24
|
+
coordinates on one axis, but are otherwise relative to the target.
|
|
25
|
+
|
|
3
26
|
## 20.11.1
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.show = show;
|
|
7
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
7
8
|
var _sharedSchedule = require("./shared-schedule");
|
|
8
9
|
// This file is a singleton for managing tooltips
|
|
9
10
|
|
|
@@ -99,7 +100,8 @@ function show(entry) {
|
|
|
99
100
|
return null;
|
|
100
101
|
}
|
|
101
102
|
function start() {
|
|
102
|
-
var
|
|
103
|
+
var shouldAlwaysFadeIn = (0, _platformFeatureFlags.fg)('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? entry.shouldAlwaysFadeIn : false;
|
|
104
|
+
var showImmediately = Boolean(active && active.isVisible()) && !shouldAlwaysFadeIn;
|
|
103
105
|
|
|
104
106
|
// If there was an active tooltip; we tell it to remove itself at once!
|
|
105
107
|
if (active) {
|
|
@@ -137,7 +139,13 @@ function show(entry) {
|
|
|
137
139
|
isActive: isActive,
|
|
138
140
|
requestHide: requestHide,
|
|
139
141
|
finishHideAnimation: finishHideAnimation,
|
|
140
|
-
mousePosition
|
|
142
|
+
// Removing old `mousePosition` behind gate because it stored a function.
|
|
143
|
+
// With the gate we just store the coords which are easier to work with.
|
|
144
|
+
mousePosition: (0, _platformFeatureFlags.fg)('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? undefined : getInitialMouse(),
|
|
145
|
+
mousePos: entry.source.type === 'mouse' && (0, _platformFeatureFlags.fg)('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? {
|
|
146
|
+
clientX: entry.source.clientX,
|
|
147
|
+
clientY: entry.source.clientY
|
|
148
|
+
} : null
|
|
141
149
|
};
|
|
142
150
|
return result;
|
|
143
151
|
}
|
package/dist/cjs/tooltip.js
CHANGED
|
@@ -17,6 +17,7 @@ var _useCloseOnEscapePress = _interopRequireDefault(require("@atlaskit/ds-lib/us
|
|
|
17
17
|
var _useStableRef = _interopRequireDefault(require("@atlaskit/ds-lib/use-stable-ref"));
|
|
18
18
|
var _openLayerObserver = require("@atlaskit/layering/experimental/open-layer-observer");
|
|
19
19
|
var _motion = require("@atlaskit/motion");
|
|
20
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
20
21
|
var _popper = require("@atlaskit/popper");
|
|
21
22
|
var _portal = _interopRequireDefault(require("@atlaskit/portal"));
|
|
22
23
|
var _constants = require("@atlaskit/theme/constants");
|
|
@@ -89,8 +90,12 @@ function Tooltip(_ref) {
|
|
|
89
90
|
ignoreTooltipPointerEvents = _ref$ignoreTooltipPoi === void 0 ? false : _ref$ignoreTooltipPoi,
|
|
90
91
|
_ref$isScreenReaderAn = _ref.isScreenReaderAnnouncementDisabled,
|
|
91
92
|
isScreenReaderAnnouncementDisabled = _ref$isScreenReaderAn === void 0 ? false : _ref$isScreenReaderAn,
|
|
92
|
-
shortcut = _ref.shortcut
|
|
93
|
-
|
|
93
|
+
shortcut = _ref.shortcut,
|
|
94
|
+
_ref$UNSAFE_shouldAlw = _ref.UNSAFE_shouldAlwaysFadeIn,
|
|
95
|
+
shouldAlwaysFadeIn = _ref$UNSAFE_shouldAlw === void 0 ? false : _ref$UNSAFE_shouldAlw;
|
|
96
|
+
// Not using a gate for this check. When the gate is disabled `mouse-y` and `mouse-x` are treated as `mouse`.
|
|
97
|
+
var isMousePosition = position === 'mouse' || position === 'mouse-y' || position === 'mouse-x';
|
|
98
|
+
var tooltipPosition = isMousePosition ? mousePosition : position;
|
|
94
99
|
var onShowHandler = (0, _analyticsNext.usePlatformLeafSyntheticEventHandler)(_objectSpread({
|
|
95
100
|
fn: onShow,
|
|
96
101
|
action: 'displayed',
|
|
@@ -131,6 +136,7 @@ function Tooltip(_ref) {
|
|
|
131
136
|
var delayStable = (0, _useStableRef.default)(delay);
|
|
132
137
|
var canAppearStable = (0, _useStableRef.default)(canAppear);
|
|
133
138
|
var hasCalledShowHandler = (0, _react.useRef)(false);
|
|
139
|
+
var shouldAlwaysFadeInStable = (0, _useStableRef.default)(shouldAlwaysFadeIn);
|
|
134
140
|
var start = (0, _react.useCallback)(function (api) {
|
|
135
141
|
// @ts-ignore
|
|
136
142
|
apiRef.current = api;
|
|
@@ -243,7 +249,7 @@ function Tooltip(_ref) {
|
|
|
243
249
|
hasCalledShowHandler.current = true;
|
|
244
250
|
onShowHandlerStable.current();
|
|
245
251
|
}
|
|
246
|
-
setState(isImmediate ? '
|
|
252
|
+
setState(!isImmediate ? 'fade-in' : 'show-immediate');
|
|
247
253
|
},
|
|
248
254
|
hide: function hide(_ref4) {
|
|
249
255
|
var isImmediate = _ref4.isImmediate;
|
|
@@ -253,11 +259,12 @@ function Tooltip(_ref) {
|
|
|
253
259
|
setState('before-fade-out');
|
|
254
260
|
}
|
|
255
261
|
},
|
|
256
|
-
done: done
|
|
262
|
+
done: done,
|
|
263
|
+
shouldAlwaysFadeIn: (0, _platformFeatureFlags.fg)('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? shouldAlwaysFadeInStable.current : false
|
|
257
264
|
};
|
|
258
265
|
var api = (0, _tooltipManager.show)(entry);
|
|
259
266
|
start(api);
|
|
260
|
-
}, [canAppearStable, delayStable, done, start, abort, onShowHandlerStable]);
|
|
267
|
+
}, [canAppearStable, delayStable, done, start, abort, onShowHandlerStable, shouldAlwaysFadeInStable]);
|
|
261
268
|
var hideTooltipOnEsc = (0, _react.useCallback)(function () {
|
|
262
269
|
var _apiRef$current2;
|
|
263
270
|
(_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 || _apiRef$current2.requestHide({
|
|
@@ -323,18 +330,22 @@ function Tooltip(_ref) {
|
|
|
323
330
|
return;
|
|
324
331
|
}
|
|
325
332
|
event.preventDefault();
|
|
326
|
-
var source =
|
|
333
|
+
var source = isMousePosition ? {
|
|
327
334
|
type: 'mouse',
|
|
328
335
|
// TODO: ideally not recalculating this object each time
|
|
329
|
-
mouse
|
|
336
|
+
// Removing old `mouse` behind gate because it stored a function.
|
|
337
|
+
// With the gate we just store the coords which are easier to work with.
|
|
338
|
+
mouse: (0, _platformFeatureFlags.fg)('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? undefined : (0, _utilities.getMousePosition)({
|
|
330
339
|
left: event.clientX,
|
|
331
340
|
top: event.clientY
|
|
332
|
-
})
|
|
341
|
+
}),
|
|
342
|
+
clientX: event.clientX,
|
|
343
|
+
clientY: event.clientY
|
|
333
344
|
} : {
|
|
334
345
|
type: 'keyboard'
|
|
335
346
|
};
|
|
336
347
|
tryShowTooltip(source);
|
|
337
|
-
}, [
|
|
348
|
+
}, [isMousePosition, tryShowTooltip]);
|
|
338
349
|
|
|
339
350
|
// Ideally we would be using onMouseEnter here, but
|
|
340
351
|
// because we are binding the event to the target parent
|
|
@@ -358,13 +369,19 @@ function Tooltip(_ref) {
|
|
|
358
369
|
});
|
|
359
370
|
}
|
|
360
371
|
}, []);
|
|
361
|
-
var onMouseMove =
|
|
372
|
+
var onMouseMove = isMousePosition ? function (event) {
|
|
362
373
|
var _apiRef$current3;
|
|
363
374
|
if ((_apiRef$current3 = apiRef.current) !== null && _apiRef$current3 !== void 0 && _apiRef$current3.isActive()) {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
375
|
+
if (!(0, _platformFeatureFlags.fg)('platform_dst_nav4_side_nav_resize_tooltip_feedback')) {
|
|
376
|
+
apiRef.current.mousePosition = (0, _utilities.getMousePosition)({
|
|
377
|
+
left: event.clientX,
|
|
378
|
+
top: event.clientY
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
apiRef.current.mousePos = {
|
|
382
|
+
clientX: event.clientX,
|
|
383
|
+
clientY: event.clientY
|
|
384
|
+
};
|
|
368
385
|
}
|
|
369
386
|
} : undefined;
|
|
370
387
|
var onMouseOverTooltip = (0, _react.useCallback)(function () {
|
|
@@ -381,7 +398,7 @@ function Tooltip(_ref) {
|
|
|
381
398
|
if (!e.target.matches(':focus-visible')) {
|
|
382
399
|
return;
|
|
383
400
|
}
|
|
384
|
-
} catch (
|
|
401
|
+
} catch (_unused) {
|
|
385
402
|
// Ignore errors from environments that don't support :focus-visible
|
|
386
403
|
}
|
|
387
404
|
|
|
@@ -431,10 +448,16 @@ function Tooltip(_ref) {
|
|
|
431
448
|
onClose: handleOpenLayerObserverCloseSignal
|
|
432
449
|
});
|
|
433
450
|
var getReferenceElement = function getReferenceElement() {
|
|
434
|
-
var _apiRef$current5;
|
|
435
|
-
if (
|
|
436
|
-
|
|
437
|
-
|
|
451
|
+
var _apiRef$current5, _apiRef$current6;
|
|
452
|
+
if (isMousePosition && (_apiRef$current5 = apiRef.current) !== null && _apiRef$current5 !== void 0 && _apiRef$current5.mousePos && targetRef.current && (0, _platformFeatureFlags.fg)('platform_dst_nav4_side_nav_resize_tooltip_feedback')) {
|
|
453
|
+
return (0, _utilities.getVirtualElementFromMousePos)(apiRef.current.mousePos, {
|
|
454
|
+
targetElement: targetRef.current,
|
|
455
|
+
tooltipPosition: position
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
if (isMousePosition && (_apiRef$current6 = apiRef.current) !== null && _apiRef$current6 !== void 0 && _apiRef$current6.mousePosition && !(0, _platformFeatureFlags.fg)('platform_dst_nav4_side_nav_resize_tooltip_feedback')) {
|
|
459
|
+
var _apiRef$current7;
|
|
460
|
+
return (_apiRef$current7 = apiRef.current) === null || _apiRef$current7 === void 0 ? void 0 : _apiRef$current7.mousePosition;
|
|
438
461
|
}
|
|
439
462
|
return targetRef.current || undefined;
|
|
440
463
|
};
|
|
@@ -514,7 +537,7 @@ function Tooltip(_ref) {
|
|
|
514
537
|
// Invert the entrance and exit directions.
|
|
515
538
|
// E.g. a tooltip's position is on the 'right', it should enter from and exit to the 'left'
|
|
516
539
|
// This gives the effect the tooltip is appearing from the target
|
|
517
|
-
var direction =
|
|
540
|
+
var direction = isMousePosition ? undefined : invertedDirection[getDirectionFromPlacement(placement)];
|
|
518
541
|
return /*#__PURE__*/_react.default.createElement(_motion.ExitingPersistence, {
|
|
519
542
|
appear: true
|
|
520
543
|
}, shouldRenderTooltipChildren && /*#__PURE__*/_react.default.createElement(_motion.FadeIn, {
|
package/dist/cjs/utilities.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getMousePosition = getMousePosition;
|
|
7
|
+
exports.getVirtualElementFromMousePos = getVirtualElementFromMousePos;
|
|
7
8
|
function getMousePosition(mouseCoordinates) {
|
|
8
9
|
var safeMouse = mouseCoordinates || {
|
|
9
10
|
top: 0,
|
|
@@ -24,4 +25,46 @@ function getMousePosition(mouseCoordinates) {
|
|
|
24
25
|
clientWidth: 0,
|
|
25
26
|
clientHeight: 0
|
|
26
27
|
};
|
|
28
|
+
}
|
|
29
|
+
function getVirtualElementFromMousePos(mousePos, _ref) {
|
|
30
|
+
var targetElement = _ref.targetElement,
|
|
31
|
+
tooltipPosition = _ref.tooltipPosition;
|
|
32
|
+
if (tooltipPosition === 'mouse') {
|
|
33
|
+
return {
|
|
34
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
35
|
+
return DOMRect.fromRect({
|
|
36
|
+
x: mousePos.clientX,
|
|
37
|
+
y: mousePos.clientY,
|
|
38
|
+
width: 0,
|
|
39
|
+
height: 0
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var targetRect = targetElement.getBoundingClientRect();
|
|
45
|
+
if (tooltipPosition === 'mouse-x') {
|
|
46
|
+
return {
|
|
47
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
48
|
+
return DOMRect.fromRect({
|
|
49
|
+
x: mousePos.clientX,
|
|
50
|
+
y: targetRect.top,
|
|
51
|
+
width: 0,
|
|
52
|
+
height: targetRect.height
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (tooltipPosition === 'mouse-y') {
|
|
58
|
+
return {
|
|
59
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
60
|
+
return DOMRect.fromRect({
|
|
61
|
+
x: targetRect.left,
|
|
62
|
+
y: mousePos.clientY,
|
|
63
|
+
width: targetRect.width,
|
|
64
|
+
height: 0
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
throw new Error("Invalid tooltip position for virtual element: ".concat(tooltipPosition));
|
|
27
70
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
1
2
|
import { clearScheduled, scheduleTimeout } from './shared-schedule';
|
|
2
3
|
|
|
3
4
|
// This file is a singleton for managing tooltips
|
|
@@ -95,7 +96,8 @@ export function show(entry) {
|
|
|
95
96
|
return null;
|
|
96
97
|
}
|
|
97
98
|
function start() {
|
|
98
|
-
const
|
|
99
|
+
const shouldAlwaysFadeIn = fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? entry.shouldAlwaysFadeIn : false;
|
|
100
|
+
const showImmediately = Boolean(active && active.isVisible()) && !shouldAlwaysFadeIn;
|
|
99
101
|
|
|
100
102
|
// If there was an active tooltip; we tell it to remove itself at once!
|
|
101
103
|
if (active) {
|
|
@@ -133,7 +135,13 @@ export function show(entry) {
|
|
|
133
135
|
isActive,
|
|
134
136
|
requestHide,
|
|
135
137
|
finishHideAnimation,
|
|
136
|
-
mousePosition
|
|
138
|
+
// Removing old `mousePosition` behind gate because it stored a function.
|
|
139
|
+
// With the gate we just store the coords which are easier to work with.
|
|
140
|
+
mousePosition: fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? undefined : getInitialMouse(),
|
|
141
|
+
mousePos: entry.source.type === 'mouse' && fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? {
|
|
142
|
+
clientX: entry.source.clientX,
|
|
143
|
+
clientY: entry.source.clientY
|
|
144
|
+
} : null
|
|
137
145
|
};
|
|
138
146
|
return result;
|
|
139
147
|
}
|
package/dist/es2019/tooltip.js
CHANGED
|
@@ -7,6 +7,7 @@ import useCloseOnEscapePress from '@atlaskit/ds-lib/use-close-on-escape-press';
|
|
|
7
7
|
import useStableRef from '@atlaskit/ds-lib/use-stable-ref';
|
|
8
8
|
import { useNotifyOpenLayerObserver } from '@atlaskit/layering/experimental/open-layer-observer';
|
|
9
9
|
import { ExitingPersistence, FadeIn } from '@atlaskit/motion';
|
|
10
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
11
|
import { Popper } from '@atlaskit/popper';
|
|
11
12
|
import Portal from '@atlaskit/portal';
|
|
12
13
|
import { layers } from '@atlaskit/theme/constants';
|
|
@@ -14,7 +15,7 @@ import { register } from './internal/drag-manager';
|
|
|
14
15
|
import { show } from './internal/tooltip-manager';
|
|
15
16
|
import useUniqueId from './internal/use-unique-id';
|
|
16
17
|
import TooltipContainer from './tooltip-container';
|
|
17
|
-
import { getMousePosition } from './utilities';
|
|
18
|
+
import { getMousePosition, getVirtualElementFromMousePos } from './utilities';
|
|
18
19
|
const tooltipZIndex = layers.tooltip();
|
|
19
20
|
const analyticsAttributes = {
|
|
20
21
|
componentName: 'tooltip',
|
|
@@ -62,9 +63,12 @@ function Tooltip({
|
|
|
62
63
|
strategy = 'fixed',
|
|
63
64
|
ignoreTooltipPointerEvents = false,
|
|
64
65
|
isScreenReaderAnnouncementDisabled = false,
|
|
65
|
-
shortcut
|
|
66
|
+
shortcut,
|
|
67
|
+
UNSAFE_shouldAlwaysFadeIn: shouldAlwaysFadeIn = false
|
|
66
68
|
}) {
|
|
67
|
-
|
|
69
|
+
// Not using a gate for this check. When the gate is disabled `mouse-y` and `mouse-x` are treated as `mouse`.
|
|
70
|
+
const isMousePosition = position === 'mouse' || position === 'mouse-y' || position === 'mouse-x';
|
|
71
|
+
const tooltipPosition = isMousePosition ? mousePosition : position;
|
|
68
72
|
const onShowHandler = usePlatformLeafSyntheticEventHandler({
|
|
69
73
|
fn: onShow,
|
|
70
74
|
action: 'displayed',
|
|
@@ -104,6 +108,7 @@ function Tooltip({
|
|
|
104
108
|
const delayStable = useStableRef(delay);
|
|
105
109
|
const canAppearStable = useStableRef(canAppear);
|
|
106
110
|
const hasCalledShowHandler = useRef(false);
|
|
111
|
+
const shouldAlwaysFadeInStable = useStableRef(shouldAlwaysFadeIn);
|
|
107
112
|
const start = useCallback(api => {
|
|
108
113
|
// @ts-ignore
|
|
109
114
|
apiRef.current = api;
|
|
@@ -218,7 +223,7 @@ function Tooltip({
|
|
|
218
223
|
hasCalledShowHandler.current = true;
|
|
219
224
|
onShowHandlerStable.current();
|
|
220
225
|
}
|
|
221
|
-
setState(isImmediate ? '
|
|
226
|
+
setState(!isImmediate ? 'fade-in' : 'show-immediate');
|
|
222
227
|
},
|
|
223
228
|
hide: ({
|
|
224
229
|
isImmediate
|
|
@@ -229,11 +234,12 @@ function Tooltip({
|
|
|
229
234
|
setState('before-fade-out');
|
|
230
235
|
}
|
|
231
236
|
},
|
|
232
|
-
done
|
|
237
|
+
done,
|
|
238
|
+
shouldAlwaysFadeIn: fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? shouldAlwaysFadeInStable.current : false
|
|
233
239
|
};
|
|
234
240
|
const api = show(entry);
|
|
235
241
|
start(api);
|
|
236
|
-
}, [canAppearStable, delayStable, done, start, abort, onShowHandlerStable]);
|
|
242
|
+
}, [canAppearStable, delayStable, done, start, abort, onShowHandlerStable, shouldAlwaysFadeInStable]);
|
|
237
243
|
const hideTooltipOnEsc = useCallback(() => {
|
|
238
244
|
var _apiRef$current2;
|
|
239
245
|
(_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 ? void 0 : _apiRef$current2.requestHide({
|
|
@@ -299,18 +305,22 @@ function Tooltip({
|
|
|
299
305
|
return;
|
|
300
306
|
}
|
|
301
307
|
event.preventDefault();
|
|
302
|
-
const source =
|
|
308
|
+
const source = isMousePosition ? {
|
|
303
309
|
type: 'mouse',
|
|
304
310
|
// TODO: ideally not recalculating this object each time
|
|
305
|
-
mouse
|
|
311
|
+
// Removing old `mouse` behind gate because it stored a function.
|
|
312
|
+
// With the gate we just store the coords which are easier to work with.
|
|
313
|
+
mouse: fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? undefined : getMousePosition({
|
|
306
314
|
left: event.clientX,
|
|
307
315
|
top: event.clientY
|
|
308
|
-
})
|
|
316
|
+
}),
|
|
317
|
+
clientX: event.clientX,
|
|
318
|
+
clientY: event.clientY
|
|
309
319
|
} : {
|
|
310
320
|
type: 'keyboard'
|
|
311
321
|
};
|
|
312
322
|
tryShowTooltip(source);
|
|
313
|
-
}, [
|
|
323
|
+
}, [isMousePosition, tryShowTooltip]);
|
|
314
324
|
|
|
315
325
|
// Ideally we would be using onMouseEnter here, but
|
|
316
326
|
// because we are binding the event to the target parent
|
|
@@ -334,13 +344,19 @@ function Tooltip({
|
|
|
334
344
|
});
|
|
335
345
|
}
|
|
336
346
|
}, []);
|
|
337
|
-
const onMouseMove =
|
|
347
|
+
const onMouseMove = isMousePosition ? event => {
|
|
338
348
|
var _apiRef$current3;
|
|
339
349
|
if ((_apiRef$current3 = apiRef.current) !== null && _apiRef$current3 !== void 0 && _apiRef$current3.isActive()) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
350
|
+
if (!fg('platform_dst_nav4_side_nav_resize_tooltip_feedback')) {
|
|
351
|
+
apiRef.current.mousePosition = getMousePosition({
|
|
352
|
+
left: event.clientX,
|
|
353
|
+
top: event.clientY
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
apiRef.current.mousePos = {
|
|
357
|
+
clientX: event.clientX,
|
|
358
|
+
clientY: event.clientY
|
|
359
|
+
};
|
|
344
360
|
}
|
|
345
361
|
} : undefined;
|
|
346
362
|
const onMouseOverTooltip = useCallback(() => {
|
|
@@ -357,7 +373,7 @@ function Tooltip({
|
|
|
357
373
|
if (!e.target.matches(':focus-visible')) {
|
|
358
374
|
return;
|
|
359
375
|
}
|
|
360
|
-
} catch
|
|
376
|
+
} catch {
|
|
361
377
|
// Ignore errors from environments that don't support :focus-visible
|
|
362
378
|
}
|
|
363
379
|
|
|
@@ -407,10 +423,16 @@ function Tooltip({
|
|
|
407
423
|
onClose: handleOpenLayerObserverCloseSignal
|
|
408
424
|
});
|
|
409
425
|
const getReferenceElement = () => {
|
|
410
|
-
var _apiRef$current5;
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
426
|
+
var _apiRef$current5, _apiRef$current6;
|
|
427
|
+
if (isMousePosition && (_apiRef$current5 = apiRef.current) !== null && _apiRef$current5 !== void 0 && _apiRef$current5.mousePos && targetRef.current && fg('platform_dst_nav4_side_nav_resize_tooltip_feedback')) {
|
|
428
|
+
return getVirtualElementFromMousePos(apiRef.current.mousePos, {
|
|
429
|
+
targetElement: targetRef.current,
|
|
430
|
+
tooltipPosition: position
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
if (isMousePosition && (_apiRef$current6 = apiRef.current) !== null && _apiRef$current6 !== void 0 && _apiRef$current6.mousePosition && !fg('platform_dst_nav4_side_nav_resize_tooltip_feedback')) {
|
|
434
|
+
var _apiRef$current7;
|
|
435
|
+
return (_apiRef$current7 = apiRef.current) === null || _apiRef$current7 === void 0 ? void 0 : _apiRef$current7.mousePosition;
|
|
414
436
|
}
|
|
415
437
|
return targetRef.current || undefined;
|
|
416
438
|
};
|
|
@@ -490,7 +512,7 @@ function Tooltip({
|
|
|
490
512
|
// Invert the entrance and exit directions.
|
|
491
513
|
// E.g. a tooltip's position is on the 'right', it should enter from and exit to the 'left'
|
|
492
514
|
// This gives the effect the tooltip is appearing from the target
|
|
493
|
-
const direction =
|
|
515
|
+
const direction = isMousePosition ? undefined : invertedDirection[getDirectionFromPlacement(placement)];
|
|
494
516
|
return /*#__PURE__*/React.createElement(ExitingPersistence, {
|
|
495
517
|
appear: true
|
|
496
518
|
}, shouldRenderTooltipChildren && /*#__PURE__*/React.createElement(FadeIn, {
|
package/dist/es2019/utilities.js
CHANGED
|
@@ -16,4 +16,41 @@ export function getMousePosition(mouseCoordinates) {
|
|
|
16
16
|
clientWidth: 0,
|
|
17
17
|
clientHeight: 0
|
|
18
18
|
};
|
|
19
|
+
}
|
|
20
|
+
export function getVirtualElementFromMousePos(mousePos, {
|
|
21
|
+
targetElement,
|
|
22
|
+
tooltipPosition
|
|
23
|
+
}) {
|
|
24
|
+
if (tooltipPosition === 'mouse') {
|
|
25
|
+
return {
|
|
26
|
+
getBoundingClientRect: () => DOMRect.fromRect({
|
|
27
|
+
x: mousePos.clientX,
|
|
28
|
+
y: mousePos.clientY,
|
|
29
|
+
width: 0,
|
|
30
|
+
height: 0
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const targetRect = targetElement.getBoundingClientRect();
|
|
35
|
+
if (tooltipPosition === 'mouse-x') {
|
|
36
|
+
return {
|
|
37
|
+
getBoundingClientRect: () => DOMRect.fromRect({
|
|
38
|
+
x: mousePos.clientX,
|
|
39
|
+
y: targetRect.top,
|
|
40
|
+
width: 0,
|
|
41
|
+
height: targetRect.height
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (tooltipPosition === 'mouse-y') {
|
|
46
|
+
return {
|
|
47
|
+
getBoundingClientRect: () => DOMRect.fromRect({
|
|
48
|
+
x: targetRect.left,
|
|
49
|
+
y: mousePos.clientY,
|
|
50
|
+
width: targetRect.width,
|
|
51
|
+
height: 0
|
|
52
|
+
})
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`Invalid tooltip position for virtual element: ${tooltipPosition}`);
|
|
19
56
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
1
2
|
import { clearScheduled, scheduleTimeout } from './shared-schedule';
|
|
2
3
|
|
|
3
4
|
// This file is a singleton for managing tooltips
|
|
@@ -94,7 +95,8 @@ export function show(entry) {
|
|
|
94
95
|
return null;
|
|
95
96
|
}
|
|
96
97
|
function start() {
|
|
97
|
-
var
|
|
98
|
+
var shouldAlwaysFadeIn = fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? entry.shouldAlwaysFadeIn : false;
|
|
99
|
+
var showImmediately = Boolean(active && active.isVisible()) && !shouldAlwaysFadeIn;
|
|
98
100
|
|
|
99
101
|
// If there was an active tooltip; we tell it to remove itself at once!
|
|
100
102
|
if (active) {
|
|
@@ -132,7 +134,13 @@ export function show(entry) {
|
|
|
132
134
|
isActive: isActive,
|
|
133
135
|
requestHide: requestHide,
|
|
134
136
|
finishHideAnimation: finishHideAnimation,
|
|
135
|
-
mousePosition
|
|
137
|
+
// Removing old `mousePosition` behind gate because it stored a function.
|
|
138
|
+
// With the gate we just store the coords which are easier to work with.
|
|
139
|
+
mousePosition: fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? undefined : getInitialMouse(),
|
|
140
|
+
mousePos: entry.source.type === 'mouse' && fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? {
|
|
141
|
+
clientX: entry.source.clientX,
|
|
142
|
+
clientY: entry.source.clientY
|
|
143
|
+
} : null
|
|
136
144
|
};
|
|
137
145
|
return result;
|
|
138
146
|
}
|
package/dist/esm/tooltip.js
CHANGED
|
@@ -11,6 +11,7 @@ import useCloseOnEscapePress from '@atlaskit/ds-lib/use-close-on-escape-press';
|
|
|
11
11
|
import useStableRef from '@atlaskit/ds-lib/use-stable-ref';
|
|
12
12
|
import { useNotifyOpenLayerObserver } from '@atlaskit/layering/experimental/open-layer-observer';
|
|
13
13
|
import { ExitingPersistence, FadeIn } from '@atlaskit/motion';
|
|
14
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
14
15
|
import { Popper } from '@atlaskit/popper';
|
|
15
16
|
import Portal from '@atlaskit/portal';
|
|
16
17
|
import { layers } from '@atlaskit/theme/constants';
|
|
@@ -18,7 +19,7 @@ import { register } from './internal/drag-manager';
|
|
|
18
19
|
import { show } from './internal/tooltip-manager';
|
|
19
20
|
import useUniqueId from './internal/use-unique-id';
|
|
20
21
|
import TooltipContainer from './tooltip-container';
|
|
21
|
-
import { getMousePosition } from './utilities';
|
|
22
|
+
import { getMousePosition, getVirtualElementFromMousePos } from './utilities';
|
|
22
23
|
var tooltipZIndex = layers.tooltip();
|
|
23
24
|
var analyticsAttributes = {
|
|
24
25
|
componentName: 'tooltip',
|
|
@@ -80,8 +81,12 @@ function Tooltip(_ref) {
|
|
|
80
81
|
ignoreTooltipPointerEvents = _ref$ignoreTooltipPoi === void 0 ? false : _ref$ignoreTooltipPoi,
|
|
81
82
|
_ref$isScreenReaderAn = _ref.isScreenReaderAnnouncementDisabled,
|
|
82
83
|
isScreenReaderAnnouncementDisabled = _ref$isScreenReaderAn === void 0 ? false : _ref$isScreenReaderAn,
|
|
83
|
-
shortcut = _ref.shortcut
|
|
84
|
-
|
|
84
|
+
shortcut = _ref.shortcut,
|
|
85
|
+
_ref$UNSAFE_shouldAlw = _ref.UNSAFE_shouldAlwaysFadeIn,
|
|
86
|
+
shouldAlwaysFadeIn = _ref$UNSAFE_shouldAlw === void 0 ? false : _ref$UNSAFE_shouldAlw;
|
|
87
|
+
// Not using a gate for this check. When the gate is disabled `mouse-y` and `mouse-x` are treated as `mouse`.
|
|
88
|
+
var isMousePosition = position === 'mouse' || position === 'mouse-y' || position === 'mouse-x';
|
|
89
|
+
var tooltipPosition = isMousePosition ? mousePosition : position;
|
|
85
90
|
var onShowHandler = usePlatformLeafSyntheticEventHandler(_objectSpread({
|
|
86
91
|
fn: onShow,
|
|
87
92
|
action: 'displayed',
|
|
@@ -122,6 +127,7 @@ function Tooltip(_ref) {
|
|
|
122
127
|
var delayStable = useStableRef(delay);
|
|
123
128
|
var canAppearStable = useStableRef(canAppear);
|
|
124
129
|
var hasCalledShowHandler = useRef(false);
|
|
130
|
+
var shouldAlwaysFadeInStable = useStableRef(shouldAlwaysFadeIn);
|
|
125
131
|
var start = useCallback(function (api) {
|
|
126
132
|
// @ts-ignore
|
|
127
133
|
apiRef.current = api;
|
|
@@ -234,7 +240,7 @@ function Tooltip(_ref) {
|
|
|
234
240
|
hasCalledShowHandler.current = true;
|
|
235
241
|
onShowHandlerStable.current();
|
|
236
242
|
}
|
|
237
|
-
setState(isImmediate ? '
|
|
243
|
+
setState(!isImmediate ? 'fade-in' : 'show-immediate');
|
|
238
244
|
},
|
|
239
245
|
hide: function hide(_ref4) {
|
|
240
246
|
var isImmediate = _ref4.isImmediate;
|
|
@@ -244,11 +250,12 @@ function Tooltip(_ref) {
|
|
|
244
250
|
setState('before-fade-out');
|
|
245
251
|
}
|
|
246
252
|
},
|
|
247
|
-
done: done
|
|
253
|
+
done: done,
|
|
254
|
+
shouldAlwaysFadeIn: fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? shouldAlwaysFadeInStable.current : false
|
|
248
255
|
};
|
|
249
256
|
var api = show(entry);
|
|
250
257
|
start(api);
|
|
251
|
-
}, [canAppearStable, delayStable, done, start, abort, onShowHandlerStable]);
|
|
258
|
+
}, [canAppearStable, delayStable, done, start, abort, onShowHandlerStable, shouldAlwaysFadeInStable]);
|
|
252
259
|
var hideTooltipOnEsc = useCallback(function () {
|
|
253
260
|
var _apiRef$current2;
|
|
254
261
|
(_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 || _apiRef$current2.requestHide({
|
|
@@ -314,18 +321,22 @@ function Tooltip(_ref) {
|
|
|
314
321
|
return;
|
|
315
322
|
}
|
|
316
323
|
event.preventDefault();
|
|
317
|
-
var source =
|
|
324
|
+
var source = isMousePosition ? {
|
|
318
325
|
type: 'mouse',
|
|
319
326
|
// TODO: ideally not recalculating this object each time
|
|
320
|
-
mouse
|
|
327
|
+
// Removing old `mouse` behind gate because it stored a function.
|
|
328
|
+
// With the gate we just store the coords which are easier to work with.
|
|
329
|
+
mouse: fg('platform_dst_nav4_side_nav_resize_tooltip_feedback') ? undefined : getMousePosition({
|
|
321
330
|
left: event.clientX,
|
|
322
331
|
top: event.clientY
|
|
323
|
-
})
|
|
332
|
+
}),
|
|
333
|
+
clientX: event.clientX,
|
|
334
|
+
clientY: event.clientY
|
|
324
335
|
} : {
|
|
325
336
|
type: 'keyboard'
|
|
326
337
|
};
|
|
327
338
|
tryShowTooltip(source);
|
|
328
|
-
}, [
|
|
339
|
+
}, [isMousePosition, tryShowTooltip]);
|
|
329
340
|
|
|
330
341
|
// Ideally we would be using onMouseEnter here, but
|
|
331
342
|
// because we are binding the event to the target parent
|
|
@@ -349,13 +360,19 @@ function Tooltip(_ref) {
|
|
|
349
360
|
});
|
|
350
361
|
}
|
|
351
362
|
}, []);
|
|
352
|
-
var onMouseMove =
|
|
363
|
+
var onMouseMove = isMousePosition ? function (event) {
|
|
353
364
|
var _apiRef$current3;
|
|
354
365
|
if ((_apiRef$current3 = apiRef.current) !== null && _apiRef$current3 !== void 0 && _apiRef$current3.isActive()) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
366
|
+
if (!fg('platform_dst_nav4_side_nav_resize_tooltip_feedback')) {
|
|
367
|
+
apiRef.current.mousePosition = getMousePosition({
|
|
368
|
+
left: event.clientX,
|
|
369
|
+
top: event.clientY
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
apiRef.current.mousePos = {
|
|
373
|
+
clientX: event.clientX,
|
|
374
|
+
clientY: event.clientY
|
|
375
|
+
};
|
|
359
376
|
}
|
|
360
377
|
} : undefined;
|
|
361
378
|
var onMouseOverTooltip = useCallback(function () {
|
|
@@ -372,7 +389,7 @@ function Tooltip(_ref) {
|
|
|
372
389
|
if (!e.target.matches(':focus-visible')) {
|
|
373
390
|
return;
|
|
374
391
|
}
|
|
375
|
-
} catch (
|
|
392
|
+
} catch (_unused) {
|
|
376
393
|
// Ignore errors from environments that don't support :focus-visible
|
|
377
394
|
}
|
|
378
395
|
|
|
@@ -422,10 +439,16 @@ function Tooltip(_ref) {
|
|
|
422
439
|
onClose: handleOpenLayerObserverCloseSignal
|
|
423
440
|
});
|
|
424
441
|
var getReferenceElement = function getReferenceElement() {
|
|
425
|
-
var _apiRef$current5;
|
|
426
|
-
if (
|
|
427
|
-
|
|
428
|
-
|
|
442
|
+
var _apiRef$current5, _apiRef$current6;
|
|
443
|
+
if (isMousePosition && (_apiRef$current5 = apiRef.current) !== null && _apiRef$current5 !== void 0 && _apiRef$current5.mousePos && targetRef.current && fg('platform_dst_nav4_side_nav_resize_tooltip_feedback')) {
|
|
444
|
+
return getVirtualElementFromMousePos(apiRef.current.mousePos, {
|
|
445
|
+
targetElement: targetRef.current,
|
|
446
|
+
tooltipPosition: position
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
if (isMousePosition && (_apiRef$current6 = apiRef.current) !== null && _apiRef$current6 !== void 0 && _apiRef$current6.mousePosition && !fg('platform_dst_nav4_side_nav_resize_tooltip_feedback')) {
|
|
450
|
+
var _apiRef$current7;
|
|
451
|
+
return (_apiRef$current7 = apiRef.current) === null || _apiRef$current7 === void 0 ? void 0 : _apiRef$current7.mousePosition;
|
|
429
452
|
}
|
|
430
453
|
return targetRef.current || undefined;
|
|
431
454
|
};
|
|
@@ -505,7 +528,7 @@ function Tooltip(_ref) {
|
|
|
505
528
|
// Invert the entrance and exit directions.
|
|
506
529
|
// E.g. a tooltip's position is on the 'right', it should enter from and exit to the 'left'
|
|
507
530
|
// This gives the effect the tooltip is appearing from the target
|
|
508
|
-
var direction =
|
|
531
|
+
var direction = isMousePosition ? undefined : invertedDirection[getDirectionFromPlacement(placement)];
|
|
509
532
|
return /*#__PURE__*/React.createElement(ExitingPersistence, {
|
|
510
533
|
appear: true
|
|
511
534
|
}, shouldRenderTooltipChildren && /*#__PURE__*/React.createElement(FadeIn, {
|
package/dist/esm/utilities.js
CHANGED
|
@@ -18,4 +18,46 @@ export function getMousePosition(mouseCoordinates) {
|
|
|
18
18
|
clientWidth: 0,
|
|
19
19
|
clientHeight: 0
|
|
20
20
|
};
|
|
21
|
+
}
|
|
22
|
+
export function getVirtualElementFromMousePos(mousePos, _ref) {
|
|
23
|
+
var targetElement = _ref.targetElement,
|
|
24
|
+
tooltipPosition = _ref.tooltipPosition;
|
|
25
|
+
if (tooltipPosition === 'mouse') {
|
|
26
|
+
return {
|
|
27
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
28
|
+
return DOMRect.fromRect({
|
|
29
|
+
x: mousePos.clientX,
|
|
30
|
+
y: mousePos.clientY,
|
|
31
|
+
width: 0,
|
|
32
|
+
height: 0
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
var targetRect = targetElement.getBoundingClientRect();
|
|
38
|
+
if (tooltipPosition === 'mouse-x') {
|
|
39
|
+
return {
|
|
40
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
41
|
+
return DOMRect.fromRect({
|
|
42
|
+
x: mousePos.clientX,
|
|
43
|
+
y: targetRect.top,
|
|
44
|
+
width: 0,
|
|
45
|
+
height: targetRect.height
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (tooltipPosition === 'mouse-y') {
|
|
51
|
+
return {
|
|
52
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
53
|
+
return DOMRect.fromRect({
|
|
54
|
+
x: targetRect.left,
|
|
55
|
+
y: mousePos.clientY,
|
|
56
|
+
width: targetRect.width,
|
|
57
|
+
height: 0
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
throw new Error("Invalid tooltip position for virtual element: ".concat(tooltipPosition));
|
|
21
63
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { VirtualElement } from '@popperjs/core';
|
|
2
|
+
import type { FakeMouseElement } from '../utilities';
|
|
2
3
|
export type Source = {
|
|
3
4
|
type: 'mouse';
|
|
4
|
-
mouse
|
|
5
|
+
mouse?: VirtualElement | FakeMouseElement;
|
|
6
|
+
clientX: number;
|
|
7
|
+
clientY: number;
|
|
5
8
|
} | {
|
|
6
9
|
type: 'keyboard';
|
|
7
10
|
};
|
|
@@ -15,10 +18,12 @@ export type Entry = {
|
|
|
15
18
|
}) => void;
|
|
16
19
|
delay: number;
|
|
17
20
|
done: () => void;
|
|
21
|
+
shouldAlwaysFadeIn: boolean;
|
|
18
22
|
};
|
|
19
23
|
export type API = {
|
|
20
24
|
isActive: () => boolean;
|
|
21
|
-
mousePosition: FakeMouseElement | null;
|
|
25
|
+
mousePosition: VirtualElement | FakeMouseElement | null | undefined;
|
|
26
|
+
mousePos: Pick<React.MouseEvent<HTMLElement>, 'clientX' | 'clientY'> | null;
|
|
22
27
|
requestHide: (value: {
|
|
23
28
|
isImmediate: boolean;
|
|
24
29
|
}) => void;
|
package/dist/types/tooltip.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ import { type TooltipProps } from './types';
|
|
|
5
5
|
*
|
|
6
6
|
* A tooltip is a floating, non-actionable label used to explain a user interface element or feature.
|
|
7
7
|
*/
|
|
8
|
-
declare function Tooltip({ children, position, mousePosition, content, truncate, component: Container, tag: TargetContainer, testId, delay, onShow, onHide, canAppear, hideTooltipOnClick, hideTooltipOnMouseDown, analyticsContext, strategy, ignoreTooltipPointerEvents, isScreenReaderAnnouncementDisabled, shortcut, }: TooltipProps): React.JSX.Element;
|
|
8
|
+
declare function Tooltip({ children, position, mousePosition, content, truncate, component: Container, tag: TargetContainer, testId, delay, onShow, onHide, canAppear, hideTooltipOnClick, hideTooltipOnMouseDown, analyticsContext, strategy, ignoreTooltipPointerEvents, isScreenReaderAnnouncementDisabled, shortcut, UNSAFE_shouldAlwaysFadeIn: shouldAlwaysFadeIn, }: TooltipProps): React.JSX.Element;
|
|
9
9
|
export default Tooltip;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
|
3
3
|
import { type Placement } from '@atlaskit/popper';
|
|
4
4
|
import { type TooltipPrimitiveProps } from './tooltip-primitive';
|
|
5
5
|
export type PositionTypeBase = Placement;
|
|
6
|
-
export type PositionType = PositionTypeBase | 'mouse';
|
|
6
|
+
export type PositionType = PositionTypeBase | 'mouse' | 'mouse-y' | 'mouse-x';
|
|
7
7
|
export interface TriggerProps {
|
|
8
8
|
onMouseOver: (event: React.MouseEvent<HTMLElement>) => void;
|
|
9
9
|
onMouseOut: (event: React.MouseEvent<HTMLElement>) => void;
|
|
@@ -56,7 +56,7 @@ export interface TooltipProps {
|
|
|
56
56
|
hideTooltipOnMouseDown?: boolean;
|
|
57
57
|
/**
|
|
58
58
|
* Where the tooltip should appear relative to the mouse pointer.
|
|
59
|
-
* Only use this when the `position` prop is set to `"mouse"`.
|
|
59
|
+
* Only use this when the `position` prop is set to `"mouse"`, `"mouse-y"`, or `"mouse-x"`.
|
|
60
60
|
* When interacting with the target element using a keyboard, it will use this position against the target element instead.
|
|
61
61
|
*/
|
|
62
62
|
mousePosition?: PositionTypeBase;
|
|
@@ -92,6 +92,8 @@ export interface TooltipProps {
|
|
|
92
92
|
/**
|
|
93
93
|
* Where the tooltip should appear relative to its target.
|
|
94
94
|
* If set to `"mouse"`, the tooltip will display next to the mouse pointer instead.
|
|
95
|
+
* If set to `"mouse-y"`, the tooltip will use the mouse Y coordinate but the target X coordinate.
|
|
96
|
+
* If set to `"mouse-x"`, the tooltip will use the mouse X coordinate but the target Y coordinate.
|
|
95
97
|
* Make sure to utilize the `mousePosition` if you want to customize where the tooltip will show in relation to the mouse.
|
|
96
98
|
*/
|
|
97
99
|
position?: PositionType;
|
|
@@ -138,4 +140,10 @@ export interface TooltipProps {
|
|
|
138
140
|
* Keys will be displayed as individual keyboard key segments after the tooltip content.
|
|
139
141
|
*/
|
|
140
142
|
shortcut?: string[];
|
|
143
|
+
/**
|
|
144
|
+
* When set to true, the tooltip will always use the fade-in animation
|
|
145
|
+
* and never use the show-immediate behavior, even when another tooltip
|
|
146
|
+
* is already visible.
|
|
147
|
+
*/
|
|
148
|
+
UNSAFE_shouldAlwaysFadeIn?: boolean;
|
|
141
149
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { VirtualElement } from '@popperjs/core';
|
|
1
2
|
export interface FakeMouseElement {
|
|
2
3
|
getBoundingClientRect: () => {
|
|
3
4
|
top: number;
|
|
@@ -14,3 +15,10 @@ export declare function getMousePosition(mouseCoordinates: {
|
|
|
14
15
|
top: number;
|
|
15
16
|
left: number;
|
|
16
17
|
}): FakeMouseElement;
|
|
18
|
+
export declare function getVirtualElementFromMousePos(mousePos: {
|
|
19
|
+
clientX: number;
|
|
20
|
+
clientY: number;
|
|
21
|
+
}, { targetElement, tooltipPosition, }: {
|
|
22
|
+
targetElement: HTMLElement;
|
|
23
|
+
tooltipPosition: 'mouse' | 'mouse-x' | 'mouse-y';
|
|
24
|
+
}): VirtualElement;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { VirtualElement } from '@popperjs/core';
|
|
2
|
+
import type { FakeMouseElement } from '../utilities';
|
|
2
3
|
export type Source = {
|
|
3
4
|
type: 'mouse';
|
|
4
|
-
mouse
|
|
5
|
+
mouse?: VirtualElement | FakeMouseElement;
|
|
6
|
+
clientX: number;
|
|
7
|
+
clientY: number;
|
|
5
8
|
} | {
|
|
6
9
|
type: 'keyboard';
|
|
7
10
|
};
|
|
@@ -15,10 +18,12 @@ export type Entry = {
|
|
|
15
18
|
}) => void;
|
|
16
19
|
delay: number;
|
|
17
20
|
done: () => void;
|
|
21
|
+
shouldAlwaysFadeIn: boolean;
|
|
18
22
|
};
|
|
19
23
|
export type API = {
|
|
20
24
|
isActive: () => boolean;
|
|
21
|
-
mousePosition: FakeMouseElement | null;
|
|
25
|
+
mousePosition: VirtualElement | FakeMouseElement | null | undefined;
|
|
26
|
+
mousePos: Pick<React.MouseEvent<HTMLElement>, 'clientX' | 'clientY'> | null;
|
|
22
27
|
requestHide: (value: {
|
|
23
28
|
isImmediate: boolean;
|
|
24
29
|
}) => void;
|
|
@@ -5,5 +5,5 @@ import { type TooltipProps } from './types';
|
|
|
5
5
|
*
|
|
6
6
|
* A tooltip is a floating, non-actionable label used to explain a user interface element or feature.
|
|
7
7
|
*/
|
|
8
|
-
declare function Tooltip({ children, position, mousePosition, content, truncate, component: Container, tag: TargetContainer, testId, delay, onShow, onHide, canAppear, hideTooltipOnClick, hideTooltipOnMouseDown, analyticsContext, strategy, ignoreTooltipPointerEvents, isScreenReaderAnnouncementDisabled, shortcut, }: TooltipProps): React.JSX.Element;
|
|
8
|
+
declare function Tooltip({ children, position, mousePosition, content, truncate, component: Container, tag: TargetContainer, testId, delay, onShow, onHide, canAppear, hideTooltipOnClick, hideTooltipOnMouseDown, analyticsContext, strategy, ignoreTooltipPointerEvents, isScreenReaderAnnouncementDisabled, shortcut, UNSAFE_shouldAlwaysFadeIn: shouldAlwaysFadeIn, }: TooltipProps): React.JSX.Element;
|
|
9
9
|
export default Tooltip;
|
|
@@ -3,7 +3,7 @@ import { type UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
|
3
3
|
import { type Placement } from '@atlaskit/popper';
|
|
4
4
|
import { type TooltipPrimitiveProps } from './tooltip-primitive';
|
|
5
5
|
export type PositionTypeBase = Placement;
|
|
6
|
-
export type PositionType = PositionTypeBase | 'mouse';
|
|
6
|
+
export type PositionType = PositionTypeBase | 'mouse' | 'mouse-y' | 'mouse-x';
|
|
7
7
|
export interface TriggerProps {
|
|
8
8
|
onMouseOver: (event: React.MouseEvent<HTMLElement>) => void;
|
|
9
9
|
onMouseOut: (event: React.MouseEvent<HTMLElement>) => void;
|
|
@@ -56,7 +56,7 @@ export interface TooltipProps {
|
|
|
56
56
|
hideTooltipOnMouseDown?: boolean;
|
|
57
57
|
/**
|
|
58
58
|
* Where the tooltip should appear relative to the mouse pointer.
|
|
59
|
-
* Only use this when the `position` prop is set to `"mouse"`.
|
|
59
|
+
* Only use this when the `position` prop is set to `"mouse"`, `"mouse-y"`, or `"mouse-x"`.
|
|
60
60
|
* When interacting with the target element using a keyboard, it will use this position against the target element instead.
|
|
61
61
|
*/
|
|
62
62
|
mousePosition?: PositionTypeBase;
|
|
@@ -92,6 +92,8 @@ export interface TooltipProps {
|
|
|
92
92
|
/**
|
|
93
93
|
* Where the tooltip should appear relative to its target.
|
|
94
94
|
* If set to `"mouse"`, the tooltip will display next to the mouse pointer instead.
|
|
95
|
+
* If set to `"mouse-y"`, the tooltip will use the mouse Y coordinate but the target X coordinate.
|
|
96
|
+
* If set to `"mouse-x"`, the tooltip will use the mouse X coordinate but the target Y coordinate.
|
|
95
97
|
* Make sure to utilize the `mousePosition` if you want to customize where the tooltip will show in relation to the mouse.
|
|
96
98
|
*/
|
|
97
99
|
position?: PositionType;
|
|
@@ -138,4 +140,10 @@ export interface TooltipProps {
|
|
|
138
140
|
* Keys will be displayed as individual keyboard key segments after the tooltip content.
|
|
139
141
|
*/
|
|
140
142
|
shortcut?: string[];
|
|
143
|
+
/**
|
|
144
|
+
* When set to true, the tooltip will always use the fade-in animation
|
|
145
|
+
* and never use the show-immediate behavior, even when another tooltip
|
|
146
|
+
* is already visible.
|
|
147
|
+
*/
|
|
148
|
+
UNSAFE_shouldAlwaysFadeIn?: boolean;
|
|
141
149
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { VirtualElement } from '@popperjs/core';
|
|
1
2
|
export interface FakeMouseElement {
|
|
2
3
|
getBoundingClientRect: () => {
|
|
3
4
|
top: number;
|
|
@@ -14,3 +15,10 @@ export declare function getMousePosition(mouseCoordinates: {
|
|
|
14
15
|
top: number;
|
|
15
16
|
left: number;
|
|
16
17
|
}): FakeMouseElement;
|
|
18
|
+
export declare function getVirtualElementFromMousePos(mousePos: {
|
|
19
|
+
clientX: number;
|
|
20
|
+
clientY: number;
|
|
21
|
+
}, { targetElement, tooltipPosition, }: {
|
|
22
|
+
targetElement: HTMLElement;
|
|
23
|
+
tooltipPosition: 'mouse' | 'mouse-x' | 'mouse-y';
|
|
24
|
+
}): VirtualElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/tooltip",
|
|
3
|
-
"version": "20.
|
|
3
|
+
"version": "20.13.0",
|
|
4
4
|
"description": "A tooltip describes an interactive element on mouse hover or keyboard focus.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@atlaskit/analytics-next": "^11.1.0",
|
|
36
36
|
"@atlaskit/ds-lib": "^5.3.0",
|
|
37
|
-
"@atlaskit/layering": "^3.
|
|
37
|
+
"@atlaskit/layering": "^3.6.0",
|
|
38
38
|
"@atlaskit/motion": "^5.3.0",
|
|
39
39
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
40
40
|
"@atlaskit/popper": "^7.1.0",
|
|
41
|
-
"@atlaskit/portal": "^5.
|
|
41
|
+
"@atlaskit/portal": "^5.2.0",
|
|
42
42
|
"@atlaskit/theme": "^21.0.0",
|
|
43
|
-
"@atlaskit/tokens": "^9.
|
|
43
|
+
"@atlaskit/tokens": "^9.1.0",
|
|
44
44
|
"@babel/runtime": "^7.0.0",
|
|
45
45
|
"@compiled/react": "^0.18.6",
|
|
46
46
|
"bind-event-listener": "^3.0.0"
|
|
@@ -52,17 +52,19 @@
|
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@af/accessibility-testing": "workspace:^",
|
|
54
54
|
"@af/integration-testing": "workspace:^",
|
|
55
|
+
"@af/suppress-react-warnings": "workspace:^",
|
|
55
56
|
"@af/visual-regression": "workspace:^",
|
|
56
57
|
"@atlaskit/button": "^23.9.0",
|
|
57
58
|
"@atlaskit/css": "^0.19.0",
|
|
58
59
|
"@atlaskit/docs": "^11.2.0",
|
|
59
|
-
"@atlaskit/icon": "^29.
|
|
60
|
-
"@atlaskit/link": "^3.
|
|
60
|
+
"@atlaskit/icon": "^29.4.0",
|
|
61
|
+
"@atlaskit/link": "^3.3.0",
|
|
61
62
|
"@atlaskit/primitives": "^17.0.0",
|
|
62
|
-
"@atlaskit/section-message": "^8.
|
|
63
|
+
"@atlaskit/section-message": "^8.12.0",
|
|
64
|
+
"@atlassian/feature-flags-test-utils": "^1.0.0",
|
|
63
65
|
"@atlassian/ssr-tests": "workspace:^",
|
|
64
66
|
"@atlassian/testing-library": "^0.4.0",
|
|
65
|
-
"@testing-library/react": "^
|
|
67
|
+
"@testing-library/react": "^16.3.0",
|
|
66
68
|
"react-dom": "^18.2.0",
|
|
67
69
|
"tiny-invariant": "^1.2.0"
|
|
68
70
|
},
|
|
@@ -92,6 +94,9 @@
|
|
|
92
94
|
},
|
|
93
95
|
"homepage": "https://atlassian.design/components/tooltip/",
|
|
94
96
|
"platform-feature-flags": {
|
|
97
|
+
"platform_dst_nav4_side_nav_resize_tooltip_feedback": {
|
|
98
|
+
"type": "boolean"
|
|
99
|
+
},
|
|
95
100
|
"platform-component-visual-refresh": {
|
|
96
101
|
"type": "boolean",
|
|
97
102
|
"referenceOnly": true
|