react-tooltip 5.22.1-beta.1118.0 → 5.23.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/dist/react-tooltip.cjs +103 -25
- package/dist/react-tooltip.cjs.map +1 -1
- package/dist/react-tooltip.d.ts +42 -2
- package/dist/react-tooltip.min.cjs +2 -2
- package/dist/react-tooltip.min.cjs.map +1 -1
- package/dist/react-tooltip.min.mjs +2 -2
- package/dist/react-tooltip.min.mjs.map +1 -1
- package/dist/react-tooltip.mjs +104 -26
- package/dist/react-tooltip.mjs.map +1 -1
- package/dist/react-tooltip.umd.js +103 -25
- package/dist/react-tooltip.umd.js.map +1 -1
- package/dist/react-tooltip.umd.min.js +2 -2
- package/dist/react-tooltip.umd.min.js.map +1 -1
- package/package.json +1 -1
package/dist/react-tooltip.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright ReactTooltip Team
|
|
6
6
|
* @license MIT
|
|
7
7
|
*/
|
|
8
|
-
import React, { createContext, useState, useCallback, useMemo, useContext, useRef, useEffect, useLayoutEffect } from 'react';
|
|
8
|
+
import React, { createContext, useState, useCallback, useMemo, useContext, useRef, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
|
|
9
9
|
import { arrow, computePosition, offset, flip, shift, autoUpdate } from '@floating-ui/dom';
|
|
10
10
|
import classNames from 'classnames';
|
|
11
11
|
|
|
@@ -324,9 +324,10 @@ var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_ar
|
|
|
324
324
|
|
|
325
325
|
const Tooltip = ({
|
|
326
326
|
// props
|
|
327
|
-
id, className, classNameArrow, variant = 'dark', anchorId, anchorSelect, place = 'top', offset = 10, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, wrapper: WrapperElement, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, openEvents, closeEvents, globalCloseEvents, style: externalStyles, position, afterShow, afterHide,
|
|
327
|
+
forwardRef, id, className, classNameArrow, variant = 'dark', anchorId, anchorSelect, place = 'top', offset = 10, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, wrapper: WrapperElement, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly, style: externalStyles, position, afterShow, afterHide,
|
|
328
328
|
// props handled by controller
|
|
329
329
|
content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
|
|
330
|
+
var _a;
|
|
330
331
|
const tooltipRef = useRef(null);
|
|
331
332
|
const tooltipArrowRef = useRef(null);
|
|
332
333
|
const tooltipShowDelayTimerRef = useRef(null);
|
|
@@ -336,6 +337,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
336
337
|
const [inlineArrowStyles, setInlineArrowStyles] = useState({});
|
|
337
338
|
const [show, setShow] = useState(false);
|
|
338
339
|
const [rendered, setRendered] = useState(false);
|
|
340
|
+
const [imperativeOptions, setImperativeOptions] = useState(null);
|
|
339
341
|
const wasShowing = useRef(false);
|
|
340
342
|
const lastFloatPosition = useRef(null);
|
|
341
343
|
/**
|
|
@@ -372,6 +374,8 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
372
374
|
mouseleave: true,
|
|
373
375
|
blur: true,
|
|
374
376
|
click: false,
|
|
377
|
+
dblclick: false,
|
|
378
|
+
mouseup: false,
|
|
375
379
|
};
|
|
376
380
|
if (!closeEvents && shouldOpenOnClick) {
|
|
377
381
|
Object.assign(actualCloseEvents, {
|
|
@@ -387,6 +391,28 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
387
391
|
resize: closeOnResize || false,
|
|
388
392
|
clickOutsideAnchor: hasClickEvent || false,
|
|
389
393
|
};
|
|
394
|
+
if (imperativeModeOnly) {
|
|
395
|
+
Object.assign(actualOpenEvents, {
|
|
396
|
+
mouseenter: false,
|
|
397
|
+
focus: false,
|
|
398
|
+
click: false,
|
|
399
|
+
dblclick: false,
|
|
400
|
+
mousedown: false,
|
|
401
|
+
});
|
|
402
|
+
Object.assign(actualCloseEvents, {
|
|
403
|
+
mouseleave: false,
|
|
404
|
+
blur: false,
|
|
405
|
+
click: false,
|
|
406
|
+
dblclick: false,
|
|
407
|
+
mouseup: false,
|
|
408
|
+
});
|
|
409
|
+
Object.assign(actualGlobalCloseEvents, {
|
|
410
|
+
escape: false,
|
|
411
|
+
scroll: false,
|
|
412
|
+
resize: false,
|
|
413
|
+
clickOutsideAnchor: false,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
390
416
|
/**
|
|
391
417
|
* useLayoutEffect runs before useEffect,
|
|
392
418
|
* but should be used carefully because of caveats
|
|
@@ -445,17 +471,14 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
445
471
|
if (show) {
|
|
446
472
|
afterShow === null || afterShow === void 0 ? void 0 : afterShow();
|
|
447
473
|
}
|
|
448
|
-
else {
|
|
449
|
-
afterHide === null || afterHide === void 0 ? void 0 : afterHide();
|
|
450
|
-
}
|
|
451
474
|
}, [show]);
|
|
452
|
-
const handleShowTooltipDelayed = () => {
|
|
475
|
+
const handleShowTooltipDelayed = (delay = delayShow) => {
|
|
453
476
|
if (tooltipShowDelayTimerRef.current) {
|
|
454
477
|
clearTimeout(tooltipShowDelayTimerRef.current);
|
|
455
478
|
}
|
|
456
479
|
tooltipShowDelayTimerRef.current = setTimeout(() => {
|
|
457
480
|
handleShow(true);
|
|
458
|
-
},
|
|
481
|
+
}, delay);
|
|
459
482
|
};
|
|
460
483
|
const handleHideTooltipDelayed = (delay = delayHide) => {
|
|
461
484
|
if (tooltipHideDelayTimerRef.current) {
|
|
@@ -511,6 +534,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
511
534
|
}
|
|
512
535
|
};
|
|
513
536
|
const handleTooltipPosition = ({ x, y }) => {
|
|
537
|
+
var _a;
|
|
514
538
|
const virtualElement = {
|
|
515
539
|
getBoundingClientRect() {
|
|
516
540
|
return {
|
|
@@ -526,7 +550,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
526
550
|
},
|
|
527
551
|
};
|
|
528
552
|
computeTooltipPosition({
|
|
529
|
-
place,
|
|
553
|
+
place: (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place) !== null && _a !== void 0 ? _a : place,
|
|
530
554
|
offset,
|
|
531
555
|
elementReference: virtualElement,
|
|
532
556
|
tooltipReference: tooltipRef.current,
|
|
@@ -558,12 +582,16 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
558
582
|
};
|
|
559
583
|
const handleClickOutsideAnchors = (event) => {
|
|
560
584
|
var _a;
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
585
|
+
if (!show) {
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
const target = event.target;
|
|
589
|
+
if ((_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) {
|
|
564
590
|
return;
|
|
565
591
|
}
|
|
566
|
-
|
|
592
|
+
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
593
|
+
const anchors = [anchorById, ...anchorsBySelect];
|
|
594
|
+
if (anchors.some((anchor) => anchor === null || anchor === void 0 ? void 0 : anchor.contains(target))) {
|
|
567
595
|
return;
|
|
568
596
|
}
|
|
569
597
|
handleShow(false);
|
|
@@ -576,9 +604,11 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
576
604
|
const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
|
|
577
605
|
const debouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true);
|
|
578
606
|
const updateTooltipPosition = useCallback(() => {
|
|
579
|
-
|
|
607
|
+
var _a, _b;
|
|
608
|
+
const actualPosition = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position) !== null && _a !== void 0 ? _a : position;
|
|
609
|
+
if (actualPosition) {
|
|
580
610
|
// if `position` is set, override regular and `float` positioning
|
|
581
|
-
handleTooltipPosition(
|
|
611
|
+
handleTooltipPosition(actualPosition);
|
|
582
612
|
return;
|
|
583
613
|
}
|
|
584
614
|
if (float) {
|
|
@@ -599,7 +629,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
599
629
|
return;
|
|
600
630
|
}
|
|
601
631
|
computeTooltipPosition({
|
|
602
|
-
place,
|
|
632
|
+
place: (_b = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place) !== null && _b !== void 0 ? _b : place,
|
|
603
633
|
offset,
|
|
604
634
|
elementReference: activeAnchor,
|
|
605
635
|
tooltipReference: tooltipRef.current,
|
|
@@ -626,9 +656,11 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
626
656
|
content,
|
|
627
657
|
externalStyles,
|
|
628
658
|
place,
|
|
659
|
+
imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place,
|
|
629
660
|
offset,
|
|
630
661
|
positionStrategy,
|
|
631
662
|
position,
|
|
663
|
+
imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position,
|
|
632
664
|
float,
|
|
633
665
|
]);
|
|
634
666
|
useEffect(() => {
|
|
@@ -785,7 +817,8 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
785
817
|
shouldOpenOnClick,
|
|
786
818
|
]);
|
|
787
819
|
useEffect(() => {
|
|
788
|
-
|
|
820
|
+
var _a, _b;
|
|
821
|
+
let selector = (_b = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect) !== null && _b !== void 0 ? _b : '';
|
|
789
822
|
if (!selector && id) {
|
|
790
823
|
selector = `[data-tooltip-id='${id}']`;
|
|
791
824
|
}
|
|
@@ -874,7 +907,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
874
907
|
return () => {
|
|
875
908
|
documentObserver.disconnect();
|
|
876
909
|
};
|
|
877
|
-
}, [id, anchorSelect, activeAnchor]);
|
|
910
|
+
}, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect, activeAnchor]);
|
|
878
911
|
useEffect(() => {
|
|
879
912
|
updateTooltipPosition();
|
|
880
913
|
}, [updateTooltipPosition]);
|
|
@@ -914,7 +947,8 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
914
947
|
};
|
|
915
948
|
}, []);
|
|
916
949
|
useEffect(() => {
|
|
917
|
-
|
|
950
|
+
var _a;
|
|
951
|
+
let selector = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect;
|
|
918
952
|
if (!selector && id) {
|
|
919
953
|
selector = `[data-tooltip-id='${id}']`;
|
|
920
954
|
}
|
|
@@ -925,13 +959,48 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
925
959
|
const anchors = Array.from(document.querySelectorAll(selector));
|
|
926
960
|
setAnchorsBySelect(anchors);
|
|
927
961
|
}
|
|
928
|
-
catch (
|
|
962
|
+
catch (_b) {
|
|
929
963
|
// warning was already issued in the controller
|
|
930
964
|
setAnchorsBySelect([]);
|
|
931
965
|
}
|
|
932
|
-
}, [id, anchorSelect]);
|
|
966
|
+
}, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
|
|
967
|
+
const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
|
|
933
968
|
const canShow = show && Object.keys(inlineStyles).length > 0;
|
|
934
|
-
|
|
969
|
+
useImperativeHandle(forwardRef, () => ({
|
|
970
|
+
open: (options) => {
|
|
971
|
+
if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
|
|
972
|
+
try {
|
|
973
|
+
document.querySelector(options.anchorSelect);
|
|
974
|
+
}
|
|
975
|
+
catch (_a) {
|
|
976
|
+
{
|
|
977
|
+
// eslint-disable-next-line no-console
|
|
978
|
+
console.warn(`[react-tooltip] "${options.anchorSelect}" is not a valid CSS selector`);
|
|
979
|
+
}
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
setImperativeOptions(options !== null && options !== void 0 ? options : null);
|
|
984
|
+
if (options === null || options === void 0 ? void 0 : options.delay) {
|
|
985
|
+
handleShowTooltipDelayed(options.delay);
|
|
986
|
+
}
|
|
987
|
+
else {
|
|
988
|
+
handleShow(true);
|
|
989
|
+
}
|
|
990
|
+
},
|
|
991
|
+
close: (options) => {
|
|
992
|
+
if (options === null || options === void 0 ? void 0 : options.delay) {
|
|
993
|
+
handleHideTooltipDelayed(options.delay);
|
|
994
|
+
}
|
|
995
|
+
else {
|
|
996
|
+
handleShow(false);
|
|
997
|
+
}
|
|
998
|
+
},
|
|
999
|
+
activeAnchor,
|
|
1000
|
+
place: actualPlacement,
|
|
1001
|
+
isOpen: Boolean(rendered && !hidden && actualContent && canShow),
|
|
1002
|
+
}));
|
|
1003
|
+
return rendered && !hidden && actualContent ? (React.createElement(WrapperElement, { id: id, role: "tooltip", className: classNames('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, coreStyles[canShow ? 'show' : 'closing'], canShow ? 'react-tooltip__show' : 'react-tooltip__closing', positionStrategy === 'fixed' && coreStyles['fixed'], clickable && coreStyles['clickable']), onTransitionEnd: (event) => {
|
|
935
1004
|
/**
|
|
936
1005
|
* @warning if `--rt-transition-closing-delay` is set to 0,
|
|
937
1006
|
* the tooltip will be stuck (but not visible) on the DOM
|
|
@@ -940,12 +1009,14 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
940
1009
|
return;
|
|
941
1010
|
}
|
|
942
1011
|
setRendered(false);
|
|
1012
|
+
setImperativeOptions(null);
|
|
1013
|
+
afterHide === null || afterHide === void 0 ? void 0 : afterHide();
|
|
943
1014
|
}, style: {
|
|
944
1015
|
...externalStyles,
|
|
945
1016
|
...inlineStyles,
|
|
946
1017
|
opacity: opacity !== undefined && canShow ? opacity : undefined,
|
|
947
1018
|
}, ref: tooltipRef },
|
|
948
|
-
|
|
1019
|
+
actualContent,
|
|
949
1020
|
React.createElement(WrapperElement, { className: classNames('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
|
|
950
1021
|
...inlineArrowStyles,
|
|
951
1022
|
background: arrowColor
|
|
@@ -959,7 +1030,12 @@ const TooltipContent = ({ content }) => {
|
|
|
959
1030
|
return React.createElement("span", { dangerouslySetInnerHTML: { __html: content } });
|
|
960
1031
|
};
|
|
961
1032
|
|
|
962
|
-
const
|
|
1033
|
+
const cssSupports = (property, value) => {
|
|
1034
|
+
const hasCssSupports = 'CSS' in window && 'supports' in window.CSS;
|
|
1035
|
+
return hasCssSupports ? window.CSS.supports(property, value) : true;
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
const TooltipController = React.forwardRef(({ id, anchorId, anchorSelect, content, html, render, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], openOnClick = false, positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, hidden = false, noArrow = false, clickable = false, closeOnEsc = false, closeOnScroll = false, closeOnResize = false, openEvents, closeEvents, globalCloseEvents, imperativeModeOnly = false, style, position, isOpen, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, }, ref) => {
|
|
963
1039
|
const [tooltipContent, setTooltipContent] = useState(content);
|
|
964
1040
|
const [tooltipHtml, setTooltipHtml] = useState(html);
|
|
965
1041
|
const [tooltipPlace, setTooltipPlace] = useState(place);
|
|
@@ -1153,7 +1229,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1153
1229
|
// eslint-disable-next-line no-console
|
|
1154
1230
|
console.warn('[react-tooltip] Do not set `style.border`. Use `border` prop instead.');
|
|
1155
1231
|
}
|
|
1156
|
-
if (border && !
|
|
1232
|
+
if (border && !cssSupports('border', `${border}`)) {
|
|
1157
1233
|
// eslint-disable-next-line no-console
|
|
1158
1234
|
console.warn(`[react-tooltip] "${border}" is not a valid \`border\`.`);
|
|
1159
1235
|
}
|
|
@@ -1161,7 +1237,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1161
1237
|
// eslint-disable-next-line no-console
|
|
1162
1238
|
console.warn('[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead.');
|
|
1163
1239
|
}
|
|
1164
|
-
if (opacity && !
|
|
1240
|
+
if (opacity && !cssSupports('opacity', `${opacity}`)) {
|
|
1165
1241
|
// eslint-disable-next-line no-console
|
|
1166
1242
|
console.warn(`[react-tooltip] "${opacity}" is not a valid \`opacity\`.`);
|
|
1167
1243
|
}
|
|
@@ -1183,6 +1259,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1183
1259
|
renderedContent = React.createElement(TooltipContent, { content: tooltipHtml });
|
|
1184
1260
|
}
|
|
1185
1261
|
const props = {
|
|
1262
|
+
forwardRef: ref,
|
|
1186
1263
|
id,
|
|
1187
1264
|
anchorId,
|
|
1188
1265
|
anchorSelect,
|
|
@@ -1210,6 +1287,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1210
1287
|
openEvents,
|
|
1211
1288
|
closeEvents,
|
|
1212
1289
|
globalCloseEvents,
|
|
1290
|
+
imperativeModeOnly,
|
|
1213
1291
|
style,
|
|
1214
1292
|
position,
|
|
1215
1293
|
isOpen,
|
|
@@ -1223,7 +1301,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1223
1301
|
setActiveAnchor: (anchor) => setActiveAnchor(anchor),
|
|
1224
1302
|
};
|
|
1225
1303
|
return React.createElement(Tooltip, { ...props });
|
|
1226
|
-
};
|
|
1304
|
+
});
|
|
1227
1305
|
|
|
1228
1306
|
// those content will be replaced in build time with the `react-tooltip.css` builded content
|
|
1229
1307
|
const TooltipCoreStyles = `:root {
|