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

Change from nightMode to theme #1532

Merged
merged 4 commits into from
Mar 10, 2022

Conversation

dbernheisel
Copy link
Contributor

@dbernheisel dbernheisel commented Mar 9, 2022

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 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.

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

image

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.
Comment on lines -4 to -7
.night-mode-toggle .icon-theme::before {
content: "\e901";
}

Copy link
Contributor Author

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.

@dbernheisel dbernheisel force-pushed the support-multiple-themes branch from 6a3c6a6 to e32086e Compare March 9, 2022 19:35
@dbernheisel dbernheisel force-pushed the support-multiple-themes branch from 948c605 to e8d956c Compare March 10, 2022 14:24
@josevalim josevalim merged commit d7c11cc into elixir-lang:main Mar 10, 2022
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@dbernheisel dbernheisel deleted the support-multiple-themes branch March 10, 2022 17:30
@josevalim
Copy link
Member

Hi @dbernheisel! I have one improvement to suggest. The n shortcut now cycles between all three themes, which I think is correct, but it is impossible to know which theme we are actually looking at. Perhaps we should show a small box at the top with the current theme name as text? Then it automatically disappears after 3s or so?

@dbernheisel
Copy link
Contributor Author

@josevalim I agree and that sounds good. I'll see if I can make that happen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants