Componentdata1.27 KB gzipZero dependencies

Spotlight

Full-viewport dim overlay with cutout hole positioned via target ref/bounding box; pulse ring around target; caption card.

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add spotlight

Or install the full npm package:

npm install bigbullui

Usage

tsx4 lines
import { Spotlight } from "@/components/ui/spotlight" const ref = React.useRef<HTMLDivElement>(null);<Spotlight targetRef={ref} padding={24} title="Feature" description="Highlighted area" />

Source code

spotlight.tsx + 2 helpers

Zero third-party dependencies (3 local files shown in tabs below).

tsxspotlight.tsx141 lines
"use client"; import * as React from "react";import { getFocusable, lockBodyScroll, registerEscapeLayer, trapFocus } from "./lib/focus-trap";import { cn } from "./lib/utils"; export type SpotlightProps = {  targetRef: React.RefObject<HTMLElement | null>;  padding?: number;  title?: string;  description?: string;} & Omit<React.HTMLAttributes<HTMLElement>, "title">; export function Spotlight({ targetRef, padding = 24, title, description, ...props }: SpotlightProps) {  const [visible, setVisible] = React.useState(false);  const [targetBox, setTargetBox] = React.useState({ left: 0, top: 0, width: 0, height: 0 });  const overlayRef = React.useRef<HTMLDivElement>(null);  const restoreRef = React.useRef<HTMLElement | null>(null);

Props

Interactive Prop Playground

Tweak parsed AST props below to generate ready-to-paste JSX.

tsx3 lines
import { Spotlight } from "@/components/ui/spotlight"; <Spotlight />
PropTypeDescription
targetRefReact.RefObject<HTMLElement | null>Ref to the element to highlight.
paddingnumberPadding around the highlighted element.
titlestringOptional title text in the caption card.
descriptionstringOptional description text in the caption card.