LyricsDisplay component provides a synchronized lyrics display that automatically scrolls and highlights lyrics as the track plays. It includes special styling for specific artists and albums.
Features
- Synchronized Scrolling - Auto-scrolls to keep current line centered
- Time-based Highlighting - Highlights the current lyric line based on playback progress
- Custom Styling - Special styles for specific artists/albums (Charli XCX’s Brat, Taylor Swift’s Folklore, etc.)
- Keyboard Shortcuts - Toggle lyrics with ‘L’ key
- Smooth Animations - Transitions between lines with scale and opacity effects
- View Transitions - Uses native View Transitions API when available
Component API
LyricsDisplay.Lyrics
Main lyrics display component that consumes context automatically. No props required - UsesSpotifyContext and LyricsContext internally
LyricsDisplay.Button
Button component to toggle lyrics visibility. No props required - UsesSpotifyContext and LyricsContext internally
Legacy Props Interface (for reference)
Array of lyrics lines with timing information. Each line contains:
words: string- The lyric texttimeTag: string- Start time inMM:SS.msformat
Current playback progress in milliseconds
Indicates whether the track is currently playing
The current Spotify track object containing artist and album information
Usage
Basic Implementation
Complete Example with Context
Keyboard Shortcuts
- L - Toggle lyrics visibility
- Works when lyrics are available for the current track
Custom Styling
The component applies special styling for specific artists/albums viadata-style attribute:
Styling with CSS
Active Line Styling
The current line is highlighted with:How It Works
- Time Parsing - Converts
MM:SS.mstime tags to seconds - Line Matching - Finds current line based on playback progress
- Scroll Management - Distinguishes between user and programmatic scrolling
- Artist Detection - Checks artist names and album titles for custom styling
- Smooth Scrolling - Uses
scrollIntoViewwithbehavior: 'smooth' - State Persistence - Maintains scroll position during user interaction
User Interaction
The component implements smart scrolling behavior:- Auto-scroll - Follows current line during playback
- User scroll - Pauses auto-scroll when user manually scrolls
- Resume - Auto-scroll resumes 300ms after user stops scrolling
- Track change - Scrolls to top when track changes
Implementation Details
The component at/home/daytona/workspace/source/src/components/LyricsDisplay.tsx:14 uses React.memo for performance optimization and manages multiple refs for scroll behavior tracking.