Overview
Beams Background is a canvas-based animated background component that creates flowing beams of light with customizable intensity. The beams feature smooth animations, pulsing effects, and automatically adapt to dark/light mode.Installation
- Tab Title
- Tab Title
Props
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes for the container |
children | React.ReactNode | Default hero content | Custom content to display over the background |
intensity | "subtle" | "medium" | "strong" | "strong" | Controls the opacity and visibility of the beams |
Usage
Basic Usage
Custom Content
Different Intensities
Features
- Canvas Animation: Smooth 60fps canvas-based rendering for optimal performance
- Dark Mode Support: Automatically adjusts colors based on dark/light theme
- Responsive: Adapts to window resizing with proper device pixel ratio handling
- Pulsing Effect: Beams pulse and shimmer for a more organic feel
- Customizable Intensity: Three intensity levels to match your design needs
- Blur Effects: Multiple blur layers create depth and atmosphere
- Color Gradient: HSL-based color system with blue/cyan tones
How It Works
The component uses the HTML Canvas API to render animated beams:- Beam Generation: Creates multiple beams with random properties (position, width, speed, hue)
- Animation Loop: Uses
requestAnimationFramefor smooth 60fps animations - Gradient Drawing: Each beam is rendered with a linear gradient for smooth edges
- Pulsing: Sine wave functions create organic pulsing effects
- Dark Mode Detection: Observes DOM changes to adapt colors automatically
Dependencies
motion(Framer Motion) - For overlay animationsreact- Core React hooks (useEffect, useRef)cnutility - For className merging (from shadcn/ui)
Accessibility
- The canvas element is decorative and does not require ARIA labels
- Content placed inside the component should be properly structured with semantic HTML
- Ensure sufficient color contrast for text placed over the background
Performance Notes
- Uses
devicePixelRatiofor sharp rendering on high-DPI displays - Implements proper cleanup of animation frames and event listeners
- Canvas is positioned absolutely to avoid layout reflows
- Blur effects are applied via CSS
filterproperty for GPU acceleration
Browser Support
Works in all modern browsers that support:- HTML Canvas 2D Context
- CSS backdrop-filter
- requestAnimationFrame
- ES6+ JavaScript features