Shiny Text

Text with a light sheen sweeping across it on a loop.

Unlock the vault

Install

$npx shadcn@latest add https://norvault.septiandwirestu.com/r/shiny-text.json

Or, with the @norvault namespace configured:

$npx shadcn@latest add @norvault/shiny-text

Source

"use client";

import { motion, useReducedMotion } from "motion/react";
import { cn } from "@/lib/utils";

export type ShinyTextProps = {
  children: React.ReactNode;
  /** Seconds per sweep. */
  speed?: number;
  /** Stop the animation (the text stays readable). */
  disabled?: boolean;
  className?: string;
};

export function ShinyText({ children, speed = 3, disabled = false, className }: ShinyTextProps) {
  const reduceMotion = useReducedMotion();
  const still = disabled || reduceMotion;

  return (
    <motion.span
      className={cn(
        "inline-block bg-[length:200%_100%] bg-clip-text text-transparent",
        "bg-[linear-gradient(110deg,var(--muted-foreground)_35%,var(--foreground)_50%,var(--muted-foreground)_65%)]",
        className,
      )}
      initial={{ backgroundPosition: "140% 0" }}
      animate={still ? undefined : { backgroundPosition: "-40% 0" }}
      transition={{ duration: speed, ease: "linear", repeat: Infinity }}
    >
      {children}
    </motion.span>
  );
}