This commit is contained in:
parent
dc223ae1b8
commit
ea648498e2
10 changed files with 166 additions and 16 deletions
26
assets/js/themeToggle.js
Normal file
26
assets/js/themeToggle.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
export function themeToggle() {
|
||||
const button = document.querySelector('#theme-toggle');
|
||||
const root = document.documentElement;
|
||||
|
||||
if (!button) return;
|
||||
|
||||
// Appliquer le thème sauvegardé (si présent)
|
||||
const savedTheme = localStorage.getItem('theme');
|
||||
if (savedTheme === 'light') {
|
||||
root.setAttribute('data-theme', 'light');
|
||||
}
|
||||
|
||||
button.addEventListener('click', () => {
|
||||
const isLight = root.getAttribute('data-theme') === 'light';
|
||||
const nextTheme = isLight ? 'dark' : 'light';
|
||||
|
||||
root.setAttribute('data-theme', nextTheme);
|
||||
localStorage.setItem('theme', nextTheme);
|
||||
|
||||
button.setAttribute(
|
||||
'aria-label',
|
||||
nextTheme === 'light' ? 'Activer le mode sombre' : 'Activer le mode clair'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue