swag-for-dev
swag-for-dev copied to clipboard
Add Dark Mode 🌚
It's relatively simple to add a toggle between light and dark mode, and javascript can be used to toggle a dark
class to the body
Here's an example of one (styles are in sass):
<style>
.toggle {
$toggle-width: 50px;
$toggle-height: $toggle-width / 2 - 2;
$toggle-border: white;
$toggle-background: $secondary;
$toggle-transition: 0.25s;
position: relative;
display: inline-flex;
width: $toggle-width;
height: $toggle-height;
.toggle-input {
display: none;
&:checked + .toggle-ui:before {
transform: translateX($toggle-height);
}
}
.toggle-icon {
position: relative;
width: 18px;
height: 18px;
top: -3px;
}
.toggle-ui {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
transition: all $toggle-transition ease-in-out;
background: $toggle-background;
border: 2px solid darken($toggle-border, 10%);
border-radius: 25px;
&:before {
position: absolute;
content: '';
height: $toggle-height - 10px;
width: $toggle-height - 10px;
left: 4px;
bottom: 2.75px;
background-color: darken($toggle-border, 10%);
transition: all $toggle-transition ease-in-out;
border-radius: 50%;
}
}
}
</style>
<div class="toggle-wrapper">
<label class="toggle" for="theme">
<input class="toggle-input" type="checkbox" id="theme">
<span class="toggle-ui"></span>
<span class="sr-only">Toggle between light and dark theme</span>
</label>
</div>
Yep, I don't see a reason why not? 😏
I'll work on it after frontend perf (which is scheduled for Friday) if nobody picks it up 👍
Cool!
I would like to take on this enhancement as my first contribution. If anyone has already started working on it please let me know! :)
@sseficha go ahead 😄
@sseficha Let us know if you need any help! :)
Yes sorry for the delay, I will post a version within the next few days. :) I have been having some trouble accessing the form at the end of the page so I can toggle a class to give it a dark theme. I cant seem to find the proper selector to use in javascript and toggling a class to the whole body doesn't take the form into account.
https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme
Hi this issue has been inactive for a while now. Is it okay if I work on it? Thanks.
@tsonge go for it!