Files
CodePilot/src/components/ai-elements/shimmer.tsx
T
7418andClaude Opus 4.6 9b166be8d6 fix: resolve 25 error-level lint issues (P1-3)
Fix no-require-imports, no-explicit-any, no-html-link-for-pages,
set-state-in-effect, purity, static-components, and refs rules
across 15 files. 0 errors remain (52 warnings unchanged).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-13 01:24:51 +08:00

58 lines
1.5 KiB
TypeScript

"use client";
import type { CSSProperties } from "react";
import { cn } from "@/lib/utils";
import { motion } from "motion/react";
import { memo, useMemo } from "react";
// Pre-create the motion.p component at module level to avoid creating during render
const MotionP = motion.create("p");
export interface TextShimmerProps {
children: string;
className?: string;
duration?: number;
spread?: number;
}
const ShimmerComponent = ({
children,
className,
duration = 2,
spread = 2,
}: TextShimmerProps) => {
const dynamicSpread = useMemo(
() => (children?.length ?? 0) * spread,
[children, spread]
);
return (
<MotionP
animate={{ backgroundPosition: "0% center" }}
className={cn(
"relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent",
"[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",
className
)}
initial={{ backgroundPosition: "100% center" }}
style={
{
"--spread": `${dynamicSpread}px`,
backgroundImage:
"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))",
} as CSSProperties
}
transition={{
duration,
ease: "linear",
repeat: Number.POSITIVE_INFINITY,
}}
>
{children}
</MotionP>
);
};
export const Shimmer = memo(ShimmerComponent);