Spotlight Card
A dark elevated surface that illuminates border and inner surfaces dynamically based on mouse pointer coordinates.
Live preview from the library's source
Install
From EasyUI
npx shadcn@latest add Surajmaurya1/easyui/spotlight-cardFrom this collection
npx shadcn@latest add https://allcomps.vercel.app/r/easyui--spotlight-card.jsonCode
'use client';
import React, { useRef } from 'react';
import { motion, useMotionTemplate, useMotionValue } from 'framer-motion';
import { cn } from '../../lib/utils';
export interface SpotlightCardProps extends React.HTMLAttributes<HTMLDivElement> {
children: React.ReactNode;
spotlightColor?: string;
spotlightSize?: number;
className?: string;
}
export const SpotlightCard: React.FC<SpotlightCardProps> = ({
children,
spotlightColor = 'rgba(56, 189, 248, 0.08)',
spotlightSize = 350,
className,
...props
}) => {
const mouseX = useMotionValue(-1000);
const mouseY = useMotionValue(-1000);
const cardRef = useRef<HTMLDivElement>(null);
const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
if (!cardRef.current) return;
const { left, top } = cardRef.current.getBoundingClientRect();
mouseX.set(e.clientX - left);
mouseY.set(e.clientY - top);
};
const backgroundGradient = useMotionTemplate`radial-gradient(${spotlightSize}px circle at ${mouseX}px ${mouseY}px, ${spotlightColor}, transparent 80%)`;
const borderGradient = useMotionTemplate`radial-gradient(220px circle at ${mouseX}px ${mouseY}px, rgba(255, 255, 255, 0.18), transparent 80%)`;
return (
<div
ref={cardRef}
onMouseMove={handleMouseMove}
onMouseLeave={() => {
mouseX.set(-1000);
mouseY.set(-1000);
}}
className={cn(
'group relative rounded-xl border border-[#1F1F1F] bg-[#0E0E0E] p-6 transition-colors duration-300 hover:border-[#4A4A4A] overflow-hidden',
className
)}
{...props}
>
{/* Animated subtle dynamic border spotlight */}
<motion.div
className="pointer-events-none absolute -inset-px rounded-[inherit] opacity-0 transition-opacity duration-300 group-hover:opacity-100"
style={{
background: borderGradient,
}}
/>
{/* Internal ambient radial glow */}
<motion.div
className="pointer-events-none absolute inset-0 opacity-0 transition-opacity duration-300 group-hover:opacity-100"
style={{
background: backgroundGradient,
}}
/>
{/* Content */}
<div className="relative z-10">{children}</div>
</div>
);
};
Other cards
The same kind of component from the other libraries in the collection.