import { ChangeEventHandler, useEffect, useRef } from "react"; export type SliderProps = { label: string; min: number; max: number; step: number; value?: number; valueDisplay?: string; onChange: ChangeEventHandler; }; export function Slider(props: SliderProps) { const ref = useRef(null); useEffect(() => { const e = ref.current as HTMLInputElement; e.style.setProperty("--value", e.value); e.style.setProperty("--min", e.min === "" ? "0" : e.min); e.style.setProperty("--max", e.max === "" ? "100" : e.max); e.addEventListener("input", () => e.style.setProperty("--value", e.value)); }, [ref]); return (
{props.valueDisplay ?? props.value}
); }