# RangeSlider

> A range slider with a glass thumb: a small pill at rest that opens into a wide lens while you hold it.

```tsx
import { useState } from 'react'

import { RangeSlider } from '@/components/liquid-glass/controls/RangeSlider'

export default function Demo() {
  const [brightness, setBrightness] = useState(40)
  return (
    <div className="w-full max-w-sm">
      <RangeSlider label="Brightness" value={brightness} onChange={setBrightness} startIcon="moon" endIcon="sun" />
    </div>
  )
}
```

**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.

```bash
npx shadcn@latest add https://onemorethink.dev/r/slider.json
```

> Slider, 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

```tsx
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.

## Examples

### Colours

```tsx
import { RangeSlider } from '@/components/liquid-glass/controls/RangeSlider'

// `color` is the filled part of the track. Without it the slider is the kit's blue.
export default function Demo() {
  return (
    <div className="flex w-full max-w-sm flex-col gap-8">
      <RangeSlider label="Blue" value={30} />
      <RangeSlider label="Green" color="#34c759" value={45} />
      <RangeSlider label="Orange" color="#ff9500" value={60} />
      <RangeSlider label="Pink" color="#ff2d55" value={75} />
    </div>
  )
}
```

`color` is the filled part of the track; without it the slider is the kit's blue. The thumb stays white at rest and clear glass while held.

## API reference

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `number` | `50` | Current value. |
| `onChange` | `(value: number) => void` | — | Called with the new value. |
| `min / max / step` | `number` | `0 / 100 / 1` | The range and its step. |
| `label` | `string` | `'Volume'` | Label above the track; an empty string hides it. |
| `name` | `string` | — | Submits the value under this name with the form around it. |
| `showValue` | `boolean` | `true` | Shows the value next to the label. |
| `size` | `'sm' \| 'md' \| 'lg' \| 'xl'` | `'md'` | Track height 8, 12, 18 or 26 px; the glass scales with it. |
| `startIcon / endIcon` | `IconName \| 'none'` | `'none'` | Icons at either end of the track. |
| `color` | `string` | `'#3291FF'` | The filled part of the track: a hex, `rgb()` or named colour, not a CSS variable. |
| `theme` | `'light' \| 'dark'` | — | Overrides the page theme for this slider. |
| `restFrost` | `number` | `1` | The thumb at rest: 1 = a white pill, 0 = clear glass. Held, it is always clear glass. |
| `refraction` | `number` | `37` | How far the lens bends what lies beneath. |
| `dispersion / rimIntensity / magnification` | `number` | `0.12 / 0.55 / 0` | Colour fringing, rim light and zoom of the lens. |
| `motionStretch / motionSmoothing` | `number` | `3 / 30` | Squash and stretch with speed; how tightly the glass follows. |
| `pressSpeed / pressBounce` | `number` | `16 / 0.4` | The spring that opens and closes the lens. |

## Accessibility

- A native range input does the work: arrow keys, Home, End and Page Up / Down, and screen readers announce the value.
- The `label` names the input.
- With reduced motion the glass follows without springs.

Source: https://onemorethink.dev/docs/slider
