Updated
Elastic Slider
Customize
Start value40
Min0
Max100
Width320px
Installation
npx shadcn@latest add https://uibrik.com/r/elastic-slider.jsonInstall the packages
npm install @number-flow/react motionSet up squircle corners
Needs
@squircle/core,@squircle/tailwindcssand a few lines of CSS. See squircle setup.Copy the source into your project
components/uibrik/elastic-slider/elastic-slider.tsx"use client"; import React, { useCallback, useEffect, useRef, useState } from "react"; import { motion, useMotionValue, useSpring, useTransform, animate, } from "motion/react"; import NumberFlow from "@number-flow/react"; // ─── Constants ──────────────────────────────────────────────────────────────── const THUMB_SIZE = 24; // At the lowest value the fill rests as a small pill with the handle centred // inside it, rather than shrinking to nothing and leaving the handle outside. const REST = 36; // ─── Rubber-band formula ────────────────────────────────────────────────────── function rubberband(x: number, min: number, max: number): number { if (x >= min && x <= max) return x; const dim = max - min; if (x < min) { const d = min - x;
Adds the files to
components/uibrik/elastic-slider and installs @number-flow/react and motion. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/elastic-slider.Usage
import { ElasticSlider } from "@/components/uibrik/elastic-slider/elastic-slider";<ElasticSlider label="Elastic Slider" defaultValue={40} min={0} max={100} width={320} onChange={(value) => {}}/>Where to use Elastic Slider
Volume and brightness
A slider that stretches past its ends and springs back makes limits feel physical.
Consumer settings
A rubbery feel suits playful apps where a plain range input looks out of place.
Media controls
The stretch gives clear feedback when a value is already at its minimum or maximum.
Pairs with Music Player
Props
ElasticSlider- label
- Type string
- "Elastic Slider"
- defaultValue
- Type number
- 40
- Starting value.
- min
- Type number
- 0
- Lowest value.
- max
- Type number
- 100
- Highest value.
- width
- Type number
- 320
- Track width.
- onChange
- Type (value: number) => void
- –
- Called as the value changes.