0

Component

Spotlight card

A card whose edge and surface light up under the cursor.

One chat

Every model in one room.

One bill

One subscription, not five.

One memory

It remembers what you were doing.

Usage

<SpotlightCard color="#7c5cff">
  <h3>One chat</h3>
  <p>Every model in one room.</p>
</SpotlightCard>

Source

Copy both files into your project. The component has no dependencies beyond React.

"use client";

import { useRef, type CSSProperties, type PointerEvent, type ReactNode } from "react";
import styles from "./spotlight-card.module.css";

type SpotlightCardProps = {
  children: ReactNode;
  /** The colour of the light. */
  color?: string;
  className?: string;
};

export function SpotlightCard({ children, color = "#7c5cff", className }: SpotlightCardProps) {
  const ref = useRef<HTMLDivElement>(null);

  function follow(event: PointerEvent<HTMLDivElement>) {
    const node = ref.current;
    if (!node) return;
    const rect = node.getBoundingClientRect();
    node.style.setProperty("--x", `${event.clientX - rect.left}px`);
    node.style.setProperty("--y", `${event.clientY - rect.top}px`);
  }

  return (
    <div
      ref={ref}
      className={[styles.card, className].filter(Boolean).join(" ")}
      style={{ "--spot": color } as CSSProperties}
      onPointerMove={follow}
    >
      <div className={styles.content}>{children}</div>
    </div>
  );
}