From d531a9bd6acf0539a4f7f1acd0ee05d6f36e2b55 Mon Sep 17 00:00:00 2001 From: Gavin McDonald Date: Wed, 2 Jul 2025 12:01:31 -0400 Subject: [PATCH] cards that shine --- components/TiltCard.tsx | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/components/TiltCard.tsx b/components/TiltCard.tsx index fd190ca..34e0c9a 100644 --- a/components/TiltCard.tsx +++ b/components/TiltCard.tsx @@ -4,6 +4,24 @@ import type { Tilt } from '@/types'; const ZERO_ROTATION = 'rotateX(0deg) rotateY(0deg)'; +const tiltSheen = (sheen: HTMLDivElement, tiltX: number, tiltY: number) => { + const rect = sheen.getBoundingClientRect(); + const centerX = rect.width / 2; + const centerY = rect.height / 2; + const sheenX = centerX + (tiltY / -20) * centerX; + const sheenY = centerY + (tiltX / 20) * centerY; + + sheen.style.opacity = '1'; + sheen.style.backgroundImage = ` + radial-gradient( + circle at + ${sheenX}px ${sheenY}px, + #ffffff44, + #0000000f + ) + `; +}; + export default function TiltCard({ children, cardIndex, @@ -14,6 +32,7 @@ export default function TiltCard({ className?: string; }) { const cardRef = useRef(null); + const sheenRef = useRef(null); const [untilt, setUntilt] = useState(false); const { gameData, @@ -24,7 +43,8 @@ export default function TiltCard({ useEffect(() => { const card = cardRef.current; - if (!card) return; + const sheen = sheenRef.current; + if (!card || !sheen) return; if (tilt) { const rotateX = localTilts[cardIndex]?.rotateX || 0; @@ -47,7 +67,12 @@ export default function TiltCard({ if (count && (totalX || totalY)) { setUntilt(false); - card.style.transform = `rotateX(${totalX / count}deg) rotateY(${totalY / count}deg)`; + + const x = totalX / count; + const y = totalY / count; + + card.style.transform = `rotateX(${x}deg) rotateY(${y}deg)`; + tiltSheen(sheen, x, y); } else { setUntilt(true); } @@ -58,9 +83,11 @@ export default function TiltCard({ useEffect(() => { const card = cardRef.current; - if (!card || !untilt) return; + const sheen = sheenRef.current; + if (!card || !sheen || !untilt) return; card.style.transform = ZERO_ROTATION; + sheen.style.opacity = '0'; }, [untilt]); const handleMouseMove = (e: React.MouseEvent) => { @@ -88,7 +115,7 @@ export default function TiltCard({ return (
@@ -98,6 +125,10 @@ export default function TiltCard({ className={`h-full w-full transition-transform ${untilt ? 'duration-500' : 'duration-0'}`} > {children} +
);