This repository has been archived on 2025-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
Files
pypages/static/components/ThemeToggle.js
2025-11-16 18:01:30 +01:00

27 lines
703 B
JavaScript

// Theme Toggle Component
export class ThemeToggle {
constructor() {
this.html = document.documentElement;
this.toggle = document.getElementById('themeToggle');
this.init();
}
init() {
// Load saved theme
const savedTheme = localStorage.getItem('theme') || 'light';
this.html.setAttribute('data-theme', savedTheme);
if (this.toggle) {
this.toggle.addEventListener('click', () => this.toggleTheme());
}
}
toggleTheme() {
const currentTheme = this.html.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
this.html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
}
}