FoilCard — from pointer movement to element styles
FoilCard turns pointer movement into values that CSS can use to change a card's appearance. Its event handler measures the pointer's position within the card, converts that position into percentages and angles, and writes those values onto the element. The supplied component shows this path; its missing stylesheet means it does not establish the exact foil effect.
From an event to a position
React connects the element's onPointerMove event to the move function. Writing onPointerMove={move} registers that function; it does not call it immediately. The function runs when a pointer event occurs, so the order of the function definitions is not a timeline of interactions.
Inside the handler, event.currentTarget identifies the card. getBoundingClientRect() supplies its measured bounds, allowing the handler to express the pointer position relative to that rectangle:
const x = (event.clientX - rect.left) / rect.width;
const y = (event.clientY - rect.top) / rect.height;
Subtracting the left edge gives a horizontal distance within the rectangle. Dividing by its width expresses the same position as a ratio: halfway across is 0.5, and three quarters across is 0.75. A position inside those bounds gives a ratio between 0 and 1; the component does not clamp it.
From a position to an appearance input
The handler converts these ratios into percentages and rotation values, then writes four inline CSS properties: --x, --y, --rx and --ry. For example, at x = 0.75 with strength = 12, (x - 0.5) * strength produces a Y-axis rotation value of 3deg.
Pointer moves over the card
→ React calls move(event)
→ the handler measures the card and relative pointer position
→ ratios become percentages and rotation angles
→ setProperty() writes values onto the element
→ CSS using those properties can change its appearance
The property names connect JavaScript and CSS. JavaScript supplies changing values; the stylesheet determines how they affect the image. Without that stylesheet, the exact visual result and the author's performance rationale remain unverified.
This also shows why a function's return value does not describe everything it does. move() matters because it changes the element's styles. Its temporary x and y variables belong to one handler call, while the written properties remain on the element until removed or replaced. This implementation does not use React state for those values; that is an implementation choice, not a general rule for interactive components.
Resetting and the browser boundary
Pointer leave and pointer cancellation call reset(). It removes the four inline declarations; it does not explicitly set the rotation to zero. The resulting appearance depends on other CSS declarations and fallbacks. MDN: removing a style property
The component also begins with "use client". This is a React Server Components directive used by supporting frameworks, marking a client module boundary. It does not mean that a framework can never produce initial HTML for the component on the server. In Next.js, Client Components can contribute server-rendered initial HTML; the interactive handlers and DOM operations described here run in the browser. React directive, Next.js server and client components
The component came from the shared FoilCard example. It is a code-reading example, not a complete runnable demonstration because the imported stylesheet was not supplied.