Slider
A skeuomorphic range slider with a recessed groove, a raised fill and a thin handle line.
Preview
Setup
Install with the shadcn CLI
One command adds every file, the npm packages and any Kinetik components it builds on. Needs a components.json; the CLI offers to create one if your project has none.
Or install manually
- 1
Run in your terminal:
$npm install clsx tailwind-merge - 2
Copy
lib/utils.tsfrom the Code tab. Skip if you already havecn(). - 3
Copy
styles/tokens.cssfrom the Code tab and import it in your global CSS after Tailwind:@import "./styles/tokens.css"; - 4
Create a
components/ui/slider/folder and copy every file from the Code tab into it. Each file does one job, so you can read or change a piece without the rest. - 5
Import and render:
Exampleimport { Slider } from "@/components/ui/slider" <Slider label="Volume" defaultValue={40} />
Usage
Leave value unset and the slider keeps its own value, starting at defaultValue.
Pass value and onValueChange to control it yourself.
import { Slider } from "@/components/ui/slider"
export function Settings() {
const [images, setImages] = useState(2)
return (
<Slider
label="Num Images"
description="The number of images to generate."
value={images}
defaultValue={1}
min={1}
max={4}
onValueChange={setImages}
/>
)
}For ranges that go negative, set bipolar. The fill then grows outwards from the
centre, and at the midpoint it shows as a small centred knob.
<Slider label="Wind" min={-1} max={1} step={0.05} defaultValue={0} bipolar accent="#38b6ff" />Double-click the track to reset it to defaultValue.
Set variant="flat" to drop the raised shading. The groove is plain, the fill is only a
shade lighter, and a 1px shine border, brightest along the top edge, outlines it. The handle
line stays muted until you grab it, then lights up in accent.
<Slider label="Volume" defaultValue={40} variant="flat" accent="#ff7a12" />Props
| Prop | Type | Default | Notes |
|---|---|---|---|
label | string | — | Title above the track, linked to the input. |
description | string | — | Smaller line under the label. |
value | number | — | Controlled value. Leave unset for the slider to keep its own. |
defaultValue | number | min, or centre if bipolar | Starting value, shown as Default, and what double-click resets to. |
onValueChange | (value: number) => void | — | Fires on every change. |
min | number | 0 | |
max | number | 100 | |
step | number | 1 | |
format | (value: number) => string | up to 2 decimals | How numbers are shown beside the track and in the meta row. |
bipolar | boolean | false | Fill outwards from the centre. |
dots | number | 5 | Step dots along the empty groove. |
accent | string | — | Colour the handle line glows while dragging or focused. |
variant | "depth" | "flat" | "depth" | Raised fill in a recessed groove, or a flat fill with a 1px shine border. |
showValue | boolean | true | Show the value beside the track. |
showMeta | boolean | true | Show the Default / Min / Max row. |
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, e.g. "L 40" rather than "-0.4"- The handle glows in
accentwhile focused, so keyboard focus is visible