Skip to content

Conversation

@mtsz-pl
Copy link
Contributor

@mtsz-pl mtsz-pl commented Oct 17, 2025

When using "toggle" mode for theme, instead of toggling between "always dark" and "always light" modes, a three-state toggle is employed: "always light", "always dark" and "auto". That way user has total autonomy over how they want the theme to behave.

Because of that, toggle icon needs to display currently selected mode: sun for light, moon for dark, half circle for auto.

Working example: https://mtsz.pl/

Firefox extension to quickly change browser theme with single button: https://addons.mozilla.org/firefox/addon/toggley/

@not-matthias
Copy link
Owner

Thanks for the PR! Is this setting used on any other sites? I haven't really seen it anywhere, which is why I feel like it might be a bit confusing.

@mtsz-pl
Copy link
Contributor Author

mtsz-pl commented Oct 22, 2025

My idea was:

  • when website owner sets "light", "dark", or "auto" modes, they "force" user to use that particular mode
  • so when they set "toggle" mode for the website, it should allow users to pick between all of them, and not only between the "fixed" ones
    For the three-state toggle, I believe it's easy enough for users to discover and understand how it works.
    There are plenty of websites that have this toggle somewhere in interface settings, with popups/menus/radio buttons - I didn't want to introduce any of these; I love the minimal desing language of this theme, that's why I implemented it that way.
    I guess we could add some on-hover hints to make it more clear whats happening.

@not-matthias not-matthias requested a review from Copilot October 25, 2025 19:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a three-state theme toggle system, allowing users to choose between "always light", "always dark", and "auto" (system preference) modes. Previously, the toggle only supported two states: light and dark.

Key Changes:

  • Modified the toggle cycle to include an intermediate "auto" state between dark and light modes
  • Added a new auto icon to visually represent the auto theme state
  • Implemented system theme preference detection and automatic updates when in auto mode

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
templates/partials/nav.html Added auto-icon image element to support the new three-state toggle UI
static/js/themetoggle.js Implemented auto mode logic, system preference detection, and event listener for system theme changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 12 to +15
} else if (localStorage.getItem("theme-storage") === "dark") {
setTheme("auto");
updateItemToggleTheme();
} else {
Copy link

Copilot AI Oct 25, 2025

Choose a reason for hiding this comment

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

The logic uses getSavedTheme() at line 61 but directly calls localStorage.getItem(\"theme-storage\") here. Consider using getSavedTheme() consistently for better maintainability and to avoid potential issues if the saved theme is null/undefined.

Copilot uses AI. Check for mistakes.
autoIcon.style.display = (mode === "auto") ? "block" : "none";

if (mode === "auto") {
autoIcon.style.filter = getSystemPrefersDark() ? "invert(1)" : "invert(0)";
Copy link

Copilot AI Oct 25, 2025

Choose a reason for hiding this comment

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

The auto icon filter is only updated when mode is 'auto', but the filter persists when switching modes. This could cause visual issues if the icon is reused. Consider resetting the filter when switching away from auto mode or moving this logic outside the conditional.

Suggested change
autoIcon.style.filter = getSystemPrefersDark() ? "invert(1)" : "invert(0)";
autoIcon.style.filter = getSystemPrefersDark() ? "invert(1)" : "invert(0)";
} else {
autoIcon.style.filter = "none";

Copilot uses AI. Check for mistakes.
@not-matthias
Copy link
Owner

Ohhh, yeah. I've seen the "Auto" field sometimes. I guess it could be useful. Will merge this in a sec.

@not-matthias
Copy link
Owner

Thanks for the PR, it's merged! de3f539

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants