import RcSlider from 'rc-slider'; import styles from './Slider.module.css'; import 'rc-slider/assets/index.css'; export interface Props { min: number; max: number; step: number; value: number; onChange: (value: number) => void; // true if you want to always show the tooltip dataCy: string; visibleTooltip?: boolean; } export function Slider({ min, max, step, value, onChange, dataCy, visibleTooltip: visible, }: Props) { const SliderWithTooltip = RcSlider.createSliderWithTooltip(RcSlider); // if the tooltip is always visible, hide the marks when tooltip value gets close to the edges const marks = { [min]: visible && value / max < 0.1 ? '' : translateMinValue(min), [max]: visible && value / max > 0.9 ? '' : max.toString(), }; return (
); } function translateMinValue(value: number) { if (value === 0) { return 'unlimited'; } return value.toString(); }