Scramble Button
A ringed arrow and a label in spaced monospaced capitals that decode themselves. As it comes into view the arrow draws itself from a dot to a dash to an arrow and the label types out, then a glitch flickers over it. Hover and a solid disc blooms out of your cursor inside the ring and swells to fill it, still leaning after your cursor; the arrow redraws itself in light and a band of glitch glyphs sweeps across the label. Leave and the disc shrinks to a dot and slips away the way you went. A real link or button, with an icon-only form.
Tweak
LIVELIVEButton
Colours
Usage
Follows your tweaks.
import { ScrambleButton } from "@/components/inreact/scramble-button";
export function Cta() {
return (
<div className="flex items-center gap-10">
<ScrambleButton href="/start">Get started</ScrambleButton>
<ScrambleButton iconOnly aria-label="Next" />
</div>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/scramble-button.jsonOr copy the source
Install the dependencies, then save this as components/inreact/scramble-button.tsx.
npm install gsap"use client";
import { gsap } from "gsap";
import { useEffect, useRef, type MouseEvent as RMouseEvent, type PointerEvent as RPointerEvent } from "react";
/**
* Scramble Button: a ringed arrow and a monospaced label that decode themselves.
*
* A fine ring holds an arrow; beside it, a label in spaced capitals. As it
* comes into view the arrow draws itself from a dot to a dash to an arrow and
* the label types out, then a glitch passes over it. Hover and a solid disc
* blooms out of your cursor inside the ring and swells to fill it, still leaning
* after your cursor; the arrow redraws itself in light, dot, dash, arrow, and a
* band of glitch glyphs sweeps across the label. Leave and the disc shrinks to
* a dot and slips away the way you went.
*
* <ScrambleButton href="/start">Get started</ScrambleButton>
* <ScrambleButton iconOnly aria-label="Next" onClick={next} />
*
* A real <a> or <button>; keyboard focus blooms it too. Reduced motion: no
* glitch, no typing, a plain fill.
*/
export interface ScrambleButtonProps {
/** The label. */
children?: string;
/** Render a link. */
href?: string;
onClick?: (e: RMouseEvent<HTMLElement>) => void;
/** Only the ring and arrow (give it an aria-label). */
iconOnly?: boolean;
/** Colour of the label, arrow and disc. */
ink?: string;
/** Colour of the arrow over the disc (usually your page colour). */
paper?: string;
/** Colour of the ring. */
ring?: string;
/** Diameter of the ring in px. */
size?: number;
/** Type the label and draw the arrow when it comes into view. */
intro?: boolean;
className?: string;
"aria-label"?: string;
}
const GLYPHS = "!<>-_\\/[]{}=+*^?#;:.@";
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const glyph = () => GLYPHS[(Math.random() * GLYPHS.length) | 0];
// a band of glitch glyphs sweeping left to right; with `typing`, the text after the band isn't written yet
function sweep(el: HTMLElement, text: string, opts: { duration?: number; band?: number; typing?: boolean; delay?: number } = {}) {
const { duration = 0.6, band = 3, typing = false, delay = 0 } = opts;
if (reduced()) {
el.textContent = text;
return null;
}
const st = { p: 0, f: -1 };
return gsap.to(st, {
p: 1,
duration,
delay,
ease: "none",
onUpdate() {
const f = Math.floor(st.p * duration * 30); // glyphs change at film rate
if (f === st.f) return;
st.f = f;
const head = st.p * (text.length + band);
let out = "";
for (let i = 0; i < text.length; i++) {
const c = text[i];
if (i < head - band) out += c;
else if (i < head) out += c === " " ? " " : glyph();
else out += typing ? "" : c;
}
el.textContent = out;
},
onComplete() {
el.textContent = text;
},
});
}
// a few glyphs flicker in place for a moment, then settle
function glitch(el: HTMLElement, text: string, duration = 0.55, delay = 0) {
if (reduced()) return null;
const st = { p: 0, f: -1 };
return gsap.to(st, {
p: 1,
duration,
delay,
ease: "none",
onUpdate() {
const f = Math.floor(st.p * duration * 15);
if (f === st.f) return;
st.f = f;
const chars = text.split("");
const n = 1 + ((Math.random() * 3) | 0);
for (let k = 0; k < n; k++) {
const i = (Math.random() * chars.length) | 0;
if (chars[i] !== " ") chars[i] = glyph();
}
el.textContent = chars.join("");
},
onComplete() {
el.textContent = text;
},
});
}
export function ScrambleButton({
children = "Get started",
href,
onClick,
iconOnly = false,
ink = "#0e0c0a",
paper = "#f8f9ef",
ring = "#d6d7ce",
size = 60,
intro = true,
className,
"aria-label": ariaLabel,
}: ScrambleButtonProps) {
const rootRef = useRef<HTMLElement | null>(null);
const ringRef = useRef<HTMLSpanElement>(null);
const discRef = useRef<HTMLSpanElement>(null);
const iconRef = useRef<HTMLSpanElement>(null);
const textRef = useRef<HTMLSpanElement>(null);
const label = children.toUpperCase();
const fs = Math.max(10, Math.round(size * 0.19));
const follow = useRef<{ x: (v: number) => void; y: (v: number) => void } | null>(null);
const inside = useRef(false);
const textTween = useRef<gsap.core.Tween | null>(null);
// the arrow is drawn in three beats: a dot, a dash, the arrow
const drawArrow = (delay = 0) => {
const g = iconRef.current;
if (!g || reduced()) return;
const parts = ["dot", "dash", "arrow"].map((k) => g.querySelector<SVGGElement>(`[data-k="${k}"]`)!);
gsap
.timeline({ delay })
.set(parts, { opacity: 0 })
.set(parts[0], { opacity: 1 })
.set(parts[0], { opacity: 0 }, 0.07)
.set(parts[1], { opacity: 1 }, 0.07)
.set(parts[1], { opacity: 0 }, 0.14)
.set(parts[2], { opacity: 1 }, 0.14);
};
useEffect(() => {
const d = discRef.current;
if (!d) return;
follow.current = { x: gsap.quickTo(d, "x", { duration: 0.5, ease: "power3.out" }), y: gsap.quickTo(d, "y", { duration: 0.5, ease: "power3.out" }) };
return () => {
gsap.killTweensOf(d);
};
}, []);
// in view: the arrow draws itself and the label types out, then a glitch passes over it
useEffect(() => {
const root = rootRef.current;
if (!root || !intro || reduced()) return;
const text = textRef.current, icon = iconRef.current;
if (text) text.textContent = "";
if (icon) gsap.set(icon.querySelectorAll("[data-k]"), { opacity: 0 });
const io = new IntersectionObserver(
([en]) => {
if (!en.isIntersecting) return;
io.disconnect();
drawArrow(0.05);
if (text) {
sweep(text, label, { duration: 0.55, band: 1, typing: true, delay: 0.12 });
glitch(text, label, 0.6, 0.75);
}
},
{ threshold: 0.5 },
);
io.observe(root);
return () => {
io.disconnect();
if (text) text.textContent = label;
icon?.querySelectorAll<SVGGElement>("[data-k]").forEach((el) => (el.style.opacity = el.dataset.k === "arrow" ? "1" : "0"));
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [intro, label]);
const rel = (e: { clientX: number; clientY: number }) => {
const r = ringRef.current!.getBoundingClientRect();
return { x: e.clientX - (r.left + r.width / 2), y: e.clientY - (r.top + r.height / 2) };
};
// hover: a disc blooms out of the cursor inside the ring and swells to fill it, still leaning after the cursor
const enter = (p: { x: number; y: number }) => {
inside.current = true;
const d = discRef.current, icon = iconRef.current, text = textRef.current;
if (!d || !icon) return;
if (reduced()) {
gsap.set(d, { x: 0, y: 0, scale: 1, opacity: 1 });
icon.style.color = paper;
return;
}
gsap.killTweensOf(d, "scale,opacity");
gsap.set(d, { x: p.x * 0.7, y: p.y * 0.7, opacity: 1 });
gsap.fromTo(d, { scale: 0.12 }, { scale: 1, duration: 0.5, ease: "expo.out" });
follow.current?.x(p.x * 0.22);
follow.current?.y(p.y * 0.22);
icon.style.color = paper;
drawArrow();
if (text) {
textTween.current?.kill();
textTween.current = sweep(text, label, { duration: 0.6, band: 3 });
}
};
const move = (e: RPointerEvent<HTMLElement>) => {
if (!inside.current || reduced()) return;
const p = rel(e);
follow.current?.x(p.x * 0.22);
follow.current?.y(p.y * 0.22);
};
// leave: the disc shrinks to a dot and slips away the way you went
const leave = (p: { x: number; y: number }) => {
inside.current = false;
const d = discRef.current, icon = iconRef.current;
if (!d || !icon) return;
if (reduced()) {
gsap.set(d, { opacity: 0 });
icon.style.color = ink;
return;
}
const l = Math.hypot(p.x, p.y) || 1;
const R = size / 2;
gsap.killTweensOf(d);
gsap
.timeline()
.to(d, { scale: 0.22, x: (p.x / l) * R * 0.55, y: (p.y / l) * R * 0.55, duration: 0.32, ease: "power3.inOut" })
.to(d, { x: (p.x / l) * R * 1.05, y: (p.y / l) * R * 1.05, scale: 0.05, opacity: 0, duration: 0.2, ease: "power2.in" });
gsap.delayedCall(0.12, () => {
if (!inside.current) icon.style.color = ink;
});
// the follow tweens were killed with the disc's tweens: make them again
follow.current = { x: gsap.quickTo(d, "x", { duration: 0.5, ease: "power3.out" }), y: gsap.quickTo(d, "y", { duration: 0.5, ease: "power3.out" }) };
};
const onDown = () => {
if (!reduced() && ringRef.current) gsap.fromTo(ringRef.current, { scale: 0.93 }, { scale: 1, duration: 0.55, ease: "elastic.out(1, 0.5)" });
};
const R = size / 2;
const content = (
<>
<span ref={ringRef} className="relative grid shrink-0 place-items-center rounded-full" style={{ width: size, height: size, boxShadow: `inset 0 0 0 1.5px ${ring}` }}>
<span ref={discRef} aria-hidden="true" className="absolute inset-0 rounded-full opacity-0" style={{ background: ink, willChange: "transform" }} />
<span ref={iconRef} aria-hidden="true" className="relative grid place-items-center" style={{ width: size * 0.3, height: size * 0.3, color: ink, transition: "color 120ms" }}>
<svg viewBox="0 0 24 24" width="100%" height="100%" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
<g data-k="dot" style={{ opacity: 0 }}>
<circle cx="12" cy="12" r="0.9" fill="currentColor" stroke="none" />
</g>
<g data-k="dash" style={{ opacity: 0 }}>
<path d="M8.5 12h7" />
</g>
<g data-k="arrow">
<path d="M4.5 12h15M14 6.5l5.5 5.5-5.5 5.5" />
</g>
</svg>
</span>
</span>
{!iconOnly && (
<span className="relative font-mono uppercase" style={{ fontSize: fs, letterSpacing: "0.1em", color: ink }}>
<span aria-hidden="true" className="invisible whitespace-nowrap">
{label}
</span>
<span ref={textRef} aria-hidden="true" className="absolute inset-0 whitespace-nowrap">
{label}
</span>
</span>
)}
</>
);
const shared = {
className: ["inline-flex items-center rounded-full outline-none select-none focus-visible:shadow-[0_0_0_1px_currentColor]", className].filter(Boolean).join(" "),
style: { gap: Math.round(size * 0.42), color: ink },
"aria-label": ariaLabel ?? (iconOnly ? undefined : children),
onPointerEnter: (e: RPointerEvent<HTMLElement>) => enter(rel(e)),
onPointerLeave: (e: RPointerEvent<HTMLElement>) => leave(rel(e)),
onPointerMove: move,
onPointerDown: onDown,
onFocus: () => !inside.current && enter({ x: -R, y: 0 }),
onBlur: () => leave({ x: R, y: 0 }),
onClick,
};
return href ? (
<a ref={(el) => void (rootRef.current = el)} href={href} {...shared}>
{content}
</a>
) : (
<button ref={(el) => void (rootRef.current = el)} type="button" {...shared}>
{content}
</button>
);
}
export default ScrambleButton;
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
11 propschildrenstringThe label.default "Get started"default "Get started"hrefstringRender a link.onClick(e) => voidClick handler.iconOnlybooleanOnly the ring and arrow (give it an aria-label).default falsedefault falseinkstringLabel, arrow and disc.default "#0e0c0a"default "#0e0c0a"paperstringThe arrow over the disc (usually your page colour).default "#f8f9ef"default "#f8f9ef"ringstringThe ring.default "#d6d7ce"default "#d6d7ce"sizenumberRing diameter, px.default 60default 60introbooleanType the label and draw the arrow when it comes into view.default truedefault truearia-labelstringAccessible name (needed when iconOnly).classNamestringExtra classes.