spotlight.tsx


Overview

spotlight.tsx defines a React functional component named Spotlight that renders a visual "spotlight" effect overlay. This effect creates a softly blurred, radial gradient glow that can be used as a UI enhancement to highlight or accentuate areas of an interface. The component dynamically adapts its color based on the current theme (dark or light) by leveraging the useIsDarkTheme hook.

The main purpose of this file is to provide a reusable, theme-aware spotlight overlay that can be positioned absolutely within a container and customized via opacity and coverage parameters.


Detailed Explanation

Interface: SpotlightProps

Defines the props accepted by the Spotlight component.

Property

Type

Optional

Default

Description

className

string

Yes

undefined

Additional CSS classes to apply to the outermost div.

opcity

number

Yes

0.5

Controls the opacity of the spotlight's radial gradient color; expected range is 0 to 1. (Note: typo in prop name)

coverage

number

Yes

60

Percentage radius of the radial gradient coverage; expected range 0 to 100.

Note: The prop opcity appears to have a typographical error and likely should be opacity. The component uses opcity as is.


Component: Spotlight

const Spotlight: React.FC<SpotlightProps>

Purpose

Renders an absolute-positioned, blurred radial spotlight overlay that adjusts its base color depending on the user's theme (dark or light). The overlay is designed to be placed behind other content (zIndex: -1) and to be visually subtle yet noticeable.

Parameters

Returns

A JSX element consisting of two nested <div> elements:

  1. Outer div:

    • Positioned absolutely, inset to fill its relative container (inset-0).

    • Applies rounded corners (rounded-lg), opacity, and any extra classes.

    • Applies a strong blur effect (backdropFilter: blur(30px)).

    • Positioned behind other content with zIndex: -1.

  2. Inner div:

    • Also absolutely fills the parent container.

    • Applies a radial-gradient background centered slightly below the middle (circle at 50% 190%).

    • The gradient transitions from a semi-transparent color (white or light blue depending on theme) at the center to fully transparent at the coverage radius.

    • pointerEvents: 'none' ensures the spotlight does not interfere with mouse interactions.

Usage Example

import Spotlight from './spotlight';

function MyComponent() {
  return (
    <div className="relative h-64 w-64">
      <Spotlight opcity={0.7} coverage={70} className="custom-spotlight" />
      {/* Other content here */}
    </div>
  );
}

In this example, the Spotlight component creates a slightly more opaque and broader glow effect inside a container with relative positioning.


Important Implementation Details


Interaction with Other System Parts


Mermaid Component Diagram

componentDiagram
    component Spotlight {
        +className?: string
        +opcity?: number
        +coverage?: number
        +render(): JSX.Element
    }
    component useIsDarkTheme
    Spotlight ..> useIsDarkTheme : "uses for theme detection"

Summary


End of documentation for spotlight.tsx.