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 |
|---|---|---|---|---|
|
| Yes | Additional CSS classes to apply to the outermost div. | |
|
| Yes |
| Controls the opacity of the spotlight's radial gradient color; expected range is 0 to 1. (Note: typo in prop name) |
|
| Yes |
| Percentage radius of the radial gradient coverage; expected range 0 to 100. |
Note: The prop
opcityappears to have a typographical error and likely should beopacity. The component usesopcityas 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
className(optional): Additional CSS classes for outer container styling.opcity(optional, default = 0.5): Opacity for the radial gradient's colored center.coverage(optional, default = 60): Percentage indicating how far the radial gradient spreads from the center.
Returns
A JSX element consisting of two nested <div> elements:
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.
Inner div:
Also absolutely fills the parent container.
Applies a
radial-gradientbackground 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
coverageradius.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
Theme Awareness:
The component uses theuseIsDarkThemehook from the theme provider to determine if the app is in dark mode. It then switches the spotlight color accordingly:Dark theme: white glow (
rgb(255, 255, 255))Light theme: soft blue glow (
rgb(194, 221, 243))
Backdrop Blur:
The use of CSSbackdropFilter: blur(30px)creates a distinctive frosted glass effect behind the spotlight overlay, enhancing the visual depth.Radial Gradient Positioning:
The radial gradient is positioned at50% 190%, meaning horizontally centered but vertically below the visible container area. This positioning likely creates a subtle, bottom-focused glow that softly spreads upward.Z-index Handling:
The outer div haszIndex: -1to ensure the spotlight is rendered beneath other UI elements while still visible.Typographical Error in Prop (
opcity):
The prop is namedopcityinstead ofopacity. This should be corrected to avoid confusion and potential bugs.
Interaction with Other System Parts
Theme Provider:
The component depends onuseIsDarkThemefrom the theme provider module to adapt its color scheme. This establishes a link to the application's global theme management system.Parent Containers:
The component is designed to be used within relatively positioned parent containers to ensure its absolute positioning aligns correctly.Styling Framework:
It uses Tailwind CSS utility classes for styling (absolute,inset-0,rounded-lg, etc.), so it assumes Tailwind CSS is part of the project's styling stack.
Mermaid Component Diagram
componentDiagram
component Spotlight {
+className?: string
+opcity?: number
+coverage?: number
+render(): JSX.Element
}
component useIsDarkTheme
Spotlight ..> useIsDarkTheme : "uses for theme detection"
Summary
File:
spotlight.tsxPurpose: Provides a theme-aware spotlight overlay component for UI highlighting.
Key Features:
Theme-dependent glow color
Customizable opacity and coverage
Backdrop blur for frosted glass effect
Non-interfering with pointer events
Dependencies: React, theme provider hook, Tailwind CSS classes
Usage Context: Enhancing UI visuals by adding soft glowing highlights behind elements.
End of documentation for spotlight.tsx.