Hacker Text
atlas-ui/hacker-textFreeComponent
A text animation that scrambles letters before revealing the final text.
Live preview
live · rendered by the registry
Rendered by atlas-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://atlasui.dev/r/hacker-text.jsonSource
1"use client";23import { useEffect } from "react";45import { Bebas_Neue } from "next/font/google";67import { cn } from "@/lib/utils";89const bebas = Bebas_Neue({ subsets: ["latin"], weight: ["400"] });1011export const HackerText = ({12 text,13 className,14}: {15 text: string;16 className?: string;17}) => {18 const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";1920 useEffect(() => {21 const textElement = document.getElementById("text");22 let interval: NodeJS.Timeout | null = null;23 let timeout: NodeJS.Timeout | null = null;2425 const scrambleText = (target: HTMLElement) => {26 let iteration = 0;2728 clearInterval(interval as NodeJS.Timeout);2930 interval = setInterval(() => {31 if (!target.dataset.value) return;3233 target.innerText = target.innerText34 .split("")35 .map((letter, index) => {36 if (index < iteration) {37 return target.dataset.value![index];38 }39 return letters[Math.floor(Math.random() * 26)];40 })41 .join("");4243 if (iteration >= target.dataset.value.length) {44 clearInterval(interval as NodeJS.Timeout);45 }4647 iteration += 1 / 3;48 }, 30);49 };5051 const applyEffect = () => {52 if (window.matchMedia("(min-width: 768px)").matches) {53 // For non-mobile devices54 if (textElement) {55 textElement.addEventListener("mouseover", (event) => {56 const target = event.target as HTMLElement;57 scrambleText(target);58 });59 }60 }61 // Run the effect after 600ms on page load for all devices62 if (textElement) {63 timeout = setTimeout(() => {64 scrambleText(textElement);65 }, 600);66 }67 };6869 applyEffect();7071 return () => {72 if (textElement && window.matchMedia("(min-width: 768px)").matches) {73 textElement.removeEventListener("mouseover", (event) => {74 const target = event.target as HTMLElement;75 scrambleText(target);76 });77 }78 if (interval) {79 clearInterval(interval);80 }81 if (timeout) {82 clearTimeout(timeout);83 }84 };85 }, [letters]);86 return (87 <span88 id="text"89 data-value={text}90 className={cn("text-4xl uppercase", bebas.className, className)}91 >92 {text}93 </span>94 );95};
What it pulls in
Other registry items
Files it writes
More from atlas-ui
All 99 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Mobile Navbaranimated-mobile-navbar | atlas-ui | Components | Free | 2 deps | |
| Blend Mouse Trailerblend-mouse-trailer | atlas-ui | Components | Free | 1 dep | |
| Blob Mouse Trailerblob-mouse-trailer | atlas-ui | Components | Free | 1 dep | |
| Box Revealbox-reveal | atlas-ui | Components | Free | 1 dep | |
| Cascade Textcascade-text | atlas-ui | Components | Free | 1 dep | |
| Dot And Circle Mouse Trailerdot-and-circle-mouse-trailer | atlas-ui | Components | Free | 1 dep | |
| Fancy Theme Togglefancy-theme-toggle | atlas-ui | Components | Free | 1 dep | |
| Letter Swapletter-swap | atlas-ui | Components | Free | 1 dep |
