react-tooltip 5.22.0-beta.1106.0 → 5.22.0-beta.1108.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-tokens.css +0 -2
- package/dist/react-tooltip.cjs +141 -50
- package/dist/react-tooltip.cjs.map +1 -1
- package/dist/react-tooltip.css +4 -9
- package/dist/react-tooltip.d.ts +38 -5
- package/dist/react-tooltip.min.cjs +2 -2
- package/dist/react-tooltip.min.cjs.map +1 -1
- package/dist/react-tooltip.min.css +1 -1
- package/dist/react-tooltip.min.mjs +2 -2
- package/dist/react-tooltip.min.mjs.map +1 -1
- package/dist/react-tooltip.mjs +141 -50
- package/dist/react-tooltip.mjs.map +1 -1
- package/dist/react-tooltip.umd.js +141 -50
- 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
|
@@ -318,13 +318,13 @@ const computeTooltipPosition = async ({ elementReference = null, tooltipReferenc
|
|
|
318
318
|
});
|
|
319
319
|
};
|
|
320
320
|
|
|
321
|
-
var coreStyles = {"tooltip":"core-styles-module_tooltip__3vRRp","fixed":"core-styles-module_fixed__pcSol","arrow":"core-styles-module_arrow__cvMwQ","noArrow":"core-styles-module_noArrow__xock6","clickable":"core-styles-module_clickable__ZuTTB","show":"core-styles-module_show__Nt9eE"
|
|
321
|
+
var coreStyles = {"tooltip":"core-styles-module_tooltip__3vRRp","fixed":"core-styles-module_fixed__pcSol","arrow":"core-styles-module_arrow__cvMwQ","noArrow":"core-styles-module_noArrow__xock6","clickable":"core-styles-module_clickable__ZuTTB","show":"core-styles-module_show__Nt9eE"};
|
|
322
322
|
|
|
323
323
|
var styles = {"tooltip":"styles-module_tooltip__mnnfp","arrow":"styles-module_arrow__K0L3T","dark":"styles-module_dark__xNqje","light":"styles-module_light__Z6W-X","success":"styles-module_success__A2AKt","warning":"styles-module_warning__SCK0X","error":"styles-module_error__JvumD","info":"styles-module_info__BWdHW"};
|
|
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, style: externalStyles, position, afterShow, afterHide,
|
|
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,
|
|
328
328
|
// props handled by controller
|
|
329
329
|
content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
|
|
330
330
|
const tooltipRef = useRef(null);
|
|
@@ -345,7 +345,48 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
345
345
|
const hoveringTooltip = useRef(false);
|
|
346
346
|
const [anchorsBySelect, setAnchorsBySelect] = useState([]);
|
|
347
347
|
const mounted = useRef(false);
|
|
348
|
+
/**
|
|
349
|
+
* @todo Update when deprecated stuff gets removed.
|
|
350
|
+
*/
|
|
348
351
|
const shouldOpenOnClick = openOnClick || events.includes('click');
|
|
352
|
+
const hasClickEvent = shouldOpenOnClick || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.click) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.dblclick) || (openEvents === null || openEvents === void 0 ? void 0 : openEvents.mousedown);
|
|
353
|
+
const actualOpenEvents = openEvents
|
|
354
|
+
? { ...openEvents }
|
|
355
|
+
: {
|
|
356
|
+
mouseenter: true,
|
|
357
|
+
focus: true,
|
|
358
|
+
click: false,
|
|
359
|
+
dblclick: false,
|
|
360
|
+
mousedown: false,
|
|
361
|
+
};
|
|
362
|
+
if (!openEvents && shouldOpenOnClick) {
|
|
363
|
+
Object.assign(actualOpenEvents, {
|
|
364
|
+
mouseenter: false,
|
|
365
|
+
focus: false,
|
|
366
|
+
click: true,
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
const actualCloseEvents = closeEvents
|
|
370
|
+
? { ...closeEvents }
|
|
371
|
+
: {
|
|
372
|
+
mouseleave: true,
|
|
373
|
+
blur: true,
|
|
374
|
+
click: false,
|
|
375
|
+
};
|
|
376
|
+
if (!closeEvents && shouldOpenOnClick) {
|
|
377
|
+
Object.assign(actualCloseEvents, {
|
|
378
|
+
mouseleave: false,
|
|
379
|
+
blur: false,
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
const actualGlobalCloseEvents = globalCloseEvents
|
|
383
|
+
? { ...globalCloseEvents }
|
|
384
|
+
: {
|
|
385
|
+
escape: closeOnEsc || false,
|
|
386
|
+
scroll: closeOnScroll || false,
|
|
387
|
+
resize: closeOnResize || false,
|
|
388
|
+
clickOutsideAnchor: hasClickEvent || false,
|
|
389
|
+
};
|
|
349
390
|
/**
|
|
350
391
|
* useLayoutEffect runs before useEffect,
|
|
351
392
|
* but should be used carefully because of caveats
|
|
@@ -357,6 +398,23 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
357
398
|
mounted.current = false;
|
|
358
399
|
};
|
|
359
400
|
}, []);
|
|
401
|
+
useEffect(() => {
|
|
402
|
+
if (!show) {
|
|
403
|
+
/**
|
|
404
|
+
* this fixes weird behavior when switching between two anchor elements very quickly
|
|
405
|
+
* remove the timeout and switch quickly between two adjancent anchor elements to see it
|
|
406
|
+
*
|
|
407
|
+
* in practice, this means the tooltip is not immediately removed from the DOM on hide
|
|
408
|
+
*/
|
|
409
|
+
const timeout = setTimeout(() => {
|
|
410
|
+
setRendered(false);
|
|
411
|
+
}, 150);
|
|
412
|
+
return () => {
|
|
413
|
+
clearTimeout(timeout);
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
return () => null;
|
|
417
|
+
}, [show]);
|
|
360
418
|
const handleShow = (value) => {
|
|
361
419
|
if (!mounted.current) {
|
|
362
420
|
return;
|
|
@@ -515,12 +573,6 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
515
573
|
handleTooltipPosition(mousePosition);
|
|
516
574
|
lastFloatPosition.current = mousePosition;
|
|
517
575
|
};
|
|
518
|
-
const handleClickTooltipAnchor = (event) => {
|
|
519
|
-
handleShowTooltip(event);
|
|
520
|
-
if (delayHide) {
|
|
521
|
-
handleHideTooltipDelayed();
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
576
|
const handleClickOutsideAnchors = (event) => {
|
|
525
577
|
var _a;
|
|
526
578
|
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
@@ -611,13 +663,13 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
611
663
|
};
|
|
612
664
|
const anchorScrollParent = getScrollParent(activeAnchor);
|
|
613
665
|
const tooltipScrollParent = getScrollParent(tooltipRef.current);
|
|
614
|
-
if (
|
|
666
|
+
if (actualGlobalCloseEvents.scroll) {
|
|
615
667
|
window.addEventListener('scroll', handleScrollResize);
|
|
616
668
|
anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.addEventListener('scroll', handleScrollResize);
|
|
617
669
|
tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.addEventListener('scroll', handleScrollResize);
|
|
618
670
|
}
|
|
619
671
|
let updateTooltipCleanup = null;
|
|
620
|
-
if (
|
|
672
|
+
if (actualGlobalCloseEvents.resize) {
|
|
621
673
|
window.addEventListener('resize', handleScrollResize);
|
|
622
674
|
}
|
|
623
675
|
else if (activeAnchor && tooltipRef.current) {
|
|
@@ -633,22 +685,56 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
633
685
|
}
|
|
634
686
|
handleShow(false);
|
|
635
687
|
};
|
|
636
|
-
if (
|
|
688
|
+
if (actualGlobalCloseEvents.escape) {
|
|
637
689
|
window.addEventListener('keydown', handleEsc);
|
|
638
690
|
}
|
|
639
|
-
|
|
640
|
-
if (shouldOpenOnClick) {
|
|
691
|
+
if (actualGlobalCloseEvents.clickOutsideAnchor) {
|
|
641
692
|
window.addEventListener('click', handleClickOutsideAnchors);
|
|
642
|
-
enabledEvents.push({ event: 'click', listener: handleClickTooltipAnchor });
|
|
643
693
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
if (
|
|
647
|
-
|
|
648
|
-
event: 'mousemove',
|
|
649
|
-
listener: handleMouseMove,
|
|
650
|
-
});
|
|
694
|
+
const enabledEvents = [];
|
|
695
|
+
const handleClickOpenTooltipAnchor = (event) => {
|
|
696
|
+
if (show) {
|
|
697
|
+
return;
|
|
651
698
|
}
|
|
699
|
+
handleShowTooltip(event);
|
|
700
|
+
};
|
|
701
|
+
const handleClickCloseTooltipAnchor = () => {
|
|
702
|
+
if (!show) {
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
handleHideTooltip();
|
|
706
|
+
};
|
|
707
|
+
const regularEvents = ['mouseenter', 'mouseleave', 'focus', 'blur'];
|
|
708
|
+
const clickEvents = ['click', 'dblclick', 'mousedown', 'mouseup'];
|
|
709
|
+
Object.entries(actualOpenEvents).forEach(([event, enabled]) => {
|
|
710
|
+
if (!enabled) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
if (regularEvents.includes(event)) {
|
|
714
|
+
enabledEvents.push({ event, listener: debouncedHandleShowTooltip });
|
|
715
|
+
}
|
|
716
|
+
else if (clickEvents.includes(event)) {
|
|
717
|
+
enabledEvents.push({ event, listener: handleClickOpenTooltipAnchor });
|
|
718
|
+
}
|
|
719
|
+
else ;
|
|
720
|
+
});
|
|
721
|
+
Object.entries(actualCloseEvents).forEach(([event, enabled]) => {
|
|
722
|
+
if (!enabled) {
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
if (regularEvents.includes(event)) {
|
|
726
|
+
enabledEvents.push({ event, listener: debouncedHandleHideTooltip });
|
|
727
|
+
}
|
|
728
|
+
else if (clickEvents.includes(event)) {
|
|
729
|
+
enabledEvents.push({ event, listener: handleClickCloseTooltipAnchor });
|
|
730
|
+
}
|
|
731
|
+
else ;
|
|
732
|
+
});
|
|
733
|
+
if (float) {
|
|
734
|
+
enabledEvents.push({
|
|
735
|
+
event: 'mousemove',
|
|
736
|
+
listener: handleMouseMove,
|
|
737
|
+
});
|
|
652
738
|
}
|
|
653
739
|
const handleMouseEnterTooltip = () => {
|
|
654
740
|
hoveringTooltip.current = true;
|
|
@@ -657,7 +743,9 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
657
743
|
hoveringTooltip.current = false;
|
|
658
744
|
handleHideTooltip();
|
|
659
745
|
};
|
|
660
|
-
if (clickable && !
|
|
746
|
+
if (clickable && !hasClickEvent) {
|
|
747
|
+
// used to keep the tooltip open when hovering content.
|
|
748
|
+
// not needed if using click events.
|
|
661
749
|
(_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mouseenter', handleMouseEnterTooltip);
|
|
662
750
|
(_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseleave', handleMouseLeaveTooltip);
|
|
663
751
|
}
|
|
@@ -669,24 +757,24 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
669
757
|
});
|
|
670
758
|
return () => {
|
|
671
759
|
var _a, _b;
|
|
672
|
-
if (
|
|
760
|
+
if (actualGlobalCloseEvents.scroll) {
|
|
673
761
|
window.removeEventListener('scroll', handleScrollResize);
|
|
674
762
|
anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.removeEventListener('scroll', handleScrollResize);
|
|
675
763
|
tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.removeEventListener('scroll', handleScrollResize);
|
|
676
764
|
}
|
|
677
|
-
if (
|
|
765
|
+
if (actualGlobalCloseEvents.resize) {
|
|
678
766
|
window.removeEventListener('resize', handleScrollResize);
|
|
679
767
|
}
|
|
680
768
|
else {
|
|
681
769
|
updateTooltipCleanup === null || updateTooltipCleanup === void 0 ? void 0 : updateTooltipCleanup();
|
|
682
770
|
}
|
|
683
|
-
if (
|
|
771
|
+
if (actualGlobalCloseEvents.clickOutsideAnchor) {
|
|
684
772
|
window.removeEventListener('click', handleClickOutsideAnchors);
|
|
685
773
|
}
|
|
686
|
-
if (
|
|
774
|
+
if (actualGlobalCloseEvents.escape) {
|
|
687
775
|
window.removeEventListener('keydown', handleEsc);
|
|
688
776
|
}
|
|
689
|
-
if (clickable && !
|
|
777
|
+
if (clickable && !hasClickEvent) {
|
|
690
778
|
(_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mouseenter', handleMouseEnterTooltip);
|
|
691
779
|
(_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mouseleave', handleMouseLeaveTooltip);
|
|
692
780
|
}
|
|
@@ -707,8 +795,11 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
707
795
|
rendered,
|
|
708
796
|
anchorRefs,
|
|
709
797
|
anchorsBySelect,
|
|
710
|
-
|
|
711
|
-
|
|
798
|
+
// the effect uses the `actual*Events` objects, but this should work
|
|
799
|
+
openEvents,
|
|
800
|
+
closeEvents,
|
|
801
|
+
globalCloseEvents,
|
|
802
|
+
shouldOpenOnClick,
|
|
712
803
|
]);
|
|
713
804
|
useEffect(() => {
|
|
714
805
|
let selector = anchorSelect !== null && anchorSelect !== void 0 ? anchorSelect : '';
|
|
@@ -857,22 +948,24 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
857
948
|
}
|
|
858
949
|
}, [id, anchorSelect]);
|
|
859
950
|
const canShow = !hidden && content && show && Object.keys(inlineStyles).length > 0;
|
|
860
|
-
return rendered ? (React.createElement(WrapperElement, { id: id, role: "tooltip", className: classNames('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`,
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
return;
|
|
867
|
-
}
|
|
868
|
-
setRendered(false);
|
|
869
|
-
}, style: {
|
|
951
|
+
return rendered ? (React.createElement(WrapperElement, { id: id, role: "tooltip", className: classNames('react-tooltip', coreStyles['tooltip'], styles['tooltip'], styles[variant], className, `react-tooltip__place-${actualPlacement}`, {
|
|
952
|
+
'react-tooltip__show': canShow,
|
|
953
|
+
[coreStyles['show']]: canShow,
|
|
954
|
+
[coreStyles['fixed']]: positionStrategy === 'fixed',
|
|
955
|
+
[coreStyles['clickable']]: clickable,
|
|
956
|
+
}), style: {
|
|
870
957
|
...externalStyles,
|
|
871
958
|
...inlineStyles,
|
|
872
959
|
opacity: opacity !== undefined && canShow ? opacity : undefined,
|
|
873
960
|
}, ref: tooltipRef },
|
|
874
961
|
content,
|
|
875
|
-
React.createElement(WrapperElement, { className: classNames('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow,
|
|
962
|
+
React.createElement(WrapperElement, { className: classNames('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, {
|
|
963
|
+
/**
|
|
964
|
+
* changed from dash `no-arrow` to camelcase because of:
|
|
965
|
+
* https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
|
|
966
|
+
*/
|
|
967
|
+
[coreStyles['noArrow']]: noArrow,
|
|
968
|
+
}), style: {
|
|
876
969
|
...inlineArrowStyles,
|
|
877
970
|
background: arrowColor
|
|
878
971
|
? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
|
|
@@ -885,7 +978,7 @@ const TooltipContent = ({ content }) => {
|
|
|
885
978
|
return React.createElement("span", { dangerouslySetInnerHTML: { __html: content } });
|
|
886
979
|
};
|
|
887
980
|
|
|
888
|
-
const TooltipController = ({ 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, style, position, isOpen, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, }) => {
|
|
981
|
+
const TooltipController = ({ 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, style, position, isOpen, disableStyleInjection = false, border, opacity, arrowColor, setIsOpen, afterShow, afterHide, }) => {
|
|
889
982
|
const [tooltipContent, setTooltipContent] = useState(content);
|
|
890
983
|
const [tooltipHtml, setTooltipHtml] = useState(html);
|
|
891
984
|
const [tooltipPlace, setTooltipPlace] = useState(place);
|
|
@@ -1133,6 +1226,9 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1133
1226
|
closeOnEsc,
|
|
1134
1227
|
closeOnScroll,
|
|
1135
1228
|
closeOnResize,
|
|
1229
|
+
openEvents,
|
|
1230
|
+
closeEvents,
|
|
1231
|
+
globalCloseEvents,
|
|
1136
1232
|
style,
|
|
1137
1233
|
position,
|
|
1138
1234
|
isOpen,
|
|
@@ -1157,17 +1253,17 @@ const TooltipCoreStyles = `:root {
|
|
|
1157
1253
|
--rt-color-warning: #f0ad4e;
|
|
1158
1254
|
--rt-color-info: #337ab7;
|
|
1159
1255
|
--rt-opacity: 0.9;
|
|
1160
|
-
--rt-transition-show-delay: 0.15s;
|
|
1161
|
-
--rt-transition-closing-delay: 0.15s;
|
|
1162
1256
|
}
|
|
1163
1257
|
|
|
1164
1258
|
.core-styles-module_tooltip__3vRRp {
|
|
1259
|
+
visibility: hidden;
|
|
1165
1260
|
position: absolute;
|
|
1166
1261
|
top: 0;
|
|
1167
1262
|
left: 0;
|
|
1168
1263
|
pointer-events: none;
|
|
1169
1264
|
opacity: 0;
|
|
1170
|
-
|
|
1265
|
+
transition: opacity 0.3s ease-out;
|
|
1266
|
+
will-change: opacity, visibility;
|
|
1171
1267
|
}
|
|
1172
1268
|
|
|
1173
1269
|
.core-styles-module_fixed__pcSol {
|
|
@@ -1188,13 +1284,8 @@ const TooltipCoreStyles = `:root {
|
|
|
1188
1284
|
}
|
|
1189
1285
|
|
|
1190
1286
|
.core-styles-module_show__Nt9eE {
|
|
1287
|
+
visibility: visible;
|
|
1191
1288
|
opacity: var(--rt-opacity);
|
|
1192
|
-
transition: opacity var(--rt-transition-show-delay) ease-out;
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
.core-styles-module_closing__sGnxF {
|
|
1196
|
-
opacity: 0;
|
|
1197
|
-
transition: opacity var(--rt-transition-closing-delay) ease-in;
|
|
1198
1289
|
}
|
|
1199
1290
|
|
|
1200
1291
|
`;
|