DynamicBackground component analyzes the currently playing track’s album artwork and generates a dynamic gradient background that adapts to the dominant colors in the image.
Features
- Color Extraction - Uses ColorThief to extract dominant colors from album artwork
- Smooth Transitions - Animates between color palettes when tracks change
- CSS Variables - Sets global CSS variables for theming throughout the app
- Adaptive Text Color - Calculates optimal text color based on background brightness
- Multiple Variants - Includes standard and TEST variants with different effects
Installation
Component API
DynamicBackground
The URL of the album artwork image to extract colors from. Supports CORS-enabled images.
Indicates whether music is currently playing. Used to control animation states.
Usage
Advanced Usage
Using DynamicBackgroundTEST
The TEST variant includes additional visual effects with SVG filters and animated marquee elements:CSS Variables
The component sets these CSS variables that can be used throughout your app:--color- The dominant background color asrgb(r, g, b)--text-color- Calculated text color for optimal contrast asrgb(r, g, b)--color-0through--color-6- Individual palette colors for gradient stops
Using CSS Variables
How It Works
- Image Loading - Loads the album artwork with CORS enabled
- Color Extraction - Uses ColorThief to extract 4-color palette and dominant color
- Brightness Calculation - Calculates perceived brightness using luminance formula
- Text Color Adjustment - Lightens or darkens the dominant color for text contrast
- CSS Variable Updates - Sets CSS custom properties on document root
- Gradient Rendering - Renders radial gradients using extracted colors
- Transition Animation - Fades between color schemes with 1s ease-in-out
Helper Functions
getTextColor
RGB array
[r, g, b] representing the dominant background colorPerformance Considerations
- Component includes transition states to prevent jarring color changes
- Uses
requestAnimationFramein TEST variant for smooth updates - Fixed positioning with
z-index: -2ensures it stays behind content - Memoized TEST variant reduces unnecessary re-renders
Implementation Details
The component at/home/daytona/workspace/source/src/components/DynamicBackground.tsx:9 creates a fixed-position div with multiple radial gradients positioned at different points to create a dynamic, multi-colored background effect.