Typewriter
fancy/typewriterFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/typewriter.jsonSource
1"use client"23import { ElementType, useEffect, useState } from "react"4import { motion, Variants } from "motion/react"56import { cn } from "@/lib/utils"78interface TypewriterProps {9 /**10 * Text or array of texts to type out11 */12 text: string | string[]1314 /**15 * HTML Tag to render the component as16 * @default div17 */18 as?: ElementType1920 /**21 * Speed of typing in milliseconds22 * @default 5023 */24 speed?: number2526 /**27 * Initial delay before typing starts28 * @default 029 */30 initialDelay?: number3132 /**33 * Time to wait between typing and deleting34 * @default 200035 */36 waitTime?: number3738 /**39 * Speed of deleting characters40 * @default 3041 */42 deleteSpeed?: number4344 /**45 * Whether to loop through texts array46 * @default true47 */48 loop?: boolean4950 /**51 * Optional class name for styling52 */53 className?: string5455 /**56 * Whether to show the cursor57 * @default true58 */59 showCursor?: boolean6061 /**62 * Hide cursor while typing63 * @default false64 */65 hideCursorOnType?: boolean6667 /**68 * Character or React node to use as cursor69 * @default "|"70 */71 cursorChar?: string | React.ReactNode7273 /**74 * Animation variants for cursor75 */76 cursorAnimationVariants?: {77 initial: Variants["initial"]78 animate: Variants["animate"]79 }8081 /**82 * Optional class name for cursor styling83 */84 cursorClassName?: string85}8687const Typewriter = ({88 text,89 as: Tag = "div",90 speed = 50,91 initialDelay = 0,92 waitTime = 2000,93 deleteSpeed = 30,94 loop = true,95 className,96 showCursor = true,97 hideCursorOnType = false,98 cursorChar = "|",99 cursorClassName = "ml-1",100 cursorAnimationVariants = {101 initial: { opacity: 0 },102 animate: {103 opacity: 1,104 transition: {105 duration: 0.01,106 repeat: Infinity,107 repeatDelay: 0.4,108 repeatType: "reverse",109 },110 },111 },112 ...props113}: TypewriterProps & React.HTMLAttributes<HTMLElement>) => {114 const [displayText, setDisplayText] = useState("")115 const [currentIndex, setCurrentIndex] = useState(0)116 const [isDeleting, setIsDeleting] = useState(false)117 const [currentTextIndex, setCurrentTextIndex] = useState(0)118119 const texts = Array.isArray(text) ? text : [text]120121 useEffect(() => {122 let timeout: NodeJS.Timeout123124 const currentText = texts[currentTextIndex]125126 const startTyping = () => {127 if (isDeleting) {128 if (displayText === "") {129 setIsDeleting(false)130// … truncated
What it pulls in
npm packages
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient With Svganimated-gradient-with-svg | fancy | Components | Free | no deps | |
| Basic Number Tickerbasic-number-ticker | fancy | Components | Free | 1 dep | |
| Box Carouselbox-carousel | fancy | Components | Free | 1 dep | |
| Breathing Textbreathing-text | fancy | Components | Free | 1 dep | |
| Circling Elementscircling-elements | fancy | Components | Free | 1 dep | |
| Css Boxcss-box | fancy | Components | Free | 1 dep | |
| Cursor Attractor And Gravitycursor-attractor-and-gravity | fancy | Components | Free | 5 deps | |
| Drag Elementsdrag-elements | fancy | Components | Free | 1 dep |
