Components

Elastic Slider

Slider with elastic rubber-band drag and magnetic snap feedback.

Loading…

Good recreation! Focus state is nice touch

joshpuckettTeaching at interfacecraft.dev

Features

  • Track stretches with rubber-band tension when dragged past bounds.
  • Snaps magnetically to exact steps or continuous deciles.
  • Inline label and value text dynamically fade to avoid handle overlap.
  • Supports keyboard navigation and respects prefers-reduced-motion

Installation

pnpm dlx shadcn@latest add @ncdai/elastic-slider

Usage

import { ElasticSlider } from "@/components/elastic-slider"
const [opacity, setOpacity] = useState(0.5)
 
<ElasticSlider
  label="Opacity"
  min={0}
  max={1}
  value={opacity}
  onValueChange={setOpacity}
/>

Uncontrolled:

<ElasticSlider label="Opacity" min={0} max={1} defaultValue={0.5} />

Accessibility

Keyboard

KeyDescription
ArrowRight ArrowUpIncrease by one step
ArrowLeft ArrowDownDecrease by one step
Shift + ArrowIncrease or decrease by step*10
HomeJump to min
EndJump to max

Reduced motion

When prefers-reduced-motion is on, rubber-band stretch and spring-based fill motion are skipped; the handle still updates without spring transitions on opacity and scale.

API Reference

ElasticSlider

Prop

Type

Styling

CSS Variables

VariableMeaning
--elastic-slider-heightTotal height of the control (theme spacing scale).
--elastic-slider-radiusCorner radius of the track.
--elastic-slider-bgTrack background.
--elastic-slider-fillFill behind the thumb when the track is idle.
--elastic-slider-fill-activeFill behind the thumb when hovered, keyboard-focused, or dragging.
--elastic-slider-hashStep or decile tick marks when the track is active.
--elastic-slider-handleThumb color.
--elastic-slider-labelLabel text color; base tint for the numeric value.
--elastic-slider-focusNumeric value color when the track is active (stronger than the label).

Data Slots

SlotDescription
elastic-sliderRoot wrapper; CSS variables are defined here.
elastic-slider-trackFocusable track, rubber-band width, focus ring.
elastic-slider-hash-marksContainer for tick marks.
elastic-slider-fillFilled portion of the track.
elastic-slider-handleVertical handle.
elastic-slider-labelInline label.
elastic-slider-valueFormatted value.

References

Command Palette

Search for a command to run...