Slider
A range slider with a glass thumb: a small pill at rest that opens into a wide lens while you hold it.
Latest changeImprovedv1.3.8A color prop for the filled part of the track. The examples are now the slider in a few colours, nothing else.
- v1.3.8ImprovedA
colorprop for the filled part of the track. The examples are now the slider in a few colours, nothing else. - v1.3.3ImprovedExamples for the four sizes, a range of its own with
min,maxandstep, icons, and clear glass at rest. - v1.3.0NewThe range slider of the first previews: a glass pill that opens into a wide lens while held.
- All changes →
Use it for
- Picking a value on a continuous range: volume, brightness, opacity.
Not for
- Exact numbers the user must type: use a number input.
- Confirming one action: that is Slide to Confirm.
Installation
npx shadcn@latest add https://onemorethink.dev/r/slider.jsonSlider, Switch and Checkbox are drawn by their own renderer, which needs three, and take their behaviour (keyboard, the label, the input a form reads) from UI SDK: @ui-sdk/core and @ui-sdk/react. The install command adds all three; UI SDK is in beta, so it is added at the exact version this was built on.
Usage
import { RangeSlider } from '@/components/liquid-glass/controls/RangeSlider'
const [volume, setVolume] = useState(60)
<RangeSlider label="Volume" value={volume} onChange={setVolume} />Drag the glass, or press the track to bring it there. While held, the pill swells into a clear lens that bends the track and the fill beneath it, and squashes and stretches with its speed; released, it springs back to the small pill.
API reference
| Prop | Type | Default |
|---|---|---|
valueCurrent value. | number | 50 |
onChangeCalled with the new value. | (value: number) => void | — |
min / max / stepThe range and its step. | number | 0 / 100 / 1 |
labelLabel above the track; an empty string hides it. | string | 'Volume' |
nameSubmits the value under this name with the form around it. | string | — |
showValueShows the value next to the label. | boolean | true |
sizeTrack height 8, 12, 18 or 26 px; the glass scales with it. | 'sm' | 'md' | 'lg' | 'xl' | 'md' |
startIcon / endIconIcons at either end of the track. | IconName | 'none' | 'none' |
colorThe filled part of the track: a hex, | string | '#3291FF' |
themeOverrides the page theme for this slider. | 'light' | 'dark' | — |
restFrostThe thumb at rest: 1 = a white pill, 0 = clear glass. Held, it is always clear glass. | number | 1 |
refractionHow far the lens bends what lies beneath. | number | 37 |
dispersion / rimIntensity / magnificationColour fringing, rim light and zoom of the lens. | number | 0.12 / 0.55 / 0 |
motionStretch / motionSmoothingSquash and stretch with speed; how tightly the glass follows. | number | 3 / 30 |
pressSpeed / pressBounceThe spring that opens and closes the lens. | number | 16 / 0.4 |
Accessibility
- A native range input does the work: arrow keys, Home, End and Page Up / Down, and screen readers announce the value.
- The
labelnames the input. - With reduced motion the glass follows without springs.