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.cjs
CHANGED
|
@@ -327,13 +327,13 @@ const computeTooltipPosition = async ({ elementReference = null, tooltipReferenc
|
|
|
327
327
|
});
|
|
328
328
|
};
|
|
329
329
|
|
|
330
|
-
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"
|
|
330
|
+
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"};
|
|
331
331
|
|
|
332
332
|
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"};
|
|
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, style: externalStyles, position, afterShow, afterHide,
|
|
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,
|
|
337
337
|
// props handled by controller
|
|
338
338
|
content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, border, opacity, arrowColor, }) => {
|
|
339
339
|
const tooltipRef = React.useRef(null);
|
|
@@ -354,7 +354,48 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
354
354
|
const hoveringTooltip = React.useRef(false);
|
|
355
355
|
const [anchorsBySelect, setAnchorsBySelect] = React.useState([]);
|
|
356
356
|
const mounted = React.useRef(false);
|
|
357
|
+
/**
|
|
358
|
+
* @todo Update when deprecated stuff gets removed.
|
|
359
|
+
*/
|
|
357
360
|
const shouldOpenOnClick = openOnClick || events.includes('click');
|
|
361
|
+
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);
|
|
362
|
+
const actualOpenEvents = openEvents
|
|
363
|
+
? { ...openEvents }
|
|
364
|
+
: {
|
|
365
|
+
mouseenter: true,
|
|
366
|
+
focus: true,
|
|
367
|
+
click: false,
|
|
368
|
+
dblclick: false,
|
|
369
|
+
mousedown: false,
|
|
370
|
+
};
|
|
371
|
+
if (!openEvents && shouldOpenOnClick) {
|
|
372
|
+
Object.assign(actualOpenEvents, {
|
|
373
|
+
mouseenter: false,
|
|
374
|
+
focus: false,
|
|
375
|
+
click: true,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
const actualCloseEvents = closeEvents
|
|
379
|
+
? { ...closeEvents }
|
|
380
|
+
: {
|
|
381
|
+
mouseleave: true,
|
|
382
|
+
blur: true,
|
|
383
|
+
click: false,
|
|
384
|
+
};
|
|
385
|
+
if (!closeEvents && shouldOpenOnClick) {
|
|
386
|
+
Object.assign(actualCloseEvents, {
|
|
387
|
+
mouseleave: false,
|
|
388
|
+
blur: false,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
const actualGlobalCloseEvents = globalCloseEvents
|
|
392
|
+
? { ...globalCloseEvents }
|
|
393
|
+
: {
|
|
394
|
+
escape: closeOnEsc || false,
|
|
395
|
+
scroll: closeOnScroll || false,
|
|
396
|
+
resize: closeOnResize || false,
|
|
397
|
+
clickOutsideAnchor: hasClickEvent || false,
|
|
398
|
+
};
|
|
358
399
|
/**
|
|
359
400
|
* useLayoutEffect runs before useEffect,
|
|
360
401
|
* but should be used carefully because of caveats
|
|
@@ -366,6 +407,23 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
366
407
|
mounted.current = false;
|
|
367
408
|
};
|
|
368
409
|
}, []);
|
|
410
|
+
React.useEffect(() => {
|
|
411
|
+
if (!show) {
|
|
412
|
+
/**
|
|
413
|
+
* this fixes weird behavior when switching between two anchor elements very quickly
|
|
414
|
+
* remove the timeout and switch quickly between two adjancent anchor elements to see it
|
|
415
|
+
*
|
|
416
|
+
* in practice, this means the tooltip is not immediately removed from the DOM on hide
|
|
417
|
+
*/
|
|
418
|
+
const timeout = setTimeout(() => {
|
|
419
|
+
setRendered(false);
|
|
420
|
+
}, 150);
|
|
421
|
+
return () => {
|
|
422
|
+
clearTimeout(timeout);
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
return () => null;
|
|
426
|
+
}, [show]);
|
|
369
427
|
const handleShow = (value) => {
|
|
370
428
|
if (!mounted.current) {
|
|
371
429
|
return;
|
|
@@ -524,12 +582,6 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
524
582
|
handleTooltipPosition(mousePosition);
|
|
525
583
|
lastFloatPosition.current = mousePosition;
|
|
526
584
|
};
|
|
527
|
-
const handleClickTooltipAnchor = (event) => {
|
|
528
|
-
handleShowTooltip(event);
|
|
529
|
-
if (delayHide) {
|
|
530
|
-
handleHideTooltipDelayed();
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
585
|
const handleClickOutsideAnchors = (event) => {
|
|
534
586
|
var _a;
|
|
535
587
|
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
@@ -620,13 +672,13 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
620
672
|
};
|
|
621
673
|
const anchorScrollParent = getScrollParent(activeAnchor);
|
|
622
674
|
const tooltipScrollParent = getScrollParent(tooltipRef.current);
|
|
623
|
-
if (
|
|
675
|
+
if (actualGlobalCloseEvents.scroll) {
|
|
624
676
|
window.addEventListener('scroll', handleScrollResize);
|
|
625
677
|
anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.addEventListener('scroll', handleScrollResize);
|
|
626
678
|
tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.addEventListener('scroll', handleScrollResize);
|
|
627
679
|
}
|
|
628
680
|
let updateTooltipCleanup = null;
|
|
629
|
-
if (
|
|
681
|
+
if (actualGlobalCloseEvents.resize) {
|
|
630
682
|
window.addEventListener('resize', handleScrollResize);
|
|
631
683
|
}
|
|
632
684
|
else if (activeAnchor && tooltipRef.current) {
|
|
@@ -642,22 +694,56 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
642
694
|
}
|
|
643
695
|
handleShow(false);
|
|
644
696
|
};
|
|
645
|
-
if (
|
|
697
|
+
if (actualGlobalCloseEvents.escape) {
|
|
646
698
|
window.addEventListener('keydown', handleEsc);
|
|
647
699
|
}
|
|
648
|
-
|
|
649
|
-
if (shouldOpenOnClick) {
|
|
700
|
+
if (actualGlobalCloseEvents.clickOutsideAnchor) {
|
|
650
701
|
window.addEventListener('click', handleClickOutsideAnchors);
|
|
651
|
-
enabledEvents.push({ event: 'click', listener: handleClickTooltipAnchor });
|
|
652
702
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
if (
|
|
656
|
-
|
|
657
|
-
event: 'mousemove',
|
|
658
|
-
listener: handleMouseMove,
|
|
659
|
-
});
|
|
703
|
+
const enabledEvents = [];
|
|
704
|
+
const handleClickOpenTooltipAnchor = (event) => {
|
|
705
|
+
if (show) {
|
|
706
|
+
return;
|
|
660
707
|
}
|
|
708
|
+
handleShowTooltip(event);
|
|
709
|
+
};
|
|
710
|
+
const handleClickCloseTooltipAnchor = () => {
|
|
711
|
+
if (!show) {
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
handleHideTooltip();
|
|
715
|
+
};
|
|
716
|
+
const regularEvents = ['mouseenter', 'mouseleave', 'focus', 'blur'];
|
|
717
|
+
const clickEvents = ['click', 'dblclick', 'mousedown', 'mouseup'];
|
|
718
|
+
Object.entries(actualOpenEvents).forEach(([event, enabled]) => {
|
|
719
|
+
if (!enabled) {
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
if (regularEvents.includes(event)) {
|
|
723
|
+
enabledEvents.push({ event, listener: debouncedHandleShowTooltip });
|
|
724
|
+
}
|
|
725
|
+
else if (clickEvents.includes(event)) {
|
|
726
|
+
enabledEvents.push({ event, listener: handleClickOpenTooltipAnchor });
|
|
727
|
+
}
|
|
728
|
+
else ;
|
|
729
|
+
});
|
|
730
|
+
Object.entries(actualCloseEvents).forEach(([event, enabled]) => {
|
|
731
|
+
if (!enabled) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
if (regularEvents.includes(event)) {
|
|
735
|
+
enabledEvents.push({ event, listener: debouncedHandleHideTooltip });
|
|
736
|
+
}
|
|
737
|
+
else if (clickEvents.includes(event)) {
|
|
738
|
+
enabledEvents.push({ event, listener: handleClickCloseTooltipAnchor });
|
|
739
|
+
}
|
|
740
|
+
else ;
|
|
741
|
+
});
|
|
742
|
+
if (float) {
|
|
743
|
+
enabledEvents.push({
|
|
744
|
+
event: 'mousemove',
|
|
745
|
+
listener: handleMouseMove,
|
|
746
|
+
});
|
|
661
747
|
}
|
|
662
748
|
const handleMouseEnterTooltip = () => {
|
|
663
749
|
hoveringTooltip.current = true;
|
|
@@ -666,7 +752,9 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
666
752
|
hoveringTooltip.current = false;
|
|
667
753
|
handleHideTooltip();
|
|
668
754
|
};
|
|
669
|
-
if (clickable && !
|
|
755
|
+
if (clickable && !hasClickEvent) {
|
|
756
|
+
// used to keep the tooltip open when hovering content.
|
|
757
|
+
// not needed if using click events.
|
|
670
758
|
(_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('mouseenter', handleMouseEnterTooltip);
|
|
671
759
|
(_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseleave', handleMouseLeaveTooltip);
|
|
672
760
|
}
|
|
@@ -678,24 +766,24 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
678
766
|
});
|
|
679
767
|
return () => {
|
|
680
768
|
var _a, _b;
|
|
681
|
-
if (
|
|
769
|
+
if (actualGlobalCloseEvents.scroll) {
|
|
682
770
|
window.removeEventListener('scroll', handleScrollResize);
|
|
683
771
|
anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.removeEventListener('scroll', handleScrollResize);
|
|
684
772
|
tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.removeEventListener('scroll', handleScrollResize);
|
|
685
773
|
}
|
|
686
|
-
if (
|
|
774
|
+
if (actualGlobalCloseEvents.resize) {
|
|
687
775
|
window.removeEventListener('resize', handleScrollResize);
|
|
688
776
|
}
|
|
689
777
|
else {
|
|
690
778
|
updateTooltipCleanup === null || updateTooltipCleanup === void 0 ? void 0 : updateTooltipCleanup();
|
|
691
779
|
}
|
|
692
|
-
if (
|
|
780
|
+
if (actualGlobalCloseEvents.clickOutsideAnchor) {
|
|
693
781
|
window.removeEventListener('click', handleClickOutsideAnchors);
|
|
694
782
|
}
|
|
695
|
-
if (
|
|
783
|
+
if (actualGlobalCloseEvents.escape) {
|
|
696
784
|
window.removeEventListener('keydown', handleEsc);
|
|
697
785
|
}
|
|
698
|
-
if (clickable && !
|
|
786
|
+
if (clickable && !hasClickEvent) {
|
|
699
787
|
(_a = tooltipRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener('mouseenter', handleMouseEnterTooltip);
|
|
700
788
|
(_b = tooltipRef.current) === null || _b === void 0 ? void 0 : _b.removeEventListener('mouseleave', handleMouseLeaveTooltip);
|
|
701
789
|
}
|
|
@@ -716,8 +804,11 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
716
804
|
rendered,
|
|
717
805
|
anchorRefs,
|
|
718
806
|
anchorsBySelect,
|
|
719
|
-
|
|
720
|
-
|
|
807
|
+
// the effect uses the `actual*Events` objects, but this should work
|
|
808
|
+
openEvents,
|
|
809
|
+
closeEvents,
|
|
810
|
+
globalCloseEvents,
|
|
811
|
+
shouldOpenOnClick,
|
|
721
812
|
]);
|
|
722
813
|
React.useEffect(() => {
|
|
723
814
|
let selector = anchorSelect !== null && anchorSelect !== void 0 ? anchorSelect : '';
|
|
@@ -866,22 +957,24 @@ content, contentWrapperRef, isOpen, setIsOpen, activeAnchor, setActiveAnchor, bo
|
|
|
866
957
|
}
|
|
867
958
|
}, [id, anchorSelect]);
|
|
868
959
|
const canShow = !hidden && content && show && Object.keys(inlineStyles).length > 0;
|
|
869
|
-
return rendered ? (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}`,
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
return;
|
|
876
|
-
}
|
|
877
|
-
setRendered(false);
|
|
878
|
-
}, style: {
|
|
960
|
+
return rendered ? (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}`, {
|
|
961
|
+
'react-tooltip__show': canShow,
|
|
962
|
+
[coreStyles['show']]: canShow,
|
|
963
|
+
[coreStyles['fixed']]: positionStrategy === 'fixed',
|
|
964
|
+
[coreStyles['clickable']]: clickable,
|
|
965
|
+
}), style: {
|
|
879
966
|
...externalStyles,
|
|
880
967
|
...inlineStyles,
|
|
881
968
|
opacity: opacity !== undefined && canShow ? opacity : undefined,
|
|
882
969
|
}, ref: tooltipRef },
|
|
883
970
|
content,
|
|
884
|
-
React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow,
|
|
971
|
+
React__default["default"].createElement(WrapperElement, { className: classNames__default["default"]('react-tooltip-arrow', coreStyles['arrow'], styles['arrow'], classNameArrow, {
|
|
972
|
+
/**
|
|
973
|
+
* changed from dash `no-arrow` to camelcase because of:
|
|
974
|
+
* https://github.com/indooorsman/esbuild-css-modules-plugin/issues/42
|
|
975
|
+
*/
|
|
976
|
+
[coreStyles['noArrow']]: noArrow,
|
|
977
|
+
}), style: {
|
|
885
978
|
...inlineArrowStyles,
|
|
886
979
|
background: arrowColor
|
|
887
980
|
? `linear-gradient(to right bottom, transparent 50%, ${arrowColor} 50%)`
|
|
@@ -894,7 +987,7 @@ const TooltipContent = ({ content }) => {
|
|
|
894
987
|
return React__default["default"].createElement("span", { dangerouslySetInnerHTML: { __html: content } });
|
|
895
988
|
};
|
|
896
989
|
|
|
897
|
-
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, }) => {
|
|
990
|
+
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, }) => {
|
|
898
991
|
const [tooltipContent, setTooltipContent] = React.useState(content);
|
|
899
992
|
const [tooltipHtml, setTooltipHtml] = React.useState(html);
|
|
900
993
|
const [tooltipPlace, setTooltipPlace] = React.useState(place);
|
|
@@ -1142,6 +1235,9 @@ const TooltipController = ({ id, anchorId, anchorSelect, content, html, render,
|
|
|
1142
1235
|
closeOnEsc,
|
|
1143
1236
|
closeOnScroll,
|
|
1144
1237
|
closeOnResize,
|
|
1238
|
+
openEvents,
|
|
1239
|
+
closeEvents,
|
|
1240
|
+
globalCloseEvents,
|
|
1145
1241
|
style,
|
|
1146
1242
|
position,
|
|
1147
1243
|
isOpen,
|
|
@@ -1166,17 +1262,17 @@ const TooltipCoreStyles = `:root {
|
|
|
1166
1262
|
--rt-color-warning: #f0ad4e;
|
|
1167
1263
|
--rt-color-info: #337ab7;
|
|
1168
1264
|
--rt-opacity: 0.9;
|
|
1169
|
-
--rt-transition-show-delay: 0.15s;
|
|
1170
|
-
--rt-transition-closing-delay: 0.15s;
|
|
1171
1265
|
}
|
|
1172
1266
|
|
|
1173
1267
|
.core-styles-module_tooltip__3vRRp {
|
|
1268
|
+
visibility: hidden;
|
|
1174
1269
|
position: absolute;
|
|
1175
1270
|
top: 0;
|
|
1176
1271
|
left: 0;
|
|
1177
1272
|
pointer-events: none;
|
|
1178
1273
|
opacity: 0;
|
|
1179
|
-
|
|
1274
|
+
transition: opacity 0.3s ease-out;
|
|
1275
|
+
will-change: opacity, visibility;
|
|
1180
1276
|
}
|
|
1181
1277
|
|
|
1182
1278
|
.core-styles-module_fixed__pcSol {
|
|
@@ -1197,13 +1293,8 @@ const TooltipCoreStyles = `:root {
|
|
|
1197
1293
|
}
|
|
1198
1294
|
|
|
1199
1295
|
.core-styles-module_show__Nt9eE {
|
|
1296
|
+
visibility: visible;
|
|
1200
1297
|
opacity: var(--rt-opacity);
|
|
1201
|
-
transition: opacity var(--rt-transition-show-delay) ease-out;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
.core-styles-module_closing__sGnxF {
|
|
1205
|
-
opacity: 0;
|
|
1206
|
-
transition: opacity var(--rt-transition-closing-delay) ease-in;
|
|
1207
1298
|
}
|
|
1208
1299
|
|
|
1209
1300
|
`;
|