Shimmering Text
lyminhnghia/shimmering-textFreeComponent
Smooth, light-sweeping shimmer animation for text.
Install it
npx shadcn@latest add https://lyminhnghia.github.io/r/shimmering-text.jsonSource
1"use client"23import type { Variants } from "motion/react"4import { motion } from "motion/react"5import * as React from "react"67import { cn } from "@/lib/utils"89export type ShimmeringTextProps = Omit<10 React.ComponentProps<typeof motion.span>,11 "children"12> & {13 /** The text to render with the shimmering effect. */14 text: string15 /**16 * Duration in seconds for one shimmer cycle.17 * @defaultValue 1 */18 duration?: number19 /**20 * Whether the shimmer animation is paused.21 * @defaultValue false */22 isStopped?: boolean23}2425export function ShimmeringText({26 text,27 duration = 1,28 isStopped = false,29 className,30 ...props31}: ShimmeringTextProps) {32 const createCharVariants = React.useCallback(33 (charIndex: number): Variants => ({34 running: {35 color: ["var(--color)", "var(--shimmering-color)", "var(--color)"],36 transition: {37 duration,38 repeat: Infinity,39 repeatType: "loop" as const,40 repeatDelay: text.length * 0.05,41 delay: (charIndex * duration) / text.length,42 ease: "easeInOut",43 },44 },45 stopped: {46 color: "var(--color)",47 transition: {48 duration: duration * 0.5,49 ease: "easeOut",50 },51 },52 }),53 [duration, text.length]54 )5556 return (57 <motion.span58 className={cn(59 "inline-block select-none",60 "[--color:var(--muted-foreground)] [--shimmering-color:var(--foreground)]",61 className62 )}63 {...props}64 >65 {text?.split("")?.map((char, i) => (66 <motion.span67 key={i}68 className="inline-block whitespace-pre"69 initial="stopped"70 animate={isStopped ? "stopped" : "running"}71 variants={createCharVariants(i)}72 >73 {char}74 </motion.span>75 ))}76 </motion.span>77 )78}
What it pulls in
npm packages
Files it writes
More from lyminhnghia
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Apple Hello Effectapple-hello-effect | lyminhnghia | Components | Free | 1 dep | |
| chevrons-up-down-iconchevrons-up-down-icon | lyminhnghia | Components | Free | no deps | |
| Code Block Commandcode-block-command | lyminhnghia | Components | Free | 4 deps · 3 files | |
| Consent Managerconsent-manager | lyminhnghia | Components | Free | 1 dep | |
| Copy Buttoncopy-button | lyminhnghia | Components | Free | 2 deps · 2 files | |
| GitHub Starsgithub-stars | lyminhnghia | Components | Free | no deps | |
| Scroll Fade Effectscroll-fade-effect | lyminhnghia | Components | Free | no deps | |
| Slide to Unlockslide-to-unlock | lyminhnghia | Components | Free | 1 dep |
