-
Notifications
You must be signed in to change notification settings - Fork 336
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
Change from nightMode to theme #1532
Change from nightMode to theme #1532
Conversation
Instead of a boolean theme (dark or not), change to a generic 'theme' setting. This keeps backwards-compatibility from older settings. The new themes are 'dark' and 'light' and 'system'. 'system' will allow for the user's OS to apply darkMode automatically depending on their system settings. Null and 'system' are treated as the same. 'dark' and 'light' will ignore OS settings. This also introduces reactivity from the OS's changing `prefers-color-scheme`, for example if your system is set to go into dark mode at sunrise, then the browser will switch to `prefers-color-scheme: dark`. Before this commit, the theme would not react to this change until page reload. Now, it will watch for media changes and apply the dark theme if appropriate.
.night-mode-toggle .icon-theme::before { | ||
content: "\e901"; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems to be unused.
6a3c6a6
to
e32086e
Compare
948c605
to
e8d956c
Compare
💚 💙 💜 💛 ❤️ |
Hi @dbernheisel! I have one improvement to suggest. The |
@josevalim I agree and that sounds good. I'll see if I can make that happen |
Currently, if you have set nightMode to true, there's not a way to go back and use the OS system default. Turning nightMode off will set it to false (not null). There's a hidden third setting of null that a user can't back to without clearing their localStorage.
Instead of a boolean nightMode (dark or not), change it to a 'theme' setting. The new themes are 'dark' and 'light' and 'system'. 'system' will allow for the user's OS to apply nightMode automatically depending on their system settings. Null and 'system' are treated as the same. 'dark' and 'light' will ignore OS settings. This keeps backwards-compatibility from older settings. The themes themselves are unchanged, however I did change verbiage from "night mode" to "dark mode"; there's technically a difference-- night mode is typically associated with removing blue light to help folks prepare to sleep, whereas dark mode is associated with not making eyes bleed with bright whites.
This also introduces reactivity from the OS changing
prefers-color-scheme
, for example if your system is set to go into night mode at sunset, then the browser will switch toprefers-color-scheme: dark
. Before this commit, the theme would not react to this change until page reload. Now, it will watch for media changes and apply the dark theme if appropriate.Plus, this allows for implementing additional themes in the future, like a Windows 95 theme or perhaps a way to dynamically set it based on whether it's an erlang module or a gleam module.
This is inspired by Tailwind's guide to dark mode: https://tailwindcss.com/docs/dark-mode
Demo
theme-demo-exdocs-720.mov