/** * rc-tooltip tooltip slider */ import * as React from "react"; import "rc-tooltip/assets/bootstrap.css"; import Slider from "rc-slider"; import type { SliderProps } from "rc-slider"; import raf from "rc-util/lib/raf"; import Tooltip from "rc-tooltip"; const HandleTooltip = (props: { value: number; children: React.ReactElement; visible: boolean; tipFormatter?: (value: number) => React.ReactNode; }) => { const { value, children, visible, tipFormatter = (val) => `${val} %`, ...restProps } = props; const tooltipRef = React.useRef(); const rafRef = React.useRef(null); function cancelKeepAlign() { raf.cancel(rafRef.current!); } function keepAlign() { rafRef.current = raf(() => { // tooltipRef.current?.forcePopupAlign(); }); } React.useEffect(() => { if (visible) { keepAlign(); } else { cancelKeepAlign(); } return cancelKeepAlign; }, [value, visible]); return ( {children} ); }; export const handleRender: SliderProps["handleRender"] = (node, props) => { return ( {node} ); }; const TooltipSlider = ({ tipFormatter, tipProps, ...props }: SliderProps & { tipFormatter?: (value: number) => React.ReactNode; tipProps: any; }) => { const tipHandleRender: SliderProps["handleRender"] = (node, handleProps) => { return ( {node} ); }; return ; }; export default TooltipSlider;