Skip to content

Commit

Permalink
New changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaNwaizu committed Jan 26, 2024
1 parent 9699ef7 commit 8ecd194
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
33 changes: 32 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ function handleClick() {
optionListItem.addEventListener('click', handleClick)

/*=============== SHOW MENU ===============*/
/*
const showMenu = (toggleId) => {
const toggle = document.getElementById(toggleId)
toggle.addEventListener('click', () => {
// Add show-menu class to nav menu
Expand All @@ -20,4 +20,35 @@ const showMenu = (toggleId) => {
})
}
showMenu('toggle-box')
-*/

/*=============== DARK LIGHT THEME ===============*/
const toggle = document.getElementById('toggle-box')
const darkTheme = 'dark-theme'
const iconTheme = 'toggle-icon'

// Previously selected topic (if user selected)
const selectedTheme = localStorage.getItem('selected-theme')
const selectedIcon = localStorage.getItem('selected-icon')

// We obtain the current theme that the interface has by validating the dark-theme class
const getCurrentTheme = () => document.body.classList.contains(darkTheme) ? 'dark' : 'light'
const getCurrentIcon = () => toggle.classList.contains(iconTheme) ? 'toggle-icon' : ''

// We validate if the user previously chose a topic
if (selectedTheme) {
// If the validation is fulfilled, we ask what the issue was to know if we activated or deactivated the dark
document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](darkTheme)
toggle.classList[selectedIcon === 'ri-moon-line' ? 'add' : 'remove'](iconTheme)
}

// Activate / deactivate the theme manually with the button
toggle.addEventListener('click', () => {
// Add or remove the dark / icon theme
document.body.classList.toggle(darkTheme)
toggle.classList.toggle(iconTheme)
// We save the theme and the current icon that the user chose
localStorage.setItem('selected-theme', getCurrentTheme())
localStorage.setItem('selected-icon', getCurrentIcon())
})

2 changes: 1 addition & 1 deletion styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ h4 {
.toggle__box {
cursor: pointer;
}
.show-menu {
.toggle-icon {
justify-content: flex-start;
}

Expand Down

0 comments on commit 8ecd194

Please sign in to comment.