Typewriter
atlas-ui/typewriterFreeComponent
A typewriter component that cycles through text with a synced flashing highlight animation.
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/typewriter.jsonSource
1"use client";23import { useEffect, useState } from "react";45import { AnimatePresence, motion } from "motion/react";67import { cn } from "@/lib/utils";89interface TypewriterProps {10 /**11 * Array of strings to display12 */13 text: string[];14 /**15 * Delay between each letter (in seconds)16 * @default 0.02517 */18 letterDelay?: number;19 /**20 * Duration of the box fade (in seconds)21 * @default 0.12522 */23 boxFadeDuration?: number;24 /**25 * Duration of the text fade out (in seconds)26 * @default 0.2527 */28 textFadeOutDuration?: number;29 /**30 * Delay between each text fade out (in ms)31 * @default 550032 */33 delayBetween?: number;34 /**35 * Additional classNames36 */37 className?: string;38}3940export const Typewriter = ({41 text,42 letterDelay = 0.025,43 boxFadeDuration = 0.125,44 textFadeOutDuration = 0.25,45 delayBetween = 5500,46 className,47}: TypewriterProps) => {48 const [currentIndex, setCurrentIndex] = useState(0);4950 useEffect(() => {51 const intervalId = setInterval(() => {52 setCurrentIndex((prevIndex) => (prevIndex + 1) % text.length);53 }, delayBetween);5455 return () => clearInterval(intervalId);56 }, []);5758 return (59 <p className={cn("text-sm font-light uppercase", className)}>60 <AnimatePresence mode="wait">61 <motion.span62 key={currentIndex}63 initial={{ opacity: 1 }}64 exit={{ opacity: 0 }}65 transition={{66 duration: textFadeOutDuration,67 ease: "easeInOut",68 }}69 >70 {text[currentIndex].split("").map((char, index) => (71 <span key={index} className="relative">72 <motion.span73 initial={{ opacity: 0 }}74 animate={{ opacity: 1 }}75 transition={{ delay: index * letterDelay, duration: 0 }}76 >77 {char}78 </motion.span>79 <motion.span80 initial={{ opacity: 0 }}81 animate={{ opacity: [0, 1, 0] }}82 transition={{83 delay: index * letterDelay,84 times: [0, 0.1, 1],85 duration: boxFadeDuration,86 ease: "easeInOut",87 }}88 className="bg-foreground absolute inset-x-0.25 inset-y-0"89 />90 </span>91 ))}92 </motion.span>93 </AnimatePresence>94 </p>95 );96};
What it pulls in
npm packages
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 | |
| Hacker Texthacker-text | atlas-ui | Components | Free | no deps |
