42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
|
|
import * as React from 'react';
|
|
import Tooltip from '../tooltip';
|
|
export default function SliderTooltip(props) {
|
|
var visible = props.visible;
|
|
var tooltipRef = React.useRef(null);
|
|
var rafRef = React.useRef(null);
|
|
|
|
function cancelKeepAlign() {
|
|
window.cancelAnimationFrame(rafRef.current);
|
|
rafRef.current = null;
|
|
}
|
|
|
|
function keepAlign() {
|
|
if (rafRef.current !== null) {
|
|
return;
|
|
}
|
|
|
|
rafRef.current = window.requestAnimationFrame(function () {
|
|
if (tooltipRef.current && tooltipRef.current.tooltip) {
|
|
tooltipRef.current.tooltip.forcePopupAlign();
|
|
}
|
|
|
|
rafRef.current = null;
|
|
keepAlign();
|
|
});
|
|
}
|
|
|
|
React.useEffect(function () {
|
|
if (visible) {
|
|
keepAlign();
|
|
} else {
|
|
cancelKeepAlign();
|
|
}
|
|
|
|
return cancelKeepAlign;
|
|
}, [visible]);
|
|
return /*#__PURE__*/React.createElement(Tooltip, _extends({
|
|
ref: tooltipRef
|
|
}, props));
|
|
} |