Files
pbakaus_impeccable/public/js/utils/theme.js
T
Paul BakausandClaude Opus 4.5 6b77213f91 Redesign hero, add theme toggle, fix dark mode
- Remove GPU-intensive shader from hero section
- Combine hero with problem section for immediate impact
- Add before/after demo directly in first viewport
- Move "works with" logos inline with CTA
- Remove redundant "Common AI defaults" tags

- Add three-way theme toggle (light/system/dark)
- Persist theme preference to localStorage
- Position toggle in bottom-right corner

- Fix dark mode throughout:
  - Update glass terminal and source window backgrounds
  - Add CSS custom properties for framework category colors
  - Muted dark backgrounds with brighter text for cards

- Replace smooth scroll with instant jump for anchor links
- Remove Lenis smooth scroll library dependency

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 14:37:46 -08:00

57 lines
1.5 KiB
JavaScript

// Theme toggle - supports light, dark, and system preference
const STORAGE_KEY = 'impeccable-theme';
function getStoredTheme() {
return localStorage.getItem(STORAGE_KEY);
}
function setStoredTheme(theme) {
localStorage.setItem(STORAGE_KEY, theme);
}
function applyTheme(theme) {
const html = document.documentElement;
// Remove both classes first
html.classList.remove('light', 'dark');
if (theme === 'light') {
html.classList.add('light');
} else if (theme === 'dark') {
html.classList.add('dark');
}
// 'system' = no class, falls back to media query
// Update active state on buttons
document.querySelectorAll('.theme-toggle-btn').forEach(btn => {
btn.classList.toggle('active', btn.dataset.theme === theme);
});
}
export function initThemeToggle() {
const toggle = document.querySelector('.theme-toggle');
if (!toggle) return;
// Get stored theme or default to system
const storedTheme = getStoredTheme() || 'system';
applyTheme(storedTheme);
// Handle button clicks
toggle.addEventListener('click', (e) => {
const btn = e.target.closest('.theme-toggle-btn');
if (!btn) return;
const theme = btn.dataset.theme;
setStoredTheme(theme);
applyTheme(theme);
});
// Listen for system preference changes (only matters when in 'system' mode)
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
if (getStoredTheme() === 'system' || !getStoredTheme()) {
applyTheme('system');
}
});
}