feat: agregar selector de tema oscuro/claro
Toggle sol/luna en el navbar que permite cambiar entre tema oscuro (por defecto) y tema claro. Preferencia guardada en localStorage. Incluye overrides de CSS para todos los componentes con colores hardcodeados, inversión de logo, y transición suave entre temas. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -177,4 +177,39 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
}
|
||||
});
|
||||
|
||||
// ================================================================
|
||||
// 7. Dark / Light Theme Toggle
|
||||
// ================================================================
|
||||
var themeToggle = document.getElementById('themeToggle');
|
||||
var themeIcon = document.getElementById('themeIcon');
|
||||
|
||||
function setTheme(theme) {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
localStorage.setItem('theme', theme);
|
||||
if (themeIcon) {
|
||||
themeIcon.className = theme === 'light' ? 'fas fa-sun' : 'fas fa-moon';
|
||||
}
|
||||
// Update theme-color meta tag
|
||||
var metaTheme = document.querySelector('meta[name="theme-color"]');
|
||||
if (metaTheme) {
|
||||
metaTheme.setAttribute('content', theme === 'light' ? '#f5f5f5' : '#0a0a0a');
|
||||
}
|
||||
}
|
||||
|
||||
// Determine initial theme: localStorage > system preference > dark
|
||||
var savedTheme = localStorage.getItem('theme');
|
||||
if (savedTheme) {
|
||||
setTheme(savedTheme);
|
||||
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
||||
setTheme('light');
|
||||
}
|
||||
// else: default is dark (no data-theme attribute needed)
|
||||
|
||||
if (themeToggle) {
|
||||
themeToggle.addEventListener('click', function () {
|
||||
var current = document.documentElement.getAttribute('data-theme');
|
||||
setTheme(current === 'light' ? 'dark' : 'light');
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user