94 lines
2.1 KiB
TypeScript
94 lines
2.1 KiB
TypeScript
'use client';
|
|||
|
|
|
||
|
|
import React from 'react';
|
||
|
|
import { motion, Variants } from 'framer-motion';
|
||
|
|
|
||
|
|
interface MotionTextRevealProps {
|
||
|
|
text: string;
|
||
|
|
className?: string;
|
||
|
|
highlightWords?: string[];
|
||
|
|
highlightClassName?: string;
|
||
|
|
delay?: number;
|
||
|
|
stagger?: number;
|
||
|
|
as?: 'h1' | 'h2' | 'h3' | 'h4' | 'p' | 'span';
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Animate UI - Motion Text Reveal
|
||
|
|
* Staggered word-by-word 3D kinetic entrance animation with blur-to-sharp physics.
|
||
|
|
* Reference: https://animate-ui.com/docs
|
||
|
|
*/
|
||
|
|
export function MotionTextReveal({
|
||
|
|
text,
|
||
|
|
className = '',
|
||
|
|
highlightWords = [],
|
||
|
|
highlightClassName = 'text-transparent bg-clip-text bg-gradient-to-r from-blue-700 via-indigo-600 to-purple-600',
|
||
|
|
delay = 0.1,
|
||
|
|
stagger = 0.045,
|
||
|
|
as: Component = 'span',
|
||
|
|
}: MotionTextRevealProps) {
|
||
|
|
const words = text.split(' ');
|
||
|
|
|
||
|
|
const containerVariants: Variants = {
|
||
|
|
hidden: { opacity: 0 },
|
||
|
|
visible: {
|
||
|
|
opacity: 1,
|
||
|
|
transition: {
|
||
|
|
staggerChildren: stagger,
|
||
|
|
delayChildren: delay,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
const wordVariants: Variants = {
|
||
|
|
hidden: {
|
||
|
|
opacity: 0,
|
||
|
|
y: 28,
|
||
|
|
rotateX: -35,
|
||
|
|
filter: 'blur(8px)',
|
||
|
|
scale: 0.94,
|
||
|
|
},
|
||
|
|
visible: {
|
||
|
|
opacity: 1,
|
||
|
|
y: 0,
|
||
|
|
rotateX: 0,
|
||
|
|
filter: 'blur(0px)',
|
||
|
|
scale: 1,
|
||
|
|
transition: {
|
||
|
|
type: 'spring',
|
||
|
|
damping: 18,
|
||
|
|
stiffness: 140,
|
||
|
|
mass: 0.8,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
return (
|
||
|
|
<motion.span
|
||
|
|
variants={containerVariants}
|
||
|
|
initial="hidden"
|
||
|
|
whileInView="visible"
|
||
|
|
viewport={{ once: true, margin: '-50px' }}
|
||
|
|
className={`inline-block perspective-1000 ${className}`}
|
||
|
|
>
|
||
|
|
{words.map((word, idx) => {
|
||
|
|
const isHighlight = highlightWords.some(
|
||
|
|
(hw) => word.toLowerCase().includes(hw.toLowerCase())
|
||
|
|
);
|
||
|
|
|
||
|
|
return (
|
||
|
|
<motion.span
|
||
|
|
key={idx}
|
||
|
|
variants={wordVariants}
|
||
|
|
className={`inline-block mr-[0.26em] last:mr-0 preserve-3d will-change-transform ${
|
||
|
|
isHighlight ? highlightClassName : ''
|
||
|
|
}`}
|
||
|
|
>
|
||
|
|
{word}
|
||
|
|
</motion.span>
|
||
|
|
);
|
||
|
|
})}
|
||
|
|
</motion.span>
|
||
|
|
);
|
||
|
|
}
|