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