Hyper Text
componentry/hyper-textFreeComponent
A text effect that scrambles and cycles characters before revealing the final text, inspired by cyberpunk aesthetics.
Live preview
live · rendered by the registry
Rendered by componentry on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://componentry.dev/r/hyper-text.jsonSource
1"use client";23import { cn } from "@workspace/ui/lib/utils";4import { useEffect, useRef, useState } from "react";56interface HyperTextProps {7 className?: string;8 duration?: number;9 text: string;10 animateOnLoad?: boolean;11}1213const alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";1415export const HyperText = ({16 className,17 duration = 800,18 text,19 animateOnLoad = true,20}: HyperTextProps) => {21 const [displayText, setDisplayText] = useState(text.split(""));22 const [trigger, setTrigger] = useState(false);23 const iterations = useRef(0);24 const isFirstRender = useRef(true);2526 const triggerAnimation = () => {27 iterations.current = 0;28 setTrigger(true);29 };3031 useEffect(() => {32 const interval = setInterval(() => {33 if (!animateOnLoad && isFirstRender.current) {34 clearInterval(interval);35 isFirstRender.current = false;36 return;37 }38 if (iterations.current < text.length) {39 setDisplayText((t) =>40 t.map((l, i) =>41 l === " "42 ? l43 : i <= iterations.current44 ? text[i] ?? ""45 : alphabets[Math.floor(Math.random() * alphabets.length)]46 )47 );48 iterations.current = iterations.current + 0.1;49 } else {50 setTrigger(false);51 clearInterval(interval);52 }53 }, duration / (text.length * 10));54 // Clean up interval on unmount55 return () => clearInterval(interval);56 }, [text, duration, trigger, animateOnLoad]);5758 return (59 <div60 className={cn("flex cursor-default overflow-hidden py-2 font-mono", className)}61 onMouseEnter={triggerAnimation}62 >63 {displayText.map((letter, i) => (64 <span key={i} className="min-w-[0.1em]">65 {letter}66 </span>67 ))}68 </div>69 );70};
More from componentry
All 59 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradientanimated-gradient | componentry | Components | Free | no deps | |
| ASCII Effectascii-effect | componentry | Components | Free | no deps | |
| Aurora Flowaurora-flow | componentry | Components | Free | no deps | |
| auth-modalauth-modal | componentry | Components | Free | no deps | |
| border-beamborder-beam | componentry | Components | Free | no deps | |
| circuit-boardcircuit-board | componentry | Components | Free | no deps | |
| closing-plasmaclosing-plasma | componentry | Components | Free | no deps | |
| collection-surfercollection-surfer | componentry | Components | Free | no deps |
