A draggable element tied to its place by a spring coil, which pulls it back on release.
Drag
Installation
Usage
import {
Spring,
SpringElement,
SpringProvider,
} from '@animate-ui/react/primitives/spring';
export function Avatar() {
return (
<SpringProvider>
<Spring className="text-muted-foreground" />
<SpringElement>
<img src="/avatar.png" alt="Avatar" draggable={false} />
</SpringElement>
</SpringProvider>
);
}Add draggable={false} to images inside SpringElement, so the browser's
native drag image doesn't take over the drag.
Animation
- Dragging stretches a coil between the element's place and the element. The coil tightens as it stretches.
- On release, the element springs back with a bounce, the coil following it.
Springis a full-viewport SVG that never catches the pointer.- Under reduced motion, the element is back in place at once on release.
API Reference
SpringProvider
| Prop | Type | Default |
|---|---|---|
transition? | SpringOptions | { stiffness: 200, damping: 16 } |
pathConfig? | SpringPathConfig | {} |
children | React.ReactNode | - |
SpringPathConfig
| Prop | Type | Default |
|---|---|---|
coilCount? | number | 8 |
amplitudeMin? | number | 8 |
amplitudeMax? | number | 20 |
curveRatioMin? | number | 0.5 |
curveRatioMax? | number | 1 |
bezierOffset? | number | 8 |
Spring
The coil. Its color is currentColor.
| Prop | Type | Default |
|---|---|---|
...props? | React.SVGProps<SVGSVGElement> | - |
SpringElement
| Prop | Type | Default |
|---|---|---|
asChild? | boolean | false |
children | React.ReactElement | - |
...props? | Omit<HTMLMotionProps<'div'>, 'children'> | - |
useSpring
Returns the spring state: the x/y and springX/springY motion values, isDragging / setIsDragging, the coil path and childRef.