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.cjs
CHANGED
|
@@ -333,9 +333,10 @@ var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_ar
|
|
|
333
333
|
|
|
334
334
|
const Tooltip = ({
|
|
335
335
|
// props
|
|
336
|
-
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,
|
|
336
|
+
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,
|
|
337
337
|
// props handled by controller
|
|
338
338
|
content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
|
|
339
|
+
var _a;
|
|
339
340
|
const tooltipRef = React.useRef(null);
|
|
340
341
|
const tooltipArrowRef = React.useRef(null);
|
|
341
342
|
const tooltipShowDelayTimerRef = React.useRef(null);
|
|
@@ -345,6 +346,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
345
346
|
const [inlineArrowStyles, setInlineArrowStyles] = React.useState({});
|
|
346
347
|
const [show, setShow] = React.useState(false);
|
|
347
348
|
const [rendered, setRendered] = React.useState(false);
|
|
349
|
+
const [imperativeOptions, setImperativeOptions] = React.useState(null);
|
|
348
350
|
const wasShowing = React.useRef(false);
|
|
349
351
|
const lastFloatPosition = React.useRef(null);
|
|
350
352
|
/**
|
|
@@ -381,6 +383,8 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
381
383
|
mouseleave: true,
|
|
382
384
|
blur: true,
|
|
383
385
|
click: false,
|
|
386
|
+
dblclick: false,
|
|
387
|
+
mouseup: false,
|
|
384
388
|
};
|
|
385
389
|
if (!closeEvents && shouldOpenOnClick) {
|
|
386
390
|
Object.assign(actualCloseEvents, {
|
|
@@ -396,6 +400,28 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
396
400
|
resize: closeOnResize || false,
|
|
397
401
|
clickOutsideAnchor: hasClickEvent || false,
|
|
398
402
|
};
|
|
403
|
+
if (imperativeModeOnly) {
|
|
404
|
+
Object.assign(actualOpenEvents, {
|
|
405
|
+
mouseenter: false,
|
|
406
|
+
focus: false,
|
|
407
|
+
click: false,
|
|
408
|
+
dblclick: false,
|
|
409
|
+
mousedown: false,
|
|
410
|
+
});
|
|
411
|
+
Object.assign(actualCloseEvents, {
|
|
412
|
+
mouseleave: false,
|
|
413
|
+
blur: false,
|
|
414
|
+
click: false,
|
|
415
|
+
dblclick: false,
|
|
416
|
+
mouseup: false,
|
|
417
|
+
});
|
|
418
|
+
Object.assign(actualGlobalCloseEvents, {
|
|
419
|
+
escape: false,
|
|
420
|
+
scroll: false,
|
|
421
|
+
resize: false,
|
|
422
|
+
clickOutsideAnchor: false,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
399
425
|
/**
|
|
400
426
|
* useLayoutEffect runs before useEffect,
|
|
401
427
|
* but should be used carefully because of caveats
|
|
@@ -454,17 +480,14 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
454
480
|
if (show) {
|
|
455
481
|
afterShow === null || afterShow === void 0 ? void 0 : afterShow();
|
|
456
482
|
}
|
|
457
|
-
else {
|
|
458
|
-
afterHide === null || afterHide === void 0 ? void 0 : afterHide();
|
|
459
|
-
}
|
|
460
483
|
}, [show]);
|
|
461
|
-
const handleShowTooltipDelayed = () => {
|
|
484
|
+
const handleShowTooltipDelayed = (delay = delayShow) => {
|
|
462
485
|
if (tooltipShowDelayTimerRef.current) {
|
|
463
486
|
clearTimeout(tooltipShowDelayTimerRef.current);
|
|
464
487
|
}
|
|
465
488
|
tooltipShowDelayTimerRef.current = setTimeout(() => {
|
|
466
489
|
handleShow(true);
|
|
467
|
-
},
|
|
490
|
+
}, delay);
|
|
468
491
|
};
|
|
469
492
|
const handleHideTooltipDelayed = (delay = delayHide) => {
|
|
470
493
|
if (tooltipHideDelayTimerRef.current) {
|
|
@@ -520,6 +543,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
520
543
|
}
|
|
521
544
|
};
|
|
522
545
|
const handleTooltipPosition = ({ x, y }) => {
|
|
546
|
+
var _a;
|
|
523
547
|
const virtualElement = {
|
|
524
548
|
getBoundingClientRect() {
|
|
525
549
|
return {
|
|
@@ -535,7 +559,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
535
559
|
},
|
|
536
560
|
};
|
|
537
561
|
computeTooltipPosition({
|
|
538
|
-
place,
|
|
562
|
+
place: (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place) !== null && _a !== void 0 ? _a : place,
|
|
539
563
|
offset,
|
|
540
564
|
elementReference: virtualElement,
|
|
541
565
|
tooltipReference: tooltipRef.current,
|
|
@@ -567,12 +591,16 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
567
591
|
};
|
|
568
592
|
const handleClickOutsideAnchors = (event) => {
|
|
569
593
|
var _a;
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
594
|
+
if (!show) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
const target = event.target;
|
|
598
|
+
if ((_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) {
|
|
573
599
|
return;
|
|
574
600
|
}
|
|
575
|
-
|
|
601
|
+
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
602
|
+
const anchors = [anchorById, ...anchorsBySelect];
|
|
603
|
+
if (anchors.some((anchor) => anchor === null || anchor === void 0 ? void 0 : anchor.contains(target))) {
|
|
576
604
|
return;
|
|
577
605
|
}
|
|
578
606
|
handleShow(false);
|
|
@@ -585,9 +613,11 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
585
613
|
const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
|
|
586
614
|
const debouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true);
|
|
587
615
|
const updateTooltipPosition = React.useCallback(() => {
|
|
588
|
-
|
|
616
|
+
var _a, _b;
|
|
617
|
+
const actualPosition = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position) !== null && _a !== void 0 ? _a : position;
|
|
618
|
+
if (actualPosition) {
|
|
589
619
|
// if `position` is set, override regular and `float` positioning
|
|
590
|
-
handleTooltipPosition(
|
|
620
|
+
handleTooltipPosition(actualPosition);
|
|
591
621
|
return;
|
|
592
622
|
}
|
|
593
623
|
if (float) {
|
|
@@ -608,7 +638,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
608
638
|
return;
|
|
609
639
|
}
|
|
610
640
|
computeTooltipPosition({
|
|
611
|
-
place,
|
|
641
|
+
place: (_b = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place) !== null && _b !== void 0 ? _b : place,
|
|
612
642
|
offset,
|
|
613
643
|
elementReference: activeAnchor,
|
|
614
644
|
tooltipReference: tooltipRef.current,
|
|
@@ -635,9 +665,11 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
635
665
|
content,
|
|
636
666
|
externalStyles,
|
|
637
667
|
place,
|
|
668
|
+
imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.place,
|
|
638
669
|
offset,
|
|
639
670
|
positionStrategy,
|
|
640
671
|
position,
|
|
672
|
+
imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.position,
|
|
641
673
|
float,
|
|
642
674
|
]);
|
|
643
675
|
React.useEffect(() => {
|
|
@@ -794,7 +826,8 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
794
826
|
shouldOpenOnClick,
|
|
795
827
|
]);
|
|
796
828
|
React.useEffect(() => {
|
|
797
|
-
|
|
829
|
+
var _a, _b;
|
|
830
|
+
let selector = (_b = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect) !== null && _b !== void 0 ? _b : '';
|
|
798
831
|
if (!selector && id) {
|
|
799
832
|
selector = `[data-tooltip-id='${id}']`;
|
|
800
833
|
}
|
|
@@ -883,7 +916,7 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
883
916
|
return () => {
|
|
884
917
|
documentObserver.disconnect();
|
|
885
918
|
};
|
|
886
|
-
}, [id, anchorSelect, activeAnchor]);
|
|
919
|
+
}, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect, activeAnchor]);
|
|
887
920
|
React.useEffect(() => {
|
|
888
921
|
updateTooltipPosition();
|
|
889
922
|
}, [updateTooltipPosition]);
|
|
@@ -923,7 +956,8 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
923
956
|
};
|
|
924
957
|
}, []);
|
|
925
958
|
React.useEffect(() => {
|
|
926
|
-
|
|
959
|
+
var _a;
|
|
960
|
+
let selector = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect) !== null && _a !== void 0 ? _a : anchorSelect;
|
|
927
961
|
if (!selector && id) {
|
|
928
962
|
selector = `[data-tooltip-id='${id}']`;
|
|
929
963
|
}
|
|
@@ -934,13 +968,48 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
934
968
|
const anchors = Array.from(document.querySelectorAll(selector));
|
|
935
969
|
setAnchorsBySelect(anchors);
|
|
936
970
|
}
|
|
937
|
-
catch (
|
|
971
|
+
catch (_b) {
|
|
938
972
|
// warning was already issued in the controller
|
|
939
973
|
setAnchorsBySelect([]);
|
|
940
974
|
}
|
|
941
|
-
}, [id, anchorSelect]);
|
|
975
|
+
}, [id, anchorSelect, imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.anchorSelect]);
|
|
976
|
+
const actualContent = (_a = imperativeOptions === null || imperativeOptions === void 0 ? void 0 : imperativeOptions.content) !== null && _a !== void 0 ? _a : content;
|
|
942
977
|
const canShow = show && Object.keys(inlineStyles).length > 0;
|
|
943
|
-
|
|
978
|
+
React.useImperativeHandle(forwardRef, () => ({
|
|
979
|
+
open: (options) => {
|
|
980
|
+
if (options === null || options === void 0 ? void 0 : options.anchorSelect) {
|
|
981
|
+
try {
|
|
982
|
+
document.querySelector(options.anchorSelect);
|
|
983
|
+
}
|
|
984
|
+
catch (_a) {
|
|
985
|
+
{
|
|
986
|
+
// eslint-disable-next-line no-console
|
|
987
|
+
console.warn(`[react-tooltip] "${options.anchorSelect}" is not a valid CSS selector`);
|
|
988
|
+
}
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
setImperativeOptions(options !== null && options !== void 0 ? options : null);
|
|
993
|
+
if (options === null || options === void 0 ? void 0 : options.delay) {
|
|
994
|
+
handleShowTooltipDelayed(options.delay);
|
|
995
|
+
}
|
|
996
|
+
else {
|
|
997
|
+
handleShow(true);
|
|
998
|
+
}
|
|
999
|
+
},
|
|
1000
|
+
close: (options) => {
|
|
1001
|
+
if (options === null || options === void 0 ? void 0 : options.delay) {
|
|
1002
|
+
handleHideTooltipDelayed(options.delay);
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
handleShow(false);
|
|
1006
|
+
}
|
|
1007
|
+
},
|
|
1008
|
+
activeAnchor,
|
|
1009
|
+
place: actualPlacement,
|
|
1010
|
+
isOpen: Boolean(rendered && !hidden && actualContent && canShow),
|
|
1011
|
+
}));
|
|
1012
|
+
return rendered && !hidden && actualContent ? (React__default["default"].createElement(WrapperElement, { id: id, role: "tooltip", className: classNames__default["default"]('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) => {
|
|
944
1013
|
/**
|
|
945
1014
|
* @warning if `--rt-transition-closing-delay` is set to 0,
|
|
946
1015
|
* the tooltip will be stuck (but not visible) on the DOM
|
|
@@ -949,12 +1018,14 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
949
1018
|
return;
|
|
950
1019
|
}
|
|
951
1020
|
setRendered(false);
|
|
1021
|
+
setImperativeOptions(null);
|
|
1022
|
+
afterHide === null || afterHide === void 0 ? void 0 : afterHide();
|
|
952
1023
|
}, style: {
|
|
953
1024
|
...externalStyles,
|
|
954
1025
|
...inlineStyles,
|
|
955
1026
|
opacity: opacity !== undefined && canShow ? opacity : undefined,
|
|
956
1027
|
}, ref: tooltipRef },
|
|
957
|
-
|
|
1028
|
+
actualContent,
|
|
958
1029
|
React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, noArrow && coreStyles['noArrow']), style: {
|
|
959
1030
|
...inlineArrowStyles,
|
|
960
1031
|
background: arrowColor
|
|
@@ -968,7 +1039,12 @@ const TooltipContent = ({ content }) => {
|
|
|
968
1039
|
return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
|
|
969
1040
|
};
|
|
970
1041
|
|
|
971
|
-
const
|
|
1042
|
+
const cssSupports = (property, value) => {
|
|
1043
|
+
const hasCssSupports = 'CSS' in window && 'supports' in window.CSS;
|
|
1044
|
+
return hasCssSupports ? window.CSS.supports(property, value) : true;
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
const TooltipController = React__default["default"].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) => {
|
|
972
1048
|
const [tooltipContent, setTooltipContent] = React.useState(content);
|
|
973
1049
|
const [tooltipHtml, setTooltipHtml] = React.useState(html);
|
|
974
1050
|
const [tooltipPlace, setTooltipPlace] = React.useState(place);
|
|
@@ -1162,7 +1238,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1162
1238
|
// eslint-disable-next-line no-console
|
|
1163
1239
|
console.warn('[react-tooltip] Do not set `style.border`. Use `border` prop instead.');
|
|
1164
1240
|
}
|
|
1165
|
-
if (border && !
|
|
1241
|
+
if (border && !cssSupports('border', `${border}`)) {
|
|
1166
1242
|
// eslint-disable-next-line no-console
|
|
1167
1243
|
console.warn(`[react-tooltip] "${border}" is not a valid \`border\`.`);
|
|
1168
1244
|
}
|
|
@@ -1170,7 +1246,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1170
1246
|
// eslint-disable-next-line no-console
|
|
1171
1247
|
console.warn('[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead.');
|
|
1172
1248
|
}
|
|
1173
|
-
if (opacity && !
|
|
1249
|
+
if (opacity && !cssSupports('opacity', `${opacity}`)) {
|
|
1174
1250
|
// eslint-disable-next-line no-console
|
|
1175
1251
|
console.warn(`[react-tooltip] "${opacity}" is not a valid \`opacity\`.`);
|
|
1176
1252
|
}
|
|
@@ -1192,6 +1268,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1192
1268
|
renderedContent = React__default["default"].createElement(TooltipContent, { content: tooltipHtml });
|
|
1193
1269
|
}
|
|
1194
1270
|
const props = {
|
|
1271
|
+
forwardRef: ref,
|
|
1195
1272
|
id,
|
|
1196
1273
|
anchorId,
|
|
1197
1274
|
anchorSelect,
|
|
@@ -1219,6 +1296,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1219
1296
|
openEvents,
|
|
1220
1297
|
closeEvents,
|
|
1221
1298
|
globalCloseEvents,
|
|
1299
|
+
imperativeModeOnly,
|
|
1222
1300
|
style,
|
|
1223
1301
|
position,
|
|
1224
1302
|
isOpen,
|
|
@@ -1232,7 +1310,7 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1232
1310
|
setActiveAnchor: (anchor) => setActiveAnchor(anchor),
|
|
1233
1311
|
};
|
|
1234
1312
|
return React__default["default"].createElement(Tooltip, { ...props });
|
|
1235
|
-
};
|
|
1313
|
+
});
|
|
1236
1314
|
|
|
1237
1315
|
// those content will be replaced in build time with the `react-tooltip.css` builded content
|
|
1238
1316
|
const TooltipCoreStyles = `:root {
|