"use client"; import { useId, type CSSProperties } from "react"; export function RangeSelector({ label, value, onValueChange, min = 0, max = 100, step = 1, format = (v) => String(v), className = "", }: { label: string; value: readonly [number, number]; onValueChange: (value: [number, number]) => void; min?: number; max?: number; step?: number; format?: (value: number) => string; className?: string; }) { const id = useId(), low = Number.isFinite(min) ? min : 0, high = Number.isFinite(max) ? Math.max(low, max) : 100; const start = Math.max( low, Math.min(high, Number.isFinite(value[0]) ? value[0] : low), ), end = Math.max( start, Math.min(high, Number.isFinite(value[1]) ? value[1] : high), ); // Each input spans only the stretch it can reach, so both thumbs share one scale. const at = (v: number) => high > low ? Math.round(((v - low) / (high - low)) * 1e4) / 1e4 : 0; const stretch = (from: number, to: number) => ({ "--mizu-range-min": at(from), "--mizu-range-max": at(to), }) as CSSProperties; return (
); }