Spotlight Card
Card with a soft radial highlight that follows the pointer inside its bounds and fades out on leave. The highlight size and colour are CSS variables that default to the primary token.
How it differs. A single card lit by one radial layer positioned through custom properties set on pointer move, with content above the layer and no layer on touch.
Install
pnpm dlx shadcn@latest add @hazine/spotlight-cardAdds 1 file.
First time? Add the registry to components.json
{
"registries": {
"@hazine": "https://api.hazine.dev/r/{name}.json"
}
}Needed once per project. Items resolve each other through the @hazine namespace.
components/hazine/spotlight-card.tsx, 51 lines
"use client"
import * as React from "react"
import { cn } from "@/lib/utils"
// Geometry and colour come from custom properties, so a consumer can set
// --spotlight-size and --spotlight-color in CSS. The colour defaults to primary.
const SPOTLIGHT_BACKGROUND =
"radial-gradient(var(--spotlight-size, 20rem) circle at var(--spotlight-x, 50%) var(--spotlight-y, 50%), var(--spotlight-color, var(--primary)), transparent 70%)"
/**
* A div. The highlight reads --spotlight-size and --spotlight-color from CSS and is
* absent on touch pointers and under reduced motion.
*/
export type SpotlightCardProps = React.ComponentProps<"div">
export function SpotlightCard({
className,
children,
onPointerMove,
...props
}: SpotlightCardProps) {
function handlePointerMove(event: React.PointerEvent<HTMLDivElement>) {
onPointerMove?.(event)
const node = event.currentTarget
const bounds = node.getBoundingClientRect()
node.style.setProperty("--spotlight-x", `${event.clientX - bounds.x}px`)
node.style.setProperty("--spotlight-y", `${event.clientY - bounds.y}px`)
}
return (
<div
data-slot="spotlight-card"
className={cn(
"group relative overflow-hidden rounded-xl border border-border bg-card p-6 text-card-foreground",
className
)}
onPointerMove={handlePointerMove}
{...props}
>
<div
aria-hidden="true"
data-slot="spotlight-card-highlight"
className="pointer-events-none absolute inset-0 opacity-0 transition-opacity duration-300 group-hover:opacity-10 motion-reduce:hidden pointer-coarse:hidden"
style={{ background: SPOTLIGHT_BACKGROUND }}
/>
<div className="relative">{children}</div>
</div>
)
}
The demo in the preview, 13 lines
import { SpotlightCard } from "@/components/hazine/spotlight-card"
export default function SpotlightCardDemo() {
return (
<SpotlightCard>
<p className="text-sm font-semibold">Recurring invoices</p>
<p className="mt-1 max-w-[40ch] text-sm text-muted-foreground">
Set a schedule once. Tallyroom drafts, sends and reconciles each invoice
on the day it is due.
</p>
</SpotlightCard>
)
}
Props0
Accepts every prop of React.ComponentProps<"div">.
Accessibility
- Pattern
- Landmarks and headings
- Keyboard
- Nothing to operate. The item has no focusable parts.
- Screen reader
A plain container. The highlight layer is decorative, hidden from assistive technology and ignores pointer events.
- Reduced motion
- The highlight layer is not rendered.
- Checked
- Not checked yet. Automated results appear here once CI has run.
Dependencies0
None. The item is one self-contained file.
Tokens shipped0
None. The item is styled by the tokens your theme already has.