blog-template
blog-template copied to clipboard
Feat #6 night mode toggler
Feature #6
Solution: Added JS function and listener to save and handle current state in localStorage. Added new scss file with night mode styles (wrapped into .night-mode).
I've done point 2 and point 4 (mixins).
About prefers-color-scheme
- we should discuss, how to figure it out. Right now, if user prefers dark scheme - anyway dark style will be used. There is couple of options:
- Remove
prefers-color-scheme
from styles, detect it by JS and applynight-mode
class. Disadvantages: when JS disabled - night mode won't be applied (we can figure it out by<noscript>
actually, but it makes code more complicated. And one more disadvantage - we will have short "flashlight" on page load (before JS is load). - Just remove button when night mode enabled (fastest way, but may be not user friendly). If user already configured his browser to dark mode - he want dark site I think (just as option).
About 3 - what element, on your opinion will be semantic correct? Maybe <button type="button></button>
?
We should definitely not be setting the page style in JS when CSS is available. JS just needs to know what state the page is in to override if the option is changed, not set it initially.
Personally I would use a checkbox styled as a toggle switch.
JS just needs to know what state the page is in to override if the option is changed, not set it initially.
window.matchMedia("(prefers-color-scheme: dark)").matches
will tell if the user prefers dark theme, which can be the initial state.
Ok, I've added mirror mixins to light mode. It works without JS and with JS styles should overlap correctly. Check it please.
Notify me please, if all is ok (I'm going to do rebase with squash).
My initial thought is that there is a lot of styling that's been pulled out into the mixins that is going to be hard to keep track of. I think keeping the components' styling in their original file would be more maintainable.
@danrabbit Has conflicts and no recent activity. Does this need closing or converting to draft? I do not have the necessary rights.