Shimmer Text
Smooth shimmer animation for premium touch.
Processing prompt to generate result.
TSX
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108"use client"; import { motion } from "motion/react"; import { cn } from "@/lib/utils"; type Variant = | "default" | "secondary" | "destructive" | "red" | "blue" | "green" | "yellow" | "purple" | "pink" | "orange" | "cyan" | "indigo" | "violet" | "rose" | "amber" | "lime" | "emerald" | "sky" | "slate" | "fuchsia"; interface ShimmerTextProps { children: React.ReactNode; className?: string; variant?: Variant; duration?: number; delay?: number; spread?: number; } const variantMap: Record<Variant, string> = { default: "", secondary: "text-secondary-foreground", destructive: "text-destructive dark:text-destructive-foreground", red: "text-red-600 dark:text-red-400", blue: "text-blue-600 dark:text-blue-400", green: "text-green-600 dark:text-green-400", yellow: "text-yellow-600 dark:text-yellow-400", purple: "text-purple-600 dark:text-purple-400", pink: "text-pink-600 dark:text-pink-400", orange: "text-orange-600 dark:text-orange-400", cyan: "text-cyan-600 dark:text-cyan-400", indigo: "text-indigo-600 dark:text-indigo-400", violet: "text-violet-600 dark:text-violet-400", rose: "text-rose-600 dark:text-rose-400", amber: "text-amber-600 dark:text-amber-400", lime: "text-lime-600 dark:text-lime-400", emerald: "text-emerald-600 dark:text-emerald-400", sky: "text-sky-600 dark:text-sky-400", slate: "text-slate-600 dark:text-slate-400", fuchsia: "text-fuchsia-600 dark:text-fuchsia-400", }; export function ShimmerText({ children, className, variant = "default", duration = 1.5, delay = 1.5, }: ShimmerTextProps) { return ( <div className="group overflow-hidden"> <div> <motion.div className={cn( "inline-block [--shimmer-contrast:rgba(255,255,255,0.6)] dark:[--shimmer-contrast:rgba(0,0,0,0.5)]", variantMap[variant], className, )} style={ { WebkitTextFillColor: "transparent", background: "currentColor linear-gradient(to right, currentColor 0%, var(--shimmer-contrast) 40%, var(--shimmer-contrast) 60%, currentColor 100%)", WebkitBackgroundClip: "text", backgroundClip: "text", backgroundRepeat: "no-repeat", backgroundSize: "50% 200%", } as React.CSSProperties } initial={{ backgroundPositionX: "250%", }} animate={{ backgroundPositionX: ["-100%", "250%"], }} transition={{ duration: duration, delay: delay, repeat: Infinity, repeatDelay: 1.5, ease: "linear", }} > <span>{children}</span> </motion.div> </div> </div> ); } export default ShimmerText;
Installation
pnpm dlx shadcn@latest add @satoriui/shimmer-text