Skip to content

Commit 7b9c9cf

Browse files
committed
feat: Add CursorSpotlight UI component for a cursor-following visual effect.
1 parent 8062308 commit 7b9c9cf

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

frontend/components/ui/CursorSpotlight.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import { useEffect, useRef, useState } from "react";
44

55
export default function CursorSpotlight() {
66
const divRef = useRef<HTMLDivElement>(null);
7-
const [position, setPosition] = useState({ x: 0, y: 0 });
7+
const spotlightRef = useRef<HTMLDivElement>(null);
88
const [opacity, setOpacity] = useState(0);
99

1010
useEffect(() => {
1111
const handleMouseMove = (e: MouseEvent) => {
12-
if (!divRef.current) return;
13-
const div = divRef.current;
14-
const rect = div.getBoundingClientRect();
15-
setPosition({ x: e.clientX - rect.left, y: e.clientY - rect.top });
12+
if (!spotlightRef.current) return;
13+
14+
const x = e.clientX;
15+
const y = e.clientY;
16+
17+
spotlightRef.current.style.background = `radial-gradient(600px circle at ${x}px ${y}px, rgba(255,255,255,0.06), transparent 40%)`;
1618
setOpacity(1);
1719
};
1820

@@ -36,9 +38,9 @@ export default function CursorSpotlight() {
3638
style={{ opacity }}
3739
>
3840
<div
39-
className="absolute -inset-px bg-gradient-to-r from-white/10 to-transparent opacity-0 transition-opacity duration-300"
41+
ref={spotlightRef}
42+
className="absolute -inset-px bg-gradient-to-r from-white/10 to-transparent transition-opacity duration-300"
4043
style={{
41-
background: `radial-gradient(600px circle at ${position.x}px ${position.y}px, rgba(255,255,255,0.06), transparent 40%)`,
4244
opacity: 1,
4345
}}
4446
/>

0 commit comments

Comments
 (0)