mhsf-dev/apps/www/src/components/ui/animated-text.tsx

38 lines
968 B
TypeScript
Raw Normal View History

2025-03-15 16:58:24 -05:00
"use client";
import { useState, useEffect } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { cn } from "@/lib/utils";
interface AnimatedTextProps {
text: string;
className?: string;
2025-03-26 23:58:46 -05:00
glimmer?: boolean;
2025-03-15 16:58:24 -05:00
}
2025-03-26 23:58:46 -05:00
export function AnimatedText({ text, className, glimmer }: AnimatedTextProps) {
2025-03-15 16:58:24 -05:00
const [currentText, setCurrentText] = useState(text);
useEffect(() => {
setCurrentText(text);
}, [text]);
return (
<div className="relative h-6 min-w-[200px] text-sm">
<AnimatePresence mode="wait">
<motion.span
key={currentText}
initial={{ y: 20, opacity: 0 }}
animate={{ y: 0, opacity: 1 }}
exit={{ y: -20, opacity: 0 }}
transition={{ duration: 0.3 }}
2025-03-26 23:58:46 -05:00
className={cn("absolute left-0", className, {
"loading-shimmer": glimmer,
})}
2025-03-15 16:58:24 -05:00
>
{currentText}
</motion.span>
</AnimatePresence>
</div>
);
}