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>
)
}















