"use client"; import { useRef, ReactNode } from "react"; interface TiltCardProps { children: ReactNode; className?: string; tiltAmount?: number; glareOpacity?: number; glareColor?: string; } const TiltCard = ({ children, className = "", tiltAmount = 10, glareOpacity = 0.2, glareColor = "rgba(255, 255, 255, 0.4)", }: TiltCardProps) => { const cardRef = useRef(null); const handleMouseMove = (e: React.MouseEvent) => { const card = cardRef.current; if (!card) return; const rect = card.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; const centerX = rect.width / 2; const centerY = rect.height / 2; const rotateX = ((y - centerY) / centerY) * -tiltAmount; const rotateY = ((x - centerX) / centerX) * tiltAmount; const glareX = (x / rect.width) * 100; const glareY = (y / rect.height) * 100; card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`; card.style.setProperty("--glare-x", `${glareX}%`); card.style.setProperty("--glare-y", `${glareY}%`); }; const handleMouseLeave = () => { const card = cardRef.current; if (!card) return; card.style.transform = "perspective(1000px) rotateX(0deg) rotateY(0deg)"; }; return (
{children}
); }; export default TiltCard;