Open this example in the interactive library
Live preview
Source code
// components/AdjustableThreshold.tsx
import { useState } from "react";
export default function AdjustableThreshold({
value = 24,
unit = "kg",
}: { value?: number; unit?: string } = {}) {
const [n, set] = useState(Math.min(100, Math.max(0, value)));
return (
<label>
Threshold{" "}
<input
type="range"
min={0}
max={100}
value={n}
onChange={(e) => set(e.target.valueAsNumber)}
/>
<output>
{n} {unit}
</output>
</label>
);
}
