react-tooltip 5.7.5 → 5.8.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 +42 -19
- package/dist/react-tooltip.cjs.js +130 -35
- package/dist/react-tooltip.cjs.min.js +3 -3
- package/dist/react-tooltip.d.ts +19 -1
- package/dist/react-tooltip.esm.js +131 -36
- package/dist/react-tooltip.esm.min.js +3 -3
- package/dist/react-tooltip.umd.js +130 -35
- package/dist/react-tooltip.umd.min.js +3 -3
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -46,9 +46,12 @@ yarn add react-tooltip
|
|
|
46
46
|
|
|
47
47
|
## Usage
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
> :warning: If you were already using `react-tooltip<=5.7.5`, you'll be getting some deprecation warnings regarding the `anchorId` prop and some other features.
|
|
50
|
+
In versions >=5.8.0, we've introduced the `data-tooltip-id` attribute, and the `anchorSelect` prop, which are our recommended methods of using the tooltip moving forward. Check [the docs](https://react-tooltip.com/docs/getting-started) for more details.
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
### Using NPM package
|
|
53
|
+
|
|
54
|
+
1 . Import the CSS file to set default styling.
|
|
52
55
|
|
|
53
56
|
```js
|
|
54
57
|
import 'react-tooltip/dist/react-tooltip.css'
|
|
@@ -56,7 +59,7 @@ import 'react-tooltip/dist/react-tooltip.css'
|
|
|
56
59
|
|
|
57
60
|
This needs to be done only once. We suggest you do it on your `src/index.js` or equivalent file.
|
|
58
61
|
|
|
59
|
-
2 . Import `react-tooltip` after installation
|
|
62
|
+
2 . Import `react-tooltip` after installation.
|
|
60
63
|
|
|
61
64
|
```js
|
|
62
65
|
import { Tooltip } from 'react-tooltip'
|
|
@@ -68,20 +71,41 @@ or if you want to still use the name ReactTooltip as V4:
|
|
|
68
71
|
import { Tooltip as ReactTooltip } from 'react-tooltip'
|
|
69
72
|
```
|
|
70
73
|
|
|
71
|
-
3 . Add `data-tooltip-content="your placeholder"` to your element
|
|
74
|
+
3 . Add `data-tooltip-id="<tooltip id>"` and `data-tooltip-content="<your placeholder>"` to your element.
|
|
75
|
+
|
|
76
|
+
> `data-tooltip-id` is the equivalent of V4's `data-for`.
|
|
72
77
|
|
|
73
78
|
```jsx
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
</
|
|
79
|
+
<a data-tooltip-id="my-tooltip" data-tooltip-content="Hello world!">
|
|
80
|
+
◕‿‿◕
|
|
81
|
+
</a>
|
|
77
82
|
```
|
|
78
83
|
|
|
79
|
-
4 . Include
|
|
84
|
+
4 . Include the `<Tooltip />` element.
|
|
85
|
+
|
|
86
|
+
> Don't forget to set the id, it won't work without it!
|
|
80
87
|
|
|
81
88
|
```jsx
|
|
82
|
-
<
|
|
89
|
+
<Tooltip id="my-tooltip" />
|
|
83
90
|
```
|
|
84
91
|
|
|
92
|
+
#### Using multiple anchor elements
|
|
93
|
+
|
|
94
|
+
You can also set the `anchorSelect` tooltip prop to use the tooltip with multiple anchor elements without having to set `data-tooltip-id` on each of them.
|
|
95
|
+
`anchorSelect` must be a valid [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors).
|
|
96
|
+
|
|
97
|
+
```jsx
|
|
98
|
+
<a className="my-anchor-element" data-tooltip-content="Hello world!">
|
|
99
|
+
◕‿‿◕
|
|
100
|
+
</a>
|
|
101
|
+
<a className="my-anchor-element" data-tooltip-content="Hello to you too!">
|
|
102
|
+
◕‿‿◕
|
|
103
|
+
</a>
|
|
104
|
+
<Tooltip anchorSelect=".my-anchor-element" />
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Check [the V5 docs](https://react-tooltip.com/docs/getting-started) for more complex use cases.
|
|
108
|
+
|
|
85
109
|
### Standalone
|
|
86
110
|
|
|
87
111
|
You can import `node_modules/react-tooltip/dist/react-tooltip.[mode].js` into your page. Please make sure that you have already imported `react` and `react-dom` into your page.
|
|
@@ -98,27 +122,26 @@ PS: all the files have a minified version and a non-minified version.
|
|
|
98
122
|
|
|
99
123
|
For all available options, please check [React Tooltip Options](https://react-tooltip.com/docs/options)
|
|
100
124
|
|
|
101
|
-
### Security
|
|
125
|
+
### Security note
|
|
102
126
|
|
|
103
127
|
The `html` option allows a tooltip to directly display raw HTML. This is a security risk if any of that content is supplied by the user. Any user-supplied content must be sanitized, using a package like [sanitize-html](https://www.npmjs.com/package/sanitize-html). We chose not to include sanitization after discovering it [increased our package size](https://github.com/wwayne/react-tooltip/issues/429) too much - we don't want to penalize people who don't use the `html` option.
|
|
104
128
|
|
|
105
|
-
#### JSX
|
|
129
|
+
#### JSX note
|
|
106
130
|
|
|
107
|
-
You can use
|
|
131
|
+
You can use [`React.renderToStaticMarkup()` function](https://reactjs.org/docs/react-dom-server.html#rendertostaticmarkup) to use JSX instead of HTML.
|
|
108
132
|
**Example:**
|
|
109
133
|
|
|
110
134
|
```jsx
|
|
111
135
|
import ReactDOMServer from 'react-dom/server';
|
|
112
136
|
[...]
|
|
113
|
-
<
|
|
114
|
-
|
|
115
|
-
</
|
|
137
|
+
<a
|
|
138
|
+
data-tooltip-id="my-tooltip"
|
|
139
|
+
data-tooltip-html={ReactDOMServer.renderToStaticMarkup(<div>I am <b>JSX</b> content</div>)}
|
|
140
|
+
>
|
|
141
|
+
◕‿‿◕
|
|
142
|
+
</a>
|
|
116
143
|
```
|
|
117
144
|
|
|
118
|
-
#### Note
|
|
119
|
-
|
|
120
|
-
- **id** is necessary, because `<ReactTooltip anchorId="my-element" />` finds the tooltip via this attribute
|
|
121
|
-
|
|
122
145
|
## Article
|
|
123
146
|
|
|
124
147
|
[How I insert sass into react component](https://medium.com/@wwayne_me/how-i-insert-sass-into-my-npm-react-component-b46b9811c226#.gi4hxu44a)
|
|
@@ -2543,6 +2543,10 @@ const DEFAULT_CONTEXT_DATA_WRAPPER = {
|
|
|
2543
2543
|
getTooltipData: () => DEFAULT_CONTEXT_DATA,
|
|
2544
2544
|
};
|
|
2545
2545
|
const TooltipContext = require$$0.createContext(DEFAULT_CONTEXT_DATA_WRAPPER);
|
|
2546
|
+
/**
|
|
2547
|
+
* @deprecated Use the `data-tooltip-id` attribute, or the `anchorSelect` prop instead.
|
|
2548
|
+
* See https://react-tooltip.com/docs/getting-started
|
|
2549
|
+
*/
|
|
2546
2550
|
const TooltipProvider = ({ children }) => {
|
|
2547
2551
|
const [anchorRefMap, setAnchorRefMap] = require$$0.useState({
|
|
2548
2552
|
[DEFAULT_TOOLTIP_ID]: new Set(),
|
|
@@ -2603,6 +2607,10 @@ function useTooltip(tooltipId = DEFAULT_TOOLTIP_ID) {
|
|
|
2603
2607
|
return require$$0.useContext(TooltipContext).getTooltipData(tooltipId);
|
|
2604
2608
|
}
|
|
2605
2609
|
|
|
2610
|
+
/**
|
|
2611
|
+
* @deprecated Use the `data-tooltip-id` attribute, or the `anchorSelect` prop instead.
|
|
2612
|
+
* See https://react-tooltip.com/docs/getting-started
|
|
2613
|
+
*/
|
|
2606
2614
|
const TooltipWrapper = ({ tooltipId, children, className, place, content, html, variant, offset, wrapper, events, positionStrategy, delayShow, delayHide, }) => {
|
|
2607
2615
|
const { attach, detach } = useTooltip(tooltipId);
|
|
2608
2616
|
const anchorRef = require$$0.useRef(null);
|
|
@@ -2666,9 +2674,9 @@ var styles = {"tooltip":"styles-module_tooltip__mnnfp","fixed":"styles-module_fi
|
|
|
2666
2674
|
|
|
2667
2675
|
const Tooltip = ({
|
|
2668
2676
|
// props
|
|
2669
|
-
id, className, classNameArrow, variant = 'dark', anchorId, place = 'top', offset = 10, events = ['hover'], positionStrategy = 'absolute', middlewares, wrapper: WrapperElement, children = null, delayShow = 0, delayHide = 0, float = false, noArrow = false, clickable = false, closeOnEsc = false, style: externalStyles, position, afterShow, afterHide,
|
|
2677
|
+
id, className, classNameArrow, variant = 'dark', anchorId, anchorSelect, place = 'top', offset = 10, events = ['hover'], positionStrategy = 'absolute', middlewares, wrapper: WrapperElement, children = null, delayShow = 0, delayHide = 0, float = false, noArrow = false, clickable = false, closeOnEsc = false, style: externalStyles, position, afterShow, afterHide,
|
|
2670
2678
|
// props handled by controller
|
|
2671
|
-
content, html, isOpen, setIsOpen, }) => {
|
|
2679
|
+
content, html, isOpen, setIsOpen, activeAnchor, setActiveAnchor, }) => {
|
|
2672
2680
|
const tooltipRef = require$$0.useRef(null);
|
|
2673
2681
|
const tooltipArrowRef = require$$0.useRef(null);
|
|
2674
2682
|
const tooltipShowDelayTimerRef = require$$0.useRef(null);
|
|
@@ -2679,21 +2687,71 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2679
2687
|
const [rendered, setRendered] = require$$0.useState(false);
|
|
2680
2688
|
const wasShowing = require$$0.useRef(false);
|
|
2681
2689
|
const lastFloatPosition = require$$0.useRef(null);
|
|
2690
|
+
/**
|
|
2691
|
+
* @todo Remove this in a future version (provider/wrapper method is deprecated)
|
|
2692
|
+
*/
|
|
2682
2693
|
const { anchorRefs, setActiveAnchor: setProviderActiveAnchor } = useTooltip(id);
|
|
2683
|
-
const [activeAnchor, setActiveAnchor] = require$$0.useState({ current: null });
|
|
2684
2694
|
const hoveringTooltip = require$$0.useRef(false);
|
|
2695
|
+
const [anchorsBySelect, setAnchorsBySelect] = require$$0.useState([]);
|
|
2696
|
+
const mounted = require$$0.useRef(false);
|
|
2697
|
+
require$$0.useEffect(() => {
|
|
2698
|
+
let selector = anchorSelect;
|
|
2699
|
+
if (!selector && id) {
|
|
2700
|
+
selector = `[data-tooltip-id='${id}']`;
|
|
2701
|
+
}
|
|
2702
|
+
if (!selector) {
|
|
2703
|
+
return;
|
|
2704
|
+
}
|
|
2705
|
+
try {
|
|
2706
|
+
const anchors = Array.from(document.querySelectorAll(selector));
|
|
2707
|
+
setAnchorsBySelect(anchors);
|
|
2708
|
+
}
|
|
2709
|
+
catch (_a) {
|
|
2710
|
+
// warning was already issued in the controller
|
|
2711
|
+
setAnchorsBySelect([]);
|
|
2712
|
+
}
|
|
2713
|
+
}, [anchorSelect, activeAnchor]);
|
|
2714
|
+
/**
|
|
2715
|
+
* useLayoutEffect runs before useEffect,
|
|
2716
|
+
* but should be used carefully because of caveats
|
|
2717
|
+
* https://beta.reactjs.org/reference/react/useLayoutEffect#caveats
|
|
2718
|
+
*/
|
|
2719
|
+
require$$0.useLayoutEffect(() => {
|
|
2720
|
+
mounted.current = true;
|
|
2721
|
+
return () => {
|
|
2722
|
+
mounted.current = false;
|
|
2723
|
+
};
|
|
2724
|
+
}, []);
|
|
2685
2725
|
require$$0.useEffect(() => {
|
|
2686
2726
|
if (!show) {
|
|
2687
|
-
|
|
2727
|
+
/**
|
|
2728
|
+
* this fixes weird behavior when switching between two anchor elements very quickly
|
|
2729
|
+
* remove the timeout and switch quickly between two adjancent anchor elements to see it
|
|
2730
|
+
*
|
|
2731
|
+
* in practice, this means the tooltip is not immediately removed from the DOM on hide
|
|
2732
|
+
*/
|
|
2733
|
+
const timeout = setTimeout(() => {
|
|
2734
|
+
setRendered(false);
|
|
2735
|
+
}, 150);
|
|
2736
|
+
return () => {
|
|
2737
|
+
clearTimeout(timeout);
|
|
2738
|
+
};
|
|
2688
2739
|
}
|
|
2740
|
+
return () => null;
|
|
2689
2741
|
}, [show]);
|
|
2690
2742
|
const handleShow = (value) => {
|
|
2743
|
+
if (!mounted.current) {
|
|
2744
|
+
return;
|
|
2745
|
+
}
|
|
2691
2746
|
setRendered(true);
|
|
2692
2747
|
/**
|
|
2693
2748
|
* wait for the component to render and calculate position
|
|
2694
2749
|
* before actually showing
|
|
2695
2750
|
*/
|
|
2696
2751
|
setTimeout(() => {
|
|
2752
|
+
if (!mounted.current) {
|
|
2753
|
+
return;
|
|
2754
|
+
}
|
|
2697
2755
|
setIsOpen === null || setIsOpen === void 0 ? void 0 : setIsOpen(value);
|
|
2698
2756
|
if (isOpen === undefined) {
|
|
2699
2757
|
setShow(value);
|
|
@@ -2761,7 +2819,7 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2761
2819
|
handleShow(true);
|
|
2762
2820
|
}
|
|
2763
2821
|
const target = (_a = event.currentTarget) !== null && _a !== void 0 ? _a : event.target;
|
|
2764
|
-
setActiveAnchor(
|
|
2822
|
+
setActiveAnchor(target);
|
|
2765
2823
|
setProviderActiveAnchor({ current: target });
|
|
2766
2824
|
if (tooltipHideDelayTimerRef.current) {
|
|
2767
2825
|
clearTimeout(tooltipHideDelayTimerRef.current);
|
|
@@ -2832,9 +2890,12 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2832
2890
|
handleHideTooltipDelayed();
|
|
2833
2891
|
}
|
|
2834
2892
|
};
|
|
2835
|
-
const
|
|
2836
|
-
|
|
2837
|
-
if (
|
|
2893
|
+
const handleClickOutsideAnchors = (event) => {
|
|
2894
|
+
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
2895
|
+
if (anchorById === null || anchorById === void 0 ? void 0 : anchorById.contains(event.target)) {
|
|
2896
|
+
return;
|
|
2897
|
+
}
|
|
2898
|
+
if (anchorsBySelect.some((anchor) => anchor.contains(event.target))) {
|
|
2838
2899
|
return;
|
|
2839
2900
|
}
|
|
2840
2901
|
handleShow(false);
|
|
@@ -2852,9 +2913,11 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2852
2913
|
require$$0.useEffect(() => {
|
|
2853
2914
|
var _a, _b;
|
|
2854
2915
|
const elementRefs = new Set(anchorRefs);
|
|
2916
|
+
anchorsBySelect.forEach((anchor) => {
|
|
2917
|
+
elementRefs.add({ current: anchor });
|
|
2918
|
+
});
|
|
2855
2919
|
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
2856
2920
|
if (anchorById) {
|
|
2857
|
-
setActiveAnchor((anchor) => anchor.current === anchorById ? anchor : { current: anchorById });
|
|
2858
2921
|
elementRefs.add({ current: anchorById });
|
|
2859
2922
|
}
|
|
2860
2923
|
if (!elementRefs.size) {
|
|
@@ -2865,7 +2928,7 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2865
2928
|
}
|
|
2866
2929
|
const enabledEvents = [];
|
|
2867
2930
|
if (events.find((event) => event === 'click')) {
|
|
2868
|
-
window.addEventListener('click',
|
|
2931
|
+
window.addEventListener('click', handleClickOutsideAnchors);
|
|
2869
2932
|
enabledEvents.push({ event: 'click', listener: handleClickTooltipAnchor });
|
|
2870
2933
|
}
|
|
2871
2934
|
if (events.find((event) => event === 'hover')) {
|
|
@@ -2894,9 +2957,8 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2894
2957
|
(_a = ref.current) === null || _a === void 0 ? void 0 : _a.addEventListener(event, listener);
|
|
2895
2958
|
});
|
|
2896
2959
|
});
|
|
2897
|
-
const anchorElement = anchorById !== null && anchorById !== void 0 ? anchorById : activeAnchor.current;
|
|
2898
2960
|
const parentObserverCallback = (mutationList) => {
|
|
2899
|
-
if (!
|
|
2961
|
+
if (!activeAnchor) {
|
|
2900
2962
|
return;
|
|
2901
2963
|
}
|
|
2902
2964
|
mutationList.some((mutation) => {
|
|
@@ -2904,8 +2966,9 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2904
2966
|
return false;
|
|
2905
2967
|
}
|
|
2906
2968
|
return [...mutation.removedNodes].some((node) => {
|
|
2907
|
-
if (node.contains(
|
|
2969
|
+
if (node.contains(activeAnchor)) {
|
|
2908
2970
|
handleShow(false);
|
|
2971
|
+
setActiveAnchor(null);
|
|
2909
2972
|
return true;
|
|
2910
2973
|
}
|
|
2911
2974
|
return false;
|
|
@@ -2918,7 +2981,7 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2918
2981
|
return () => {
|
|
2919
2982
|
var _a, _b;
|
|
2920
2983
|
if (events.find((event) => event === 'click')) {
|
|
2921
|
-
window.removeEventListener('click',
|
|
2984
|
+
window.removeEventListener('click', handleClickOutsideAnchors);
|
|
2922
2985
|
}
|
|
2923
2986
|
if (closeOnEsc) {
|
|
2924
2987
|
window.removeEventListener('keydown', handleEsc);
|
|
@@ -2939,12 +3002,12 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2939
3002
|
* rendered is also a dependency to ensure anchor observers are re-registered
|
|
2940
3003
|
* since `tooltipRef` becomes stale after removing/adding the tooltip to the DOM
|
|
2941
3004
|
*/
|
|
2942
|
-
}, [rendered, anchorRefs, activeAnchor, closeOnEsc,
|
|
3005
|
+
}, [rendered, anchorRefs, activeAnchor, closeOnEsc, events, delayHide, delayShow]);
|
|
2943
3006
|
require$$0.useEffect(() => {
|
|
2944
3007
|
if (position) {
|
|
2945
3008
|
// if `position` is set, override regular and `float` positioning
|
|
2946
3009
|
handleTooltipPosition(position);
|
|
2947
|
-
return
|
|
3010
|
+
return;
|
|
2948
3011
|
}
|
|
2949
3012
|
if (float) {
|
|
2950
3013
|
if (lastFloatPosition.current) {
|
|
@@ -2958,24 +3021,18 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2958
3021
|
handleTooltipPosition(lastFloatPosition.current);
|
|
2959
3022
|
}
|
|
2960
3023
|
// if `float` is set, override regular positioning
|
|
2961
|
-
return
|
|
2962
|
-
}
|
|
2963
|
-
let elementReference = activeAnchor.current;
|
|
2964
|
-
if (anchorId) {
|
|
2965
|
-
// `anchorId` element takes precedence
|
|
2966
|
-
elementReference = document.querySelector(`[id='${anchorId}']`);
|
|
3024
|
+
return;
|
|
2967
3025
|
}
|
|
2968
|
-
let mounted = true;
|
|
2969
3026
|
computeTooltipPosition({
|
|
2970
3027
|
place,
|
|
2971
3028
|
offset,
|
|
2972
|
-
elementReference,
|
|
3029
|
+
elementReference: activeAnchor,
|
|
2973
3030
|
tooltipReference: tooltipRef.current,
|
|
2974
3031
|
tooltipArrowReference: tooltipArrowRef.current,
|
|
2975
3032
|
strategy: positionStrategy,
|
|
2976
3033
|
middlewares,
|
|
2977
3034
|
}).then((computedStylesData) => {
|
|
2978
|
-
if (!mounted) {
|
|
3035
|
+
if (!mounted.current) {
|
|
2979
3036
|
// invalidate computed positions after remount
|
|
2980
3037
|
return;
|
|
2981
3038
|
}
|
|
@@ -2986,10 +3043,20 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
2986
3043
|
setInlineArrowStyles(computedStylesData.tooltipArrowStyles);
|
|
2987
3044
|
}
|
|
2988
3045
|
});
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
3046
|
+
}, [show, activeAnchor, content, html, place, offset, positionStrategy, position]);
|
|
3047
|
+
require$$0.useEffect(() => {
|
|
3048
|
+
var _a;
|
|
3049
|
+
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
3050
|
+
const anchors = [...anchorsBySelect, anchorById];
|
|
3051
|
+
if (!activeAnchor || !anchors.includes(activeAnchor)) {
|
|
3052
|
+
/**
|
|
3053
|
+
* if there is no active anchor,
|
|
3054
|
+
* or if the current active anchor is not amongst the allowed ones,
|
|
3055
|
+
* reset it
|
|
3056
|
+
*/
|
|
3057
|
+
setActiveAnchor((_a = anchorsBySelect[0]) !== null && _a !== void 0 ? _a : anchorById);
|
|
3058
|
+
}
|
|
3059
|
+
}, [anchorId, anchorsBySelect, activeAnchor]);
|
|
2993
3060
|
require$$0.useEffect(() => {
|
|
2994
3061
|
return () => {
|
|
2995
3062
|
if (tooltipShowDelayTimerRef.current) {
|
|
@@ -3001,17 +3068,17 @@ content, html, isOpen, setIsOpen, }) => {
|
|
|
3001
3068
|
};
|
|
3002
3069
|
}, []);
|
|
3003
3070
|
const hasContentOrChildren = Boolean(html || content || children);
|
|
3004
|
-
const canShow =
|
|
3071
|
+
const canShow = hasContentOrChildren && show && Object.keys(inlineStyles).length > 0;
|
|
3005
3072
|
return rendered ? (jsxRuntime.exports.jsxs(WrapperElement, { id: id, role: "tooltip", className: classNames('react-tooltip', styles['tooltip'], styles[variant], className, {
|
|
3006
3073
|
[styles['show']]: canShow,
|
|
3007
3074
|
[styles['fixed']]: positionStrategy === 'fixed',
|
|
3008
3075
|
[styles['clickable']]: clickable,
|
|
3009
|
-
}), style: { ...externalStyles, ...inlineStyles }, ref: tooltipRef, children: [
|
|
3076
|
+
}), style: { ...externalStyles, ...inlineStyles }, ref: tooltipRef, children: [(html && jsxRuntime.exports.jsx(TooltipContent, { content: html })) || content || children, jsxRuntime.exports.jsx(WrapperElement, { className: classNames('react-tooltip-arrow', styles['arrow'], classNameArrow, {
|
|
3010
3077
|
[styles['no-arrow']]: noArrow,
|
|
3011
3078
|
}), style: inlineArrowStyles, ref: tooltipArrowRef })] })) : null;
|
|
3012
3079
|
};
|
|
3013
3080
|
|
|
3014
|
-
const TooltipController = ({ id, anchorId, content, html, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, noArrow = false, clickable = false, closeOnEsc = false, style, position, isOpen, setIsOpen, afterShow, afterHide, }) => {
|
|
3081
|
+
const TooltipController = ({ id, anchorId, anchorSelect, content, html, className, classNameArrow, variant = 'dark', place = 'top', offset = 10, wrapper = 'div', children = null, events = ['hover'], positionStrategy = 'absolute', middlewares, delayShow = 0, delayHide = 0, float = false, noArrow = false, clickable = false, closeOnEsc = false, style, position, isOpen, setIsOpen, afterShow, afterHide, }) => {
|
|
3015
3082
|
const [tooltipContent, setTooltipContent] = require$$0.useState(content);
|
|
3016
3083
|
const [tooltipHtml, setTooltipHtml] = require$$0.useState(html);
|
|
3017
3084
|
const [tooltipPlace, setTooltipPlace] = require$$0.useState(place);
|
|
@@ -3023,7 +3090,11 @@ const TooltipController = ({ id, anchorId, content, html, className, classNameAr
|
|
|
3023
3090
|
const [tooltipWrapper, setTooltipWrapper] = require$$0.useState(wrapper);
|
|
3024
3091
|
const [tooltipEvents, setTooltipEvents] = require$$0.useState(events);
|
|
3025
3092
|
const [tooltipPositionStrategy, setTooltipPositionStrategy] = require$$0.useState(positionStrategy);
|
|
3026
|
-
const
|
|
3093
|
+
const [activeAnchor, setActiveAnchor] = require$$0.useState(null);
|
|
3094
|
+
/**
|
|
3095
|
+
* @todo Remove this in a future version (provider/wrapper method is deprecated)
|
|
3096
|
+
*/
|
|
3097
|
+
const { anchorRefs, activeAnchor: providerActiveAnchor } = useTooltip(id);
|
|
3027
3098
|
const getDataAttributesFromAnchorElement = (elementReference) => {
|
|
3028
3099
|
const dataAttributes = elementReference === null || elementReference === void 0 ? void 0 : elementReference.getAttributeNames().reduce((acc, name) => {
|
|
3029
3100
|
var _a;
|
|
@@ -3090,9 +3161,30 @@ const TooltipController = ({ id, anchorId, content, html, className, classNameAr
|
|
|
3090
3161
|
require$$0.useEffect(() => {
|
|
3091
3162
|
setTooltipHtml(html);
|
|
3092
3163
|
}, [html]);
|
|
3164
|
+
require$$0.useEffect(() => {
|
|
3165
|
+
setTooltipPlace(place);
|
|
3166
|
+
}, [place]);
|
|
3093
3167
|
require$$0.useEffect(() => {
|
|
3094
3168
|
var _a;
|
|
3095
3169
|
const elementRefs = new Set(anchorRefs);
|
|
3170
|
+
let selector = anchorSelect;
|
|
3171
|
+
if (!selector && id) {
|
|
3172
|
+
selector = `[data-tooltip-id='${id}']`;
|
|
3173
|
+
}
|
|
3174
|
+
if (selector) {
|
|
3175
|
+
try {
|
|
3176
|
+
const anchorsBySelect = document.querySelectorAll(selector);
|
|
3177
|
+
anchorsBySelect.forEach((anchor) => {
|
|
3178
|
+
elementRefs.add({ current: anchor });
|
|
3179
|
+
});
|
|
3180
|
+
}
|
|
3181
|
+
catch (_b) {
|
|
3182
|
+
{
|
|
3183
|
+
// eslint-disable-next-line no-console
|
|
3184
|
+
console.warn(`[react-tooltip] "${anchorSelect}" is not a valid CSS selector`);
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
}
|
|
3096
3188
|
const anchorById = document.querySelector(`[id='${anchorId}']`);
|
|
3097
3189
|
if (anchorById) {
|
|
3098
3190
|
elementRefs.add({ current: anchorById });
|
|
@@ -3100,7 +3192,7 @@ const TooltipController = ({ id, anchorId, content, html, className, classNameAr
|
|
|
3100
3192
|
if (!elementRefs.size) {
|
|
3101
3193
|
return () => null;
|
|
3102
3194
|
}
|
|
3103
|
-
const anchorElement = (_a = activeAnchor
|
|
3195
|
+
const anchorElement = (_a = activeAnchor !== null && activeAnchor !== void 0 ? activeAnchor : anchorById) !== null && _a !== void 0 ? _a : providerActiveAnchor.current;
|
|
3104
3196
|
const observerCallback = (mutationList) => {
|
|
3105
3197
|
mutationList.forEach((mutation) => {
|
|
3106
3198
|
var _a;
|
|
@@ -3129,10 +3221,11 @@ const TooltipController = ({ id, anchorId, content, html, className, classNameAr
|
|
|
3129
3221
|
// Remove the observer when the tooltip is destroyed
|
|
3130
3222
|
observer.disconnect();
|
|
3131
3223
|
};
|
|
3132
|
-
}, [anchorRefs, activeAnchor, anchorId]);
|
|
3224
|
+
}, [anchorRefs, providerActiveAnchor, activeAnchor, anchorId, anchorSelect]);
|
|
3133
3225
|
const props = {
|
|
3134
3226
|
id,
|
|
3135
3227
|
anchorId,
|
|
3228
|
+
anchorSelect,
|
|
3136
3229
|
className,
|
|
3137
3230
|
classNameArrow,
|
|
3138
3231
|
content: tooltipContent,
|
|
@@ -3156,6 +3249,8 @@ const TooltipController = ({ id, anchorId, content, html, className, classNameAr
|
|
|
3156
3249
|
setIsOpen,
|
|
3157
3250
|
afterShow,
|
|
3158
3251
|
afterHide,
|
|
3252
|
+
activeAnchor,
|
|
3253
|
+
setActiveAnchor: (anchor) => setActiveAnchor(anchor),
|
|
3159
3254
|
};
|
|
3160
3255
|
return children ? jsxRuntime.exports.jsx(Tooltip, { ...props, children: children }) : jsxRuntime.exports.jsx(Tooltip, { ...props });
|
|
3161
3256
|
};
|