Components75 / 118
Spark Button
A quiet button that lights up the whole section. Hover and colour blooms out across the section behind it, the button pops into hot pink glass with a warm highlight that follows you, and sparkles blink on around it, more the faster you move. Click for a ring of sparkles and a pulse of light.
ButtonButtonSection lightSection lightSparklesSparklesSpringsSpringsSquash & stretchSquash & stretchGSAPGSAP
Hover, then move fastClick for a burst
Tweak
LIVELIVEText
Look
60px
#ff2d74
#e52bd8
Light up the section
Usage
Follows your tweaks.
usage.tsx
import { SparkButton } from "@/components/inreact/spark-button";
export function Cta() {
// the section it lights needs isolate + overflow-hidden
return (
<section className="relative isolate grid place-items-center overflow-hidden bg-neutral-950 py-32">
<SparkButton onClick={() => improve()} size={60} />
</section>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/spark-button.jsonOr copy the source
Install the dependencies, then save this as components/inreact/spark-button.tsx.
terminal
npm install gsapcomponents/inreact/spark-button.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef } from "react";
/**
* Spark Button: a quiet button that lights up the whole section.
*
* At rest it's a dim outlined pill on a dark page. Hover it and colour blooms
* out from the button across the section behind it (a drifting blue and cyan
* light), the button pops into a hot pink glass pill with a cool rim, a warm
* highlight that follows your cursor, and its sparkle icon twinkles. Sparkles
* blink on around it, more of them the faster you move, drifting outward.
* Click and a ring of sparkles bursts out while a pulse of light crosses the
* section. Leave and the room goes dark again.
*
* It lights the nearest section behind it: give that section
* `isolation: isolate` and `overflow: hidden` (Tailwind: `isolate overflow-hidden`).
*
* <section className="relative isolate overflow-hidden bg-neutral-950"><SparkButton /></section>
*/
export interface SparkButtonProps {
label?: string;
href?: string;
onClick?: () => void;
/** Height, px. */
size?: number;
/** Light up the section behind the button. */
flood?: boolean;
/** The button's colours when lit (left → right). */
from?: string;
to?: string;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const clamp = (a: number, b: number, v: number) => Math.max(a, Math.min(b, v));
const POOL = 18;
function Star({ s }: { s: number }) {
return (
<svg data-twinkle viewBox="0 0 24 24" aria-hidden="true" style={{ width: s, height: s, overflow: "visible" }} fill="currentColor">
<path data-big d="M13 3.5c.6 4.6 2.9 6.9 7.5 7.5-4.6.6-6.9 2.9-7.5 7.5-.6-4.6-2.9-6.9-7.5-7.5 4.6-.6 6.9-2.9 7.5-7.5Z" />
<path data-small d="M5.5 2.5c.25 1.7 1.05 2.5 2.75 2.75-1.7.25-2.5 1.05-2.75 2.75-.25-1.7-1.05-2.5-2.75-2.75 1.7-.25 2.5-1.05 2.75-2.75Z" />
<circle data-dot cx="5" cy="17.5" r="1.3" />
</svg>
);
}
export function SparkButton({ label = "Make Better", href, onClick, size = 56, flood = true, from = "#ff2d74", to = "#e52bd8", className }: SparkButtonProps) {
const rootRef = useRef<HTMLElement | null>(null);
const bodyRef = useRef<HTMLSpanElement>(null);
const litRef = useRef<HTMLSpanElement>(null);
const hotRef = useRef<HTMLSpanElement>(null);
const textRef = useRef<HTMLSpanElement>(null);
const floodRef = useRef<HTMLSpanElement>(null);
const pulseRef = useRef<HTMLSpanElement>(null);
const sparks = useRef<(HTMLSpanElement | null)[]>([]);
const H = size;
useEffect(() => {
const root = rootRef.current, body = bodyRef.current, lit = litRef.current, hot = hotRef.current, text = textRef.current;
const fl = floodRef.current, pulse = pulseRef.current;
if (!root || !body || !lit || !hot || !text) return;
const still = reduced();
const st = { on: 0, ton: 0, s: 0, vs: 0, hx: 0.3, thx: 0.3, sp: 0 };
const last = { body: "", lit: "", hot: "", fl: "" };
let next = 0;
let box = root.getBoundingClientRect();
let lastMove = { x: 0, y: 0, t: 0 };
const icon = root.querySelector<SVGSVGElement>("[data-twinkle]");
// a sparkle: pops in (stretching its arms), drifts outward, fades
let slot = 0;
const spark = (x: number, y: number, scale: number, drift: number, delay = 0) => {
const el = sparks.current[slot++ % POOL];
if (!el || still) return;
gsap.killTweensOf(el);
const ang = Math.atan2(y, x) || Math.random() * Math.PI * 2;
gsap.set(el, { x, y, scale: 0, opacity: 1, rotation: Math.random() * 30 - 15 });
gsap.timeline({ delay })
.to(el, { scale: scale * 1.15, duration: 0.28, ease: "back.out(3)" })
.to(el, { scale: scale * 0.9, duration: 0.2, ease: "power1.inOut" })
.to(el, { scale: 0, opacity: 0, x: x + Math.cos(ang) * drift, y: y + Math.sin(ang) * drift, rotation: "+=25", duration: 0.7, ease: "power2.in" }, 0.3);
};
const twinkle = () => {
if (!icon || still) return;
const parts: [string, number, number, number][] = [["[data-big]", 13, 11, 0], ["[data-small]", 5.5, 5.25, 0.08], ["[data-dot]", 5, 17.5, 0.14]];
for (const [sel, ox, oy, delay] of parts) {
const el = icon.querySelector(sel);
if (!el) continue;
const p = { s: 0.4, r: -40 };
gsap.killTweensOf(p);
const put = () => el.setAttribute("transform", `translate(${ox} ${oy}) rotate(${p.r.toFixed(2)}) scale(${p.s.toFixed(4)}) translate(${-ox} ${-oy})`);
put();
gsap.to(p, { s: 1, r: 0, duration: 0.7, delay, ease: "elastic.out(1.1, 0.4)", onUpdate: put, onComplete: () => el.removeAttribute("transform") });
}
};
const tick = (time: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
if (still) {
st.on = st.ton;
st.s = 0;
} else {
st.on += (st.ton - st.on) * Math.min(1, dt * (st.ton > st.on ? 6 : 3));
const h = dt / 2;
for (let i = 0; i < 2; i++) {
const k = 380, c = 2 * 0.22 * Math.sqrt(k);
st.vs += (-k * st.s - c * st.vs) * h;
st.s += st.vs * h;
}
st.hx += (st.thx - st.hx) * Math.min(1, dt * 8);
st.sp *= Math.pow(0.02, dt);
}
const s = clamp(-0.12, 0.12, st.s);
const b = `scale(${(1 + st.on * 0.04 + s * 0.6).toFixed(4)},${(1 + st.on * 0.04 - s).toFixed(4)})`;
if (b !== last.body) {
body.style.transform = b;
last.body = b;
}
const o = st.on.toFixed(3);
if (o !== last.lit) {
lit.style.opacity = o;
text.style.color = `rgba(255,255,255,${(0.5 + st.on * 0.5).toFixed(3)})`;
last.lit = o;
}
const hk = `${st.hx.toFixed(3)}|${o}`;
if (hk !== last.hot) {
hot.style.transform = `translate3d(${((st.hx - 0.5) * 100).toFixed(2)}%,0,0)`;
last.hot = hk;
}
if (fl) {
const f = `${o}`;
if (f !== last.fl) {
// never quite 0: the soft light stays drawn, so the first hover doesn't hitch
fl.style.opacity = Math.max(0.003, st.on).toFixed(3);
fl.style.transform = `translate(-50%,-50%) scale(${(0.55 + st.on * 0.45).toFixed(4)})`;
last.fl = f;
}
// the light drifts slowly while it's on
if (st.on > 0.01 && !still) {
const blobs = fl.children;
for (let i = 0; i < blobs.length; i++) {
const el = blobs[i] as HTMLElement;
el.style.transform = `translate3d(${(Math.sin(time * (0.23 + i * 0.07) + i * 2) * 60).toFixed(1)}px,${(Math.cos(time * (0.19 + i * 0.05) + i) * 45).toFixed(1)}px,0)`;
}
}
}
// sparkles blink on around the button while it's lit; more when you move fast
if (st.ton > 0 && !still && time > next) {
next = time + clamp(0.08, 0.42, 0.42 - st.sp * 0.0004);
const a = Math.random() * Math.PI * 2;
const rx = box.width * (0.7 + Math.random() * 1.4), ry = box.height * (1.4 + Math.random() * 3.2);
spark(Math.cos(a) * rx, Math.sin(a) * ry, 0.55 + Math.random() * 0.7, 18 + Math.random() * 20);
}
};
gsap.ticker.add(tick);
const onEnter = () => {
box = root.getBoundingClientRect();
st.ton = 1;
if (!still) st.vs += 2.6; // pops: stretches up, then wobbles
twinkle();
};
const onLeave = () => {
st.ton = 0;
if (!still) st.vs -= 1.2;
st.thx = 0.3;
};
const onMove = (e: PointerEvent) => {
st.thx = clamp(0, 1, (e.clientX - box.left) / box.width);
const now = performance.now();
if (lastMove.t) {
const v = Math.hypot(e.clientX - lastMove.x, e.clientY - lastMove.y) / Math.max(1, now - lastMove.t) * 1000;
st.sp = Math.max(st.sp, v);
// fast moves shake a few sparkles off the cursor
if (v > 500 && Math.random() < 0.35) {
spark(e.clientX - (box.left + box.width / 2), e.clientY - (box.top + box.height / 2), 0.35 + Math.random() * 0.3, 26);
}
}
lastMove = { x: e.clientX, y: e.clientY, t: now };
};
const onDown = () => {
if (still) return;
st.vs -= 2.6;
};
const onUp = () => {
if (still) return;
st.vs += 2.2;
twinkle();
// a ring of sparkles bursts out, and a pulse of light crosses the section
for (let i = 0; i < 10; i++) {
const a = (i / 10) * Math.PI * 2 + Math.random() * 0.3;
spark(Math.cos(a) * box.width * 0.55, Math.sin(a) * box.height * 0.9, 0.6 + Math.random() * 0.5, 70 + Math.random() * 50, i * 0.012);
}
if (pulse) gsap.fromTo(pulse, { scale: 0.2, opacity: 0.85 }, { scale: 1.6, opacity: 0, duration: 1.1, ease: "power2.out" });
};
const onFocus = () => root.matches(":focus-visible") && onEnter();
const onBlur = () => !root.matches(":hover") && onLeave();
root.addEventListener("pointerenter", onEnter);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerdown", onDown);
root.addEventListener("pointerup", onUp);
root.addEventListener("focus", onFocus);
root.addEventListener("blur", onBlur);
return () => {
gsap.ticker.remove(tick);
sparks.current.forEach((el) => el && gsap.killTweensOf(el));
root.removeEventListener("pointerenter", onEnter);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("pointerup", onUp);
root.removeEventListener("focus", onFocus);
root.removeEventListener("blur", onBlur);
};
}, [H]);
const cls = ["relative inline-grid shrink-0 select-none place-items-center outline-none [-webkit-tap-highlight-color:transparent] focus-visible:[&>span:last-child]:ring-2 focus-visible:[&>span:last-child]:ring-white/40", className].filter(Boolean).join(" ");
const inner = (
<>
{/* the light that floods the section (behind everything in it) */}
{flood && (
<span aria-hidden="true" className="pointer-events-none absolute top-1/2 left-1/2 -z-10" style={{ width: 0, height: 0 }}>
<span
ref={floodRef}
className="absolute top-0 left-0 opacity-[0.003] will-change-[transform,opacity]"
style={{ width: 2600, height: 2000, transform: "translate(-50%,-50%) scale(.55)", background: "radial-gradient(50% 50% at 50% 50%, #1157ff 0%, #0b3be0 35%, #0a2ab0 60%, rgba(8,20,90,0) 100%)" }}
>
{[
{ c: "#16d9e8", x: "28%", y: "30%", w: 900 },
{ c: "#1f6bff", x: "62%", y: "58%", w: 1000 },
{ c: "#7a3cff", x: "34%", y: "66%", w: 700 },
].map((b, i) => (
<span
key={i}
className="absolute rounded-full will-change-transform"
style={{ left: b.x, top: b.y, width: b.w, height: b.w * 0.7, marginLeft: -b.w / 2, marginTop: -b.w * 0.35, background: `radial-gradient(closest-side, ${b.c}, transparent)`, opacity: 0.7 }}
/>
))}
</span>
<span ref={pulseRef} className="absolute top-0 left-0 opacity-0 will-change-[transform,opacity]" style={{ width: 1400, height: 1400, marginLeft: -700, marginTop: -700, borderRadius: "50%", background: "radial-gradient(closest-side, rgba(170,230,255,0) 55%, rgba(170,230,255,.28) 72%, rgba(170,230,255,0) 82%)" }} />
{/* sparkles: four arms with a gap at the centre */}
{Array.from({ length: POOL }, (_, i) => (
<span key={i} ref={(el) => void (sparks.current[i] = el)} className="absolute top-0 left-0 opacity-0 will-change-transform" style={{ width: 0, height: 0 }}>
<svg viewBox="-12 -12 24 24" width={30} height={30} style={{ position: "absolute", left: -15, top: -15, overflow: "visible" }} aria-hidden="true">
<g stroke="#e9f6ff" strokeWidth="1.4" strokeLinecap="round">
<path d="M0-11v6M0 5v6M-11 0h6M5 0h6" />
</g>
<circle r="1.1" fill="#ffffff" />
</svg>
</span>
))}
</span>
)}
<span
ref={bodyRef}
className="relative flex h-full items-center overflow-hidden will-change-transform"
style={{
padding: `0 ${Math.round(H * 0.5)}px 0 ${Math.round(H * 0.38)}px`,
borderRadius: H,
background: "rgba(255,255,255,.035)",
boxShadow: "inset 0 0 0 1.5px rgba(255,255,255,.2), inset 0 1px 0 rgba(255,255,255,.08), 0 6px 18px rgba(0,0,0,.35)",
}}
>
{/* lit: hot pink glass with a cool rim and a warm highlight that follows you */}
<span
ref={litRef}
aria-hidden="true"
className="pointer-events-none absolute inset-0 opacity-0 will-change-[opacity]"
style={{
borderRadius: H,
background: `linear-gradient(90deg, ${from}, ${to})`,
boxShadow: "inset 0 0 0 2.5px rgba(170,225,255,.85), inset 0 0 0 5px rgba(255,255,255,.18), inset 0 2px 6px rgba(255,255,255,.45), inset 0 -6px 12px rgba(120,0,80,.35)",
}}
>
<span ref={hotRef} className="absolute inset-0 will-change-transform">
<span className="absolute top-[-30%] left-1/2 h-[160%] w-[55%] -translate-x-1/2" style={{ background: "radial-gradient(closest-side, rgba(255,214,150,.75), rgba(255,170,120,0))" }} />
</span>
<span className="absolute inset-x-[8%] top-[10%] h-[34%] rounded-full" style={{ background: "linear-gradient(180deg, rgba(255,255,255,.4), rgba(255,255,255,0))" }} />
</span>
<span ref={textRef} className="relative flex items-center whitespace-nowrap" style={{ gap: Math.round(H * 0.16), fontSize: Math.round(H * 0.34), fontWeight: 500, letterSpacing: "0.005em", color: "rgba(255,255,255,.5)" }}>
<Star s={Math.round(H * 0.42)} />
{label}
</span>
</span>
</>
);
return href ? (
<a ref={(el) => void (rootRef.current = el)} href={href} onClick={onClick} className={cls} style={{ height: H }}>
{inner}
</a>
) : (
<button ref={(el) => void (rootRef.current = el)} type="button" onClick={onClick} className={cls} style={{ height: H }}>
{inner}
</button>
);
}
export default SparkButton;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
8 propslabelstringButton text.default "Make Better"default "Make Better"hrefstringRender a link.onClick() => voidClick handler.sizenumberHeight, px.default 56default 56floodbooleanLight up the section behind it (needs isolate + overflow-hidden on the section).default truedefault truefromstringLit colour, left.default "#ff2d74"default "#ff2d74"tostringLit colour, right.default "#e52bd8"default "#e52bd8"classNamestringExtra classes.