Chánh Đại

Text Swap

Text 1

About

Animated text that swaps through items with a fade transition. From chanhdai.com (ncdai), MIT.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Text Swap to your project and fits it to your theme.

Code

How Text Swap is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client"

import { useRef } from "react"
import { motion, useInView, usePageInView } from "motion/react"
import { TextSwap } from "@/components/ui/chanhdai-text-swap"

const WORDS = ["Developer", "Designer", "Creator", "Builder"]

export default function TextSwapDemo() {
  const ref = useRef<HTMLDivElement>(null)
  const isPageInView = usePageInView()
  const isInView = useInView(ref)
  const play = isPageInView && isInView

  return (
    <div
      ref={ref}
      className="flex items-center gap-1.5 text-2xl font-medium text-muted-foreground"
    >
      <span>I am a</span>
      <span className="inline-grid">
        {/* Placeholder for the tallest word */}
        <span className="invisible col-start-1 row-start-1" aria-hidden>
          {WORDS.reduce((a, b) => (a.length >= b.length ? a : b))}
        </span>
        <TextSwap
          as={motion.span}
          className="col-start-1 row-start-1 text-foreground"
          play={play}
        >
          {WORDS.map((word) => (
            <span key={word}>{word}</span>
          ))}
        </TextSwap>
      </span>
    </div>
  )
}

Dependencies

More by Chánh Đại

View all
  • Apple Hello Effect

    Apple Hello Effect

    692
  • Theme Switcher

    Theme Switcher

    364
  • Hero Golden Spiral

    Hero Golden Spiral

    121
  • Mobius Loop Icon

    Mobius Loop Icon

    90
  • Wheel Picker

    Wheel Picker

    79
  • Testimonial 2

    Testimonial 2

    50
  • Glow Card Grid

    Glow Card Grid

    49
  • Spinning Circular Text

    Spinning Circular Text

    26

More in Text

View all
  • Astryx Chat Tokenized Text

    Astryx Chat Tokenized Text

    16
  • Vertical Cut Reveal Characters

    Vertical Cut Reveal Characters

    135
  • Blur Reveal

    Blur Reveal

    401
  • Scroll Fill Headline

    Scroll Fill Headline

    67
  • Text Reveal

    Text Reveal

    411
  • Per Word Crossfade

    Per Word Crossfade

    20
  • Italic Sweep Scroll Text

    Italic Sweep Scroll Text

    77
  • Toolbar

    Toolbar

    60