{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"card-spotlight","type":"registry:ui","title":"CardSpotlight","description":"Card whose radial-gradient spotlight tracks the cursor as it moves inside, fading in on hover and parking itself off-canvas when the pointer leaves, with configurable gradient size, color, and opacity","author":"fancy-ui <https://fancy-ui.rama.app>","categories":["cards"],"registryDependencies":["https://fancy-ui.rama.app/r/internals-dom.json","https://fancy-ui.rama.app/r/utils.json"],"files":[{"path":"react/src/components/card-spotlight/CardSpotlight.tsx","content":"\"use client\";\n\nimport { useRef } from \"react\";\nimport type { MouseEvent, ReactNode } from \"react\";\n\nimport { useIsomorphicLayoutEffect } from \"../../internals/dom/ssr\";\nimport { cn } from \"../../utils\";\n\nexport interface CardSpotlightProps {\n\t/** Classes for the outer container. */\n\tclassName?: string;\n\t/** Classes for the content wrapper. */\n\tslotClass?: string;\n\t/** Radius of the spotlight gradient. */\n\tgradientSize?: number;\n\t/** Color of the spotlight. */\n\tgradientColor?: string;\n\t/** Opacity of the gradient overlay. */\n\tgradientOpacity?: number;\n\t/** The card content. */\n\tchildren?: ReactNode;\n}\n\nexport function CardSpotlight({\n\tclassName = \"\",\n\tslotClass = \"\",\n\tgradientSize = 200,\n\tgradientColor = \"#262626\",\n\tgradientOpacity = 0.8,\n\tchildren,\n}: CardSpotlightProps) {\n\tconst overlayRef = useRef<HTMLDivElement>(null);\n\tconst restingX = -gradientSize * 10;\n\tconst restingY = -gradientSize * 10;\n\n\t// The pointer position lives in a ref and is written straight to the overlay's\n\t// `background`: a mousemove patches one style property instead of re-rendering\n\t// the card and re-running its class merges.\n\tconst pointerRef = useRef({ x: restingX, y: restingY });\n\n\tfunction paint(x: number, y: number) {\n\t\tpointerRef.current = { x, y };\n\t\tconst overlay = overlayRef.current;\n\t\tif (overlay) {\n\t\t\toverlay.style.background = `radial-gradient(circle at ${x}px ${y}px, ${gradientColor} 0%, rgba(0, 0, 0, 0) 70%)`;\n\t\t}\n\t}\n\n\tfunction handleMouseMove(e: MouseEvent<HTMLDivElement>) {\n\t\tconst target = e.currentTarget;\n\t\tconst rect = target.getBoundingClientRect();\n\t\tpaint(e.clientX - rect.left, e.clientY - rect.top);\n\t}\n\n\tfunction handleMouseLeave() {\n\t\tpaint(restingX, restingY);\n\t}\n\n\tconst restingBackground = `radial-gradient(circle at ${restingX}px ${restingY}px, ${gradientColor} 0%, rgba(0, 0, 0, 0) 70%)`;\n\n\t// React rewrites `background` whenever the value in the style object below changes,\n\t// which would snap a live spotlight back to the resting offsets; put the current\n\t// pointer position back in the same commit.\n\tuseIsomorphicLayoutEffect(() => {\n\t\tconst overlay = overlayRef.current;\n\t\tif (!overlay) return;\n\t\tconst { x, y } = pointerRef.current;\n\t\toverlay.style.background = `radial-gradient(circle at ${x}px ${y}px, ${gradientColor} 0%, rgba(0, 0, 0, 0) 70%)`;\n\t}, [restingBackground, gradientColor]);\n\n\treturn (\n\t\t<div\n\t\t\tclassName={cn(\n\t\t\t\t\"group relative flex size-full overflow-hidden rounded-xl border bg-neutral-100 text-black dark:bg-neutral-900 dark:text-white\",\n\t\t\t\tclassName\n\t\t\t)}\n\t\t\tonMouseMove={handleMouseMove}\n\t\t\tonMouseLeave={handleMouseLeave}\n\t\t>\n\t\t\t<div className={cn(\"relative z-10\", slotClass)}>{children}</div>\n\t\t\t<div\n\t\t\t\tref={overlayRef}\n\t\t\t\tclassName=\"pointer-events-none absolute inset-0 rounded-xl opacity-0 group-hover:opacity-100 motion-safe:transition-opacity motion-safe:duration-300\"\n\t\t\t\tstyle={{ background: restingBackground, opacity: gradientOpacity }}\n\t\t\t></div>\n\t\t</div>\n\t);\n}\n","type":"registry:ui","target":"@ui/fancy/components/card-spotlight/CardSpotlight.tsx"},{"path":"react/src/components/card-spotlight/index.ts","content":"\"use client\";\n\nexport { CardSpotlight } from \"./CardSpotlight\";\nexport type { CardSpotlightProps } from \"./CardSpotlight\";\n","type":"registry:ui","target":"@ui/fancy/components/card-spotlight/index.ts"}],"meta":{"license":"MIT","package":"fancy-ui-react","version":"0.7.0","source":"https://fancy-ui.rama.app/docs/components/card-spotlight?framework=react"}}