返回 presentation-ai
word-fade-in.tsx
根目录 / src / components / ui / word-fade-in.tsx
1 "use client";
2
3 import { cn } from "@/lib/utils";
4 import { motion, type Variants } from "motion/react";
5
6 interface WordFadeInProps {
7 words: string;
8 className?: string;
9 delay?: number;
10 variants?: Variants;
11 }
12
13 export default function WordFadeIn({
14 words,
15 delay = 0.15,
16 variants = {
17 hidden: { opacity: 0 },
18 visible: (i: number) => ({
19 y: 0,
20 opacity: 1,
21 transition: { delay: i * delay },
22 }),
23 },
24 className,
25 }: WordFadeInProps) {
26 const _words = words.split(" ");
27
28 return (
29 <motion.h1
30 variants={variants}
31 initial="hidden"
32 animate="visible"
33 className={cn("font-display text-center", className)}
34 >
35 {_words.map((word, i) => (
36 <motion.span key={word} variants={variants} custom={i}>
37 {word}{" "}
38 </motion.span>
39 ))}
40 </motion.h1>
41 );
42 }
43
43 lines Plain Text