-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Se programo la interaccion de dark mode
- Loading branch information
Mauricio Cox
committed
Feb 1, 2024
1 parent
0b7f7ab
commit aa21e3b
Showing
2 changed files
with
15 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
console.log("Hola mundo!"); | ||
const themeButton = document.getElementById('theme_button'); | ||
const darkTheme = 'dark-theme'; | ||
const selectedTheme = localStorage.getItem('selected-theme'); | ||
const userHasDarkTheme = window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
const getCurrentTheme = () => document.body.classList.contains(darkTheme) ? 'dark' : 'light'; | ||
if (selectedTheme) { | ||
document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](darkTheme); | ||
} else { | ||
if (userHasDarkTheme) document.body.classList.add(darkTheme); | ||
} | ||
|
||
themeButton.addEventListener('click', () => { | ||
document.body.classList.toggle(darkTheme); | ||
localStorage.setItem('selected-theme', getCurrentTheme()); | ||
}); |