Scramble text
Words decode letter by letter on hover — a tiny reward for curiosity.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/and the colour tokens go into your CSS.$ pnpm dlx asta-ui@latest add scramble-textOr install the package
Don’t want the file? Import from
asta-ui/scramble-textand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-uiimport { ScrambleText } from "asta-ui/scramble-text";Or copy it by hand
Copy this file. Keep the paths, or fix the
@/imports. Then add the tokens fromglobals.css."use client"; import { useEffect, useRef } from "react"; const GLYPHS = "!<>-_\\/[]{}—=+*^?#ABCDEFGHIJKLMNOPQRSTUVWXYZ01"; const WORDS = ["Strategy", "Identity", "Interface", "Motion", "Engineering"]; function Word({ text }: { text: string }) { const ref = useRef<HTMLSpanElement>(null); const raf = useRef(0); useEffect(() => () => cancelAnimationFrame(raf.current), []); // Runs once per hover or focus and stops by itself. Skipped for reduced motion and in a hidden tab. const run = () => { cancelAnimationFrame(raf.current); if (document.hidden || matchMedia("(prefers-reduced-motion: reduce)").matches) return; let frame = 0; const total = text.length * 3 + 6; const step = () => { const out = text .split("") .map((ch, i) => (frame / 3 > i ? ch : ch === " " ? " " : GLYPHS[Math.floor(Math.random() * GLYPHS.length)])) .join(""); if (ref.current) ref.current.textContent = out; frame++; if (frame <= total) raf.current = requestAnimationFrame(step); }; step(); }; return ( <span ref={ref} onPointerEnter={run} onFocus={run} tabIndex={0} className="block cursor-default py-0.5 font-mono text-xl uppercase tracking-tight text-ink transition-colors hover:text-signal outline-none focus-visible:text-signal"> {text} </span> ); } export default function ScrambleText() { return ( <div className="flex h-full w-full flex-col items-center justify-center"> {WORDS.map((w) => ( <Word key={w} text={w} /> ))} </div> ); }Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Scramble text component to my project. Words decode letter by letter on hover — a tiny reward for curiosity. It fills its parent, so give the wrapper a size. It is designed on a dark surface: put it inside an element with the `dark` class. Install it: ```sh pnpm dlx asta-ui@latest add scramble-text --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/scramble-text.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import ScrambleText from "@/components/astabyte/scramble-text"; ``` Usage example and props: https://ui.astabyte.com/scramble-text Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]
Usage
It fills its parent. Give the wrapper a size.
import ScrambleText from "@/components/astabyte/scramble-text";
export default function Page() {
// Scramble text
return (
<div className="relative h-96 w-full">
<ScrambleText />
</div>
);
}