@atlaskit/tooltip 17.5.12 → 17.5.15

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 CHANGED
@@ -1,5 +1,29 @@
1
1
  # @atlaskit/tooltip
2
2
 
3
+ ## 17.5.15
4
+
5
+ ### Patch Changes
6
+
7
+ - [`338ba1a1500`](https://bitbucket.org/atlassian/atlassian-frontend/commits/338ba1a1500) - [ux] Improves accuracy of Tooltip placement relative to the mouse when using `position="mouse"`
8
+
9
+ ## 17.5.14
10
+
11
+ ### Patch Changes
12
+
13
+ - [`13a202fde6b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/13a202fde6b) - Fixes a bug where undefined test IDs were being added to Tooltip wrappers when no test ID was set
14
+ - Updated dependencies
15
+
16
+ ## 17.5.13
17
+
18
+ ### Patch Changes
19
+
20
+ - [`45ebe7af434`](https://bitbucket.org/atlassian/atlassian-frontend/commits/45ebe7af434) - Moved to using declarative entrypoints internally. Public API is unchanged.
21
+ - [`4efc76f8a72`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4efc76f8a72) - [ux] Fixes a bug where tooltip entrance and exit direction animations were not working since version 12.1.7, after upgrading `react-popper`.
22
+
23
+ This involved adding a wrapper `<div>` around the tooltip to separate the positioning and animation styles. The wrapper can be identified in tests using `testId` with the pattern `{testId}--wrapper`.
24
+
25
+ - Updated dependencies
26
+
3
27
  ## 17.5.12
4
28
 
5
29
  ### Patch Changes
@@ -23,10 +23,14 @@ var _bindEventListener = require("bind-event-listener");
23
23
 
24
24
  var _analyticsNext = require("@atlaskit/analytics-next");
25
25
 
26
+ var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
27
+
26
28
  var _useCloseOnEscapePress = _interopRequireDefault(require("@atlaskit/ds-lib/use-close-on-escape-press"));
27
29
 
28
30
  var _motion = require("@atlaskit/motion");
29
31
 
32
+ var _durations = require("@atlaskit/motion/durations");
33
+
30
34
  var _popper = require("@atlaskit/popper");
31
35
 
32
36
  var _portal = _interopRequireDefault(require("@atlaskit/portal"));
@@ -54,10 +58,25 @@ var tooltipZIndex = _constants.layers.tooltip();
54
58
  var analyticsAttributes = {
55
59
  componentName: 'tooltip',
56
60
  packageName: "@atlaskit/tooltip",
57
- packageVersion: "17.5.12"
61
+ packageVersion: "17.5.15"
62
+ }; // Inverts motion direction
63
+
64
+ var invertedDirection = {
65
+ top: 'bottom',
66
+ bottom: 'top',
67
+ left: 'right',
68
+ right: 'left'
69
+ };
70
+ /**
71
+ * Converts a Popper placement to it's general direction.
72
+ *
73
+ * @param position - Popper Placement value, e.g. 'top-start'
74
+ * @returns Popper Direction, e.g. 'top'
75
+ */
76
+
77
+ var getDirectionFromPlacement = function getDirectionFromPlacement(placement) {
78
+ return placement.split('-')[0];
58
79
  };
59
-
60
- function noop() {}
61
80
 
62
81
  function Tooltip(_ref) {
63
82
  var children = _ref.children,
@@ -76,9 +95,9 @@ function Tooltip(_ref) {
76
95
  _ref$delay = _ref.delay,
77
96
  delay = _ref$delay === void 0 ? 300 : _ref$delay,
78
97
  _ref$onShow = _ref.onShow,
79
- onShow = _ref$onShow === void 0 ? noop : _ref$onShow,
98
+ onShow = _ref$onShow === void 0 ? _noop.default : _ref$onShow,
80
99
  _ref$onHide = _ref.onHide,
81
- onHide = _ref$onHide === void 0 ? noop : _ref$onHide,
100
+ onHide = _ref$onHide === void 0 ? _noop.default : _ref$onHide,
82
101
  _ref$hideTooltipOnCli = _ref.hideTooltipOnClick,
83
102
  hideTooltipOnClick = _ref$hideTooltipOnCli === void 0 ? false : _ref$hideTooltipOnCli,
84
103
  _ref$hideTooltipOnMou = _ref.hideTooltipOnMouseDown,
@@ -203,17 +222,16 @@ function Tooltip(_ref) {
203
222
  lastHandlers.current.onShowHandler();
204
223
  }
205
224
 
206
- setState(isImmediate ? 'show-immediate' : 'show-fade-in');
225
+ setState(isImmediate ? 'show-immediate' : 'fade-in');
207
226
  },
208
227
  hide: function hide(_ref3) {
209
228
  var isImmediate = _ref3.isImmediate;
210
- setState(function (current) {
211
- if (current !== 'hide') {
212
- return isImmediate ? 'hide' : 'fade-out';
213
- }
214
229
 
215
- return current;
216
- });
230
+ if (isImmediate) {
231
+ setState('hide');
232
+ } else {
233
+ setState('before-fade-out');
234
+ }
217
235
  },
218
236
  done: done
219
237
  };
@@ -233,7 +251,11 @@ function Tooltip(_ref) {
233
251
  });
234
252
  (0, _react.useEffect)(function () {
235
253
  if (state === 'hide') {
236
- return noop;
254
+ return _noop.default;
255
+ }
256
+
257
+ if (state === 'before-fade-out') {
258
+ setState('fade-out');
237
259
  }
238
260
 
239
261
  var unbind = (0, _bindEventListener.bind)(window, {
@@ -320,6 +342,16 @@ function Tooltip(_ref) {
320
342
  });
321
343
  }
322
344
  }, []);
345
+ var onMouseMove = position === 'mouse' ? function (event) {
346
+ var _apiRef$current2;
347
+
348
+ if ((_apiRef$current2 = apiRef.current) !== null && _apiRef$current2 !== void 0 && _apiRef$current2.isActive()) {
349
+ apiRef.current.mousePosition = (0, _utilities.getMousePosition)({
350
+ left: event.clientX,
351
+ top: event.clientY
352
+ });
353
+ }
354
+ } : undefined;
323
355
  var onMouseOverTooltip = (0, _react.useCallback)(function () {
324
356
  if (apiRef.current && apiRef.current.isActive()) {
325
357
  apiRef.current.keep();
@@ -348,15 +380,15 @@ function Tooltip(_ref) {
348
380
 
349
381
  var CastTargetContainer = TargetContainer;
350
382
  var shouldRenderTooltipContainer = state !== 'hide' && Boolean(content);
351
- var shouldRenderTooltipChildren = state === 'show-immediate' || state === 'show-fade-in';
383
+ var shouldRenderTooltipChildren = state !== 'hide' && state !== 'fade-out';
384
+
385
+ var getReferenceElement = function getReferenceElement() {
386
+ var _apiRef$current3;
352
387
 
353
- var getReferentElement = function getReferentElement() {
354
- // Use the initial mouse position if appropriate, or the target element
355
- var api = apiRef.current;
356
- var initialMouse = api ? api.getInitialMouse() : null;
388
+ if (position === 'mouse' && (_apiRef$current3 = apiRef.current) !== null && _apiRef$current3 !== void 0 && _apiRef$current3.mousePosition) {
389
+ var _apiRef$current4;
357
390
 
358
- if (position === 'mouse' && initialMouse) {
359
- return initialMouse;
391
+ return (_apiRef$current4 = apiRef.current) === null || _apiRef$current4 === void 0 ? void 0 : _apiRef$current4.mousePosition;
360
392
  }
361
393
 
362
394
  return targetRef.current || undefined;
@@ -366,6 +398,7 @@ function Tooltip(_ref) {
366
398
  var tooltipTriggerProps = {
367
399
  onMouseOver: onMouseOver,
368
400
  onMouseOut: onMouseOut,
401
+ onMouseMove: onMouseMove,
369
402
  onClick: onClick,
370
403
  onMouseDown: onMouseDown,
371
404
  onFocus: onFocus,
@@ -380,17 +413,25 @@ function Tooltip(_ref) {
380
413
  zIndex: tooltipZIndex
381
414
  }, (0, _core.jsx)(_popper.Popper, {
382
415
  placement: tooltipPosition,
383
- referenceElement: getReferentElement(),
416
+ referenceElement: getReferenceElement(),
384
417
  strategy: strategy
385
418
  }, function (_ref4) {
386
419
  var ref = _ref4.ref,
387
420
  style = _ref4.style,
388
- update = _ref4.update;
421
+ update = _ref4.update,
422
+ placement = _ref4.placement;
423
+ // Invert the entrance and exit directions.
424
+ // E.g. a tooltip's position is on the 'right', it should enter from and exit to the 'left'
425
+ // This gives the effect the tooltip is appearing from the target
426
+ var direction = position === 'mouse' ? undefined : invertedDirection[getDirectionFromPlacement(placement)];
389
427
  return (0, _core.jsx)(_motion.ExitingPersistence, {
390
428
  appear: true
391
429
  }, shouldRenderTooltipChildren && (0, _core.jsx)(_motion.FadeIn, {
430
+ distance: "constant",
431
+ entranceDirection: direction,
432
+ exitDirection: direction,
392
433
  onFinish: onAnimationFinished,
393
- duration: state === 'show-immediate' ? 0 : undefined
434
+ duration: state === 'show-immediate' ? 0 : _durations.mediumDurationMs
394
435
  }, function (_ref5) {
395
436
  var className = _ref5.className;
396
437
  return (// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
@@ -36,20 +36,20 @@ var TooltipPrimitive = /*#__PURE__*/(0, _react.forwardRef)(function TooltipPrimi
36
36
 
37
37
  var styleWithZIndex = _objectSpread(_objectSpread({}, style), {}, (0, _defineProperty2.default)({}, VAR_PRIMITIVE_ZINDEX, _constants.layers.tooltip()));
38
38
 
39
- return (// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
40
- (0, _core.jsx)("div", {
41
- role: "tooltip",
42
- ref: ref,
43
- style: styleWithZIndex,
44
- className: className,
45
- onMouseOut: onMouseOut,
46
- onMouseOver: onMouseOver,
47
- css: primitiveStyles,
48
- "data-placement": placement,
49
- "data-testid": testId,
50
- id: id
51
- }, children)
52
- );
39
+ return (0, _core.jsx)("div", {
40
+ ref: ref,
41
+ style: styleWithZIndex,
42
+ "data-testid": testId ? "".concat(testId, "--wrapper") : undefined
43
+ }, (0, _core.jsx)("div", {
44
+ role: "tooltip",
45
+ className: className,
46
+ onMouseOut: onMouseOut,
47
+ onMouseOver: onMouseOver,
48
+ css: primitiveStyles,
49
+ "data-placement": placement,
50
+ "data-testid": testId,
51
+ id: id
52
+ }, children));
53
53
  });
54
54
  TooltipPrimitive.displayName = 'TooltipPrimitive';
55
55
  var _default = TooltipPrimitive;
@@ -157,7 +157,7 @@ function show(entry) {
157
157
  isActive: isActive,
158
158
  requestHide: requestHide,
159
159
  finishHideAnimation: finishHideAnimation,
160
- getInitialMouse: getInitialMouse
160
+ mousePosition: getInitialMouse()
161
161
  };
162
162
  return result;
163
163
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/tooltip",
3
- "version": "17.5.12",
3
+ "version": "17.5.15",
4
4
  "sideEffects": false
5
5
  }
@@ -5,8 +5,10 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
5
5
  import { jsx } from '@emotion/core';
6
6
  import { bind } from 'bind-event-listener';
7
7
  import { usePlatformLeafSyntheticEventHandler } from '@atlaskit/analytics-next';
8
+ import noop from '@atlaskit/ds-lib/noop';
8
9
  import useCloseOnEscapePress from '@atlaskit/ds-lib/use-close-on-escape-press';
9
10
  import { ExitingPersistence, FadeIn } from '@atlaskit/motion';
11
+ import { mediumDurationMs } from '@atlaskit/motion/durations';
10
12
  import { Popper } from '@atlaskit/popper';
11
13
  import Portal from '@atlaskit/portal';
12
14
  import { layers } from '@atlaskit/theme/constants';
@@ -18,10 +20,23 @@ const tooltipZIndex = layers.tooltip();
18
20
  const analyticsAttributes = {
19
21
  componentName: 'tooltip',
20
22
  packageName: "@atlaskit/tooltip",
21
- packageVersion: "17.5.12"
23
+ packageVersion: "17.5.15"
24
+ }; // Inverts motion direction
25
+
26
+ const invertedDirection = {
27
+ top: 'bottom',
28
+ bottom: 'top',
29
+ left: 'right',
30
+ right: 'left'
22
31
  };
32
+ /**
33
+ * Converts a Popper placement to it's general direction.
34
+ *
35
+ * @param position - Popper Placement value, e.g. 'top-start'
36
+ * @returns Popper Direction, e.g. 'top'
37
+ */
23
38
 
24
- function noop() {}
39
+ const getDirectionFromPlacement = placement => placement.split('-')[0];
25
40
 
26
41
  function Tooltip({
27
42
  children,
@@ -154,18 +169,16 @@ function Tooltip({
154
169
  lastHandlers.current.onShowHandler();
155
170
  }
156
171
 
157
- setState(isImmediate ? 'show-immediate' : 'show-fade-in');
172
+ setState(isImmediate ? 'show-immediate' : 'fade-in');
158
173
  },
159
174
  hide: ({
160
175
  isImmediate
161
176
  }) => {
162
- setState(current => {
163
- if (current !== 'hide') {
164
- return isImmediate ? 'hide' : 'fade-out';
165
- }
166
-
167
- return current;
168
- });
177
+ if (isImmediate) {
178
+ setState('hide');
179
+ } else {
180
+ setState('before-fade-out');
181
+ }
169
182
  },
170
183
  done: done
171
184
  };
@@ -188,6 +201,10 @@ function Tooltip({
188
201
  return noop;
189
202
  }
190
203
 
204
+ if (state === 'before-fade-out') {
205
+ setState('fade-out');
206
+ }
207
+
191
208
  const unbind = bind(window, {
192
209
  type: 'scroll',
193
210
  listener: () => {
@@ -272,6 +289,16 @@ function Tooltip({
272
289
  });
273
290
  }
274
291
  }, []);
292
+ const onMouseMove = position === 'mouse' ? event => {
293
+ var _apiRef$current2;
294
+
295
+ if ((_apiRef$current2 = apiRef.current) !== null && _apiRef$current2 !== void 0 && _apiRef$current2.isActive()) {
296
+ apiRef.current.mousePosition = getMousePosition({
297
+ left: event.clientX,
298
+ top: event.clientY
299
+ });
300
+ }
301
+ } : undefined;
275
302
  const onMouseOverTooltip = useCallback(() => {
276
303
  if (apiRef.current && apiRef.current.isActive()) {
277
304
  apiRef.current.keep();
@@ -300,15 +327,15 @@ function Tooltip({
300
327
 
301
328
  const CastTargetContainer = TargetContainer;
302
329
  const shouldRenderTooltipContainer = state !== 'hide' && Boolean(content);
303
- const shouldRenderTooltipChildren = state === 'show-immediate' || state === 'show-fade-in';
330
+ const shouldRenderTooltipChildren = state !== 'hide' && state !== 'fade-out';
304
331
 
305
- const getReferentElement = () => {
306
- // Use the initial mouse position if appropriate, or the target element
307
- const api = apiRef.current;
308
- const initialMouse = api ? api.getInitialMouse() : null;
332
+ const getReferenceElement = () => {
333
+ var _apiRef$current3;
309
334
 
310
- if (position === 'mouse' && initialMouse) {
311
- return initialMouse;
335
+ if (position === 'mouse' && (_apiRef$current3 = apiRef.current) !== null && _apiRef$current3 !== void 0 && _apiRef$current3.mousePosition) {
336
+ var _apiRef$current4;
337
+
338
+ return (_apiRef$current4 = apiRef.current) === null || _apiRef$current4 === void 0 ? void 0 : _apiRef$current4.mousePosition;
312
339
  }
313
340
 
314
341
  return targetRef.current || undefined;
@@ -318,6 +345,7 @@ function Tooltip({
318
345
  const tooltipTriggerProps = {
319
346
  onMouseOver,
320
347
  onMouseOut,
348
+ onMouseMove,
321
349
  onClick,
322
350
  onMouseDown,
323
351
  onFocus,
@@ -332,33 +360,43 @@ function Tooltip({
332
360
  zIndex: tooltipZIndex
333
361
  }, jsx(Popper, {
334
362
  placement: tooltipPosition,
335
- referenceElement: getReferentElement(),
363
+ referenceElement: getReferenceElement(),
336
364
  strategy: strategy
337
365
  }, ({
338
366
  ref,
339
367
  style,
340
- update
341
- }) => jsx(ExitingPersistence, {
342
- appear: true
343
- }, shouldRenderTooltipChildren && jsx(FadeIn, {
344
- onFinish: onAnimationFinished,
345
- duration: state === 'show-immediate' ? 0 : undefined
346
- }, ({
347
- className
348
- }) => // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
349
- jsx(Container, {
350
- ref: ref,
351
- className: `Tooltip ${className}`,
352
- style: style,
353
- truncate: truncate,
354
- placement: tooltipPosition,
355
- testId: testId,
356
- onMouseOut: onMouseOut,
357
- onMouseOver: onMouseOverTooltip,
358
- id: tooltipId
359
- }, typeof content === 'function' ? content({
360
- update
361
- }) : content))))) : null);
368
+ update,
369
+ placement
370
+ }) => {
371
+ // Invert the entrance and exit directions.
372
+ // E.g. a tooltip's position is on the 'right', it should enter from and exit to the 'left'
373
+ // This gives the effect the tooltip is appearing from the target
374
+ const direction = position === 'mouse' ? undefined : invertedDirection[getDirectionFromPlacement(placement)];
375
+ return jsx(ExitingPersistence, {
376
+ appear: true
377
+ }, shouldRenderTooltipChildren && jsx(FadeIn, {
378
+ distance: "constant",
379
+ entranceDirection: direction,
380
+ exitDirection: direction,
381
+ onFinish: onAnimationFinished,
382
+ duration: state === 'show-immediate' ? 0 : mediumDurationMs
383
+ }, ({
384
+ className
385
+ }) => // eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
386
+ jsx(Container, {
387
+ ref: ref,
388
+ className: `Tooltip ${className}`,
389
+ style: style,
390
+ truncate: truncate,
391
+ placement: tooltipPosition,
392
+ testId: testId,
393
+ onMouseOut: onMouseOut,
394
+ onMouseOver: onMouseOverTooltip,
395
+ id: tooltipId
396
+ }, typeof content === 'function' ? content({
397
+ update
398
+ }) : content)));
399
+ })) : null);
362
400
  }
363
401
 
364
402
  Tooltip.displayName = 'Tooltip';
@@ -20,20 +20,20 @@ const TooltipPrimitive = /*#__PURE__*/forwardRef(function TooltipPrimitive({
20
20
  const styleWithZIndex = { ...style,
21
21
  [VAR_PRIMITIVE_ZINDEX]: layers.tooltip()
22
22
  };
23
- return (// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
24
- jsx("div", {
25
- role: "tooltip",
26
- ref: ref,
27
- style: styleWithZIndex,
28
- className: className,
29
- onMouseOut: onMouseOut,
30
- onMouseOver: onMouseOver,
31
- css: primitiveStyles,
32
- "data-placement": placement,
33
- "data-testid": testId,
34
- id: id
35
- }, children)
36
- );
23
+ return jsx("div", {
24
+ ref: ref,
25
+ style: styleWithZIndex,
26
+ "data-testid": testId ? `${testId}--wrapper` : undefined
27
+ }, jsx("div", {
28
+ role: "tooltip",
29
+ className: className,
30
+ onMouseOut: onMouseOut,
31
+ onMouseOver: onMouseOver,
32
+ css: primitiveStyles,
33
+ "data-placement": placement,
34
+ "data-testid": testId,
35
+ id: id
36
+ }, children));
37
37
  });
38
38
  TooltipPrimitive.displayName = 'TooltipPrimitive';
39
39
  export default TooltipPrimitive;
@@ -149,7 +149,7 @@ export function show(entry) {
149
149
  isActive,
150
150
  requestHide,
151
151
  finishHideAnimation,
152
- getInitialMouse
152
+ mousePosition: getInitialMouse()
153
153
  };
154
154
  return result;
155
155
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/tooltip",
3
- "version": "17.5.12",
3
+ "version": "17.5.15",
4
4
  "sideEffects": false
5
5
  }
@@ -11,8 +11,10 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
11
11
  import { jsx } from '@emotion/core';
12
12
  import { bind } from 'bind-event-listener';
13
13
  import { usePlatformLeafSyntheticEventHandler } from '@atlaskit/analytics-next';
14
+ import noop from '@atlaskit/ds-lib/noop';
14
15
  import useCloseOnEscapePress from '@atlaskit/ds-lib/use-close-on-escape-press';
15
16
  import { ExitingPersistence, FadeIn } from '@atlaskit/motion';
17
+ import { mediumDurationMs } from '@atlaskit/motion/durations';
16
18
  import { Popper } from '@atlaskit/popper';
17
19
  import Portal from '@atlaskit/portal';
18
20
  import { layers } from '@atlaskit/theme/constants';
@@ -24,10 +26,25 @@ var tooltipZIndex = layers.tooltip();
24
26
  var analyticsAttributes = {
25
27
  componentName: 'tooltip',
26
28
  packageName: "@atlaskit/tooltip",
27
- packageVersion: "17.5.12"
29
+ packageVersion: "17.5.15"
30
+ }; // Inverts motion direction
31
+
32
+ var invertedDirection = {
33
+ top: 'bottom',
34
+ bottom: 'top',
35
+ left: 'right',
36
+ right: 'left'
37
+ };
38
+ /**
39
+ * Converts a Popper placement to it's general direction.
40
+ *
41
+ * @param position - Popper Placement value, e.g. 'top-start'
42
+ * @returns Popper Direction, e.g. 'top'
43
+ */
44
+
45
+ var getDirectionFromPlacement = function getDirectionFromPlacement(placement) {
46
+ return placement.split('-')[0];
28
47
  };
29
-
30
- function noop() {}
31
48
 
32
49
  function Tooltip(_ref) {
33
50
  var children = _ref.children,
@@ -173,17 +190,16 @@ function Tooltip(_ref) {
173
190
  lastHandlers.current.onShowHandler();
174
191
  }
175
192
 
176
- setState(isImmediate ? 'show-immediate' : 'show-fade-in');
193
+ setState(isImmediate ? 'show-immediate' : 'fade-in');
177
194
  },
178
195
  hide: function hide(_ref3) {
179
196
  var isImmediate = _ref3.isImmediate;
180
- setState(function (current) {
181
- if (current !== 'hide') {
182
- return isImmediate ? 'hide' : 'fade-out';
183
- }
184
197
 
185
- return current;
186
- });
198
+ if (isImmediate) {
199
+ setState('hide');
200
+ } else {
201
+ setState('before-fade-out');
202
+ }
187
203
  },
188
204
  done: done
189
205
  };
@@ -206,6 +222,10 @@ function Tooltip(_ref) {
206
222
  return noop;
207
223
  }
208
224
 
225
+ if (state === 'before-fade-out') {
226
+ setState('fade-out');
227
+ }
228
+
209
229
  var unbind = bind(window, {
210
230
  type: 'scroll',
211
231
  listener: function listener() {
@@ -290,6 +310,16 @@ function Tooltip(_ref) {
290
310
  });
291
311
  }
292
312
  }, []);
313
+ var onMouseMove = position === 'mouse' ? function (event) {
314
+ var _apiRef$current2;
315
+
316
+ if ((_apiRef$current2 = apiRef.current) !== null && _apiRef$current2 !== void 0 && _apiRef$current2.isActive()) {
317
+ apiRef.current.mousePosition = getMousePosition({
318
+ left: event.clientX,
319
+ top: event.clientY
320
+ });
321
+ }
322
+ } : undefined;
293
323
  var onMouseOverTooltip = useCallback(function () {
294
324
  if (apiRef.current && apiRef.current.isActive()) {
295
325
  apiRef.current.keep();
@@ -318,15 +348,15 @@ function Tooltip(_ref) {
318
348
 
319
349
  var CastTargetContainer = TargetContainer;
320
350
  var shouldRenderTooltipContainer = state !== 'hide' && Boolean(content);
321
- var shouldRenderTooltipChildren = state === 'show-immediate' || state === 'show-fade-in';
351
+ var shouldRenderTooltipChildren = state !== 'hide' && state !== 'fade-out';
352
+
353
+ var getReferenceElement = function getReferenceElement() {
354
+ var _apiRef$current3;
322
355
 
323
- var getReferentElement = function getReferentElement() {
324
- // Use the initial mouse position if appropriate, or the target element
325
- var api = apiRef.current;
326
- var initialMouse = api ? api.getInitialMouse() : null;
356
+ if (position === 'mouse' && (_apiRef$current3 = apiRef.current) !== null && _apiRef$current3 !== void 0 && _apiRef$current3.mousePosition) {
357
+ var _apiRef$current4;
327
358
 
328
- if (position === 'mouse' && initialMouse) {
329
- return initialMouse;
359
+ return (_apiRef$current4 = apiRef.current) === null || _apiRef$current4 === void 0 ? void 0 : _apiRef$current4.mousePosition;
330
360
  }
331
361
 
332
362
  return targetRef.current || undefined;
@@ -336,6 +366,7 @@ function Tooltip(_ref) {
336
366
  var tooltipTriggerProps = {
337
367
  onMouseOver: onMouseOver,
338
368
  onMouseOut: onMouseOut,
369
+ onMouseMove: onMouseMove,
339
370
  onClick: onClick,
340
371
  onMouseDown: onMouseDown,
341
372
  onFocus: onFocus,
@@ -350,17 +381,25 @@ function Tooltip(_ref) {
350
381
  zIndex: tooltipZIndex
351
382
  }, jsx(Popper, {
352
383
  placement: tooltipPosition,
353
- referenceElement: getReferentElement(),
384
+ referenceElement: getReferenceElement(),
354
385
  strategy: strategy
355
386
  }, function (_ref4) {
356
387
  var ref = _ref4.ref,
357
388
  style = _ref4.style,
358
- update = _ref4.update;
389
+ update = _ref4.update,
390
+ placement = _ref4.placement;
391
+ // Invert the entrance and exit directions.
392
+ // E.g. a tooltip's position is on the 'right', it should enter from and exit to the 'left'
393
+ // This gives the effect the tooltip is appearing from the target
394
+ var direction = position === 'mouse' ? undefined : invertedDirection[getDirectionFromPlacement(placement)];
359
395
  return jsx(ExitingPersistence, {
360
396
  appear: true
361
397
  }, shouldRenderTooltipChildren && jsx(FadeIn, {
398
+ distance: "constant",
399
+ entranceDirection: direction,
400
+ exitDirection: direction,
362
401
  onFinish: onAnimationFinished,
363
- duration: state === 'show-immediate' ? 0 : undefined
402
+ duration: state === 'show-immediate' ? 0 : mediumDurationMs
364
403
  }, function (_ref5) {
365
404
  var className = _ref5.className;
366
405
  return (// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
@@ -25,20 +25,20 @@ var TooltipPrimitive = /*#__PURE__*/forwardRef(function TooltipPrimitive(_ref, r
25
25
 
26
26
  var styleWithZIndex = _objectSpread(_objectSpread({}, style), {}, _defineProperty({}, VAR_PRIMITIVE_ZINDEX, layers.tooltip()));
27
27
 
28
- return (// eslint-disable-next-line jsx-a11y/mouse-events-have-key-events
29
- jsx("div", {
30
- role: "tooltip",
31
- ref: ref,
32
- style: styleWithZIndex,
33
- className: className,
34
- onMouseOut: onMouseOut,
35
- onMouseOver: onMouseOver,
36
- css: primitiveStyles,
37
- "data-placement": placement,
38
- "data-testid": testId,
39
- id: id
40
- }, children)
41
- );
28
+ return jsx("div", {
29
+ ref: ref,
30
+ style: styleWithZIndex,
31
+ "data-testid": testId ? "".concat(testId, "--wrapper") : undefined
32
+ }, jsx("div", {
33
+ role: "tooltip",
34
+ className: className,
35
+ onMouseOut: onMouseOut,
36
+ onMouseOver: onMouseOver,
37
+ css: primitiveStyles,
38
+ "data-placement": placement,
39
+ "data-testid": testId,
40
+ id: id
41
+ }, children));
42
42
  });
43
43
  TooltipPrimitive.displayName = 'TooltipPrimitive';
44
44
  export default TooltipPrimitive;
@@ -149,7 +149,7 @@ export function show(entry) {
149
149
  isActive: isActive,
150
150
  requestHide: requestHide,
151
151
  finishHideAnimation: finishHideAnimation,
152
- getInitialMouse: getInitialMouse
152
+ mousePosition: getInitialMouse()
153
153
  };
154
154
  return result;
155
155
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/tooltip",
3
- "version": "17.5.12",
3
+ "version": "17.5.15",
4
4
  "sideEffects": false
5
5
  }
@@ -18,7 +18,7 @@ export declare type Entry = {
18
18
  };
19
19
  export declare type API = {
20
20
  isActive: () => boolean;
21
- getInitialMouse: () => FakeMouseElement | null;
21
+ mousePosition: FakeMouseElement | null;
22
22
  requestHide: (value: {
23
23
  isImmediate: boolean;
24
24
  }) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tooltip",
3
- "version": "17.5.12",
3
+ "version": "17.5.15",
4
4
  "description": "A tooltip is a floating, non-actionable label used to explain a user interface element or feature.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -16,17 +16,24 @@
16
16
  "atlaskit:src": "src/index.ts",
17
17
  "atlassian": {
18
18
  "team": "Design System Team",
19
- "deprecatedAutoEntryPoints": true,
20
19
  "releaseModel": "scheduled",
21
20
  "website": {
22
21
  "name": "Tooltip",
23
22
  "category": "Components"
24
23
  }
25
24
  },
25
+ "af:exports": {
26
+ ".": "./src/index.ts",
27
+ "./Tooltip": "./src/Tooltip.tsx",
28
+ "./TooltipContainer": "./src/TooltipContainer.tsx",
29
+ "./TooltipPrimitive": "./src/TooltipPrimitive.tsx",
30
+ "./types": "./src/types.tsx",
31
+ "./utilities": "./src/utilities.ts"
32
+ },
26
33
  "dependencies": {
27
34
  "@atlaskit/analytics-next": "^8.2.0",
28
- "@atlaskit/ds-lib": "^2.0.0",
29
- "@atlaskit/motion": "^1.1.0",
35
+ "@atlaskit/ds-lib": "^2.1.0",
36
+ "@atlaskit/motion": "^1.2.0",
30
37
  "@atlaskit/popper": "^5.0.0",
31
38
  "@atlaskit/portal": "^4.1.0",
32
39
  "@atlaskit/theme": "^12.1.0",
package/report.api.md ADDED
@@ -0,0 +1,171 @@
1
+ ## API Report File for "@atlaskit/tooltip"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+ /// <reference types="react" />
7
+
8
+ import { ComponentType } from 'react';
9
+ import { CSSProperties } from 'react';
10
+ import { ForwardRefExoticComponent } from 'react';
11
+ import { Placement } from '@atlaskit/popper';
12
+ import { ReactNode } from 'react';
13
+ import { RefAttributes } from 'react';
14
+ import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
15
+
16
+ export declare type PositionType = PositionTypeBase | 'mouse';
17
+
18
+ declare type PositionTypeBase = Placement;
19
+
20
+ declare function Tooltip({
21
+ children,
22
+ position,
23
+ mousePosition,
24
+ content,
25
+ truncate,
26
+ component: Container,
27
+ tag: TargetContainer,
28
+ testId,
29
+ delay,
30
+ onShow,
31
+ onHide,
32
+ hideTooltipOnClick,
33
+ hideTooltipOnMouseDown,
34
+ analyticsContext,
35
+ strategy,
36
+ }: TooltipProps): JSX.Element;
37
+
38
+ declare namespace Tooltip {
39
+ var displayName: string;
40
+ }
41
+ export default Tooltip;
42
+
43
+ export declare const TooltipPrimitive: ForwardRefExoticComponent<
44
+ Pick<
45
+ TooltipPrimitiveProps,
46
+ | 'style'
47
+ | 'className'
48
+ | 'children'
49
+ | 'placement'
50
+ | 'testId'
51
+ | 'onMouseOut'
52
+ | 'onMouseOver'
53
+ | 'id'
54
+ | 'truncate'
55
+ > &
56
+ RefAttributes<HTMLDivElement>
57
+ >;
58
+
59
+ export declare interface TooltipPrimitiveProps {
60
+ truncate?: boolean;
61
+ style?: CSSProperties;
62
+ className?: string;
63
+ children: ReactNode;
64
+ testId?: string;
65
+ placement: PositionType;
66
+ ref: React.Ref<any>;
67
+ onMouseOver?: (e: React.MouseEvent<HTMLElement>) => void;
68
+ onMouseOut?: (e: React.MouseEvent<HTMLElement>) => void;
69
+ id?: string;
70
+ }
71
+
72
+ export declare interface TooltipProps {
73
+ /**
74
+ * The content of the tooltip. It can be either a:
75
+ * 1. `ReactNode`
76
+ * 2. Function which returns a `ReactNode`
77
+
78
+ * The benefit of the second approach is that it allows you to consume the `update` render prop.
79
+ * This `update` function can be called to manually recalculate the position of the tooltip.
80
+ */
81
+ content: ReactNode | (({ update }: { update: () => void }) => ReactNode);
82
+ /**
83
+ * Extend `TooltipPrimitive` to create your own tooltip and pass it as component
84
+ */
85
+ component?: ComponentType<TooltipPrimitiveProps>;
86
+ /**
87
+ * Time in milliseconds to wait before showing and hiding the tooltip. Defaults to 300.
88
+ */
89
+ delay?: number;
90
+ /**
91
+ * Hide the tooltip when the click event is triggered. This should be
92
+ * used when tooltip should be hidden if `onClick` react synthetic event
93
+ * is triggered, which happens after `onMouseDown` event
94
+ */
95
+ hideTooltipOnClick?: boolean;
96
+ /**
97
+ * Hide the tooltip when the mousedown event is triggered. This should be
98
+ * used when tooltip should be hidden if `onMouseDown` react synthetic event
99
+ * is triggered, which happens before `onClick` event
100
+ */
101
+ hideTooltipOnMouseDown?: boolean;
102
+ /**
103
+ * Where the tooltip should appear relative to the mouse pointer.
104
+ * Only used when the `position` prop is set to `"mouse"`.
105
+ * When interacting with the target element using the keyboard will use this position against the target element instead.
106
+ */
107
+ mousePosition?: PositionTypeBase;
108
+ /**
109
+ * Function to be called when the tooltip will be shown. It is called when the
110
+ * tooltip begins to animate in.
111
+ */
112
+ onShow?: (analyticsEvent: UIAnalyticsEvent) => void;
113
+ /**
114
+ * Function to be called when the tooltip will be hidden. It is called after the
115
+ * delay, when the tooltip begins to animate out.
116
+ */
117
+ onHide?: (analyticsEvent: UIAnalyticsEvent) => void;
118
+ /**
119
+ * Where the tooltip should appear relative to its target.
120
+ * If set to `"mouse"` the tooltip will display next to the mouse pointer instead.
121
+ * Make sure to utilize the `mousePosition` if you want to customize where the tooltip will show in relation to the mouse.
122
+ */
123
+ position?: PositionType;
124
+ /**
125
+ * Replace the wrapping element. This accepts the name of a html tag which will
126
+ * be used to wrap the element.
127
+ * If you provide a component it needs to support a ref prop which is used by popper for positioning
128
+ */
129
+ tag?:
130
+ | keyof JSX.IntrinsicElements
131
+ | React.ComponentType<
132
+ React.AllHTMLAttributes<HTMLElement> & {
133
+ ref: React.Ref<HTMLElement>;
134
+ }
135
+ >;
136
+ /**
137
+ * Show only one line of text, and truncate when too long
138
+ */
139
+ truncate?: boolean;
140
+ /**
141
+ * Elements to be wrapped by the tooltip.
142
+ * It can be either a:
143
+ * 1. `ReactNode`
144
+ * 2. Function which returns a `ReactNode`
145
+ */
146
+ children: ReactNode | ((props: TriggerProps) => ReactNode);
147
+ /**
148
+ * A `testId` prop is provided for specified elements, which is a unique
149
+ * string that appears as a data attribute `data-testid` in the rendered code,
150
+ * serving as a hook for automated tests */
151
+ testId?: string;
152
+ /** Analytics context metadata */
153
+ analyticsContext?: Record<string, any>;
154
+ /**
155
+ * Used to define the strategy of popper.
156
+ */
157
+ strategy?: 'absolute' | 'fixed' | undefined;
158
+ }
159
+
160
+ declare interface TriggerProps {
161
+ onMouseOver: (event: React.MouseEvent<HTMLElement>) => void;
162
+ onMouseOut: (event: React.MouseEvent<HTMLElement>) => void;
163
+ onMouseDown: (event: React.MouseEvent<HTMLElement>) => void;
164
+ onClick: (event: React.MouseEvent<HTMLElement>) => void;
165
+ onFocus: (event: React.FocusEvent<HTMLElement>) => void;
166
+ onBlur: (event: React.FocusEvent<HTMLElement>) => void;
167
+ ref: (node: HTMLElement | null) => void;
168
+ }
169
+
170
+ export {};
171
+ ```