Command Palette

Search for a command to run...

1.4k
Blog
PreviousNext

Text Flip

Animated text component that cycles through items with a smooth flip transition built with Motion for React.

I am a Developer
"use client"
 
import { motion } from "motion/react"
 
import { TextFlip } from "@/components/ncdai/text-flip"
 
export function TextFlipDemo() {
  return (
    <div className="text-2xl font-medium text-muted-foreground">
      <span>I am a </span>
      <TextFlip as={motion.span} className="min-w-32 text-foreground">
        <span>Developer</span>
        <span>Designer</span>
        <span>Creator</span>
        <span>Builder</span>
      </TextFlip>
    </div>
  )
}

Installation

$ pnpm dlx shadcn add @ncdai/text-flip

Usage

import { TextFlip } from "@/components/ncdai/text-flip"
<TextFlip>
  <span>Developer</span>
  <span>Designer</span>
  <span>Creator</span>
</TextFlip>

API Reference

PropTypeDefaultDescription
asMotionElementmotion.pThe motion element type to render.
classNamestringAdditional CSS classes applied to the rendered element.
childrenReactNode[]List of items to cycle through.
intervalnumber2Time in seconds between each flip.
transitionTransitiondefaultTransitionMotion transition config for the flip animation.
variantsVariantsdefaultVariantsMotion variants for initial, animate, and exit states.
onIndexChange(index: number) => voidCallback fired whenever the active item index changes.
const defaultTransition = {
  duration: 0.3,
}
 
const defaultVariants = {
  initial: { y: -8, opacity: 0 },
  animate: { y: 0, opacity: 1 },
  exit: { y: 8, opacity: 0 },
}