Word Fade In
Installation
Copy and paste the following code into your project.
components/magicui/word-fade-in.tsx
"use client";
import { cn } from "@/lib/utils";
import { Variants, motion } from "framer-motion";
interface WordFadeInProps {
words: string;
className?: string;
delay?: number;
variants?: Variants;
}
export default function WordFadeIn({
words,
delay = 0.15,
variants = {
hidden: { opacity: 0 },
visible: (i: any) => ({
y: 0,
opacity: 1,
transition: { delay: i * delay },
}),
},
className,
}: WordFadeInProps) {
const _words = words.split(" ");
return (
<motion.h1
variants={variants}
initial="hidden"
animate="visible"
className={cn(
"font-display text-center text-4xl font-bold tracking-[-0.02em] text-black drop-shadow-sm dark:text-white md:text-7xl md:leading-[5rem]",
className,
)}
>
{_words.map((word, i) => (
<motion.span key={word} variants={variants} custom={i}>
{word}{" "}
</motion.span>
))}
</motion.h1>
);
}
Props
Prop | Type | Description | Default |
---|---|---|---|
className | string | The class name to be applied to the component | |
delay | number | The Delay between each word animation | 0.15 |
words | string | A Text that is animated word by word | "word fade in" |
variants | Variants | An object containing framer-motion animation props |