Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a moon/ sun before the dark mode toggle switch #599 - Fixed #613

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions Contributors.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<!-- Global site tag (gtag.js) - Google Analytics -->
<link rel="icon" href="https://hacktoberfestswaglist.com/img/Hacktoberfest_21.jpg" type="image/x-icon">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-74296045-6"></script>

<!-- <script> -->
<!-- window.dataLayer = window.dataLayer || []; -->
<!-- function gtag() { dataLayer.push(arguments); } -->
Expand Down Expand Up @@ -99,11 +100,23 @@
<h1 class="animated rubberBand delay-4s">Contributors</h1>
<p class="animated rubberBand delay-4s">Add yourself to the list if you contribute.</p>
</div>
<label class="theme-switch" for="checkbox">
<div class="mode-toggle">
<div id="sun-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" class="bi bi-sun animated rubberBand" viewBox="0 0 15 15">
<path d="M8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm0 1a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"/>
</svg>
</div>
<div id="moon-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="19" height="19" fill="currentColor" class="bi bi-moon animated rubberBand" viewBox="0 0 16 16">
<path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278zM4.858 1.311A7.269 7.269 0 0 0 1.025 7.71c0 4.02 3.279 7.276 7.319 7.276a7.316 7.316 0 0 0 5.205-2.162c-.337.042-.68.063-1.029.063-4.61 0-8.343-3.714-8.343-8.29 0-1.167.242-2.278.681-3.286z"/>
</svg>
</div>
<label class="theme-switch" for="checkbox">
<input type="checkbox" id="checkbox" />
<div class="slider round"></div>
</label>
</div>
</div>
<div class="box mx-auto">


Expand Down Expand Up @@ -360,19 +373,38 @@ <h1 class="animated rubberBand delay-4s">Contributors</h1>
})
const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]');
const currentTheme = localStorage.getItem('theme');
// for reloading without toggle
if (currentTheme === 'dark'){
document.getElementById('sun-icon').style.display='none';
document.getElementById('moon-icon').style.display='block';
}
else{
document.getElementById('sun-icon').style.display='block';
document.getElementById('moon-icon').style.display='none';
}

if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark') {
toggleSwitch.checked = true;
toggleSwitch.checked = true;

}

}
function switchTheme(e) {
if (e.target.checked) {
document.documentElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
// on toggling to dark mode
document.getElementById('moon-icon').style.display='block';
document.getElementById('sun-icon').style.display='none';

} else {
document.documentElement.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light');
// on toggling to light mode
document.getElementById('sun-icon').style.display='block';
document.getElementById('moon-icon').style.display='none';
}
}
toggleSwitch.addEventListener('change', switchTheme);
Expand Down
7 changes: 7 additions & 0 deletions css/contributors.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ input:checked + .slider {
background-color: rgb(163, 163, 163);
background-image: linear-gradient(midnightblue, rebeccapurple);
}

input:checked + .slider:before {
transform: translateX(26px);
background-color: grey;
Expand All @@ -300,3 +301,9 @@ input:checked + .slider:before {
#stats a {
padding: 0 5px;
}

.mode-toggle{
display: flex;
flex-direction: row;
}