swag-for-dev icon indicating copy to clipboard operation
swag-for-dev copied to clipboard

Add Dark Mode 🌚

Open vikaspotluri123 opened this issue 6 years ago • 12 comments

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>

vikaspotluri123 avatar Oct 09 '18 20:10 vikaspotluri123

Yep, I don't see a reason why not? 😏

swapagarwal avatar Oct 10 '18 01:10 swapagarwal

I'll work on it after frontend perf (which is scheduled for Friday) if nobody picks it up 👍

vikaspotluri123 avatar Oct 10 '18 01:10 vikaspotluri123

Cool!

swapagarwal avatar Oct 10 '18 01:10 swapagarwal

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 avatar Nov 04 '18 17:11 sseficha

@sseficha go ahead 😄

vikaspotluri123 avatar Nov 04 '18 18:11 vikaspotluri123

@sseficha Let us know if you need any help! :)

swapagarwal avatar Dec 06 '18 02:12 swapagarwal

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.

sseficha avatar Dec 07 '18 10:12 sseficha

https://drafts.csswg.org/mediaqueries-5/#prefers-color-scheme

polyzen avatar Dec 07 '18 16:12 polyzen

Hi this issue has been inactive for a while now. Is it okay if I work on it? Thanks.

tsonge avatar May 28 '20 13:05 tsonge

@tsonge go for it!

vikaspotluri123 avatar May 28 '20 15:05 vikaspotluri123