Back to PrequelUIYou are on Spring.

Spring

A draggable element tied to its home by a visible spring.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks
PrequelUI

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

Fade in place
spring.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/spring.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/spring.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
spring.tsx
"use client";

import * as React from "react";
import { motion, type HTMLMotionProps } from "motion/react";
import { cn } from "@/lib/utils";
import { useReduceMotion } from "./motion";

export type SpringProps = HTMLMotionProps<"div"> & {
  stiffness?: number;
  damping?: number;
  elastic?: number;
  snapBack?: boolean;
  pressScale?: number;
};

export function Spring({
  stiffness = 200,
  damping = 16,
  elastic = 0.7,
  snapBack = true,
  pressScale = 1.06,
  transition,
  className,
  children,
  ...props
}: SpringProps) {
  const reduce = useReduceMotion();

  return (
    <motion.div
      data-slot="spring"
      drag={reduce ? false : true}
      dragSnapToOrigin={snapBack}
      dragElastic={elastic}
      dragMomentum={false}
      whileDrag={reduce ? undefined : { scale: pressScale, cursor: "grabbing" }}
      transition={
        reduce
          ? { duration: 0 }
          : transition ?? { type: "spring", stiffness, damping }
      }
      className={cn("cursor-grab touch-none select-none active:cursor-grabbing", className)}
      {...props}
    >
      {children}
    </motion.div>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/spring.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

spring.tsx
import { Spring } from "@/components/prequelui/spring";

export default function Demo() {
  return (
    <Spring className="flex size-12 items-center justify-center rounded-full bg-primary text-primary-foreground">
      drag
    </Spring>
  );
}
import { Spring } from "@/components/prequelui/spring";

export function Variant() {
  return (
    <Spring tempo={1.2}>
      …
    </Spring>
  );
}
03

Animation

A draggable object that treats release as the real event: it may be pulled anywhere, but it always returns to its origin on a spring with no momentum.

  • Default spring: stiffness 200, damping 16.
  • Elasticity: 0.7; momentum is disabled.
  • The object lifts to 1.06 while it is held.
  • Reduced motion disables dragging and snaps to rest.
spring 500 / 50pause off-screenpointer-awareinterruptible
04

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

Spring

PropTypeDefault
stiffnessnumber200
dampingnumber16
elasticnumber0.7
snapBackbooleantrue
pressScalenumber1.06
childrenReactNode—

Next component

Button

A button that presses down and never fidgets on hover.