Line SliderPro
Usage
Pass value and onValueChange to control it. Double-click resets to defaultValue.
Example
const [volume, setVolume] = useState(40)
<LineSlider label="Volume" value={volume} onValueChange={setVolume} />variant="track" keeps dim lines on the empty part and fills them in place.
Example
<LineSlider label="Brightness" variant="track" defaultValue={75} />gap sets the space between lines and fits as many as the width allows.
Example
<LineSlider label="Volume" gap={4} lineWidth={3} bordered />Tune the motion; the defaults are exported as LINE_SLIDER_MOTION.
Example
<LineSlider label="Volume" stiffness={600} damping={1} travel={40} blur={1} />onValueCommit fires once when a drag ends. Sparks show at the max and min; sparks={false} turns them off.
Example
<LineSlider label="Volume" onValueCommit={saveVolume} sparks={false} />sound adds a soft tick per line, rising as it fills, with a chime at the max. Off by default.
Example
<LineSlider label="Volume" sound />Props
| Prop | Type | Default | Notes |
|---|---|---|---|
label | string | — | Text above the track, linked to the input. |
value | number | — | Controlled value. Leave unset for the slider to keep its own. |
defaultValue | number | min | Starting value, and what double-click resets to. |
onValueChange | (value: number) => void | — | Fires on every change. |
onValueCommit | (value: number) => void | — | Fires once when a drag, key press or double-click reset finishes. |
min | number | 0 | |
max | number | 100 | |
step | number | 1 | |
lines | number | 64 | How many lines make up the track. |
gap | number | — | px between lines. When set, as many lines as fit the width are drawn and lines is ignored. |
lineWidth | number | 2 | px width of each line, rounded to whole screen pixels. |
bordered | boolean | false | Draw a rounded outline around the whole bar. |
accent | string | "#3f7bff" | Colour of the filled lines. |
variant | "reveal" | "track" | "reveal" | Dots with lines that fly off, or dim lines that fill and empty in place. |
sparks | boolean | true | Golden sparks at the max, a dull star at the min. |
sound | boolean | false | Soft ticks as lines fill or empty, a chime at the max and a thud at the min. |
stiffness | number | 400 | How hard the fill edge pulls toward the value. Higher sweeps faster. |
damping | number | 0.85 | 1 arrives without overshooting; lower overshoots and settles back. Keep it 0.7 or above for a direct-feeling slider. |
enterDuration | number | 60 | ms for a line to catch up with the edge when filling. |
exitDuration | number | 90 | ms for a line to catch up with the edge when emptying. |
travel | number | 25 | How far a leaving line drifts up or down, in % of its height. reveal only. |
blur | number | 1.5 | px of blur on a leaving line at its furthest. reveal only. |
format | (value: number) => string | up to 2 decimals | How the value is shown and read out. |
showValue | boolean | true | Show the value beside the label. |
disabled | boolean | false | |
name | string | — | Submitted with a form. |
Accessibility
- A native
input type="range"sits over the track, so arrow keys, Page Up/Down, Home/End and screen readers all work as with any slider aria-valuetextreads the formatted value- A ring shows around the track while it has keyboard focus
- With reduced motion on, lines and stars only fade, without moving