A button that leans toward the cursor with a springy, physical pull.
A section divider you can pluck like a string: it catches the pointer, stretches as you pull, then snaps back and wobbles to rest.
Customize
Usage
import { PluckLine } from "@/components/motionkit/pluck-line";
<PluckLine>
Chapter two
</PluckLine>Motion
The exact curves this component runs, plotted with Motion's own maths.
String settles
Pluck
Section dividers, footers, about pages and playful brand sites that reward a little curiosity.
The string is an SVG quadratic curve whose control point sits at twice the pull, so the peak lands right under the pointer. When the pointer meets the line it catches and follows; past its limit, or when the pointer leaves, it's released into a damped spring simulated every animation frame, pulling back towards rest and losing a little energy each time, which gives the wobble. The loop stops as soon as the string is still.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/pluck-line.jsonnpm install motionSave as components/motionkit/pluck-line.tsx.
"use client";
import { useEffect, useId, useRef, useState, type PointerEvent, type ReactNode } from "react";
import { useReducedMotion } from "motion/react";
type PluckLineProps = {
/** Height of the area the line can be pulled across, in pixels. */
height?: number;
/** Colour of the string. */
color?: string;
/** Thickness of the string, in pixels. */
thickness?: number;
/** How tight the string is: higher snaps back faster and hums higher. */
tension?: number;
/** How quickly the wobble dies away, 0 (rings on) to 1 (stops at once). */
damping?: number;
/** A soft glow round the string. */
glow?: boolean;
/** An optional label sitting on the line, e.g. a section title. */
children?: ReactNode;
className?: string;
};
/**
* A divider you can pluck. Bring the pointer to the line and it catches, stretching as you pull; pull too far, or
* let go, and it snaps back and wobbles to rest like a plucked string.
*/
export function PluckLine({ height = 96, color = "#B9C7FF", thickness = 1.5, tension = 0.14, damping = 0.12, glow = true, children, className = "" }: PluckLineProps) {
const reduceMotion = useReducedMotion();
const gradient = `pluck-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
const box = useRef<HTMLDivElement>(null);
const paths = useRef<SVGPathElement[]>([]);
const [width, setWidth] = useState(0);
const mid = height / 2;
// the string's state, kept outside React so it can move every frame without re-rendering
const sim = useRef({ y: 0, v: 0, x: 0, held: false, target: 0, frame: 0 });
useEffect(() => {
const el = box.current;
if (!el) return;
const observer = new ResizeObserver(([entry]) => setWidth(entry.contentRect.width));
observer.observe(el);
return () => observer.disconnect();
}, []);
const draw = () => {
const { x, y } = sim.current;
// a quadratic bend whose control point sits at twice the offset, so the peak lands right under the pointer
const d = `M0 ${mid} Q ${x.toFixed(1)} ${(mid + y * 2).toFixed(1)} ${width} ${mid}`;
paths.current.forEach((path) => path?.setAttribute("d", d));
};
const tick = () => {
const s = sim.current;
if (s.held) {
const before = s.y;
s.y += (s.target - s.y) * 0.35;
s.v = s.y - before;
} else if (reduceMotion) {
s.y *= 0.6;
s.v = 0;
} else {
// a damped spring: pulled back towards rest, losing a little energy every frame
s.v = (s.v - tension * s.y) * (1 - damping);
s.y += s.v;
}
draw();
if (!s.held && Math.abs(s.y) < 0.05 && Math.abs(s.v) < 0.05) {
s.y = 0;
draw();
s.frame = 0;
return;
}
s.frame = requestAnimationFrame(tick);
};
const run = () => {
if (!sim.current.frame) sim.current.frame = requestAnimationFrame(tick);
};
useEffect(() => {
draw();
const s = sim.current;
return () => cancelAnimationFrame(s.frame);
// redraw at rest whenever the width changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [width, height]);
function move(event: PointerEvent) {
const rect = box.current!.getBoundingClientRect();
const px = event.clientX - rect.left;
const offset = event.clientY - rect.top - mid;
const s = sim.current;
const limit = mid * 0.82;
if (!s.held) {
// the string catches when the pointer meets it
if (Math.abs(offset - s.y) > 10) return;
s.held = true;
}
s.x = Math.min(width - 8, Math.max(8, px));
// past its limit it slips free and snaps back
if (Math.abs(offset) > limit) {
s.held = false;
s.v = Math.sign(offset) * -2;
} else s.target = offset;
run();
}
function release() {
sim.current.held = false;
run();
}
return (
<div
ref={box}
role="separator"
onPointerMove={move}
onPointerLeave={release}
className={`relative w-full touch-pan-y select-none ${className}`}
style={{ height }}
>
<svg aria-hidden width="100%" height={height} className="absolute inset-0 overflow-visible">
<defs>
{/* measured in page units: a flat line has no height, so a gradient sized to it would draw nothing */}
<linearGradient id={gradient} gradientUnits="userSpaceOnUse" x1="0" y1="0" x2={width || 1} y2="0">
<stop offset="0" stopColor={color} stopOpacity="0" />
<stop offset="0.18" stopColor={color} stopOpacity="0.9" />
<stop offset="0.82" stopColor={color} stopOpacity="0.9" />
<stop offset="1" stopColor={color} stopOpacity="0" />
</linearGradient>
</defs>
{glow && <path ref={(el) => void (paths.current[0] = el!)} fill="none" stroke={`url(#${gradient})`} strokeWidth={thickness * 5} strokeLinecap="round" opacity={0.35} style={{ filter: "blur(6px)" }} />}
<path ref={(el) => void (paths.current[1] = el!)} fill="none" stroke={`url(#${gradient})`} strokeWidth={thickness} strokeLinecap="round" />
</svg>
{children && (
<div className="pointer-events-none absolute inset-0 grid place-items-center">
<span className="rounded-full border border-white/10 bg-[#0C1010] px-3.5 py-1 text-xs font-medium uppercase tracking-[0.18em] text-[#DCE3E2]">{children}</span>
</div>
)}
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | An optional label on the line, e.g. a section title. |
| height | number | 96 | Height of the area it can be pulled across, in px. |
| color | string | "#B9C7FF" | Colour of the string. |
| thickness | number | 1.5 | Thickness of the string, in px. |
| tension | number | 0.14 | Higher snaps back faster. |
| damping | number | 0.12 | How quickly the wobble dies away, 0 to 1. |
| glow | boolean | true | A soft glow round the string. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Only the motion package, beside React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/pluck-line.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, the line eases straight back without wobbling.
A button that leans toward the cursor with a springy, physical pull.
Each letter leans toward the cursor and springs home, like a magnetic button for every character.
A seamless infinite scroller for logos and testimonials that pauses on hover.