-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1357 from haseebzaki-07/new_branch_4
Add theme toggle
- Loading branch information
Showing
8 changed files
with
146 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
transition: background-color 0.3s, color 0.3s; | ||
} | ||
|
||
/* Light and Dark themes */ | ||
body.light { | ||
background-color: #ffffff; | ||
color: #000000; | ||
} | ||
|
||
body.dark { | ||
background-color: #333333; | ||
color: #ffffff; | ||
} | ||
|
||
/* Container styling for the toggle switch */ | ||
.switch { | ||
position: fixed; | ||
top: 20px; | ||
right: 20px; | ||
z-index: 1000; | ||
display: inline-block; | ||
width: 60px; | ||
height: 34px; | ||
} | ||
|
||
/* Hide checkbox */ | ||
.switch input { | ||
opacity: 0; | ||
width: 0; | ||
height: 0; | ||
} | ||
|
||
/* Toggle slider styling */ | ||
.slider { | ||
position: absolute; | ||
cursor: pointer; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
background-color: #ccc; | ||
transition: 0.4s; | ||
border-radius: 34px; | ||
} | ||
|
||
/* Slider knob styling */ | ||
.slider:before { | ||
position: absolute; | ||
content: ""; | ||
height: 26px; | ||
width: 26px; | ||
left: 4px; | ||
bottom: 4px; | ||
background-color: white; | ||
border-radius: 50%; | ||
transition: 0.4s; | ||
background-size: 18px 18px; | ||
background-position: center; | ||
background-repeat: no-repeat; | ||
} | ||
|
||
|
||
/* Sun icon in light mode */ | ||
body.light .slider:before { | ||
background-image: url('/assets/img/sun.icon.png'); /* Update path as necessary */ | ||
} | ||
|
||
/* Moon icon in dark mode */ | ||
body.dark .slider:before { | ||
background-image: url('/assets/img/moon.icon.png'); /* Update path as necessary */ | ||
} | ||
|
||
/* Move knob to right when checked */ | ||
input:checked + .slider:before { | ||
transform: translateX(26px); /* Move knob to the right */ | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const themeToggleButton = document.getElementById('theme-toggle'); | ||
const body = document.body; | ||
|
||
|
||
const currentTheme = localStorage.getItem('theme') || 'light'; | ||
body.classList.add(currentTheme); | ||
themeToggleButton.checked = currentTheme === 'dark'; // Set checkbox state | ||
|
||
|
||
themeToggleButton.addEventListener('change', () => { | ||
if (themeToggleButton.checked) { | ||
body.classList.replace('light', 'dark'); | ||
localStorage.setItem('theme', 'dark'); | ||
} else { | ||
body.classList.replace('dark', 'light'); | ||
localStorage.setItem('theme', 'light'); | ||
} | ||
}); | ||
}); |
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
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