@atlaskit/tooltip 18.0.0 → 18.1.1
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 +12 -0
- package/dist/cjs/Tooltip.js +68 -32
- package/dist/cjs/internal/drag-manager.js +92 -0
- package/dist/es2019/Tooltip.js +57 -22
- package/dist/es2019/internal/drag-manager.js +85 -0
- package/dist/esm/Tooltip.js +67 -33
- package/dist/esm/internal/drag-manager.js +85 -0
- package/dist/types/Tooltip.d.ts +2 -3
- package/dist/types/internal/drag-manager.d.ts +10 -0
- package/dist/types/types.d.ts +1 -1
- package/dist/types-ts4.5/Tooltip.d.ts +2 -3
- package/dist/types-ts4.5/internal/drag-manager.d.ts +10 -0
- package/dist/types-ts4.5/types.d.ts +1 -1
- package/package.json +3 -3
- package/tmp/api-report-tmp.d.ts +0 -106
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/tooltip
|
|
2
2
|
|
|
3
|
+
## 18.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#64251](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/64251) [`92b280e734a7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/92b280e734a7) - Add a hidden tooltip content when tooltip is in a modal for screen reader announcement
|
|
8
|
+
|
|
9
|
+
## 18.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#61952](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/61952) [`d00b9272c88c`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d00b9272c88c) - [ux] Tooltips are now hidden during drags. This is to prevent janky UX.
|
|
14
|
+
|
|
3
15
|
## 18.0.0
|
|
4
16
|
|
|
5
17
|
### Major Changes
|
package/dist/cjs/Tooltip.js
CHANGED
|
@@ -10,7 +10,6 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
var _react2 = require("@emotion/react");
|
|
14
13
|
var _bindEventListener = require("bind-event-listener");
|
|
15
14
|
var _analyticsNext = require("@atlaskit/analytics-next");
|
|
16
15
|
var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
|
|
@@ -20,6 +19,7 @@ var _durations = require("@atlaskit/motion/durations");
|
|
|
20
19
|
var _popper = require("@atlaskit/popper");
|
|
21
20
|
var _portal = _interopRequireDefault(require("@atlaskit/portal"));
|
|
22
21
|
var _constants = require("@atlaskit/theme/constants");
|
|
22
|
+
var _dragManager = require("./internal/drag-manager");
|
|
23
23
|
var _tooltipManager = require("./internal/tooltip-manager");
|
|
24
24
|
var _useUniqueId = _interopRequireDefault(require("./internal/use-unique-id"));
|
|
25
25
|
var _TooltipContainer = _interopRequireDefault(require("./TooltipContainer"));
|
|
@@ -27,12 +27,12 @@ var _utilities = require("./utilities");
|
|
|
27
27
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
28
28
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
29
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
30
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
30
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
31
31
|
var tooltipZIndex = _constants.layers.tooltip();
|
|
32
32
|
var analyticsAttributes = {
|
|
33
33
|
componentName: 'tooltip',
|
|
34
34
|
packageName: "@atlaskit/tooltip",
|
|
35
|
-
packageVersion: "18.
|
|
35
|
+
packageVersion: "18.1.1"
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
// Inverts motion direction
|
|
@@ -165,7 +165,38 @@ function Tooltip(_ref) {
|
|
|
165
165
|
}
|
|
166
166
|
};
|
|
167
167
|
}, [abort]);
|
|
168
|
+
var isDraggingRef = (0, _react.useRef)(false);
|
|
169
|
+
(0, _react.useEffect)(function () {
|
|
170
|
+
return (0, _dragManager.register)({
|
|
171
|
+
onRegister: function onRegister(_ref2) {
|
|
172
|
+
var isDragging = _ref2.isDragging;
|
|
173
|
+
isDraggingRef.current = isDragging;
|
|
174
|
+
},
|
|
175
|
+
onDragStart: function onDragStart() {
|
|
176
|
+
var _apiRef$current;
|
|
177
|
+
/**
|
|
178
|
+
* Hiding any visible tooltips when a drag starts because otherwise it
|
|
179
|
+
* looks janky (disappears and reappears), and is not required.
|
|
180
|
+
*/
|
|
181
|
+
(_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 || _apiRef$current.requestHide({
|
|
182
|
+
isImmediate: true
|
|
183
|
+
});
|
|
184
|
+
isDraggingRef.current = true;
|
|
185
|
+
},
|
|
186
|
+
onDragEnd: function onDragEnd() {
|
|
187
|
+
isDraggingRef.current = false;
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}, []);
|
|
168
191
|
var showTooltip = (0, _react.useCallback)(function (source) {
|
|
192
|
+
/**
|
|
193
|
+
* Prevent tooltips from being shown during a drag. This can occur with
|
|
194
|
+
* the native drag and drop API, where some pointer events can fire
|
|
195
|
+
* when they should not and lead to jank with tooltips.
|
|
196
|
+
*/
|
|
197
|
+
if (isDraggingRef.current) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
169
200
|
if (apiRef.current && !apiRef.current.isActive()) {
|
|
170
201
|
abort();
|
|
171
202
|
}
|
|
@@ -178,8 +209,8 @@ function Tooltip(_ref) {
|
|
|
178
209
|
var entry = {
|
|
179
210
|
source: source,
|
|
180
211
|
delay: lastDelay.current,
|
|
181
|
-
show: function show(
|
|
182
|
-
var isImmediate =
|
|
212
|
+
show: function show(_ref3) {
|
|
213
|
+
var isImmediate = _ref3.isImmediate;
|
|
183
214
|
// Call the onShow handler if it hasn't been called yet
|
|
184
215
|
if (!hasCalledShowHandler.current) {
|
|
185
216
|
hasCalledShowHandler.current = true;
|
|
@@ -187,8 +218,8 @@ function Tooltip(_ref) {
|
|
|
187
218
|
}
|
|
188
219
|
setState(isImmediate ? 'show-immediate' : 'fade-in');
|
|
189
220
|
},
|
|
190
|
-
hide: function hide(
|
|
191
|
-
var isImmediate =
|
|
221
|
+
hide: function hide(_ref4) {
|
|
222
|
+
var isImmediate = _ref4.isImmediate;
|
|
192
223
|
if (isImmediate) {
|
|
193
224
|
setState('hide');
|
|
194
225
|
} else {
|
|
@@ -201,8 +232,8 @@ function Tooltip(_ref) {
|
|
|
201
232
|
start(api);
|
|
202
233
|
}, [abort, done, start]);
|
|
203
234
|
var hideTooltipOnEsc = (0, _react.useCallback)(function () {
|
|
204
|
-
var _apiRef$
|
|
205
|
-
(_apiRef$
|
|
235
|
+
var _apiRef$current2;
|
|
236
|
+
(_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 || _apiRef$current2.requestHide({
|
|
206
237
|
isImmediate: true
|
|
207
238
|
});
|
|
208
239
|
}, [apiRef]);
|
|
@@ -301,8 +332,8 @@ function Tooltip(_ref) {
|
|
|
301
332
|
}
|
|
302
333
|
}, []);
|
|
303
334
|
var onMouseMove = position === 'mouse' ? function (event) {
|
|
304
|
-
var _apiRef$
|
|
305
|
-
if ((_apiRef$
|
|
335
|
+
var _apiRef$current3;
|
|
336
|
+
if ((_apiRef$current3 = apiRef.current) !== null && _apiRef$current3 !== void 0 && _apiRef$current3.isActive()) {
|
|
306
337
|
apiRef.current.mousePosition = (0, _utilities.getMousePosition)({
|
|
307
338
|
left: event.clientX,
|
|
308
339
|
top: event.clientY
|
|
@@ -340,10 +371,10 @@ function Tooltip(_ref) {
|
|
|
340
371
|
var shouldRenderTooltipContainer = state !== 'hide' && Boolean(content);
|
|
341
372
|
var shouldRenderTooltipChildren = state !== 'hide' && state !== 'fade-out';
|
|
342
373
|
var getReferenceElement = function getReferenceElement() {
|
|
343
|
-
var _apiRef$
|
|
344
|
-
if (position === 'mouse' && (_apiRef$
|
|
345
|
-
var _apiRef$
|
|
346
|
-
return (_apiRef$
|
|
374
|
+
var _apiRef$current4;
|
|
375
|
+
if (position === 'mouse' && (_apiRef$current4 = apiRef.current) !== null && _apiRef$current4 !== void 0 && _apiRef$current4.mousePosition) {
|
|
376
|
+
var _apiRef$current5;
|
|
377
|
+
return (_apiRef$current5 = apiRef.current) === null || _apiRef$current5 === void 0 ? void 0 : _apiRef$current5.mousePosition;
|
|
347
378
|
}
|
|
348
379
|
return targetRef.current || undefined;
|
|
349
380
|
};
|
|
@@ -381,42 +412,48 @@ function Tooltip(_ref) {
|
|
|
381
412
|
target.removeAttribute('aria-describedby');
|
|
382
413
|
}
|
|
383
414
|
}, [shouldRenderTooltipContainer, tooltipId]);
|
|
384
|
-
|
|
415
|
+
var hiddenContent = /*#__PURE__*/_react.default.createElement("span", {
|
|
416
|
+
"data-testid": testId ? "".concat(testId, "-hidden") : undefined,
|
|
417
|
+
hidden: true,
|
|
418
|
+
id: tooltipId
|
|
419
|
+
}, typeof content === 'function' ? content({}) : content);
|
|
420
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, typeof children === 'function' ?
|
|
421
|
+
/*#__PURE__*/
|
|
385
422
|
// once we deprecate the wrapped approach, we can put the aria
|
|
386
423
|
// attribute back into the tooltipTriggerProps and make it required
|
|
387
424
|
// instead of optional in `types`
|
|
388
|
-
children(_objectSpread(_objectSpread({}, tooltipTriggerProps), {}, {
|
|
425
|
+
_react.default.createElement(_react.default.Fragment, null, children(_objectSpread(_objectSpread({}, tooltipTriggerProps), {}, {
|
|
389
426
|
'aria-describedby': tooltipId,
|
|
390
427
|
ref: setDirectRef
|
|
391
|
-
})) :
|
|
428
|
+
})), shouldRenderTooltipContainer && hiddenContent) : /*#__PURE__*/_react.default.createElement(CastTargetContainer, (0, _extends2.default)({}, tooltipTriggerProps, {
|
|
392
429
|
ref: setImplicitRefFromChildren,
|
|
393
430
|
role: "presentation"
|
|
394
|
-
}), children), shouldRenderTooltipContainer ?
|
|
431
|
+
}), children, shouldRenderTooltipContainer && hiddenContent), shouldRenderTooltipContainer ? /*#__PURE__*/_react.default.createElement(_portal.default, {
|
|
395
432
|
zIndex: tooltipZIndex
|
|
396
|
-
},
|
|
433
|
+
}, /*#__PURE__*/_react.default.createElement(_popper.Popper, {
|
|
397
434
|
placement: tooltipPosition,
|
|
398
435
|
referenceElement: getReferenceElement(),
|
|
399
436
|
strategy: strategy
|
|
400
|
-
}, function (
|
|
401
|
-
var ref =
|
|
402
|
-
style =
|
|
403
|
-
update =
|
|
404
|
-
placement =
|
|
437
|
+
}, function (_ref5) {
|
|
438
|
+
var ref = _ref5.ref,
|
|
439
|
+
style = _ref5.style,
|
|
440
|
+
update = _ref5.update,
|
|
441
|
+
placement = _ref5.placement;
|
|
405
442
|
// Invert the entrance and exit directions.
|
|
406
443
|
// E.g. a tooltip's position is on the 'right', it should enter from and exit to the 'left'
|
|
407
444
|
// This gives the effect the tooltip is appearing from the target
|
|
408
445
|
var direction = position === 'mouse' ? undefined : invertedDirection[getDirectionFromPlacement(placement)];
|
|
409
|
-
return
|
|
446
|
+
return /*#__PURE__*/_react.default.createElement(_motion.ExitingPersistence, {
|
|
410
447
|
appear: true
|
|
411
|
-
}, shouldRenderTooltipChildren &&
|
|
448
|
+
}, shouldRenderTooltipChildren && /*#__PURE__*/_react.default.createElement(_motion.FadeIn, {
|
|
412
449
|
distance: "constant",
|
|
413
450
|
entranceDirection: direction,
|
|
414
451
|
exitDirection: direction,
|
|
415
452
|
onFinish: onAnimationFinished,
|
|
416
453
|
duration: state === 'show-immediate' ? 0 : _durations.mediumDurationMs
|
|
417
|
-
}, function (
|
|
418
|
-
var className =
|
|
419
|
-
return
|
|
454
|
+
}, function (_ref6) {
|
|
455
|
+
var className = _ref6.className;
|
|
456
|
+
return /*#__PURE__*/_react.default.createElement(Container, {
|
|
420
457
|
ref: ref
|
|
421
458
|
/**
|
|
422
459
|
* "Tooltip" classname is a hook used by tests to manipulate
|
|
@@ -428,8 +465,7 @@ function Tooltip(_ref) {
|
|
|
428
465
|
placement: tooltipPosition,
|
|
429
466
|
testId: getReferenceElement() ? testId : testId && "".concat(testId, "--unresolved"),
|
|
430
467
|
onMouseOut: onMouseOut,
|
|
431
|
-
onMouseOver: onMouseOverTooltip
|
|
432
|
-
id: tooltipId
|
|
468
|
+
onMouseOver: onMouseOverTooltip
|
|
433
469
|
}, typeof content === 'function' ? content({
|
|
434
470
|
update: update
|
|
435
471
|
}) : content);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.register = register;
|
|
7
|
+
var _bindEventListener = require("bind-event-listener");
|
|
8
|
+
/**
|
|
9
|
+
* We are listening directly to drag events instead of using a monitor from
|
|
10
|
+
* `@atlaskit/pragmatic-drag-and-drop` to avoid the bundle size cost, as it
|
|
11
|
+
* would affect almost every view in every product.
|
|
12
|
+
*
|
|
13
|
+
* We can reconsider this choice in the future.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
var registrations = new Set();
|
|
17
|
+
var cleanupEndEventListeners = null;
|
|
18
|
+
function onDragStart() {
|
|
19
|
+
if (cleanupEndEventListeners) {
|
|
20
|
+
// If the cleanup function exists then we've already run this
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
cleanupEndEventListeners = (0, _bindEventListener.bindAll)(window, [{
|
|
24
|
+
type: 'dragend',
|
|
25
|
+
listener: onDragEnd
|
|
26
|
+
}, {
|
|
27
|
+
type: 'pointerdown',
|
|
28
|
+
listener: onDragEnd
|
|
29
|
+
}, {
|
|
30
|
+
type: 'pointermove',
|
|
31
|
+
listener: function () {
|
|
32
|
+
var callCount = 0;
|
|
33
|
+
return function listener() {
|
|
34
|
+
// Using 20 as it is far bigger than the most observed (3)
|
|
35
|
+
if (callCount < 20) {
|
|
36
|
+
callCount++;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
onDragEnd();
|
|
40
|
+
};
|
|
41
|
+
}()
|
|
42
|
+
}]);
|
|
43
|
+
var clone = Array.from(registrations);
|
|
44
|
+
clone.forEach(function (subscriber) {
|
|
45
|
+
subscriber.onDragStart();
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function onDragEnd() {
|
|
49
|
+
var _cleanupEndEventListe;
|
|
50
|
+
(_cleanupEndEventListe = cleanupEndEventListeners) === null || _cleanupEndEventListe === void 0 || _cleanupEndEventListe();
|
|
51
|
+
cleanupEndEventListeners = null;
|
|
52
|
+
var clone = Array.from(registrations);
|
|
53
|
+
clone.forEach(function (subscriber) {
|
|
54
|
+
subscriber.onDragEnd();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function bindStartEvents() {
|
|
58
|
+
return (0, _bindEventListener.bindAll)(window, [{
|
|
59
|
+
type: 'dragstart',
|
|
60
|
+
listener: onDragStart
|
|
61
|
+
}, {
|
|
62
|
+
type: 'dragenter',
|
|
63
|
+
listener: onDragStart
|
|
64
|
+
}]);
|
|
65
|
+
}
|
|
66
|
+
var cleanupStartEventListeners = null;
|
|
67
|
+
function register(registration) {
|
|
68
|
+
// if first registration, bind event listeners
|
|
69
|
+
if (!cleanupStartEventListeners) {
|
|
70
|
+
// note: currently never unbinding these event listeners
|
|
71
|
+
cleanupStartEventListeners = bindStartEvents();
|
|
72
|
+
}
|
|
73
|
+
registrations.add(registration);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The reasoning for this behavior is so that if a tooltip mounts during
|
|
77
|
+
* a drag it can still be suppressed.
|
|
78
|
+
*
|
|
79
|
+
* We use a separate callback instead of onDragStart to avoid infinite loops.
|
|
80
|
+
*/
|
|
81
|
+
registration.onRegister({
|
|
82
|
+
isDragging: cleanupEndEventListeners !== null
|
|
83
|
+
});
|
|
84
|
+
return function unregister() {
|
|
85
|
+
registrations.delete(registration);
|
|
86
|
+
if (registrations.size === 0) {
|
|
87
|
+
var _cleanupStartEventLis;
|
|
88
|
+
(_cleanupStartEventLis = cleanupStartEventListeners) === null || _cleanupStartEventLis === void 0 || _cleanupStartEventLis();
|
|
89
|
+
cleanupStartEventListeners = null;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
package/dist/es2019/Tooltip.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
/** @jsx jsx */
|
|
3
|
-
|
|
4
2
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
|
-
import { jsx } from '@emotion/react';
|
|
6
3
|
import { bind } from 'bind-event-listener';
|
|
7
4
|
import { usePlatformLeafSyntheticEventHandler } from '@atlaskit/analytics-next';
|
|
8
5
|
import noop from '@atlaskit/ds-lib/noop';
|
|
@@ -12,6 +9,7 @@ import { mediumDurationMs } from '@atlaskit/motion/durations';
|
|
|
12
9
|
import { Popper } from '@atlaskit/popper';
|
|
13
10
|
import Portal from '@atlaskit/portal';
|
|
14
11
|
import { layers } from '@atlaskit/theme/constants';
|
|
12
|
+
import { register } from './internal/drag-manager';
|
|
15
13
|
import { show } from './internal/tooltip-manager';
|
|
16
14
|
import useUniqueId from './internal/use-unique-id';
|
|
17
15
|
import TooltipContainer from './TooltipContainer';
|
|
@@ -20,7 +18,7 @@ const tooltipZIndex = layers.tooltip();
|
|
|
20
18
|
const analyticsAttributes = {
|
|
21
19
|
componentName: 'tooltip',
|
|
22
20
|
packageName: "@atlaskit/tooltip",
|
|
23
|
-
packageVersion: "18.
|
|
21
|
+
packageVersion: "18.1.1"
|
|
24
22
|
};
|
|
25
23
|
|
|
26
24
|
// Inverts motion direction
|
|
@@ -140,7 +138,39 @@ function Tooltip({
|
|
|
140
138
|
}
|
|
141
139
|
};
|
|
142
140
|
}, [abort]);
|
|
141
|
+
const isDraggingRef = useRef(false);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
return register({
|
|
144
|
+
onRegister({
|
|
145
|
+
isDragging
|
|
146
|
+
}) {
|
|
147
|
+
isDraggingRef.current = isDragging;
|
|
148
|
+
},
|
|
149
|
+
onDragStart() {
|
|
150
|
+
var _apiRef$current;
|
|
151
|
+
/**
|
|
152
|
+
* Hiding any visible tooltips when a drag starts because otherwise it
|
|
153
|
+
* looks janky (disappears and reappears), and is not required.
|
|
154
|
+
*/
|
|
155
|
+
(_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.requestHide({
|
|
156
|
+
isImmediate: true
|
|
157
|
+
});
|
|
158
|
+
isDraggingRef.current = true;
|
|
159
|
+
},
|
|
160
|
+
onDragEnd() {
|
|
161
|
+
isDraggingRef.current = false;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}, []);
|
|
143
165
|
const showTooltip = useCallback(source => {
|
|
166
|
+
/**
|
|
167
|
+
* Prevent tooltips from being shown during a drag. This can occur with
|
|
168
|
+
* the native drag and drop API, where some pointer events can fire
|
|
169
|
+
* when they should not and lead to jank with tooltips.
|
|
170
|
+
*/
|
|
171
|
+
if (isDraggingRef.current) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
144
174
|
if (apiRef.current && !apiRef.current.isActive()) {
|
|
145
175
|
abort();
|
|
146
176
|
}
|
|
@@ -178,8 +208,8 @@ function Tooltip({
|
|
|
178
208
|
start(api);
|
|
179
209
|
}, [abort, done, start]);
|
|
180
210
|
const hideTooltipOnEsc = useCallback(() => {
|
|
181
|
-
var _apiRef$
|
|
182
|
-
(_apiRef$
|
|
211
|
+
var _apiRef$current2;
|
|
212
|
+
(_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 ? void 0 : _apiRef$current2.requestHide({
|
|
183
213
|
isImmediate: true
|
|
184
214
|
});
|
|
185
215
|
}, [apiRef]);
|
|
@@ -278,8 +308,8 @@ function Tooltip({
|
|
|
278
308
|
}
|
|
279
309
|
}, []);
|
|
280
310
|
const onMouseMove = position === 'mouse' ? event => {
|
|
281
|
-
var _apiRef$
|
|
282
|
-
if ((_apiRef$
|
|
311
|
+
var _apiRef$current3;
|
|
312
|
+
if ((_apiRef$current3 = apiRef.current) !== null && _apiRef$current3 !== void 0 && _apiRef$current3.isActive()) {
|
|
283
313
|
apiRef.current.mousePosition = getMousePosition({
|
|
284
314
|
left: event.clientX,
|
|
285
315
|
top: event.clientY
|
|
@@ -317,10 +347,10 @@ function Tooltip({
|
|
|
317
347
|
const shouldRenderTooltipContainer = state !== 'hide' && Boolean(content);
|
|
318
348
|
const shouldRenderTooltipChildren = state !== 'hide' && state !== 'fade-out';
|
|
319
349
|
const getReferenceElement = () => {
|
|
320
|
-
var _apiRef$
|
|
321
|
-
if (position === 'mouse' && (_apiRef$
|
|
322
|
-
var _apiRef$
|
|
323
|
-
return (_apiRef$
|
|
350
|
+
var _apiRef$current4;
|
|
351
|
+
if (position === 'mouse' && (_apiRef$current4 = apiRef.current) !== null && _apiRef$current4 !== void 0 && _apiRef$current4.mousePosition) {
|
|
352
|
+
var _apiRef$current5;
|
|
353
|
+
return (_apiRef$current5 = apiRef.current) === null || _apiRef$current5 === void 0 ? void 0 : _apiRef$current5.mousePosition;
|
|
324
354
|
}
|
|
325
355
|
return targetRef.current || undefined;
|
|
326
356
|
};
|
|
@@ -358,20 +388,26 @@ function Tooltip({
|
|
|
358
388
|
target.removeAttribute('aria-describedby');
|
|
359
389
|
}
|
|
360
390
|
}, [shouldRenderTooltipContainer, tooltipId]);
|
|
361
|
-
|
|
391
|
+
const hiddenContent = /*#__PURE__*/React.createElement("span", {
|
|
392
|
+
"data-testid": testId ? `${testId}-hidden` : undefined,
|
|
393
|
+
hidden: true,
|
|
394
|
+
id: tooltipId
|
|
395
|
+
}, typeof content === 'function' ? content({}) : content);
|
|
396
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, typeof children === 'function' ?
|
|
397
|
+
/*#__PURE__*/
|
|
362
398
|
// once we deprecate the wrapped approach, we can put the aria
|
|
363
399
|
// attribute back into the tooltipTriggerProps and make it required
|
|
364
400
|
// instead of optional in `types`
|
|
365
|
-
children({
|
|
401
|
+
React.createElement(React.Fragment, null, children({
|
|
366
402
|
...tooltipTriggerProps,
|
|
367
403
|
'aria-describedby': tooltipId,
|
|
368
404
|
ref: setDirectRef
|
|
369
|
-
}) :
|
|
405
|
+
}), shouldRenderTooltipContainer && hiddenContent) : /*#__PURE__*/React.createElement(CastTargetContainer, _extends({}, tooltipTriggerProps, {
|
|
370
406
|
ref: setImplicitRefFromChildren,
|
|
371
407
|
role: "presentation"
|
|
372
|
-
}), children), shouldRenderTooltipContainer ?
|
|
408
|
+
}), children, shouldRenderTooltipContainer && hiddenContent), shouldRenderTooltipContainer ? /*#__PURE__*/React.createElement(Portal, {
|
|
373
409
|
zIndex: tooltipZIndex
|
|
374
|
-
},
|
|
410
|
+
}, /*#__PURE__*/React.createElement(Popper, {
|
|
375
411
|
placement: tooltipPosition,
|
|
376
412
|
referenceElement: getReferenceElement(),
|
|
377
413
|
strategy: strategy
|
|
@@ -385,9 +421,9 @@ function Tooltip({
|
|
|
385
421
|
// E.g. a tooltip's position is on the 'right', it should enter from and exit to the 'left'
|
|
386
422
|
// This gives the effect the tooltip is appearing from the target
|
|
387
423
|
const direction = position === 'mouse' ? undefined : invertedDirection[getDirectionFromPlacement(placement)];
|
|
388
|
-
return
|
|
424
|
+
return /*#__PURE__*/React.createElement(ExitingPersistence, {
|
|
389
425
|
appear: true
|
|
390
|
-
}, shouldRenderTooltipChildren &&
|
|
426
|
+
}, shouldRenderTooltipChildren && /*#__PURE__*/React.createElement(FadeIn, {
|
|
391
427
|
distance: "constant",
|
|
392
428
|
entranceDirection: direction,
|
|
393
429
|
exitDirection: direction,
|
|
@@ -395,7 +431,7 @@ function Tooltip({
|
|
|
395
431
|
duration: state === 'show-immediate' ? 0 : mediumDurationMs
|
|
396
432
|
}, ({
|
|
397
433
|
className
|
|
398
|
-
}) =>
|
|
434
|
+
}) => /*#__PURE__*/React.createElement(Container, {
|
|
399
435
|
ref: ref
|
|
400
436
|
/**
|
|
401
437
|
* "Tooltip" classname is a hook used by tests to manipulate
|
|
@@ -407,8 +443,7 @@ function Tooltip({
|
|
|
407
443
|
placement: tooltipPosition,
|
|
408
444
|
testId: getReferenceElement() ? testId : testId && `${testId}--unresolved`,
|
|
409
445
|
onMouseOut: onMouseOut,
|
|
410
|
-
onMouseOver: onMouseOverTooltip
|
|
411
|
-
id: tooltipId
|
|
446
|
+
onMouseOver: onMouseOverTooltip
|
|
412
447
|
}, typeof content === 'function' ? content({
|
|
413
448
|
update
|
|
414
449
|
}) : content)));
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We are listening directly to drag events instead of using a monitor from
|
|
3
|
+
* `@atlaskit/pragmatic-drag-and-drop` to avoid the bundle size cost, as it
|
|
4
|
+
* would affect almost every view in every product.
|
|
5
|
+
*
|
|
6
|
+
* We can reconsider this choice in the future.
|
|
7
|
+
*/
|
|
8
|
+
import { bindAll } from 'bind-event-listener';
|
|
9
|
+
const registrations = new Set();
|
|
10
|
+
let cleanupEndEventListeners = null;
|
|
11
|
+
function onDragStart() {
|
|
12
|
+
if (cleanupEndEventListeners) {
|
|
13
|
+
// If the cleanup function exists then we've already run this
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
cleanupEndEventListeners = bindAll(window, [{
|
|
17
|
+
type: 'dragend',
|
|
18
|
+
listener: onDragEnd
|
|
19
|
+
}, {
|
|
20
|
+
type: 'pointerdown',
|
|
21
|
+
listener: onDragEnd
|
|
22
|
+
}, {
|
|
23
|
+
type: 'pointermove',
|
|
24
|
+
listener: (() => {
|
|
25
|
+
let callCount = 0;
|
|
26
|
+
return function listener() {
|
|
27
|
+
// Using 20 as it is far bigger than the most observed (3)
|
|
28
|
+
if (callCount < 20) {
|
|
29
|
+
callCount++;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
onDragEnd();
|
|
33
|
+
};
|
|
34
|
+
})()
|
|
35
|
+
}]);
|
|
36
|
+
const clone = Array.from(registrations);
|
|
37
|
+
clone.forEach(subscriber => {
|
|
38
|
+
subscriber.onDragStart();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function onDragEnd() {
|
|
42
|
+
var _cleanupEndEventListe;
|
|
43
|
+
(_cleanupEndEventListe = cleanupEndEventListeners) === null || _cleanupEndEventListe === void 0 ? void 0 : _cleanupEndEventListe();
|
|
44
|
+
cleanupEndEventListeners = null;
|
|
45
|
+
const clone = Array.from(registrations);
|
|
46
|
+
clone.forEach(subscriber => {
|
|
47
|
+
subscriber.onDragEnd();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function bindStartEvents() {
|
|
51
|
+
return bindAll(window, [{
|
|
52
|
+
type: 'dragstart',
|
|
53
|
+
listener: onDragStart
|
|
54
|
+
}, {
|
|
55
|
+
type: 'dragenter',
|
|
56
|
+
listener: onDragStart
|
|
57
|
+
}]);
|
|
58
|
+
}
|
|
59
|
+
let cleanupStartEventListeners = null;
|
|
60
|
+
export function register(registration) {
|
|
61
|
+
// if first registration, bind event listeners
|
|
62
|
+
if (!cleanupStartEventListeners) {
|
|
63
|
+
// note: currently never unbinding these event listeners
|
|
64
|
+
cleanupStartEventListeners = bindStartEvents();
|
|
65
|
+
}
|
|
66
|
+
registrations.add(registration);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The reasoning for this behavior is so that if a tooltip mounts during
|
|
70
|
+
* a drag it can still be suppressed.
|
|
71
|
+
*
|
|
72
|
+
* We use a separate callback instead of onDragStart to avoid infinite loops.
|
|
73
|
+
*/
|
|
74
|
+
registration.onRegister({
|
|
75
|
+
isDragging: cleanupEndEventListeners !== null
|
|
76
|
+
});
|
|
77
|
+
return function unregister() {
|
|
78
|
+
registrations.delete(registration);
|
|
79
|
+
if (registrations.size === 0) {
|
|
80
|
+
var _cleanupStartEventLis;
|
|
81
|
+
(_cleanupStartEventLis = cleanupStartEventListeners) === null || _cleanupStartEventLis === void 0 ? void 0 : _cleanupStartEventLis();
|
|
82
|
+
cleanupStartEventListeners = null;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
package/dist/esm/Tooltip.js
CHANGED
|
@@ -3,10 +3,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
4
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
5
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
-
/** @jsx jsx */
|
|
7
|
-
|
|
8
6
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
9
|
-
import { jsx } from '@emotion/react';
|
|
10
7
|
import { bind } from 'bind-event-listener';
|
|
11
8
|
import { usePlatformLeafSyntheticEventHandler } from '@atlaskit/analytics-next';
|
|
12
9
|
import noop from '@atlaskit/ds-lib/noop';
|
|
@@ -16,6 +13,7 @@ import { mediumDurationMs } from '@atlaskit/motion/durations';
|
|
|
16
13
|
import { Popper } from '@atlaskit/popper';
|
|
17
14
|
import Portal from '@atlaskit/portal';
|
|
18
15
|
import { layers } from '@atlaskit/theme/constants';
|
|
16
|
+
import { register } from './internal/drag-manager';
|
|
19
17
|
import { show } from './internal/tooltip-manager';
|
|
20
18
|
import useUniqueId from './internal/use-unique-id';
|
|
21
19
|
import TooltipContainer from './TooltipContainer';
|
|
@@ -24,7 +22,7 @@ var tooltipZIndex = layers.tooltip();
|
|
|
24
22
|
var analyticsAttributes = {
|
|
25
23
|
componentName: 'tooltip',
|
|
26
24
|
packageName: "@atlaskit/tooltip",
|
|
27
|
-
packageVersion: "18.
|
|
25
|
+
packageVersion: "18.1.1"
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
// Inverts motion direction
|
|
@@ -157,7 +155,38 @@ function Tooltip(_ref) {
|
|
|
157
155
|
}
|
|
158
156
|
};
|
|
159
157
|
}, [abort]);
|
|
158
|
+
var isDraggingRef = useRef(false);
|
|
159
|
+
useEffect(function () {
|
|
160
|
+
return register({
|
|
161
|
+
onRegister: function onRegister(_ref2) {
|
|
162
|
+
var isDragging = _ref2.isDragging;
|
|
163
|
+
isDraggingRef.current = isDragging;
|
|
164
|
+
},
|
|
165
|
+
onDragStart: function onDragStart() {
|
|
166
|
+
var _apiRef$current;
|
|
167
|
+
/**
|
|
168
|
+
* Hiding any visible tooltips when a drag starts because otherwise it
|
|
169
|
+
* looks janky (disappears and reappears), and is not required.
|
|
170
|
+
*/
|
|
171
|
+
(_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 || _apiRef$current.requestHide({
|
|
172
|
+
isImmediate: true
|
|
173
|
+
});
|
|
174
|
+
isDraggingRef.current = true;
|
|
175
|
+
},
|
|
176
|
+
onDragEnd: function onDragEnd() {
|
|
177
|
+
isDraggingRef.current = false;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
}, []);
|
|
160
181
|
var showTooltip = useCallback(function (source) {
|
|
182
|
+
/**
|
|
183
|
+
* Prevent tooltips from being shown during a drag. This can occur with
|
|
184
|
+
* the native drag and drop API, where some pointer events can fire
|
|
185
|
+
* when they should not and lead to jank with tooltips.
|
|
186
|
+
*/
|
|
187
|
+
if (isDraggingRef.current) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
161
190
|
if (apiRef.current && !apiRef.current.isActive()) {
|
|
162
191
|
abort();
|
|
163
192
|
}
|
|
@@ -170,8 +199,8 @@ function Tooltip(_ref) {
|
|
|
170
199
|
var entry = {
|
|
171
200
|
source: source,
|
|
172
201
|
delay: lastDelay.current,
|
|
173
|
-
show: function show(
|
|
174
|
-
var isImmediate =
|
|
202
|
+
show: function show(_ref3) {
|
|
203
|
+
var isImmediate = _ref3.isImmediate;
|
|
175
204
|
// Call the onShow handler if it hasn't been called yet
|
|
176
205
|
if (!hasCalledShowHandler.current) {
|
|
177
206
|
hasCalledShowHandler.current = true;
|
|
@@ -179,8 +208,8 @@ function Tooltip(_ref) {
|
|
|
179
208
|
}
|
|
180
209
|
setState(isImmediate ? 'show-immediate' : 'fade-in');
|
|
181
210
|
},
|
|
182
|
-
hide: function hide(
|
|
183
|
-
var isImmediate =
|
|
211
|
+
hide: function hide(_ref4) {
|
|
212
|
+
var isImmediate = _ref4.isImmediate;
|
|
184
213
|
if (isImmediate) {
|
|
185
214
|
setState('hide');
|
|
186
215
|
} else {
|
|
@@ -193,8 +222,8 @@ function Tooltip(_ref) {
|
|
|
193
222
|
start(api);
|
|
194
223
|
}, [abort, done, start]);
|
|
195
224
|
var hideTooltipOnEsc = useCallback(function () {
|
|
196
|
-
var _apiRef$
|
|
197
|
-
(_apiRef$
|
|
225
|
+
var _apiRef$current2;
|
|
226
|
+
(_apiRef$current2 = apiRef.current) === null || _apiRef$current2 === void 0 || _apiRef$current2.requestHide({
|
|
198
227
|
isImmediate: true
|
|
199
228
|
});
|
|
200
229
|
}, [apiRef]);
|
|
@@ -293,8 +322,8 @@ function Tooltip(_ref) {
|
|
|
293
322
|
}
|
|
294
323
|
}, []);
|
|
295
324
|
var onMouseMove = position === 'mouse' ? function (event) {
|
|
296
|
-
var _apiRef$
|
|
297
|
-
if ((_apiRef$
|
|
325
|
+
var _apiRef$current3;
|
|
326
|
+
if ((_apiRef$current3 = apiRef.current) !== null && _apiRef$current3 !== void 0 && _apiRef$current3.isActive()) {
|
|
298
327
|
apiRef.current.mousePosition = getMousePosition({
|
|
299
328
|
left: event.clientX,
|
|
300
329
|
top: event.clientY
|
|
@@ -332,10 +361,10 @@ function Tooltip(_ref) {
|
|
|
332
361
|
var shouldRenderTooltipContainer = state !== 'hide' && Boolean(content);
|
|
333
362
|
var shouldRenderTooltipChildren = state !== 'hide' && state !== 'fade-out';
|
|
334
363
|
var getReferenceElement = function getReferenceElement() {
|
|
335
|
-
var _apiRef$
|
|
336
|
-
if (position === 'mouse' && (_apiRef$
|
|
337
|
-
var _apiRef$
|
|
338
|
-
return (_apiRef$
|
|
364
|
+
var _apiRef$current4;
|
|
365
|
+
if (position === 'mouse' && (_apiRef$current4 = apiRef.current) !== null && _apiRef$current4 !== void 0 && _apiRef$current4.mousePosition) {
|
|
366
|
+
var _apiRef$current5;
|
|
367
|
+
return (_apiRef$current5 = apiRef.current) === null || _apiRef$current5 === void 0 ? void 0 : _apiRef$current5.mousePosition;
|
|
339
368
|
}
|
|
340
369
|
return targetRef.current || undefined;
|
|
341
370
|
};
|
|
@@ -373,42 +402,48 @@ function Tooltip(_ref) {
|
|
|
373
402
|
target.removeAttribute('aria-describedby');
|
|
374
403
|
}
|
|
375
404
|
}, [shouldRenderTooltipContainer, tooltipId]);
|
|
376
|
-
|
|
405
|
+
var hiddenContent = /*#__PURE__*/React.createElement("span", {
|
|
406
|
+
"data-testid": testId ? "".concat(testId, "-hidden") : undefined,
|
|
407
|
+
hidden: true,
|
|
408
|
+
id: tooltipId
|
|
409
|
+
}, typeof content === 'function' ? content({}) : content);
|
|
410
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, typeof children === 'function' ?
|
|
411
|
+
/*#__PURE__*/
|
|
377
412
|
// once we deprecate the wrapped approach, we can put the aria
|
|
378
413
|
// attribute back into the tooltipTriggerProps and make it required
|
|
379
414
|
// instead of optional in `types`
|
|
380
|
-
children(_objectSpread(_objectSpread({}, tooltipTriggerProps), {}, {
|
|
415
|
+
React.createElement(React.Fragment, null, children(_objectSpread(_objectSpread({}, tooltipTriggerProps), {}, {
|
|
381
416
|
'aria-describedby': tooltipId,
|
|
382
417
|
ref: setDirectRef
|
|
383
|
-
})) :
|
|
418
|
+
})), shouldRenderTooltipContainer && hiddenContent) : /*#__PURE__*/React.createElement(CastTargetContainer, _extends({}, tooltipTriggerProps, {
|
|
384
419
|
ref: setImplicitRefFromChildren,
|
|
385
420
|
role: "presentation"
|
|
386
|
-
}), children), shouldRenderTooltipContainer ?
|
|
421
|
+
}), children, shouldRenderTooltipContainer && hiddenContent), shouldRenderTooltipContainer ? /*#__PURE__*/React.createElement(Portal, {
|
|
387
422
|
zIndex: tooltipZIndex
|
|
388
|
-
},
|
|
423
|
+
}, /*#__PURE__*/React.createElement(Popper, {
|
|
389
424
|
placement: tooltipPosition,
|
|
390
425
|
referenceElement: getReferenceElement(),
|
|
391
426
|
strategy: strategy
|
|
392
|
-
}, function (
|
|
393
|
-
var ref =
|
|
394
|
-
style =
|
|
395
|
-
update =
|
|
396
|
-
placement =
|
|
427
|
+
}, function (_ref5) {
|
|
428
|
+
var ref = _ref5.ref,
|
|
429
|
+
style = _ref5.style,
|
|
430
|
+
update = _ref5.update,
|
|
431
|
+
placement = _ref5.placement;
|
|
397
432
|
// Invert the entrance and exit directions.
|
|
398
433
|
// E.g. a tooltip's position is on the 'right', it should enter from and exit to the 'left'
|
|
399
434
|
// This gives the effect the tooltip is appearing from the target
|
|
400
435
|
var direction = position === 'mouse' ? undefined : invertedDirection[getDirectionFromPlacement(placement)];
|
|
401
|
-
return
|
|
436
|
+
return /*#__PURE__*/React.createElement(ExitingPersistence, {
|
|
402
437
|
appear: true
|
|
403
|
-
}, shouldRenderTooltipChildren &&
|
|
438
|
+
}, shouldRenderTooltipChildren && /*#__PURE__*/React.createElement(FadeIn, {
|
|
404
439
|
distance: "constant",
|
|
405
440
|
entranceDirection: direction,
|
|
406
441
|
exitDirection: direction,
|
|
407
442
|
onFinish: onAnimationFinished,
|
|
408
443
|
duration: state === 'show-immediate' ? 0 : mediumDurationMs
|
|
409
|
-
}, function (
|
|
410
|
-
var className =
|
|
411
|
-
return
|
|
444
|
+
}, function (_ref6) {
|
|
445
|
+
var className = _ref6.className;
|
|
446
|
+
return /*#__PURE__*/React.createElement(Container, {
|
|
412
447
|
ref: ref
|
|
413
448
|
/**
|
|
414
449
|
* "Tooltip" classname is a hook used by tests to manipulate
|
|
@@ -420,8 +455,7 @@ function Tooltip(_ref) {
|
|
|
420
455
|
placement: tooltipPosition,
|
|
421
456
|
testId: getReferenceElement() ? testId : testId && "".concat(testId, "--unresolved"),
|
|
422
457
|
onMouseOut: onMouseOut,
|
|
423
|
-
onMouseOver: onMouseOverTooltip
|
|
424
|
-
id: tooltipId
|
|
458
|
+
onMouseOver: onMouseOverTooltip
|
|
425
459
|
}, typeof content === 'function' ? content({
|
|
426
460
|
update: update
|
|
427
461
|
}) : content);
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* We are listening directly to drag events instead of using a monitor from
|
|
3
|
+
* `@atlaskit/pragmatic-drag-and-drop` to avoid the bundle size cost, as it
|
|
4
|
+
* would affect almost every view in every product.
|
|
5
|
+
*
|
|
6
|
+
* We can reconsider this choice in the future.
|
|
7
|
+
*/
|
|
8
|
+
import { bindAll } from 'bind-event-listener';
|
|
9
|
+
var registrations = new Set();
|
|
10
|
+
var cleanupEndEventListeners = null;
|
|
11
|
+
function onDragStart() {
|
|
12
|
+
if (cleanupEndEventListeners) {
|
|
13
|
+
// If the cleanup function exists then we've already run this
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
cleanupEndEventListeners = bindAll(window, [{
|
|
17
|
+
type: 'dragend',
|
|
18
|
+
listener: onDragEnd
|
|
19
|
+
}, {
|
|
20
|
+
type: 'pointerdown',
|
|
21
|
+
listener: onDragEnd
|
|
22
|
+
}, {
|
|
23
|
+
type: 'pointermove',
|
|
24
|
+
listener: function () {
|
|
25
|
+
var callCount = 0;
|
|
26
|
+
return function listener() {
|
|
27
|
+
// Using 20 as it is far bigger than the most observed (3)
|
|
28
|
+
if (callCount < 20) {
|
|
29
|
+
callCount++;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
onDragEnd();
|
|
33
|
+
};
|
|
34
|
+
}()
|
|
35
|
+
}]);
|
|
36
|
+
var clone = Array.from(registrations);
|
|
37
|
+
clone.forEach(function (subscriber) {
|
|
38
|
+
subscriber.onDragStart();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function onDragEnd() {
|
|
42
|
+
var _cleanupEndEventListe;
|
|
43
|
+
(_cleanupEndEventListe = cleanupEndEventListeners) === null || _cleanupEndEventListe === void 0 || _cleanupEndEventListe();
|
|
44
|
+
cleanupEndEventListeners = null;
|
|
45
|
+
var clone = Array.from(registrations);
|
|
46
|
+
clone.forEach(function (subscriber) {
|
|
47
|
+
subscriber.onDragEnd();
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function bindStartEvents() {
|
|
51
|
+
return bindAll(window, [{
|
|
52
|
+
type: 'dragstart',
|
|
53
|
+
listener: onDragStart
|
|
54
|
+
}, {
|
|
55
|
+
type: 'dragenter',
|
|
56
|
+
listener: onDragStart
|
|
57
|
+
}]);
|
|
58
|
+
}
|
|
59
|
+
var cleanupStartEventListeners = null;
|
|
60
|
+
export function register(registration) {
|
|
61
|
+
// if first registration, bind event listeners
|
|
62
|
+
if (!cleanupStartEventListeners) {
|
|
63
|
+
// note: currently never unbinding these event listeners
|
|
64
|
+
cleanupStartEventListeners = bindStartEvents();
|
|
65
|
+
}
|
|
66
|
+
registrations.add(registration);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The reasoning for this behavior is so that if a tooltip mounts during
|
|
70
|
+
* a drag it can still be suppressed.
|
|
71
|
+
*
|
|
72
|
+
* We use a separate callback instead of onDragStart to avoid infinite loops.
|
|
73
|
+
*/
|
|
74
|
+
registration.onRegister({
|
|
75
|
+
isDragging: cleanupEndEventListeners !== null
|
|
76
|
+
});
|
|
77
|
+
return function unregister() {
|
|
78
|
+
registrations.delete(registration);
|
|
79
|
+
if (registrations.size === 0) {
|
|
80
|
+
var _cleanupStartEventLis;
|
|
81
|
+
(_cleanupStartEventLis = cleanupStartEventListeners) === null || _cleanupStartEventLis === void 0 || _cleanupStartEventLis();
|
|
82
|
+
cleanupStartEventListeners = null;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
package/dist/types/Tooltip.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx } from '@emotion/react';
|
|
1
|
+
/// <reference types="react" />
|
|
3
2
|
import { TooltipProps } from './types';
|
|
4
|
-
declare function Tooltip({ children, position, mousePosition, content, truncate, component: Container, tag: TargetContainer, testId, delay, onShow, onHide, hideTooltipOnClick, hideTooltipOnMouseDown, analyticsContext, strategy, }: TooltipProps):
|
|
3
|
+
declare function Tooltip({ children, position, mousePosition, content, truncate, component: Container, tag: TargetContainer, testId, delay, onShow, onHide, hideTooltipOnClick, hideTooltipOnMouseDown, analyticsContext, strategy, }: TooltipProps): JSX.Element;
|
|
5
4
|
declare namespace Tooltip {
|
|
6
5
|
var displayName: string;
|
|
7
6
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface TooltipProps {
|
|
|
25
25
|
* This `update` function can be called to manually recalculate the position of the tooltip.
|
|
26
26
|
*/
|
|
27
27
|
content: ReactNode | (({ update }: {
|
|
28
|
-
update
|
|
28
|
+
update?: () => void;
|
|
29
29
|
}) => ReactNode);
|
|
30
30
|
/**
|
|
31
31
|
* Extend `TooltipPrimitive` to create your own tooltip and pass it as component
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import { jsx } from '@emotion/react';
|
|
1
|
+
/// <reference types="react" />
|
|
3
2
|
import { TooltipProps } from './types';
|
|
4
|
-
declare function Tooltip({ children, position, mousePosition, content, truncate, component: Container, tag: TargetContainer, testId, delay, onShow, onHide, hideTooltipOnClick, hideTooltipOnMouseDown, analyticsContext, strategy, }: TooltipProps):
|
|
3
|
+
declare function Tooltip({ children, position, mousePosition, content, truncate, component: Container, tag: TargetContainer, testId, delay, onShow, onHide, hideTooltipOnClick, hideTooltipOnMouseDown, analyticsContext, strategy, }: TooltipProps): JSX.Element;
|
|
5
4
|
declare namespace Tooltip {
|
|
6
5
|
var displayName: string;
|
|
7
6
|
}
|
|
@@ -25,7 +25,7 @@ export interface TooltipProps {
|
|
|
25
25
|
* This `update` function can be called to manually recalculate the position of the tooltip.
|
|
26
26
|
*/
|
|
27
27
|
content: ReactNode | (({ update }: {
|
|
28
|
-
update
|
|
28
|
+
update?: () => void;
|
|
29
29
|
}) => ReactNode);
|
|
30
30
|
/**
|
|
31
31
|
* Extend `TooltipPrimitive` to create your own tooltip and pass it as component
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/tooltip",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.1.1",
|
|
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/"
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@atlaskit/popper": "^5.5.0",
|
|
49
49
|
"@atlaskit/portal": "^4.4.0",
|
|
50
50
|
"@atlaskit/theme": "^12.6.0",
|
|
51
|
-
"@atlaskit/tokens": "^1.
|
|
51
|
+
"@atlaskit/tokens": "^1.33.0",
|
|
52
52
|
"@babel/runtime": "^7.0.0",
|
|
53
53
|
"@emotion/react": "^11.7.1",
|
|
54
54
|
"bind-event-listener": "^2.1.1",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@af/accessibility-testing": "*",
|
|
63
|
-
"@atlaskit/button": "^
|
|
63
|
+
"@atlaskit/button": "^17.2.0",
|
|
64
64
|
"@atlaskit/ssr": "*",
|
|
65
65
|
"@atlaskit/visual-regression": "*",
|
|
66
66
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
package/tmp/api-report-tmp.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
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
|
-
|
|
7
|
-
import { ComponentType } from 'react';
|
|
8
|
-
import { CSSProperties } from 'react';
|
|
9
|
-
import { ForwardRefExoticComponent } from 'react';
|
|
10
|
-
import { jsx } from '@emotion/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
|
-
// @public (undocumented)
|
|
17
|
-
export type PositionType = 'mouse' | PositionTypeBase;
|
|
18
|
-
|
|
19
|
-
// @public (undocumented)
|
|
20
|
-
type PositionTypeBase = Placement;
|
|
21
|
-
|
|
22
|
-
// @public (undocumented)
|
|
23
|
-
function Tooltip({ children, position, mousePosition, content, truncate, component: Container, tag: TargetContainer, testId, delay, onShow, onHide, hideTooltipOnClick, hideTooltipOnMouseDown, analyticsContext, strategy, }: TooltipProps): jsx.JSX.Element;
|
|
24
|
-
|
|
25
|
-
// @public (undocumented)
|
|
26
|
-
namespace Tooltip {
|
|
27
|
-
var // (undocumented)
|
|
28
|
-
displayName: string;
|
|
29
|
-
}
|
|
30
|
-
export default Tooltip;
|
|
31
|
-
|
|
32
|
-
// @public (undocumented)
|
|
33
|
-
export const TooltipPrimitive: ForwardRefExoticComponent<Pick<TooltipPrimitiveProps, "children" | "className" | "id" | "onMouseOut" | "onMouseOver" | "placement" | "style" | "testId" | "truncate"> & RefAttributes<HTMLDivElement>>;
|
|
34
|
-
|
|
35
|
-
// @public (undocumented)
|
|
36
|
-
export interface TooltipPrimitiveProps {
|
|
37
|
-
// (undocumented)
|
|
38
|
-
children: ReactNode;
|
|
39
|
-
// (undocumented)
|
|
40
|
-
className?: string;
|
|
41
|
-
// (undocumented)
|
|
42
|
-
id?: string;
|
|
43
|
-
// (undocumented)
|
|
44
|
-
onMouseOut?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
45
|
-
// (undocumented)
|
|
46
|
-
onMouseOver?: (e: React.MouseEvent<HTMLElement>) => void;
|
|
47
|
-
// (undocumented)
|
|
48
|
-
placement: PositionType;
|
|
49
|
-
// (undocumented)
|
|
50
|
-
ref: React.Ref<any>;
|
|
51
|
-
// (undocumented)
|
|
52
|
-
style?: CSSProperties;
|
|
53
|
-
// (undocumented)
|
|
54
|
-
testId?: string;
|
|
55
|
-
// (undocumented)
|
|
56
|
-
truncate?: boolean;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// @public (undocumented)
|
|
60
|
-
export interface TooltipProps {
|
|
61
|
-
analyticsContext?: Record<string, any>;
|
|
62
|
-
children: ((props: TriggerProps) => ReactNode) | ReactNode;
|
|
63
|
-
component?: ComponentType<TooltipPrimitiveProps>;
|
|
64
|
-
content: (({ update }: {
|
|
65
|
-
update: () => void;
|
|
66
|
-
}) => ReactNode) | ReactNode;
|
|
67
|
-
delay?: number;
|
|
68
|
-
hideTooltipOnClick?: boolean;
|
|
69
|
-
hideTooltipOnMouseDown?: boolean;
|
|
70
|
-
mousePosition?: PositionTypeBase;
|
|
71
|
-
onHide?: (analyticsEvent: UIAnalyticsEvent) => void;
|
|
72
|
-
onShow?: (analyticsEvent: UIAnalyticsEvent) => void;
|
|
73
|
-
position?: PositionType;
|
|
74
|
-
strategy?: 'absolute' | 'fixed' | undefined;
|
|
75
|
-
tag?: React.ComponentType<React.AllHTMLAttributes<HTMLElement> & {
|
|
76
|
-
ref: React.Ref<HTMLElement>;
|
|
77
|
-
}> | keyof JSX.IntrinsicElements;
|
|
78
|
-
testId?: string;
|
|
79
|
-
truncate?: boolean;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// @public (undocumented)
|
|
83
|
-
interface TriggerProps {
|
|
84
|
-
// (undocumented)
|
|
85
|
-
'aria-describedby'?: string | undefined;
|
|
86
|
-
// (undocumented)
|
|
87
|
-
onBlur: (event: React.FocusEvent<HTMLElement>) => void;
|
|
88
|
-
// (undocumented)
|
|
89
|
-
onClick: (event: React.MouseEvent<HTMLElement>) => void;
|
|
90
|
-
// (undocumented)
|
|
91
|
-
onFocus: (event: React.FocusEvent<HTMLElement>) => void;
|
|
92
|
-
// (undocumented)
|
|
93
|
-
onMouseDown: (event: React.MouseEvent<HTMLElement>) => void;
|
|
94
|
-
// (undocumented)
|
|
95
|
-
onMouseMove: ((event: React.MouseEvent<HTMLElement>) => void) | undefined;
|
|
96
|
-
// (undocumented)
|
|
97
|
-
onMouseOut: (event: React.MouseEvent<HTMLElement>) => void;
|
|
98
|
-
// (undocumented)
|
|
99
|
-
onMouseOver: (event: React.MouseEvent<HTMLElement>) => void;
|
|
100
|
-
// (undocumented)
|
|
101
|
-
ref: (node: HTMLElement | null) => void;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// (No @packageDocumentation comment for this package)
|
|
105
|
-
|
|
106
|
-
```
|