Fade Text
Fade Text is a React and Tailwind CSS text component from Eldora UI, licensed MIT. Copy it and paste it into your project.
Eldora UI
MIT
text
What it is
Fade Text is a React and Tailwind CSS text component from Eldora UI, licensed MIT. Copy it and paste it into your project.
How to use it
Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.
Five free copies a month. No card.
Needs
npm i motion react clsx
Licence
This component comes from Eldora UI and is redistributed under the MIT licence, which permits commercial use. The copyright notice travels with the code.
Fade Text
"use client"
import React from "react"
import clsx from "clsx"
import { motion } from "motion/react"
type FadeDirection = "in" | "up" | "down"
interface FadeTextProps {
text?: string
className?: string
direction?: FadeDirection
staggerDelay?: number
wordDelay?: number
}
export const FadeText: React.FC<FadeTextProps> = ({
text = "",
className = "",
direction = "in",
staggerDelay = 0.15,
wordDelay = 0.1,
}) => {
// For "in" direction, we animate word by word
if (direction === "in") {
const words = text.split(" ")
return (
<motion.div
initial="hidden"
animate="visible"
viewport={{ once: true }}
variants={{
hidden: {},
visible: {
transition: {
staggerChildren: wordDelay,
},
},
}}
>
<motion.h1
className={clsx(
"font-display text-center font-bold drop-shadow-sm",
"text-4xl md:text-5xl lg:text-6xl xl:text-7xl",
"tracking-[-0.02em]",
"md:leading-[4rem] lg:leading-[4.5rem] xl:leading-[5rem]",
className
)}
>
{words.map((word, i) => (
<motion.span
key={`${word}-${i}`}
variants={{
hidden: { opacity: 0 },
visible: { opacity: 1 },
}}
>
{word}{" "}
</motion.span>
))}
</motion.h1>
</motion.div>
)
}
// For "up" and "down" directions, we animate the entire text
const animationVariants =
direction === "up"
? {
hidden: { opacity: 0, y: 20 },
show: {
opacity: 1,
y: 0,
transition: {
type: "spring" as const,
stiffness: 100,
damping: 12,
duration: 0.8,
},
},
}
: {
hidden: { opacity: 0, y: -20 },
show: {
opacity: 1,
y: 0,
transition: {
type: "spring" as const,
stiffness: 100,
damping: 12,
duration: 0.8,
},
},
}
return (
<motion.div
initial="hidden"
animate="show"
viewport={{ once: true }}
transition={{ delay: staggerDelay }}
>
<motion.h1
className={clsx(
"font-display text-center font-bold drop-shadow-sm",
"text-4xl md:text-5xl lg:text-6xl xl:text-7xl",
"tracking-[-0.02em]",
"md:leading-[4rem] lg:leading-[4.5rem] xl:leading-[5rem]",
className
)}
variants={animationVariants}
>
{text}
</motion.h1>
</motion.div>
)
}