react-tooltip 5.19.0-beta.1052.0 → 5.20.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/README.md +1 -1
- package/dist/react-tooltip.cjs +113 -49
- package/dist/react-tooltip.cjs.map +1 -1
- package/dist/react-tooltip.d.ts +12 -3
- 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 +113 -50
- package/dist/react-tooltip.mjs.map +1 -1
- package/dist/react-tooltip.umd.js +116 -52
- 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 +2 -2
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
* @license MIT
|
|
7
7
|
*/
|
|
8
8
|
(function (global, factory) {
|
|
9
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('
|
|
10
|
-
typeof define === 'function' && define.amd ? define(['exports', 'react', '
|
|
11
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactTooltip = {}, global.React, global.
|
|
12
|
-
})(this, (function (exports, React,
|
|
9
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@floating-ui/dom'), require('classnames')) :
|
|
10
|
+
typeof define === 'function' && define.amd ? define(['exports', 'react', '@floating-ui/dom', 'classnames'], factory) :
|
|
11
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactTooltip = {}, global.React, global.FloatingUIDOM, global.classNames));
|
|
12
|
+
})(this, (function (exports, React, dom, classNames) { 'use strict';
|
|
13
13
|
|
|
14
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
15
|
|
|
@@ -25,6 +25,20 @@
|
|
|
25
25
|
base: false,
|
|
26
26
|
};
|
|
27
27
|
function injectStyle({ css, id = REACT_TOOLTIP_BASE_STYLES_ID, type = 'base', ref, }) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
if (!css || typeof document === 'undefined' || injected[type]) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (type === 'core' &&
|
|
33
|
+
typeof process !== 'undefined' && // this validation prevents docs from breaking even with `process?`
|
|
34
|
+
((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.REACT_TOOLTIP_DISABLE_CORE_STYLES)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (type !== 'base' &&
|
|
38
|
+
typeof process !== 'undefined' && // this validation prevents docs from breaking even with `process?`
|
|
39
|
+
((_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b.REACT_TOOLTIP_DISABLE_BASE_STYLES)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
28
42
|
if (type === 'core') {
|
|
29
43
|
// eslint-disable-next-line no-param-reassign
|
|
30
44
|
id = REACT_TOOLTIP_CORE_STYLES_ID;
|
|
@@ -34,9 +48,6 @@
|
|
|
34
48
|
ref = {};
|
|
35
49
|
}
|
|
36
50
|
const { insertAt } = ref;
|
|
37
|
-
if (!css || typeof document === 'undefined' || injected[type]) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
51
|
if (document.getElementById(id)) {
|
|
41
52
|
// this should never happen because of `injected[type]`
|
|
42
53
|
{
|
|
@@ -69,6 +80,28 @@
|
|
|
69
80
|
}
|
|
70
81
|
injected[type] = true;
|
|
71
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated Use the `disableStyleInjection` tooltip prop instead.
|
|
85
|
+
* See https://react-tooltip.com/docs/examples/styling#disabling-reacttooltip-css
|
|
86
|
+
*/
|
|
87
|
+
function removeStyle({ type = 'base', id = REACT_TOOLTIP_BASE_STYLES_ID, } = {}) {
|
|
88
|
+
if (!injected[type]) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (type === 'core') {
|
|
92
|
+
// eslint-disable-next-line no-param-reassign
|
|
93
|
+
id = REACT_TOOLTIP_CORE_STYLES_ID;
|
|
94
|
+
}
|
|
95
|
+
const style = document.getElementById(id);
|
|
96
|
+
if ((style === null || style === void 0 ? void 0 : style.tagName) === 'style') {
|
|
97
|
+
style === null || style === void 0 ? void 0 : style.remove();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// eslint-disable-next-line no-console
|
|
101
|
+
console.warn(`[react-tooltip] Failed to remove 'style' element with id '${id}'. Call \`injectStyle()\` first`);
|
|
102
|
+
}
|
|
103
|
+
injected[type] = false;
|
|
104
|
+
}
|
|
72
105
|
|
|
73
106
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
74
107
|
/**
|
|
@@ -534,6 +567,59 @@
|
|
|
534
567
|
// mouse enter and focus events being triggered toggether
|
|
535
568
|
const debouncedHandleShowTooltip = debounce(handleShowTooltip, 50, true);
|
|
536
569
|
const debouncedHandleHideTooltip = debounce(handleHideTooltip, 50, true);
|
|
570
|
+
const updateTooltipPosition = React.useCallback(() => {
|
|
571
|
+
if (position) {
|
|
572
|
+
// if `position` is set, override regular and `float` positioning
|
|
573
|
+
handleTooltipPosition(position);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
if (float) {
|
|
577
|
+
if (lastFloatPosition.current) {
|
|
578
|
+
/*
|
|
579
|
+
Without this, changes to `content`, `place`, `offset`, ..., will only
|
|
580
|
+
trigger a position calculation after a `mousemove` event.
|
|
581
|
+
|
|
582
|
+
To see why this matters, comment this line, run `yarn dev` and click the
|
|
583
|
+
"Hover me!" anchor.
|
|
584
|
+
*/
|
|
585
|
+
handleTooltipPosition(lastFloatPosition.current);
|
|
586
|
+
}
|
|
587
|
+
// if `float` is set, override regular positioning
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
computeTooltipPosition({
|
|
591
|
+
place,
|
|
592
|
+
offset,
|
|
593
|
+
elementReference: activeAnchor,
|
|
594
|
+
tooltipReference: tooltipRef.current,
|
|
595
|
+
tooltipArrowReference: tooltipArrowRef.current,
|
|
596
|
+
strategy: positionStrategy,
|
|
597
|
+
middlewares,
|
|
598
|
+
border,
|
|
599
|
+
}).then((computedStylesData) => {
|
|
600
|
+
if (!mounted.current) {
|
|
601
|
+
// invalidate computed positions after remount
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (Object.keys(computedStylesData.tooltipStyles).length) {
|
|
605
|
+
setInlineStyles(computedStylesData.tooltipStyles);
|
|
606
|
+
}
|
|
607
|
+
if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
|
|
608
|
+
setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
|
|
609
|
+
}
|
|
610
|
+
setActualPlacement(computedStylesData.place);
|
|
611
|
+
});
|
|
612
|
+
}, [
|
|
613
|
+
show,
|
|
614
|
+
activeAnchor,
|
|
615
|
+
content,
|
|
616
|
+
externalStyles,
|
|
617
|
+
place,
|
|
618
|
+
offset,
|
|
619
|
+
positionStrategy,
|
|
620
|
+
position,
|
|
621
|
+
float,
|
|
622
|
+
]);
|
|
537
623
|
React.useEffect(() => {
|
|
538
624
|
var _a, _b;
|
|
539
625
|
const elementRefs = new Set(anchorRefs);
|
|
@@ -554,9 +640,17 @@
|
|
|
554
640
|
anchorScrollParent === null || anchorScrollParent === void 0 ? void 0 : anchorScrollParent.addEventListener('scroll', handleScrollResize);
|
|
555
641
|
tooltipScrollParent === null || tooltipScrollParent === void 0 ? void 0 : tooltipScrollParent.addEventListener('scroll', handleScrollResize);
|
|
556
642
|
}
|
|
643
|
+
let updateTooltipCleanup = null;
|
|
557
644
|
if (closeOnResize) {
|
|
558
645
|
window.addEventListener('resize', handleScrollResize);
|
|
559
646
|
}
|
|
647
|
+
else if (activeAnchor && tooltipRef.current) {
|
|
648
|
+
updateTooltipCleanup = dom.autoUpdate(activeAnchor, tooltipRef.current, updateTooltipPosition, {
|
|
649
|
+
ancestorResize: true,
|
|
650
|
+
elementResize: true,
|
|
651
|
+
layoutShift: true,
|
|
652
|
+
});
|
|
653
|
+
}
|
|
560
654
|
const handleEsc = (event) => {
|
|
561
655
|
if (event.key !== 'Escape') {
|
|
562
656
|
return;
|
|
@@ -607,6 +701,9 @@
|
|
|
607
701
|
if (closeOnResize) {
|
|
608
702
|
window.removeEventListener('resize', handleScrollResize);
|
|
609
703
|
}
|
|
704
|
+
else {
|
|
705
|
+
updateTooltipCleanup === null || updateTooltipCleanup === void 0 ? void 0 : updateTooltipCleanup();
|
|
706
|
+
}
|
|
610
707
|
if (shouldOpenOnClick) {
|
|
611
708
|
window.removeEventListener('click', handleClickOutsideAnchors);
|
|
612
709
|
}
|
|
@@ -628,7 +725,15 @@
|
|
|
628
725
|
* rendered is also a dependency to ensure anchor observers are re-registered
|
|
629
726
|
* since `tooltipRef` becomes stale after removing/adding the tooltip to the DOM
|
|
630
727
|
*/
|
|
631
|
-
}, [
|
|
728
|
+
}, [
|
|
729
|
+
activeAnchor,
|
|
730
|
+
updateTooltipPosition,
|
|
731
|
+
rendered,
|
|
732
|
+
anchorRefs,
|
|
733
|
+
anchorsBySelect,
|
|
734
|
+
closeOnEsc,
|
|
735
|
+
events,
|
|
736
|
+
]);
|
|
632
737
|
React.useEffect(() => {
|
|
633
738
|
let selector = anchorSelect !== null && anchorSelect !== void 0 ? anchorSelect : '';
|
|
634
739
|
if (!selector && id) {
|
|
@@ -699,52 +804,9 @@
|
|
|
699
804
|
documentObserver.disconnect();
|
|
700
805
|
};
|
|
701
806
|
}, [id, anchorSelect, activeAnchor]);
|
|
702
|
-
const updateTooltipPosition = () => {
|
|
703
|
-
if (position) {
|
|
704
|
-
// if `position` is set, override regular and `float` positioning
|
|
705
|
-
handleTooltipPosition(position);
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
if (float) {
|
|
709
|
-
if (lastFloatPosition.current) {
|
|
710
|
-
/*
|
|
711
|
-
Without this, changes to `content`, `place`, `offset`, ..., will only
|
|
712
|
-
trigger a position calculation after a `mousemove` event.
|
|
713
|
-
|
|
714
|
-
To see why this matters, comment this line, run `yarn dev` and click the
|
|
715
|
-
"Hover me!" anchor.
|
|
716
|
-
*/
|
|
717
|
-
handleTooltipPosition(lastFloatPosition.current);
|
|
718
|
-
}
|
|
719
|
-
// if `float` is set, override regular positioning
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
computeTooltipPosition({
|
|
723
|
-
place,
|
|
724
|
-
offset,
|
|
725
|
-
elementReference: activeAnchor,
|
|
726
|
-
tooltipReference: tooltipRef.current,
|
|
727
|
-
tooltipArrowReference: tooltipArrowRef.current,
|
|
728
|
-
strategy: positionStrategy,
|
|
729
|
-
middlewares,
|
|
730
|
-
border,
|
|
731
|
-
}).then((computedStylesData) => {
|
|
732
|
-
if (!mounted.current) {
|
|
733
|
-
// invalidate computed positions after remount
|
|
734
|
-
return;
|
|
735
|
-
}
|
|
736
|
-
if (Object.keys(computedStylesData.tooltipStyles).length) {
|
|
737
|
-
setInlineStyles(computedStylesData.tooltipStyles);
|
|
738
|
-
}
|
|
739
|
-
if (Object.keys(computedStylesData.tooltipArrowStyles).length) {
|
|
740
|
-
setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
|
|
741
|
-
}
|
|
742
|
-
setActualPlacement(computedStylesData.place);
|
|
743
|
-
});
|
|
744
|
-
};
|
|
745
807
|
React.useEffect(() => {
|
|
746
808
|
updateTooltipPosition();
|
|
747
|
-
}, [
|
|
809
|
+
}, [updateTooltipPosition]);
|
|
748
810
|
React.useEffect(() => {
|
|
749
811
|
if (!(contentWrapperRef === null || contentWrapperRef === void 0 ? void 0 : contentWrapperRef.current)) {
|
|
750
812
|
return () => null;
|
|
@@ -799,6 +861,7 @@
|
|
|
799
861
|
}, [id, anchorSelect]);
|
|
800
862
|
const canShow = !hidden && content && show && Object.keys(inlineStyles).length > 0;
|
|
801
863
|
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}`, {
|
|
864
|
+
'react-tooltip__show': canShow,
|
|
802
865
|
[coreStyles['show']]: canShow,
|
|
803
866
|
[coreStyles['fixed']]: positionStrategy === 'fixed',
|
|
804
867
|
[coreStyles['clickable']]: clickable,
|
|
@@ -1189,6 +1252,7 @@
|
|
|
1189
1252
|
exports.Tooltip = TooltipController;
|
|
1190
1253
|
exports.TooltipProvider = TooltipProvider;
|
|
1191
1254
|
exports.TooltipWrapper = TooltipWrapper;
|
|
1255
|
+
exports.removeStyle = removeStyle;
|
|
1192
1256
|
|
|
1193
1257
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1194
1258
|
|