Testimonial Spotlight
lyminhnghia/testimonial-spotlightFreeComponent
Testimonial card with spotlight effect on hover.
Install it
npx shadcn@latest add https://lyminhnghia.github.io/r/testimonial-spotlight.jsonSource
1"use client"23import { useRef, useState } from "react"45import { cn } from "@/lib/utils"67type Position = {8 x: number9 y: number10}1112const SPOTLIGHT_OPACITY = 0.51314export function TestimonialSpotlight({15 children,16 className,17 spotlightColor = "rgba(255,255,255,0.2)",18}: {19 children: React.ReactNode20 className?: string21 spotlightColor?: `rgba(${number},${number},${number},${number})`22}) {23 const itemRef = useRef<HTMLDivElement>(null)2425 const [isFocused, setIsFocused] = useState<boolean>(false)26 const [opacity, setOpacity] = useState<number>(0)27 const [position, setPosition] = useState<Position>({ x: 0, y: 0 })2829 const handleFocus = () => {30 setIsFocused(true)31 setOpacity(SPOTLIGHT_OPACITY)32 }3334 const handleBlur = () => {35 setIsFocused(false)36 setOpacity(0)37 }3839 const handleMouseEnter = () => {40 setOpacity(SPOTLIGHT_OPACITY)41 }4243 const handleMouseLeave = () => {44 setOpacity(0)45 }4647 const handleMouseMove: React.MouseEventHandler<HTMLDivElement> = (e) => {48 if (!itemRef.current || isFocused) return4950 const rect = itemRef.current.getBoundingClientRect()51 setPosition({ x: e.clientX - rect.left, y: e.clientY - rect.top })52 }5354 return (55 <div56 ref={itemRef}57 className={cn(58 "relative overflow-hidden rounded-xl bg-card/50 ring-1 ring-foreground/10 ring-inset",59 className60 )}61 onFocus={handleFocus}62 onBlur={handleBlur}63 onMouseEnter={handleMouseEnter}64 onMouseLeave={handleMouseLeave}65 onMouseMove={handleMouseMove}66 >67 <div68 className="pointer-events-none absolute inset-0 opacity-0 transition-opacity duration-500 ease-in-out"69 style={{70 opacity,71 background: `radial-gradient(circle at ${position.x}px ${position.y}px, ${spotlightColor}, transparent 60%)`,72 }}73 />74 {children}75 </div>76 )77}
What it pulls in
Other registry items
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 | |
| Shimmering Textshimmering-text | lyminhnghia | Components | Free | 1 dep |
