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

Added "follow system" option to theme toggle #2261

Merged
merged 4 commits into from
Mar 14, 2024

Conversation

SamAdamDay
Copy link
Contributor

@SamAdamDay SamAdamDay commented Mar 8, 2024

The theme toggle button now has a third option, which follows the user's system preferences.

  • In the code there's now a distinction between the theme setting (which can be "dark", "light" or "system") and the computed theme.
  • The theme setting is now stored as the "theme-setting" local storage variable. Since this is different from the old variable ("theme"), this will effectively reset all current user themes to the default "system". Maybe this is not what you want.
  • The "system" theme icon is currently a half circle symbol.
  • The toggle button now displays the current theme setting, rather than the next theme setting (as far as I know this is consistent with other sites which have three theme options).
  • theme.js is now loaded regardless of site.enable_darkmode. This is because other scripts which were always loaded relied on being able to determine the theme. theme.js no longer initialises the theme itself though; this only happens when site.enable_darkmode.
  • When the theme setting is "system", the theme will change immediately whenever the user changes their system theme.

#2261

@george-gca george-gca linked an issue Mar 11, 2024 that may be closed by this pull request
2 tasks
@george-gca
Copy link
Collaborator

Thanks for your solution. My only issue here is about the icon, but not really sure how to fix this. Usually the current icon is used as contrast, but the moon-over-sun icon is pro only. What do you think @alshedivat?

@george-gca
Copy link
Collaborator

george-gca commented Mar 12, 2024

Just give a thought about this, and one possible solution to keep the icons consistent between them is to use another iconset for this specific part. What do you guys think about using tabler icons? More specifically, moon, sun, and sun-moon. It looks like this in the template:

image

image

image

And it also supports usage via scss, so after purgecss does its part, only the used icons will be kept on the final css file. I managed to make this change, so I could update your PR with this.

@SamAdamDay
Copy link
Contributor Author

Nice!

I find that sun-moon icon a little ugly, but it seems fine and it's nice to have it consistent.

@george-gca
Copy link
Collaborator

Yes, it is not the prettiest one, but at least keeps the consistency in the icons. I will apply the changes and wait for @alshedivat feedback.

Signed-off-by: George Araujo <george.gcac@gmail.com>
Signed-off-by: George Araujo <george.gcac@gmail.com>
Copy link
Owner

@alshedivat alshedivat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for implementing this!

@george-gca george-gca merged commit c788a30 into alshedivat:master Mar 14, 2024
3 checks passed
@george-gca george-gca mentioned this pull request Apr 15, 2024
2 tasks
BoAi01 pushed a commit to BoAi01/boai01.github.io that referenced this pull request May 7, 2024
The theme toggle button now has a third option, which follows the user's
system preferences.

- In the code there's now a distinction between the theme setting (which
can be "dark", "light" or "system") and the computed theme.
- The theme setting is now stored as the "theme-setting" local storage
variable. Since this is different from the old variable ("theme"), this
will effectively reset all current user themes to the default "system".
Maybe this is not what you want.
- The "system" theme icon is currently a half circle symbol.
- The toggle button now displays the current theme setting, rather than
the next theme setting (as far as I know this is consistent with other
sites which have three theme options).
- `theme.js` is now loaded regardless of `site.enable_darkmode`. This is
because other scripts which were always loaded relied on being able to
determine the theme. `theme.js` no longer initialises the theme itself
though; this only happens when `site.enable_darkmode`.
- When the theme setting is "system", the theme will change immediately
whenever the user changes their system theme.

alshedivat#2261

---------

Signed-off-by: George Araujo <george.gcac@gmail.com>
Co-authored-by: George Araujo <george.gcac@gmail.com>
@sahiljhawar
Copy link

How to toggle between only light and dark mode?

I dont want this:
image

@george-gca
Copy link
Collaborator

Can you ask this in Q&A? This PR was already merged, also there it is easier for more people to find it.

siril-teja pushed a commit to siril-teja/siril-teja.github.io-old that referenced this pull request Jun 19, 2024
The theme toggle button now has a third option, which follows the user's
system preferences.

- In the code there's now a distinction between the theme setting (which
can be "dark", "light" or "system") and the computed theme.
- The theme setting is now stored as the "theme-setting" local storage
variable. Since this is different from the old variable ("theme"), this
will effectively reset all current user themes to the default "system".
Maybe this is not what you want.
- The "system" theme icon is currently a half circle symbol.
- The toggle button now displays the current theme setting, rather than
the next theme setting (as far as I know this is consistent with other
sites which have three theme options).
- `theme.js` is now loaded regardless of `site.enable_darkmode`. This is
because other scripts which were always loaded relied on being able to
determine the theme. `theme.js` no longer initialises the theme itself
though; this only happens when `site.enable_darkmode`.
- When the theme setting is "system", the theme will change immediately
whenever the user changes their system theme.

alshedivat#2261

---------

Signed-off-by: George Araujo <george.gcac@gmail.com>
Co-authored-by: George Araujo <george.gcac@gmail.com>
karapostK pushed a commit to karapostK/karapostK.github.io that referenced this pull request Jul 4, 2024
The theme toggle button now has a third option, which follows the user's
system preferences.

- In the code there's now a distinction between the theme setting (which
can be "dark", "light" or "system") and the computed theme.
- The theme setting is now stored as the "theme-setting" local storage
variable. Since this is different from the old variable ("theme"), this
will effectively reset all current user themes to the default "system".
Maybe this is not what you want.
- The "system" theme icon is currently a half circle symbol.
- The toggle button now displays the current theme setting, rather than
the next theme setting (as far as I know this is consistent with other
sites which have three theme options).
- `theme.js` is now loaded regardless of `site.enable_darkmode`. This is
because other scripts which were always loaded relied on being able to
determine the theme. `theme.js` no longer initialises the theme itself
though; this only happens when `site.enable_darkmode`.
- When the theme setting is "system", the theme will change immediately
whenever the user changes their system theme.

alshedivat#2261

---------

Signed-off-by: George Araujo <george.gcac@gmail.com>
Co-authored-by: George Araujo <george.gcac@gmail.com>
HaukeCornell pushed a commit to haukesand/haukesand.github.io that referenced this pull request Jul 8, 2024
The theme toggle button now has a third option, which follows the user's
system preferences.

- In the code there's now a distinction between the theme setting (which
can be "dark", "light" or "system") and the computed theme.
- The theme setting is now stored as the "theme-setting" local storage
variable. Since this is different from the old variable ("theme"), this
will effectively reset all current user themes to the default "system".
Maybe this is not what you want.
- The "system" theme icon is currently a half circle symbol.
- The toggle button now displays the current theme setting, rather than
the next theme setting (as far as I know this is consistent with other
sites which have three theme options).
- `theme.js` is now loaded regardless of `site.enable_darkmode`. This is
because other scripts which were always loaded relied on being able to
determine the theme. `theme.js` no longer initialises the theme itself
though; this only happens when `site.enable_darkmode`.
- When the theme setting is "system", the theme will change immediately
whenever the user changes their system theme.

alshedivat#2261

---------

Signed-off-by: George Araujo <george.gcac@gmail.com>
Co-authored-by: George Araujo <george.gcac@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to follow system theme for dark-mode
4 participants