SliderTooltip.js
986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import * as React from 'react';
import Tooltip from 'rc-tooltip';
import { composeRef } from "rc-util/es/ref";
import raf from "rc-util/es/raf";
var SliderTooltip = React.forwardRef(function (props, ref) {
var visible = props.visible,
overlay = props.overlay;
var innerRef = React.useRef(null);
var tooltipRef = composeRef(ref, innerRef);
var rafRef = React.useRef(null);
function cancelKeepAlign() {
raf.cancel(rafRef.current);
}
function keepAlign() {
rafRef.current = raf(function () {
var _innerRef$current;
(_innerRef$current = innerRef.current) === null || _innerRef$current === void 0 ? void 0 : _innerRef$current.forcePopupAlign();
});
}
React.useEffect(function () {
if (visible) {
keepAlign();
} else {
cancelKeepAlign();
}
return cancelKeepAlign;
}, [visible, overlay]);
return React.createElement(Tooltip, Object.assign({
ref: tooltipRef
}, props));
});
export default SliderTooltip;