返回 presentation-ai
text-shimmer.tsx
根目录 / src / components / ui / text-shimmer.tsx
1 "use client";
2
3 import { motion } from "motion/react";
4 import { type CSSProperties, type ElementType, type JSX } from "react";
5
6 import { cn } from "@/lib/utils";
7
8 interface TextShimmerProps {
9 children: string;
10 as?: ElementType;
11 className?: string;
12 duration?: number;
13 spread?: number;
14 }
15
16 export function TextShimmer({
17 children,
18 as: Component = "p",
19 className,
20 duration = 2,
21 spread = 2,
22 }: TextShimmerProps) {
23 const MotionComponent = motion(Component as keyof JSX.IntrinsicElements);
24 const dynamicSpread = children.length * spread;
25
26 return (
27 <MotionComponent
28 className={cn(
29 "relative inline-block bg-size-[250%_100%,auto] bg-clip-text text-transparent",
30 "[--base-color:#a1a1aa] [--base-gradient-color:#000]",
31 "[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--base-gradient-color),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",
32 "dark:[--base-color:#71717a] dark:[--base-gradient-color:#ffffff]",
33 className,
34 )}
35 initial={{ backgroundPosition: "100% center" }}
36 animate={{ backgroundPosition: "0% center" }}
37 transition={{
38 repeat: Number.POSITIVE_INFINITY,
39 duration,
40 ease: "linear",
41 }}
42 style={
43 {
44 "--spread": `${dynamicSpread}px`,
45 backgroundImage:
46 "var(--bg), linear-gradient(var(--base-color), var(--base-color))",
47 } as CSSProperties
48 }
49 >
50 {children}
51 </MotionComponent>
52 );
53 }
54
54 lines Plain Text