// Text & type
002 / 112
Text that resolves out of cycling glyphs, left to right. Hover to decode again.
Loading…
The code
All of it, in one file: the component above, restyle included. Nothing imported but React.
"use client";
import { useEffect, useRef, useState } from "react";
/** DecodeText — resolves out of cycling glyphs, left to right. Re-runs on hover. React only. */
const G = "!<>-_\\/[]{}—=+*^?#%&";
export default function DecodeText({ text = "Decode the signal" }: { text?: string }) {
const [out, setOut] = useState(text);
const t = useRef<ReturnType<typeof setInterval>>();
const run = () => {
clearInterval(t.current);
let f = 0;
t.current = setInterval(() => {
f++;
setOut([...text].map((c, i) => (c === " " ? " " : i < f / 2 ? c : G[Math.floor(Math.random() * G.length)])).join(""));
if (f > text.length * 2) clearInterval(t.current);
}, 32);
};
useEffect(() => {
run();
return () => clearInterval(t.current);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<p onPointerEnter={run} aria-label={text} style={{ margin: 0, fontFamily: "var(--f-mono,monospace)", fontSize: "clamp(20px,2.6vw,34px)", letterSpacing: ".02em", color: "#ff630f", minHeight: "1.2em" }}>
{out}
</p>
);
}
Props
| Prop | Default |
|---|---|
text | "Decode the signal" |
Theme tokens it reads
Set these on :root to re-skin it. Each has a fallback, so it also works with none of them defined.
| Variable | Fallback | What it does |
|---|---|---|
--f-mono | monospace | Monospace face for small labels and readouts. |
Or install it
Published to a shadcn-style registry, so one command fetches the file straight into your project.
npx shadcn@latest add https://your-domain.com/r/decode-text.jsonPlaceholder domain — set NEXT_PUBLIC_SITE_URL to your deployed origin and the command updates.
// Next up