Hyper Text
magicui/hyper-textFreeComponent
A text animation that scrambles letters before revealing the final text.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/hyper-text.jsonSource
1"use client"23import {4 useEffect,5 useRef,6 useState,7 type ComponentType,8 type RefAttributes,9} from "react"10import {11 AnimatePresence,12 motion,13 type DOMMotionComponents,14 type HTMLMotionProps,15 type MotionProps,16} from "motion/react"1718import { cn } from "@/lib/utils"1920type CharacterSet = string[] | readonly string[]2122const motionElements = {23 article: motion.article,24 div: motion.div,25 h1: motion.h1,26 h2: motion.h2,27 h3: motion.h3,28 h4: motion.h4,29 h5: motion.h5,30 h6: motion.h6,31 li: motion.li,32 p: motion.p,33 section: motion.section,34 span: motion.span,35} as const3637type MotionElementType = Extract<38 keyof DOMMotionComponents,39 keyof typeof motionElements40>41type HyperTextMotionComponent = ComponentType<42 Omit<HTMLMotionProps<"div">, "ref"> & RefAttributes<HTMLElement>43>4445interface HyperTextProps extends Omit<MotionProps, "children"> {46 /** The text content to be animated */47 children: string48 /** Optional className for styling */49 className?: string50 /** Duration of the animation in milliseconds */51 duration?: number52 /** Delay before animation starts in milliseconds */53 delay?: number54 /** Component to render as - defaults to div */55 as?: MotionElementType56 /** Whether to start animation when element comes into view */57 startOnView?: boolean58 /** Whether to trigger animation on hover */59 animateOnHover?: boolean60 /** Custom character set for scramble effect. Defaults to uppercase alphabet */61 characterSet?: CharacterSet62}6364const DEFAULT_CHARACTER_SET = Object.freeze(65 "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("")66) as readonly string[]6768const getRandomInt = (max: number): number => Math.floor(Math.random() * max)6970export function HyperText({71 children,72 className,73 duration = 800,74 delay = 0,75 as: Component = "div",76 startOnView = false,77 animateOnHover = true,78 characterSet = DEFAULT_CHARACTER_SET,79 ...props80}: HyperTextProps) {81 const MotionComponent = motionElements[Component] as HyperTextMotionComponent8283 const [displayText, setDisplayText] = useState<string[]>(() =>84 children.split("")85 )86 const [isAnimating, setIsAnimating] = useState(false)87 const iterationCount = useRef(0)88 const elementRef = useRef<HTMLElement | null>(null)8990 const handleAnimationTrigger = () => {91 if (animateOnHover && !isAnimating) {92 iterationCount.current = 093 setIsAnimating(true)94 }95 }9697 // Handle animation start based on view or delay98 useEffect(() => {99 if (!startOnView) {100// … truncated
What it pulls in
npm packages
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
