Slider
A primitives-first slider component package for lynx-ui. It supports both single-value sliders and two-thumb range sliders.You can check the source code to understand how it works, and you're welcome to submit PRs to enhance its capabilities.
Basic Usage
Compose styled, disabled, and right-to-left sliders from the core primitives.
Examples
Controlled
Control slider values externally, jump to presets, and snap to fixed steps.
Dynamic Width
Remeasure the track correctly when the slider container changes width.
Facade
Wrap the slider primitives in a reusable component with replaceable thumb content.
Price Range
Build a stepped two-thumb range with live values, committed values, and presets.
Progress
Omit the thumb to reuse the slider primitives as read-only progress indicators.
Shapes
Create distinct slider treatments by styling the track, indicator, and thumb.
With ScrollView
Preserve horizontal slider gestures inside nested horizontal and vertical scroll views.
Structure
A single-value slider uses one thumb.
A range slider uses two indexed thumbs.
Component API
SliderRoot
Root primitive props for a single-value or range slider. The generic
selects the value shape and defaults to number for existing single-value
usage. A range slider must provide its tuple through either value or
defaultValue so the runtime can determine the shape.
Range-thumb collision behavior is intentionally non-crossing: thumbs may
meet, but the active thumb stops at the other value without swapping or
pushing the other thumb.
SliderTrack containing SliderIndicator and optional SliderThumb.0 when omitted; a range slider must provide a tuple.true, the slider range grows from right to left.SliderRef.updateValue. In controlled mode, use this callback to keep
the external value prop in sync with the rendered value.[0, 1]. When set, the value snaps to the nearest multiple of step.[0, 1] or an ordered
lower/upper tuple. Do not use together with defaultValue.State-based styling & rendering
This component exposes runtime states through one or both of the following channels. The table lists only the channels available for each state:
- UI variant class — when supported, a class like
ui-<state>is toggled on the corresponding component node for selectors such as.ui-<state> { ... }. - Render-prop field — when supported and
childrenis a function, the state is passed in viachildren({ <state>: boolean, ... })for runtime-driven rendering.
UI variants applied by SliderRoot.
| Class Name | Description |
|---|---|
| ui-active | Applied from the start of a pointer or touch interaction until it ends. |
| ui-disabled | Applied when the slider is disabled. |
SliderTrack
Track primitive props.
SliderTrack establishes the measurement/layout coordinate space and renders the base rail.
SliderIndicator and optional SliderThumb.UI variants applied by SliderTrack.
| Class Name | Description |
|---|---|
| ui-active | Applied from the start of a pointer or touch interaction until it ends. |
| ui-disabled | Applied when the slider is disabled. |
SliderIndicator
Indicator primitive props.
SliderIndicator is a pure visual layer. It fills from zero to the value in single-value mode and spans the selected interval in range mode.
UI variants applied by SliderIndicator.
| Class Name | Description |
|---|---|
| ui-active | Applied from the start of a pointer or touch interaction until it ends. |
| ui-disabled | Applied when the slider is disabled. |
SliderThumb
Thumb primitive props.
SliderThumb is positioned by the current ratio inside SliderTrack and does not own interaction logic.
0; a range slider uses 0 for the lower thumb and 1
for the upper thumb.UI variants applied by SliderThumb.
| Class Name | Description |
|---|---|
| ui-active | Applied only to the thumb selected for the current pointer or touch interaction, from interaction start until it ends. |
| ui-disabled | Applied when the slider is disabled. |
SliderRef
Imperative methods exposed by SliderRoot for the selected value shape.
The generic defaults to number for compatibility with existing
single-value refs; use SliderRef<SliderRangeValue> for a range slider.
[0, 1].Supporting Types
SliderRangeValue
[0, 1] scale.
During dragging, the lower and upper thumbs may meet, but they never cross,
swap identities, or push one another.SliderValue
SliderRoot: either one normalized value or an ordered
lower/upper tuple.SliderThumbIndex
0; a range
slider uses index 0 for the lower value and 1 for the upper value.SliderValueChangeSource
external: value updated by imperative API calls.
- drag: value updated by pointer/touch dragging.SliderUpdateValueOptions
Options used by SliderRef.updateValue.