{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"spotlight-card","type":"registry:component","title":"Spotlight card","description":"The cursor is a lamp: cards catch its glow and their icons cast shadows away from it.","author":"Yash Bavadiya <https://xevrion.dev>","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"components/spotlight-card.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useRef } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\n// Paints only the 1px padding ring, so the gradient shows as a lit edge.\nconst RING_MASK =\n  \"linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)\";\n\n// Monochrome on purpose: a faint dark wash in light mode, faint white in dark.\n// The fill is wide and soft so it spills across the gaps between cards; the\n// edge is tighter so only the border nearest the cursor catches it.\nconst GLOW =\n  \"radial-gradient(260px circle at var(--x) var(--y), light-dark(oklch(0 0 0 / 0.035), oklch(1 0 0 / 0.06)), transparent 70%)\";\nconst EDGE =\n  \"radial-gradient(180px circle at var(--x) var(--y), light-dark(oklch(0 0 0 / 0.28), oklch(1 0 0 / 0.4)), transparent 70%)\";\n\n// Card-space point the shadows are cast from: the middle of the icon\n// (20px padding + half of the 20px icon).\nconst SHADOW_ORIGIN = 30;\n// Longest shadow in px, when the light sits right beside the icon, and the\n// distance at which it has shrunk to nothing.\nconst SHADOW_MAX = 6;\nconst SHADOW_FALLOFF = 420;\n// Soft and low contrast, like a desk lamp on paper, in both themes.\nconst SHADOW_COLOR = \"light-dark(oklch(0 0 0 / 0.22), oklch(0 0 0 / 0.9))\";\n// While lit the shadows track the cursor with no lag (they are the light);\n// when it leaves they ease back under their objects. Reduced motion keeps\n// the glow but drops the moving shadows.\nconst CAST =\n  \"transition-[filter] duration-300 ease-[cubic-bezier(0.23,1,0.32,1)] group-data-[lit]/grid:transition-none motion-reduce:[filter:none]\";\n\nexport type Feature = {\n  title: string;\n  text: string;\n  icon: React.ReactNode;\n};\n\nexport function SpotlightGrid({\n  features,\n  className,\n}: {\n  features: Feature[];\n  className?: string;\n}) {\n  const gridRef = useRef<HTMLDivElement>(null);\n  const cards = useRef<(HTMLElement | null)[]>([]);\n\n  // One listener for the whole grid. Each card gets the cursor in its own\n  // coordinates, so a card still glows at the edge nearest a cursor that is\n  // over its neighbour.\n  const track = (e: React.PointerEvent) => {\n    if (e.pointerType !== \"mouse\") return;\n    gridRef.current?.setAttribute(\"data-lit\", \"\");\n    for (const card of cards.current) {\n      if (!card) continue;\n      const box = card.getBoundingClientRect();\n      const x = e.clientX - box.left;\n      const y = e.clientY - box.top;\n      card.style.setProperty(\"--x\", `${x}px`);\n      card.style.setProperty(\"--y\", `${y}px`);\n      // The cursor is the light: each icon casts a shadow pointing away\n      // from it, shortening as the light moves off, so every card in the\n      // grid agrees on where the lamp is.\n      const dx = SHADOW_ORIGIN - x;\n      const dy = SHADOW_ORIGIN - y;\n      const dist = Math.hypot(dx, dy) || 1;\n      const reach = Math.max(0, 1 - dist / SHADOW_FALLOFF);\n      card.style.setProperty(\"--sx\", `${((dx / dist) * SHADOW_MAX * reach).toFixed(2)}px`);\n      card.style.setProperty(\"--sy\", `${((dy / dist) * SHADOW_MAX * reach).toFixed(2)}px`);\n    }\n  };\n\n  return (\n    <div\n      ref={gridRef}\n      className={cn(\n        \"group/grid grid w-[min(520px,100%)] gap-3 sm:grid-cols-2\",\n        className,\n      )}\n      onPointerMove={track}\n      onPointerLeave={() => {\n        gridRef.current?.removeAttribute(\"data-lit\");\n        for (const card of cards.current) {\n          card?.style.setProperty(\"--sx\", \"0px\");\n          card?.style.setProperty(\"--sy\", \"0px\");\n        }\n      }}\n    >\n      {features.map((feature, i) => (\n        <article\n          key={feature.title}\n          ref={(el) => {\n            cards.current[i] = el;\n          }}\n          className=\"relative overflow-hidden rounded-2xl bg-muted p-5 shadow-[inset_0_0_0_1px_var(--border)]\"\n        >\n          {/* Fades rather than snaps, so leaving the grid doesn't flash dark. */}\n          <div\n            aria-hidden\n            className=\"pointer-events-none absolute inset-0 opacity-0 transition-[opacity] duration-300 ease-[cubic-bezier(0.23,1,0.32,1)] group-data-[lit]/grid:opacity-100\"\n            style={{ background: GLOW }}\n          />\n          <div\n            aria-hidden\n            className=\"pointer-events-none absolute inset-0 rounded-[inherit] p-px opacity-0 transition-[opacity] duration-300 ease-[cubic-bezier(0.23,1,0.32,1)] group-data-[lit]/grid:opacity-100\"\n            style={{ background: EDGE, mask: RING_MASK }}\n          />\n          {/* Shadows follow the cursor with no transition while lit (they\n              are the light), and ease back under the object when it leaves. */}\n          <div\n            className=\"relative\"\n            style={{ \"--shadow\": SHADOW_COLOR } as React.CSSProperties}\n          >\n            <span\n              className={cn(\n                CAST,\n                \"block w-fit text-muted-foreground [filter:drop-shadow(var(--sx,0px)_var(--sy,0px)_2px_var(--shadow))]\",\n              )}\n            >\n              {feature.icon}\n            </span>\n            {/* Text stays flat and crisp: a shadow on it reads as ghosting. */}\n            <h3 className=\"mt-6 text-[15px] font-medium text-foreground\">\n              {feature.title}\n            </h3>\n            <p className=\"mt-1 text-sm text-pretty text-muted-foreground\">{feature.text}</p>\n          </div>\n        </article>\n      ))}\n    </div>\n  );\n}\n\nfunction Icon({ children }: { children: React.ReactNode }) {\n  return (\n    <svg\n      viewBox=\"0 0 20 20\"\n      className=\"size-5\"\n      fill=\"none\"\n      stroke=\"currentColor\"\n      strokeWidth={1.5}\n      strokeLinecap=\"round\"\n      strokeLinejoin=\"round\"\n      aria-hidden\n    >\n      {children}\n    </svg>\n  );\n}\n\nconst FEATURES: Feature[] = [\n  {\n    title: \"Instant sync\",\n    text: \"Edits land on every device before you switch tabs.\",\n    icon: (\n      <Icon>\n        <path d=\"M15.5 8a5.5 5.5 0 0 0-10-2.5M4.5 12a5.5 5.5 0 0 0 10 2.5M15.5 3.5V8H11M4.5 16.5V12H9\" />\n      </Icon>\n    ),\n  },\n  {\n    title: \"Works offline\",\n    text: \"Keep writing on a plane. Changes merge when you reconnect.\",\n    icon: (\n      <Icon>\n        <path d=\"M3 3l14 14M7.5 16h7a3 3 0 0 0 1.2-5.75M5.1 7.1A4.5 4.5 0 0 0 7.5 16M8.5 4.3A5 5 0 0 1 14.6 8\" />\n      </Icon>\n    ),\n  },\n  {\n    title: \"End-to-end encrypted\",\n    text: \"Only you and the people you invite can read your notes.\",\n    icon: (\n      <Icon>\n        <rect x=\"4\" y=\"9\" width=\"12\" height=\"8\" rx=\"2\" />\n        <path d=\"M7 9V6.5a3 3 0 0 1 6 0V9\" />\n      </Icon>\n    ),\n  },\n  {\n    title: \"Full history\",\n    text: \"Step back to any version, down to the keystroke.\",\n    icon: (\n      <Icon>\n        <path d=\"M3.5 10a6.5 6.5 0 1 0 1.9-4.6M3.5 3.5v2.9h2.9M10 6.5V10l2.5 1.5\" />\n      </Icon>\n    ),\n  },\n];\n\nexport default function SpotlightCardDemo() {\n  return <SpotlightGrid features={FEATURES} />;\n}\n"}],"categories":["cards"],"docs":"From ui lab: https://lab.xevrion.dev/lab/spotlight-card"}