glitch-text
jolyui-ui/glitch-textFreeComponent
jolyui/ui publishes no description for this item.
Install it
npx shadcn@latest add https://jolyui.dev/r/glitch-text.jsonSource
1import * as React from "react";2import { cn } from "@/lib/utils";34interface GlitchTextProps {5 words: string[];6 className?: string;7 interval?: number;8 glitchDuration?: number;9}1011const GlitchText = React.forwardRef<HTMLSpanElement, GlitchTextProps>(12 ({ words, className, interval = 3000, glitchDuration = 300 }, ref) => {13 const [currentIndex, setCurrentIndex] = React.useState(0);14 const [isGlitching, setIsGlitching] = React.useState(false);15 const [displayText, setDisplayText] = React.useState(words[0] || "");1617 const glitchChars = "!<>-_\\/[]{}—=+*^?#________";1819 React.useEffect(() => {20 const timer = setInterval(() => {21 setIsGlitching(true);2223 const nextIndex = (currentIndex + 1) % words.length;24 const targetWord = words[nextIndex] || "";25 const iterations = 10;26 let iteration = 0;2728 const glitchInterval = setInterval(() => {29 setDisplayText(30 targetWord31 .split("")32 .map((char, i) => {33 if (i < iteration) return char;34 return glitchChars[35 Math.floor(Math.random() * glitchChars.length)36 ];37 })38 .join(""),39 );4041 iteration += 1;42 if (iteration > targetWord.length) {43 clearInterval(glitchInterval);44 setDisplayText(targetWord);45 setCurrentIndex(nextIndex);46 setIsGlitching(false);47 }48 }, glitchDuration / iterations);49 }, interval);5051 return () => clearInterval(timer);52 }, [currentIndex, words, interval, glitchDuration]);5354 return (55 <span56 ref={ref}57 className={cn(58 "inline-block font-mono",59 isGlitching && "text-primary",60 className,61 )}62 >63 {displayText}64 </span>65 );66 },67);68GlitchText.displayName = "GlitchText";6970export { GlitchText };
What it pulls in
npm packages
Files it writes
More from jolyui/ui
All 199 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-prompt-boxai-prompt-box | jolyui/ui | Components | Free | 4 deps | |
| animated-beamanimated-beam | jolyui/ui | Components | Free | 1 dep | |
| animated-tableanimated-table | jolyui/ui | Components | Free | 2 deps | |
| animated-theme-toggleanimated-theme-toggle | jolyui/ui | Components | Free | 2 deps | |
| animated-toastanimated-toast | jolyui/ui | Components | Free | 2 deps | |
| animated-tooltipanimated-tooltip | jolyui/ui | Components | Free | 1 dep | |
| bento-gridbento-grid | jolyui/ui | Components | Free | no deps | |
| buttonbutton | jolyui/ui | Components | Free | 3 deps |
