Skip to content

Commit 066b232

Browse files
committed
feat: 添加filpText组件
1 parent abb8df7 commit 066b232

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/components/FilpText.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import clsx from 'clsx';
2+
import type { Variants } from 'motion/react';
3+
import { AnimatePresence, motion } from 'motion/react';
4+
5+
interface FlipTextProps {
6+
readonly className?: string;
7+
readonly delayMultiple?: number;
8+
readonly duration?: number;
9+
readonly framerProps?: Variants;
10+
readonly word: string;
11+
}
12+
13+
const FlipText: FC<FlipTextProps> = memo(
14+
({
15+
className,
16+
delayMultiple = 0.08,
17+
duration = 0.5,
18+
framerProps = {
19+
hidden: { opacity: 0, rotateX: -90 },
20+
visible: { opacity: 1, rotateX: 0 }
21+
},
22+
word
23+
}) => {
24+
return (
25+
<AnimatePresence mode="sync">
26+
{word.split('').map((char, i) => (
27+
<motion.span
28+
animate="visible"
29+
className={clsx(' drop-shadow-sm', className)}
30+
initial="hidden"
31+
key={i}
32+
transition={{ delay: i * delayMultiple, duration }}
33+
variants={framerProps}
34+
>
35+
{char}
36+
</motion.span>
37+
))}
38+
</AnimatePresence>
39+
);
40+
}
41+
);
42+
43+
export default FlipText;

0 commit comments

Comments
 (0)