Slider
A range slider with a glass thumb: a small pill at rest that opens into a wide lens while you hold it.
Latest change Improved v3.0.19 Slider, Switch and Checkbox are now drawn in plain WebGL2, as the rest of the kit is. Their renderer no longer needs three: the install adds only UI SDK, and a project that used three for nothing else can remove it. The picture is the same: the shader is the one three.js built out of the old code, kept statement for statement, and the old and the new renderer were compared pixel by pixel.
- v3.0.19 Improved Slider, Switch and Checkbox are now drawn in plain WebGL2, as the rest of the kit is. Their renderer no longer needs
three: the install adds only UI SDK, and a project that usedthreefor nothing else can remove it. The picture is the same: the shader is the one three.js built out of the old code, kept statement for statement, and the old and the new renderer were compared pixel by pixel. - v3.0.9 Improved A vertical swipe that starts on the slider scrolls the page again, and leaves the value as it found it. A second finger no longer makes the value jump.
- v2.0.2 Fixed Slider, Switch and Checkbox share one WebGL canvas, and it was resized to each control before that control was drawn: with controls of different sizes on screen, every control got a new drawing buffer on every frame, the costliest call on such a page by far. The canvas now only grows, and each control is drawn into a corner of it.
- v1.3.8 Improved A
colorprop for the filled part of the track. The examples are now the slider in a few colours, nothing else. - v1.3.3 Improved Examples for the four sizes, a range of its own with
min,maxandstep, icons, and clear glass at rest. - v1.3.0 New The 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-svelte@latest add https://liquidglass.pulse.city/r/slider.jsonSlider, Switch and Checkbox are drawn by their own renderer, in plain WebGL2 with no graphics library, 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 both; 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 |
|---|---|---|
value Current value. | number | 50 |
onChange Called with the new value. | (value: number) => void | — |
min / max / step The range and its step. | number | 0 / 100 / 1 |
label Label above the track; an empty string hides it. | string | 'Volume' |
name Submits the value under this name with the form around it. | string | — |
showValue Shows the value next to the label. | boolean | true |
size Track height 8, 12, 18 or 26 px; the glass scales with it. | 'sm' | 'md' | 'lg' | 'xl' | 'md' |
startIcon / endIcon Icons at either end of the track. | IconName | 'none' | 'none' |
color The filled part of the track: a hex, | string | '#3291FF' |
theme Overrides the page theme for this slider. | 'light' | 'dark' | — |
restFrost The thumb at rest: 1 = a white pill, 0 = clear glass. Held, it is always clear glass. | number | 1 |
refraction How far the lens bends what lies beneath. | number | 37 |
dispersion / rimIntensity / magnification Colour fringing, rim light and zoom of the lens. | number | 0.12 / 0.55 / 0 |
motionStretch / motionSmoothing Squash and stretch with speed; how tightly the glass follows. | number | 3 / 30 |
pressSpeed / pressBounce The 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.
Liquid Glass Svelte is open source and MIT licensed. If it saves you time, you can support the project.