turkmen-tv-front/components/common/AnimatedText.tsx

55 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-01-03 12:45:58 +00:00
import { cn } from '@/lib/utils';
2025-01-02 12:47:39 +00:00
import { motion } from 'framer-motion';
interface AnimatedTextProps {
text: string;
className?: string;
2025-01-08 13:33:42 +00:00
characterClassName?: string;
2025-01-02 12:47:39 +00:00
initialY?: number;
2025-01-08 13:33:42 +00:00
exitY?: number;
duration: number;
characterDelay?: number;
2025-01-02 12:47:39 +00:00
}
const AnimatedText = ({
text,
className = '',
2025-01-08 13:33:42 +00:00
characterClassName = '',
2025-01-02 12:47:39 +00:00
initialY = -100,
2025-01-08 13:33:42 +00:00
exitY = 100,
duration,
characterDelay = 0,
2025-01-02 12:47:39 +00:00
}: AnimatedTextProps) => {
2025-01-08 13:33:42 +00:00
const characters = text.split('');
2025-01-02 12:47:39 +00:00
return (
<div className="overflow-hidden">
<motion.p
2025-01-08 13:33:42 +00:00
className={cn(`flex `, className)}
initial={{ translateY: initialY, opacity: 0 }}
animate={{ translateY: 0, opacity: 1 }}
exit={{ translateY: exitY, opacity: 0 }}>
{characters.map((character, i) => (
<motion.div
2025-01-02 12:47:39 +00:00
key={i}
2025-01-08 13:33:42 +00:00
initial={{ translateY: initialY, opacity: 0 }}
animate={{ translateY: 0, opacity: 1 }}
exit={{ translateY: exitY, opacity: 0 }}
2025-01-02 12:47:39 +00:00
transition={{
duration,
2025-01-08 13:33:42 +00:00
delay: characterDelay + (i / 2) * duration,
2025-01-02 12:47:39 +00:00
ease: 'easeOut',
}}
2025-01-08 13:33:42 +00:00
className={cn(`block `, characterClassName, {
2025-01-03 12:45:58 +00:00
'animate-dotsFlash': text === '...',
})}>
2025-01-08 13:33:42 +00:00
{character}
</motion.div>
2025-01-02 12:47:39 +00:00
))}
</motion.p>
</div>
);
};
export default AnimatedText;