Added a dark/light theme toggle feature to the Course Materials Assistant application. Users can now switch between dark and light themes with a smooth transition animation.
Changes:
- Added theme toggle button with sun and moon SVG icons
- Button positioned at the top-right of the page
- Includes proper ARIA labels for accessibility
- Button is keyboard-navigable
Location: Lines 13-29
Changes:
- Added
[data-theme="light"]selector with light theme color variables:- Background:
#f8fafc(light gray) - Surface:
#ffffff(white) - Text primary:
#0f172a(dark) - Text secondary:
#475569(medium gray) - Border color:
#e2e8f0(light gray) - Assistant message background:
#f1f5f9(very light gray)
- Background:
- Added transition properties to all elements for smooth theme switching
- Transitions apply to:
background-color,color,border-color,box-shadow - Transition duration: 0.3s with ease timing
- Fixed position in top-right corner (1.5rem from top and right)
- Circular button (48px diameter)
- Hover effects: scale up, border color change
- Focus states for accessibility
- Icon rotation animation on hover
- Conditional icon display based on theme (sun for light, moon for dark)
Changes:
-
initializeTheme(): Initializes theme on page load- Checks localStorage for saved preference
- Falls back to system preference (
prefers-color-scheme) - Defaults to dark theme if no preference found
-
toggleTheme(): Switches between light and dark themes -
setTheme(theme): Sets the theme by updatingdata-themeattribute- Saves preference to localStorage for persistence
- Added click listener for theme toggle button
- Added keyboard navigation (Enter/Space keys)
- Theme preference persists across sessions
- Added
themeToggleto global DOM elements
- Icon-based design with sun (light mode) and moon (dark mode) icons
- Positioned in top-right corner (fixed position)
- Smooth rotation animation on hover
- Accessible and keyboard-navigable (Tab, Enter, Space)
- Visual feedback on hover, focus, and active states
- Light background colors for improved readability in bright environments
- Dark text for good contrast (WCAG AA compliant)
- Adjusted border and surface colors
- Maintains visual hierarchy and design language
- Click to toggle between themes
- Keyboard support (Enter and Space keys)
- Smooth 0.3s transitions for all color changes
- Theme preference saved to localStorage
- Respects system theme preference on first visit
- Uses CSS custom properties (CSS variables) for theme switching
data-theme="light"attribute on<html>element for light theme- Dark theme is default (no attribute needed)
- All existing elements work well in both themes
- Maintains current visual hierarchy and design language
To test the theme toggle:
- Open the application in a browser
- Click the theme toggle button in the top-right corner
- Verify smooth transition between dark and light themes
- Test keyboard navigation (Tab to button, Enter/Space to toggle)
- Refresh the page - theme preference should persist
- Check that all UI elements are visible and readable in both themes
- Proper ARIA labels (
aria-label="Toggle theme") - Keyboard navigation support
- Focus indicators for keyboard users
- Good color contrast in both themes
- Smooth transitions don't trigger motion sickness (0.3s is within acceptable range)
- Works in all modern browsers (Chrome, Firefox, Safari, Edge)
- CSS custom properties are widely supported
- localStorage is universally available
- SVG icons are supported in all modern browsers