Components / Inputs
Elastic Slider
A slider that stretches like rubber when dragged past its ends and springs back.
Installation
Requires React 18+ and Tailwind CSS.
- 1
Install dependencies
$ npm install motion - 2
Add the component
Copy the code from the Code tab above into
components/ui/elastic-slider.tsx. - 3
Use it
example.tsximport { ElasticSlider } from "@/components/ui/elastic-slider"; const icon = (d: string) => ( <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"> <path d={d} /> </svg> ); export default function ElasticSliderDemo() { return ( <ElasticSlider label="Volume" defaultValue={60} leftIcon={icon("M11 5 6 9H2v6h4l5 4z")} rightIcon={icon("M11 5 6 9H2v6h4l5 4zM15.5 8.5a5 5 0 0 1 0 7M19 5a10 10 0 0 1 0 14")} /> ); }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| min / max / step | number | 0 / 100 / 1 | Range and step. |
| value | number | — | Controlled value. Omit to let it manage itself. |
| defaultValue | number | 50 | Starting value when uncontrolled. |
| onChange | (value: number) => void | — | Called as the value changes. |
| leftIcon / rightIcon | ReactNode | — | Icons that get pulled with the stretch. |