2025-12-10 20:54:43 +05:30
|
|
|
"use client"
|
|
|
|
|
|
2026-10-12 12:35:55 +09:00
|
|
|
import { type CSSProperties, type ElementType, memo, useMemo } from "react"
|
2025-12-10 20:54:43 +05:30
|
|
|
import { cn } from "@/lib/utils"
|
|
|
|
|
|
|
|
|
|
export type TextShimmerProps = {
|
|
|
|
|
children: string
|
|
|
|
|
as?: ElementType
|
|
|
|
|
className?: string
|
|
|
|
|
duration?: number
|
|
|
|
|
spread?: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ShimmerComponent = ({
|
|
|
|
|
children,
|
|
|
|
|
as: Component = "p",
|
|
|
|
|
className,
|
|
|
|
|
duration = 2,
|
|
|
|
|
spread = 2,
|
|
|
|
|
}: TextShimmerProps) => {
|
|
|
|
|
const dynamicSpread = useMemo(
|
|
|
|
|
() => (children?.length ?? 0) * spread,
|
|
|
|
|
[children, spread],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return (
|
2026-10-12 12:35:55 +09:00
|
|
|
<Component
|
2025-12-10 20:54:43 +05:30
|
|
|
className={cn(
|
2026-10-12 12:35:55 +09:00
|
|
|
"animate-shimmer relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent",
|
2025-12-10 20:54:43 +05:30
|
|
|
"[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",
|
|
|
|
|
className,
|
|
|
|
|
)}
|
|
|
|
|
style={
|
|
|
|
|
{
|
|
|
|
|
"--spread": `${dynamicSpread}px`,
|
2026-10-12 12:35:55 +09:00
|
|
|
"--shimmer-duration": `${duration}s`,
|
2025-12-10 20:54:43 +05:30
|
|
|
backgroundImage:
|
|
|
|
|
"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))",
|
|
|
|
|
} as CSSProperties
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{children}
|
2026-10-12 12:35:55 +09:00
|
|
|
</Component>
|
2025-12-10 20:54:43 +05:30
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Shimmer = memo(ShimmerComponent)
|