SliderTooltip.js
964 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
38
import _extends from "@babel/runtime/helpers/extends";
import * as React from 'react';
import { useRef } from 'react';
import { composeRef } from "rc-util/es/ref";
import raf from "rc-util/es/raf";
import Tooltip from '../tooltip';
var SliderTooltip = /*#__PURE__*/React.forwardRef(function (props, ref) {
var visible = props.visible;
var innerRef = useRef(null);
var rafRef = useRef(null);
function cancelKeepAlign() {
raf.cancel(rafRef.current);
rafRef.current = null;
}
function keepAlign() {
rafRef.current = raf(function () {
innerRef.current.forcePopupAlign();
rafRef.current = null;
keepAlign();
});
}
React.useEffect(function () {
if (visible) {
keepAlign();
} else {
cancelKeepAlign();
}
return cancelKeepAlign;
}, [visible]);
return /*#__PURE__*/React.createElement(Tooltip, _extends({
ref: composeRef(innerRef, ref)
}, props));
});
export default SliderTooltip;