Text Type

A text typing animation component with GSAP. Features typing, deleting, looping, and customizable cursor effects. Perfect for hero sections and landing pages.

Installation

npm install gsap react
pnpm install gsap react
yarn add gsap react
bun add gsap react
'use client';import { TextType } from '@/components/ui/text-type';export default function TextTypeDemo() {  return (    <div className="flex min-h-[200px] items-center justify-center">      <div className="text-center">        <h1 className="text-foreground text-3xl font-bold md:text-5xl">          <TextType            text={['Text typing effect', 'for your websites', 'Happy coding!']}            typingSpeed={75}            pauseDuration={1500}            showCursor={true}            cursorCharacter="|"            className="text-foreground"          />        </h1>      </div>    </div>  );}

Usage

import { TextType } from "@/components/ui/text-type";

export default function MyComponent() {
  return (
    <div className="text-4xl font-bold">
      <TextType
        text={["Text typing effect", "for your websites", "Happy coding!"]}
        typingSpeed={75}
        pauseDuration={1500}
        showCursor={true}
        cursorCharacter="|"
      />
    </div>
  );
}

Features

  • ⌨️ Typing Animation: Smooth character-by-character typing effect
  • 🗑️ Auto Delete: Automatically deletes text before typing next phrase
  • 🔄 Looping: Seamlessly loops through multiple text strings
  • 🎨 Customizable Cursor: Custom cursor character and blink animation
  • GSAP Powered: Smooth animations powered by GSAP
  • 📱 Responsive: Works on all screen sizes
  • 🎯 Intersection Observer: Start animation when element is visible
  • 🎨 Color Support: Custom colors for each text string

Props

PropTypeDefaultDescription
textstring | string[]RequiredText or array of texts to type
typingSpeednumber50Speed of typing in milliseconds
deletingSpeednumber30Speed of deleting in milliseconds
pauseDurationnumber2000Pause between typing and deleting
initialDelaynumber0Initial delay before starting
loopbooleantrueWhether to loop through texts
showCursorbooleantrueShow/hide cursor
cursorCharacterstring | ReactNode"|"Cursor character
cursorBlinkDurationnumber0.5Cursor blink speed
startOnVisiblebooleanfalseStart when element is visible
reverseModebooleanfalseType text in reverse
textColorsstring[][]Array of colors for each text
variableSpeed{min: number, max: number}-Random speed range
onSentenceCompletefunction-Callback when sentence completes

Examples

Basic Usage

<TextType
  text="Hello, World!"
  typingSpeed={100}
  showCursor={true}
/>

Multiple Texts

<TextType
  text={["Welcome", "to MVPBlocks", "Start building!"]}
  typingSpeed={75}
  pauseDuration={2000}
  loop={true}
/>

Custom Colors

<TextType
  text={["Red text", "Blue text", "Green text"]}
  textColors={["#ef4444", "#3b82f6", "#22c55e"]}
/>

Variable Speed

<TextType
  text="Variable speed typing"
  variableSpeed={{ min: 50, max: 150 }}
/>

Start on Visible

<TextType
  text="Starts when visible"
  startOnVisible={true}
/>

Custom Cursor

<TextType
  text="Custom cursor"
  cursorCharacter="▊"
  cursorBlinkDuration={0.8}
/>