Lightfield Surface
A small amount of physical light, not a glow.
Your preview settings
{
"intensity": 0.5,
"tilt": 3,
"highlight": 52,
"finish": "satin",
"disabled": false
}These are the exact settings driving this demo, including sample content and simulated states. For the installable component’s public API, see Usage and Props below.
Move across a card, then leave it. The surface should settle, not snap.
A real browser viewport. Scroll within the preview when the sample needs more space. Configuration stays in sync between sizes.
01What it does
A card that catches light from the pointer through a damped highlight and a heavily constrained tilt. The animation loop stops when the surface settles, and coarse pointers or reduced-motion users receive the static finish.
In this previewThree material studies on a dark showroom wall. The preview controls change intensity, tilt, highlight size and finish across all three; lighting can be switched off entirely. Selecting an object updates the sample viewing.
Design decisions
The pointer target is damped toward the current light at 18% per frame. That small lag is what makes the surface feel lit rather than cursor-attached.
The light lives above the content in screen blend mode, while the plane's tilt is clamped to six degrees. The result is depth and a specular shift, not a rotating card.
The loop compares the target and current values and cancels itself when settled. A page of twelve cards at rest runs nothing.
02Install
Registry install
Run this in a React project with components.json. The component and its stylesheet land in components/lab/lightfield-surface/.
npx shadcn@latest add https://lab.tanishk.me/r/lightfield-surface.jsonFiles included
2- components/lab/lightfield-surface/lightfield-surface.tsxcomponent
- components/lab/lightfield-surface/lightfield-surface.cssstyles
Manual install: copy each file into the same folder and preserve its relative imports. Open the source
03Usage
import { LightfieldSurface } from "@/components/lab/lightfield-surface/lightfield-surface";
export function ProductCard() {
return (
<LightfieldSurface intensity={0.55} tilt={3} highlight={50} finish="satin">
<article style={{ padding: 20 }}>
<img src="/objects/vessel.jpg" alt="Vessel 04 in matte stoneware" />
<h3>Vessel 04</h3>
</article>
</LightfieldSurface>
);
}04Props
| Prop | Type | Default | Notes |
|---|---|---|---|
children | ReactNode | — | The card surface content. |
intensity | number | 0.5 | Highlight strength from 0–1. |
tilt | number | 3 | Maximum tilt in degrees; clamped to 6. |
highlight | number | 52 | Highlight radius as a percentage of the surface. |
finish | "matte" | "satin" | "gloss" | "satin" | Surface response: diffuse, balanced or a sharper specular streak. |
focusable | boolean | false | Make the surface itself a tab stop with a visible focus ring. |
disabled | boolean | false | Stop pointer response and show the static finish. |
className | string | — | Forwarded to the root. |
style | CSSProperties | — | Merged with the lightfield custom properties. |
05Accessibility
- The light and tilt are decorative; all content remains fully readable and operable without them.
- A focusable surface has a visible focus ring and a static off-centre highlight; focus-within also lifts the light.
- Coarse pointers and prefers-reduced-motion receive a fixed light treatment with no tilt.
- The damping loop only runs while the pointer is moving or the surface is settling, then cancels itself.
- The disabled prop stops pointer response without changing layout or removing any content.
06Source
2 files, 320 lines. The combined copy is a reference; save each file separately for use.
components/lab/lightfield-surface/lightfield-surface.tsx— press enter to show or hide the source
"use client";
import {
useEffect,
useRef,
type CSSProperties,
type PointerEvent as ReactPointerEvent,
type ReactNode,
} from "react";
import "./lightfield-surface.css";
export type LightfieldSurfaceProps = {
children: ReactNode;
/** Overall highlight strength, 0–1. */
intensity?: number;
/** Maximum tilt in degrees. Keep this small. */
tilt?: number;
/** Highlight radius as a percentage of the surface. */
highlight?: number;
finish?: "matte" | "satin" | "gloss";
/** Make the surface itself a tab stop with a visible focus treatment. */
focusable?: boolean;
/** Stop responding to the pointer without changing the layout. */
disabled?: boolean;
className?: string;
style?: CSSProperties;
};
function reducedMotion() {
return (
typeof window !== "undefined" &&
window.matchMedia?.("(prefers-reduced-motion: reduce)").matches
);
}
/**
* LIGHTFIELD SURFACE
*
* A card that catches light. Pointer movement updates a damped target
* at most once per frame; the loop stops as soon as the surface has
* settled, so a page of cards at rest runs nothing. Coarse pointers and
* reduced-motion users get the static finish. The tilt is clamped and
* intentionally small: depth, not a funhouse mirror.
*/
export function LightfieldSurface({
children,
intensity = 0.5,
tilt = 3,
highlight = 52,
finish = "satin",
focusable = false,
disabled = false,
className,
style,
}: LightfieldSurfaceProps) {
const rootRef = useRef<HTMLDivElement>(null);
const target = useRef({ x: 50, y: 22, rx: 0, ry: 0 });
const current = useRef({ x: 50, y: 22, rx: 0, ry: 0 });
const frame = useRef<number | null>(null);
const fine = useRef(true);
useEffect(() => {
const query = window.matchMedia?.("(pointer: fine)");
fine.current = query ? query.matches : true;
const update = () => {
fine.current = query ? query.matches : true;
};
query?.addEventListener?.("change", update);
return () => query?.removeEventListener?.("change", update);
}, []);
const paint = () => {
const node = rootRef.current;
if (!node) return;
node.style.setProperty("--lf-x", `${current.current.x}%`);
node.style.setProperty("--lf-y", `${current.current.y}%`);
node.style.setProperty("--lf-rx", `${current.current.rx}deg`);
node.style.setProperty("--lf-ry", `${current.current.ry}deg`);
};
const stop = () => {
if (frame.current !== null) {
window.cancelAnimationFrame(frame.current);
frame.current = null;
}
};
const run = () => {
if (frame.current !== null) return;
const tick = () => {
frame.current = null;
const t = target.current;
const c = current.current;
const ease = 0.18;
c.x += (t.x - c.x) * ease;
c.y += (t.y - c.y) * ease;
c.rx += (t.rx - c.rx) * ease;
c.ry += (t.ry - c.ry) * ease;
paint();
const settled =
Math.abs(t.x - c.x) < 0.05 &&
Math.abs(t.y - c.y) < 0.05 &&
Math.abs(t.rx - c.rx) < 0.01 &&
Math.abs(t.ry - c.ry) < 0.01;
if (settled) {
c.x = t.x;
c.y = t.y;
c.rx = t.rx;
c.ry = t.ry;
paint();
return;
}
frame.current = window.requestAnimationFrame(tick);
};
frame.current = window.requestAnimationFrame(tick);
};
useEffect(() => stop, []);
const move = (event: ReactPointerEvent<HTMLDivElement>) => {
if (
disabled ||
event.pointerType === "touch" ||
!fine.current ||
reducedMotion()
)
return;
const node = rootRef.current;
if (!node) return;
const rect = node.getBoundingClientRect();
if (!rect.width || !rect.height) return;
const px = (event.clientX - rect.left) / rect.width;
const py = (event.clientY - rect.top) / rect.height;
target.current = {
x: px * 100,
y: py * 100,
rx: (0.5 - py) * tilt * 2,
ry: (px - 0.5) * tilt * 2,
};
run();
};
const leave = () => {
target.current = { x: 50, y: 16, rx: 0, ry: 0 };
if (fine.current && !reducedMotion()) run();
};
const onFocus = () => {
if (disabled || !fine.current) return;
target.current = { x: 30, y: 10, rx: 0, ry: 0 };
if (!reducedMotion()) run();
};
const onBlur = () => {
if (disabled) return;
target.current = { x: 50, y: 16, rx: 0, ry: 0 };
if (!reducedMotion()) run();
};
const inline = {
...style,
"--lf-intensity": Math.max(0, Math.min(1, intensity)),
"--lf-tilt": `${Math.max(0, Math.min(6, tilt))}deg`,
"--lf-size": `${Math.max(16, Math.min(100, highlight))}%`,
} as CSSProperties;
return (
<div
ref={rootRef}
className={`lf-root${className ? ` ${className}` : ""}`}
data-finish={finish}
data-disabled={disabled ? "true" : "false"}
data-focusable={focusable ? "true" : "false"}
style={inline}
tabIndex={focusable ? 0 : undefined}
onPointerMove={move}
onPointerLeave={leave}
onFocus={onFocus}
onBlur={onBlur}
>
<div className="lf-plane">{children}</div>
<span className="lf-light" aria-hidden="true" />
<span className="lf-edge" aria-hidden="true" />
</div>
);
}components/lab/lightfield-surface/lightfield-surface.css— press enter to show or hide the source
.lf-root {
--lf-x: 50%;
--lf-y: 22%;
--lf-rx: 0deg;
--lf-ry: 0deg;
--lf-intensity: 0.5;
--lf-tilt: 3deg;
--lf-size: 52%;
--lf-focus: #d9b98a;
position: relative;
min-width: 0;
border-radius: 14px;
perspective: 900px;
isolation: isolate;
font: inherit;
transform-style: preserve-3d;
}
.lf-plane {
position: relative;
z-index: 1;
height: 100%;
overflow: hidden;
border-radius: inherit;
transform: rotateX(var(--lf-rx)) rotateY(var(--lf-ry));
transform-style: preserve-3d;
will-change: transform;
}
.lf-light {
position: absolute;
inset: 0;
z-index: 2;
border-radius: inherit;
pointer-events: none;
background: radial-gradient(
circle at var(--lf-x) var(--lf-y),
rgba(255, 250, 236, calc(var(--lf-intensity) * 0.42)),
rgba(255, 250, 236, calc(var(--lf-intensity) * 0.12)) 32%,
transparent var(--lf-size)
);
mix-blend-mode: screen;
opacity: 1;
transition: opacity 260ms ease;
}
.lf-root[data-finish="matte"] .lf-light {
background: radial-gradient(
circle at var(--lf-x) var(--lf-y),
rgba(255, 250, 236, calc(var(--lf-intensity) * 0.16)),
transparent var(--lf-size)
);
}
.lf-root[data-finish="gloss"] .lf-light {
background:
radial-gradient(
circle at var(--lf-x) var(--lf-y),
rgba(255, 253, 246, calc(var(--lf-intensity) * 0.62)),
rgba(255, 253, 246, calc(var(--lf-intensity) * 0.16)) 18%,
transparent var(--lf-size)
),
linear-gradient(
118deg,
transparent 28%,
rgba(255, 255, 255, calc(var(--lf-intensity) * 0.08)) 44%,
transparent 58%
);
}
.lf-edge {
position: absolute;
inset: 0;
z-index: 3;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: inherit;
pointer-events: none;
background: linear-gradient(
145deg,
rgba(255, 255, 255, calc(var(--lf-intensity) * 0.14)),
transparent 30%
);
mask: linear-gradient(#000, #000) content-box, linear-gradient(#000, #000);
mask-composite: exclude;
padding: 1px;
}
.lf-root:focus-visible {
outline: 2px solid var(--lf-focus);
outline-offset: 3px;
}
.lf-root:focus-within .lf-light {
opacity: 1;
}
.lf-root[data-disabled="true"] .lf-light {
opacity: 0.35;
}
.lf-root[data-disabled="true"] .lf-plane {
transform: none;
}
@media (hover: none), (prefers-reduced-motion: reduce) {
.lf-plane {
transform: none;
}
.lf-light {
background: radial-gradient(
circle at 50% 16%,
rgba(255, 250, 236, calc(var(--lf-intensity) * 0.3)),
transparent var(--lf-size)
);
}
.lf-root[data-finish="gloss"] .lf-light {
background:
radial-gradient(
circle at 50% 16%,
rgba(255, 253, 246, calc(var(--lf-intensity) * 0.5)),
transparent var(--lf-size)
),
linear-gradient(
118deg,
transparent 28%,
rgba(255, 255, 255, calc(var(--lf-intensity) * 0.06)) 44%,
transparent 58%
);
}
}