Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/spring.jsonFirst 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.
"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.jsonDependencies
motion lucide-reactThe 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.
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.
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>
);
}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.
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
| Prop | Type | Default |
|---|---|---|
| stiffness | number | 200 |
| damping | number | 16 |
| elastic | number | 0.7 |
| snapBack | boolean | true |
| pressScale | number | 1.06 |
| children | ReactNode | — |