Slider
A thin capsule track with the macOS 27 pill knob. Supports ranges and tick marks.
"use client"
import { Slider } from "@/components/ui/slider"
export default function SliderDemo() {
return <Slider defaultValue={[40]} className="max-w-64" aria-label="Volume" />
}Installation
pnpm dlx shadcn@latest add @cupertinoui/sliderThe first install also adds the macOS theme. See Installation to set up the registry.
Usage
import { Slider } from "@/components/ui/slider"
<Slider defaultValue={[40]} aria-label="Volume" />Examples
Range
Pass two values to get two knobs.
"use client"
import * as React from "react"
import { Slider } from "@/components/ui/slider"
export default function SliderRange() {
const [value, setValue] = React.useState([22, 68])
return (
<div className="flex w-full max-w-64 flex-col gap-2">
<Slider value={value} onValueChange={setValue} aria-label="Price range" />
<div className="flex justify-between text-mac-subheadline text-mac-label-secondary tabular-nums">
<span>{value[0]} €</span>
<span>{value[1]} €</span>
</div>
</div>
)
}Tick marks
The labelled style of System Settings, composed from the slider and plain markup.
"use client"
import { Slider } from "@/components/ui/slider"
// The slider style of System Settings › Desktop & Dock.
export default function SliderTicks() {
return (
<div className="flex w-56 flex-col">
<span className="text-mac-body">Size</span>
<Slider defaultValue={[30]} aria-label="Dock size" />
<div className="relative mt-px flex justify-between px-[10px]">
<span className="h-0.5 w-px bg-mac-label-tertiary" />
<span className="h-0.5 w-px bg-mac-label-tertiary" />
</div>
<div className="flex justify-between text-mac-footnote font-medium">
<span>Small</span>
<span>Large</span>
</div>
</div>
)
}API Reference
Every part forwards the props of the underlying Base UI Slider part. The props below are the ones CupertinoUI adds or changes.
Slider
| Prop | Type | Description |
|---|---|---|
defaultValue | number[] | The initial value; one entry per knob. |
value | number[] | The controlled value. |
onValueChange | (value: number[]) => void | Called while the knob moves. |
min / max / step | numberDefault: 0 / 100 / 1 | The range and step. |
orientation | "horizontal" | "vertical"Default: "horizontal" | The direction of the track. |
className | string | Extra classes, merged with the component's own. |