Skip to content

Commit

Permalink
Se programo la interaccion de dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauricio Cox committed Feb 1, 2024
1 parent 0b7f7ab commit aa21e3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ html {
font-size: 18px;
font-family: var(--font-family);
text-wrap: balance;
background-color: pink;
}

body {
Expand Down
16 changes: 15 additions & 1 deletion js/script.js
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());
});

0 comments on commit aa21e3b

Please sign in to comment.