import { useMemo, useState } from "react"; type RangeSliderProps = { min?: number; max?: number; step?: number; initialMax?: number; }; export function RangeSlider({ min = 0, max = 20, step = 1, initialMax = 10, }: RangeSliderProps) { const clampedInitial = Math.min(Math.max(initialMax, min), max); const [value, setValue] = useState(clampedInitial); const bars = useMemo(() => { const count = Math.max(0, Math.floor((value - min) / step)); return Array.from({ length: count }, (_, i) => i); }, [value, min, step]); return (
setValue(Number(e.target.value))} style={{ width: "100%", marginBottom: 12 }} />
{bars.map((i) => ( ))}
); }