W
a
v
y
T
e
x
t
Installation
Copy and paste the following code into your project.
components/magicui/wavy-text.tsx
"use client";
import { cn } from "@/lib/utils";
import { AnimatePresence, motion } from "framer-motion";
import { useMemo } from "react";
interface WavyTextProps {
word: string;
className?: string;
variant?: {
hidden: { y: number };
visible: { y: number };
};
duration?: number;
delay?: number;
}
const WavyText = ({
word,
className,
variant,
duration = 0.5,
delay = 0.05,
}: WavyTextProps) => {
const defaultVariants = {
hidden: { y: 10 },
visible: { y: -10 },
};
const combinedVariants = variant || defaultVariants;
const characters = useMemo(() => word.split(""), [word]);
return (
<div className="flex justify-center space-x-2 overflow-hidden p-3">
<AnimatePresence>
{characters.map((char, i) => (
<motion.h1
key={i}
initial="hidden"
animate="visible"
exit="hidden"
variants={combinedVariants}
transition={{
yoyo: Infinity,
duration: duration,
delay: i * delay,
}}
className={cn(
className,
"font-display text-center text-4xl font-bold tracking-[-0.15em] md:text-7xl",
)}
>
{char}
</motion.h1>
))}
</AnimatePresence>
</div>
);
};
export default WavyText;
Props
Prop | Type | Description | Default |
---|---|---|---|
className | string | The class name to be applied to the component | |
duration | number | Durations (seconds) for the animation | 0.5 |
delay | number | Duration (seconds) for stagger between each letter | 0.02 |
words | string | The word to be animated | |
variant | object | Custom animation variants for motion component | hidden: { y: 10 },visible: { y: -10 } |