Components72 / 118
Comet Button
A black glass pill with a comet of light running its edge. Hover and the comet races round to the point nearest your cursor and brakes there with a wobble, its tail stretching with speed and bunching as it stops; it follows you along the edge. Click and it bursts both ways round the button while the sparkle twinkles.
ButtonButtonBorder lightBorder lightCursor awareCursor awareSpringsSpringsSquash & stretchSquash & stretchGSAPGSAP
Hover, then move along the edgeClick to burst the comet
Tweak
LIVELIVEText
Sparkle icon
Look
64px
#f3c66d
Usage
Follows your tweaks.
usage.tsx
import { CometButton } from "@/components/inreact/comet-button";
export function Cta() {
return <CometButton href="/signup" size={64} />;
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/comet-button.jsonOr copy the source
Install the dependencies, then save this as components/inreact/comet-button.tsx.
terminal
npm install gsapcomponents/inreact/comet-button.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useLayoutEffect, useRef, useState } from "react";
/**
* Comet Button: a black glass pill with a comet of light running its edge.
*
* A comet (white core, gold tail) orbits the hairline border, lighting the
* glass inside as it passes. It notices you: hover and it races round the edge
* to the point nearest your cursor and brakes there with a wobble, its tail
* stretching with speed and bunching up as it stops; move and it follows you
* along the edge. Leave and it shoots off on its orbit again. Click and it
* bursts into two comets that sweep both ways round the button, while the
* sparkle twinkles and the pill squashes and springs back.
*
* <CometButton label="Get Started" onClick={start} />
*/
export interface CometButtonProps {
label?: string;
href?: string;
onClick?: () => void;
/** Height, px. */
size?: number;
/** The comet's tail. */
tail?: string;
/** Show the sparkle icon. */
icon?: boolean;
className?: string;
}
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const mod = (a: number, m: number) => ((a % m) + m) % m;
function Sparkle({ s }: { s: number }) {
return (
<svg data-sparkle viewBox="0 0 24 24" aria-hidden="true" style={{ width: s, height: s, overflow: "visible" }} fill="currentColor">
<path data-big d="M10.5 3.5c.5 4.3 2.7 6.5 7 7-4.3.5-6.5 2.7-7 7-.5-4.3-2.7-6.5-7-7 4.3-.5 6.5-2.7 7-7Z" />
<path data-small d="M18.5 2.2c.2 1.6 1 2.4 2.6 2.6-1.6.2-2.4 1-2.6 2.6-.2-1.6-1-2.4-2.6-2.6 1.6-.2 2.4-1 2.6-2.6Z" />
<circle data-dot cx="5" cy="19.5" r="1.6" />
</svg>
);
}
export function CometButton({ label = "Get Started", href, onClick, size = 56, tail = "#f3c66d", icon = true, className }: CometButtonProps) {
const rootRef = useRef<HTMLElement | null>(null);
const bodyRef = useRef<HTMLSpanElement>(null);
const svgRef = useRef<SVGSVGElement>(null);
const railRef = useRef<SVGRectElement>(null);
const layers = useRef<(SVGRectElement | null)[]>([]); // long tail, mid tail, core halo, core
const bursts = useRef<(SVGRectElement | null)[]>([]);
const sheenRef = useRef<HTMLSpanElement>(null);
const [W, setW] = useState(0);
const H = size;
// the pill's width, for the border path
useLayoutEffect(() => {
const el = bodyRef.current;
if (!el) return;
const ro = new ResizeObserver(() => setW(el.offsetWidth));
ro.observe(el);
setW(el.offsetWidth);
return () => ro.disconnect();
}, []);
useEffect(() => {
const root = rootRef.current, body = bodyRef.current, rail = railRef.current, sheen = sheenRef.current, svg = svgRef.current;
if (!root || !body || !rail || !sheen || !svg || !W) return;
const still = reduced();
const P = rail.getTotalLength();
// sample the edge once, to find the point nearest the cursor
const N = 180;
const pts = Array.from({ length: N }, (_, i) => rail.getPointAtLength((i / N) * P));
const at = (u: number) => {
// interpolate between samples, so the inner light glides instead of stepping
const f = (mod(u, P) / P) * N, i = Math.floor(f) % N, j = (i + 1) % N, t = f - Math.floor(f);
return { x: pts[i].x + (pts[j].x - pts[i].x) * t, y: pts[i].y + (pts[j].y - pts[i].y) * t };
};
const cruise = P / 3.4; // px per second while orbiting
const p0 = at(P * 0.1);
const st = { u: P * 0.1, v: cruise, mode: "orbit" as "orbit" | "seek", tu: 0, dir: 1, dirT: 1, len: P * 0.14, js: 0, jv: 0, lit: 0.55, tlit: 0.55, sx: p0.x, sy: p0.y };
const last = { dash: "", body: "", sheen: "" };
const sparkle = svg.closest("[data-comet]")?.querySelector<SVGSVGElement>("[data-sparkle]") ?? null;
const draw = (dt: number) => {
// the tail trails behind the head: it stretches with speed and bunches when
// braking, but never shrinks to a stub, and it swings smoothly through the
// head when the comet turns back (no snapping from one side to the other)
const want = Math.min(P * 0.4, P * 0.11 + Math.abs(st.v) * 0.18);
st.len += (want - st.len) * Math.min(1, dt * 9);
if (Math.abs(st.v) > 18) st.dirT = st.v > 0 ? 1 : -1;
st.dir += (st.dirT - st.dir) * Math.min(1, dt * 7);
const fracs = [1, 0.55, 0.16, 0.12];
layers.current.forEach((el, k) => {
if (!el) return;
const L = st.len * fracs[k];
const back = L * st.dir;
// the white core keeps its size while the tail swings round
const seg = k >= 2 ? Math.max(L * 0.7, Math.abs(back)) : Math.max(1.2, Math.abs(back));
const start = back >= 0 ? st.u - seg : st.u - (k >= 2 ? seg * 0.15 : 0);
el.setAttribute("stroke-dasharray", `${seg.toFixed(2)} ${(P - seg).toFixed(2)}`);
el.setAttribute("stroke-dashoffset", (-mod(start, P)).toFixed(2));
});
// the glass inside lights up near the comet: it glides after the head
// (never jumps), and stays a soft reflection rather than a smudge
const p = at(st.u);
const f = Math.min(1, dt * 7);
st.sx += (p.x - st.sx) * f;
st.sy += (p.y - st.sy) * f;
const sh = `${st.sx.toFixed(1)}|${st.sy.toFixed(1)}|${st.lit.toFixed(3)}`;
if (sh !== last.sheen) {
sheen.style.transform = `translate3d(${(st.sx - H * 0.8).toFixed(1)}px,${(st.sy - H * 0.8).toFixed(1)}px,0)`;
sheen.style.opacity = (st.lit * 0.75).toFixed(3);
last.sheen = sh;
}
};
const tick = (_t: number, ms: number) => {
const dt = Math.min(ms / 1000, 1 / 30);
if (still) {
st.v = 0;
if (st.mode === "seek") st.u = st.tu;
} else if (st.mode === "orbit") {
st.v += (cruise - st.v) * Math.min(1, dt * 2.2);
st.u += st.v * dt;
} else {
// seek the point nearest the cursor the short way round: a spring with a wobble
const k = 46, c = 2 * 0.5 * Math.sqrt(k), h = dt / 2;
for (let i = 0; i < 2; i++) {
const dd = mod(st.tu - st.u + P / 2, P) - P / 2;
st.v += (k * dd - c * st.v) * h;
st.u += st.v * h;
}
}
st.lit += (st.tlit - st.lit) * Math.min(1, dt * 5);
const kj = 420, cj = 2 * 0.24 * Math.sqrt(kj);
st.jv += (-kj * st.js - cj * st.jv) * dt;
st.js += st.jv * dt;
const js = Math.max(-0.1, Math.min(0.1, st.js));
const bt = `scale(${(1 + js * 0.5).toFixed(4)},${(1 - js).toFixed(4)})`;
if (bt !== last.body) {
body.style.transform = bt;
last.body = bt;
}
draw(dt);
};
gsap.ticker.add(tick);
let box = root.getBoundingClientRect();
// the point on the edge nearest the cursor, with hysteresis: over the middle
// of the pill the top and bottom edges are almost equally near, so the comet
// keeps to the side it's on unless the other side is clearly closer
const nearest = (e: PointerEvent, fresh = false) => {
const x = e.clientX - box.left, y = e.clientY - box.top;
let bo = 0, dO = Infinity, bl = -1, dL = Infinity;
for (let i = 0; i < N; i++) {
const d = (pts[i].x - x) ** 2 + (pts[i].y - y) ** 2;
if (d < dO) {
dO = d;
bo = i;
}
const u = (i / N) * P;
if (Math.abs(mod(u - st.tu + P / 2, P) - P / 2) < P * 0.22 && d < dL) {
dL = d;
bl = i;
}
}
if (!fresh && bl >= 0 && Math.sqrt(dL) - Math.sqrt(dO) < H * 0.45) return (bl / N) * P;
return (bo / N) * P;
};
const onEnter = (e: PointerEvent) => {
box = root.getBoundingClientRect();
st.mode = "seek";
st.tu = nearest(e, true);
st.tlit = 1;
};
const onMove = (e: PointerEvent) => {
if (st.mode === "seek") st.tu = nearest(e);
};
const onLeave = () => {
st.mode = "orbit";
st.tlit = 0.55;
if (!still) st.v = Math.sign(st.v || 1) * Math.max(Math.abs(st.v), cruise * 2.6); // shoots off
};
// the sparkle twinkles: each star scales about its own centre (transforms we
// write ourselves, so repeated twinkles always land exactly back at rest)
const star = (sel: string, ox: number, oy: number, from: { s: number; r: number }, delay: number, ease: string, dur: number) => {
const el = sparkle?.querySelector(sel);
if (!el) return;
const p = { s: from.s, r: from.r };
gsap.killTweensOf(el);
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: dur, delay, ease, onUpdate: put, onComplete: () => el.removeAttribute("transform") });
};
const twinkle = () => {
if (!sparkle || still) return;
star("[data-big]", 10.5, 10.5, { s: 0.55, r: -45 }, 0, "elastic.out(1.1, 0.4)", 0.75);
star("[data-small]", 18.5, 4.8, { s: 0, r: 0 }, 0.08, "elastic.out(1.2, 0.4)", 0.6);
star("[data-dot]", 5, 19.5, { s: 0, r: 0 }, 0.14, "back.out(3)", 0.55);
};
const onDown = () => {
if (still) return;
st.jv -= 2.4;
twinkle();
// the comet bursts both ways round the edge
const start = mod(st.u, P);
bursts.current.forEach((el, k) => {
if (!el) return;
const o = { t: 0 };
const dir = k ? -1 : 1;
gsap.killTweensOf(o);
gsap.to(o, {
t: 1,
duration: 0.85,
ease: "power2.out",
onUpdate: () => {
const L = P * 0.16 * (1 - o.t * 0.6);
const head = start + dir * (P / 2) * o.t;
const s = dir > 0 ? head - L : head;
el.setAttribute("stroke-dasharray", `${L.toFixed(2)} ${(P - L).toFixed(2)}`);
el.setAttribute("stroke-dashoffset", (-mod(s, P)).toFixed(2));
el.style.opacity = (1 - o.t * o.t).toFixed(3);
},
});
});
};
const onUp = () => {
if (!still) st.jv += 1.6;
};
const onFocus = () => {
if (root.matches(":focus-visible")) {
st.tlit = 1;
twinkle();
}
};
const onBlur = () => (st.tlit = 0.55);
root.addEventListener("pointerenter", onEnter);
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("pointerdown", onDown);
root.addEventListener("pointerup", onUp);
root.addEventListener("focus", onFocus);
root.addEventListener("blur", onBlur);
draw(1);
return () => {
gsap.ticker.remove(tick);
root.removeEventListener("pointerenter", onEnter);
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("pointerup", onUp);
root.removeEventListener("focus", onFocus);
root.removeEventListener("blur", onBlur);
};
}, [W, H]);
const sw = 1.6;
const rx = (H - sw) / 2;
const rect = (props: Record<string, unknown>, ref?: (el: SVGRectElement | null) => void) => (
<rect ref={ref} x={sw / 2} y={sw / 2} width={Math.max(0, W - sw)} height={H - sw} rx={rx} fill="none" strokeLinecap="round" {...props} />
);
const cls = ["relative inline-grid shrink-0 select-none place-items-center outline-none [-webkit-tap-highlight-color:transparent] focus-visible:[&>span]:ring-2 focus-visible:[&>span]:ring-white/30", className].filter(Boolean).join(" ");
const inner = (
<span
ref={bodyRef}
data-comet
className="relative flex h-full items-center will-change-transform"
style={{
gap: Math.round(H * 0.16),
padding: `0 ${Math.round(H * 0.5)}px 0 ${Math.round(H * 0.4)}px`,
borderRadius: H,
background: "radial-gradient(120% 140% at 50% 0%, #1a1426 0%, #07050c 62%)",
boxShadow: "inset 0 1px 0 rgba(255,255,255,.07), inset 0 -1px 0 rgba(255,255,255,.03), 0 2px 4px rgba(0,0,0,.35), 0 12px 30px rgba(0,0,0,.4)",
}}
>
{/* the glass lit from inside, near the comet */}
<span aria-hidden="true" className="pointer-events-none absolute inset-0 overflow-hidden" style={{ borderRadius: H }}>
<span
ref={sheenRef}
className="absolute top-0 left-0 will-change-[transform,opacity]"
style={{ width: H * 1.6, height: H * 1.6, background: "radial-gradient(closest-side, rgba(255,255,255,.17), rgba(255,255,255,0))" }}
/>
</span>
{/* the edge: a faint rail, the comet and its bursts */}
<svg ref={svgRef} aria-hidden="true" className="pointer-events-none absolute inset-0 overflow-visible" width={W} height={H} viewBox={`0 0 ${W} ${H}`}>
{rect({ stroke: "rgba(255,255,255,.08)", strokeWidth: sw }, (el) => void (railRef.current = el))}
{rect({ stroke: tail, strokeWidth: sw, opacity: 0.45 }, (el) => void (layers.current[0] = el))}
{rect({ stroke: tail, strokeWidth: sw, opacity: 0.95 }, (el) => void (layers.current[1] = el))}
{rect({ stroke: "#fff", strokeWidth: sw * 3, opacity: 0.3 }, (el) => void (layers.current[2] = el))}
{rect({ stroke: "#fff", strokeWidth: sw * 1.2 }, (el) => void (layers.current[3] = el))}
{rect({ stroke: tail, strokeWidth: sw * 1.2, opacity: 0 }, (el) => void (bursts.current[0] = el))}
{rect({ stroke: tail, strokeWidth: sw * 1.2, opacity: 0 }, (el) => void (bursts.current[1] = el))}
</svg>
{icon && (
<span className="relative text-white">
<Sparkle s={Math.round(H * 0.4)} />
</span>
)}
<span className="relative whitespace-nowrap text-white" style={{ fontSize: Math.round(H * 0.31), fontWeight: 600, letterSpacing: "0.005em" }}>
{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 CometButton;
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
7 propslabelstringButton text.default "Get Started"default "Get Started"hrefstringRender a link.onClick() => voidClick handler.sizenumberHeight, px.default 56default 56tailstringThe comet's tail colour.default "#f3c66d"default "#f3c66d"iconbooleanShow the sparkle icon.default truedefault trueclassNamestringExtra classes.