shimmering-text
elevenlabs/shimmering-textFreeComponent
shadcn/ui publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/elevenlabs/ui/main/apps/www/public/r/shimmering-text.jsonSource
1"use client"23import React, { useMemo, useRef } from "react"4import { motion, useInView, UseInViewOptions } from "motion/react"56import { cn } from "@/lib/utils"78interface ShimmeringTextProps {9 /** Text to display with shimmer effect */10 text: string11 /** Animation duration in seconds */12 duration?: number13 /** Delay before starting animation */14 delay?: number15 /** Whether to repeat the animation */16 repeat?: boolean17 /** Pause duration between repeats in seconds */18 repeatDelay?: number19 /** Custom className */20 className?: string21 /** Whether to start animation when component enters viewport */22 startOnView?: boolean23 /** Whether to animate only once */24 once?: boolean25 /** Margin for in-view detection (rootMargin) */26 inViewMargin?: UseInViewOptions["margin"]27 /** Shimmer spread multiplier */28 spread?: number29 /** Base text color */30 color?: string31 /** Shimmer gradient color */32 shimmerColor?: string33}3435export function ShimmeringText({36 text,37 duration = 2,38 delay = 0,39 repeat = true,40 repeatDelay = 0.5,41 className,42 startOnView = true,43 once = false,44 inViewMargin,45 spread = 2,46 color,47 shimmerColor,48}: ShimmeringTextProps) {49 const ref = useRef<HTMLSpanElement>(null)50 const isInView = useInView(ref, { once, margin: inViewMargin })5152 // Calculate dynamic spread based on text length53 const dynamicSpread = useMemo(() => {54 return text.length * spread55 }, [text, spread])5657 // Determine if we should start animation58 const shouldAnimate = !startOnView || isInView5960 return (61 <motion.span62 ref={ref}63 className={cn(64 "relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent",65 "[--base-color:var(--muted-foreground)] [--shimmer-color:var(--foreground)]",66 "[background-repeat:no-repeat,padding-box]",67 "[--shimmer-bg:linear-gradient(90deg,transparent_calc(50%-var(--spread)),var(--shimmer-color),transparent_calc(50%+var(--spread)))]",68 "dark:[--base-color:var(--muted-foreground)] dark:[--shimmer-color:var(--foreground)]",69 className70 )}71 style={72 {73 "--spread": `${dynamicSpread}px`,74 ...(color && { "--base-color": color }),75 ...(shimmerColor && { "--shimmer-color": shimmerColor }),76 backgroundImage: `var(--shimmer-bg), linear-gradient(var(--base-color), var(--base-color))`,77 } as React.CSSProperties78 }79 initial={{80 backgroundPosition: "100% center",81// … truncated
What it pulls in
npm packages
Files it writes
More from shadcn/ui
All 50 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| audio-playeraudio-player | shadcn/ui | Components | Free | 2 deps | |
| bar-visualizerbar-visualizer | shadcn/ui | Components | Free | no deps | |
| conversationconversation | shadcn/ui | Components | Free | 1 dep | |
| conversation-barconversation-bar | shadcn/ui | Components | Free | 1 dep | |
| live-waveformlive-waveform | shadcn/ui | Components | Free | no deps | |
| matrixmatrix | shadcn/ui | Components | Free | no deps | |
| messagemessage | shadcn/ui | Components | Free | 1 dep | |
| mic-selectormic-selector | shadcn/ui | Components | Free | no deps |
