/** * @Author: ?? * @Date: ?? */ import React, { useCallback, useRef } from "react"; import { SliderProps } from "./interface"; import RcSlider, { SliderProps as RcSliderProps } from "rc-slider"; import "rc-slider/assets/index.css"; import SliderConfig from "./SliderConfig"; import "./index.css"; /** * ### 引用方法 * ```tsx * import { Slider } from "@atomintl/exchange-ui"; * ``` * ####更多使用:https://github.com/react-component/slider */ export const Slider: React.FC = props => { const { onSliderChange, adsorptionRadius, sliderValue, tipFormatter } = props; // const [value, setValue] = useState(defaultValue ?? SliderConfig.defaultValue); const handle = (child: React.ReactNode) => { const { transform } = child?.props?.style; return (
{tipFormatter ? tipFormatter(child.props?.["aria-valuenow"]) : `${child.props?.["aria-valuenow"]}%`}
); }; const ADJUST_NUM = adsorptionRadius ?? 5; const touchStatus = useRef(false); const runTime = useRef(0); const onBeforeChange = () => { touchStatus.current = true; runTime.current = 0; }; const onChange = (val: number | number[]) => { ++runTime.current; onSliderChange(Number(val)); }; const onAfterChange = (val: number | number[]) => { touchStatus.current = false; if (runTime.current <= 1) { Object.keys(SliderConfig.marks).forEach(_item => { const n = Number(_item); if (val >= n - ADJUST_NUM && val <= n + ADJUST_NUM) { val = n; } }); onSliderChange(Number(val)); } }; return (
); }; Slider.defaultProps = {}; export type { SliderProps }; export default Slider;