spring-io / spring-asciidoctor-backends

A backend for Asciidoctor used to produce Spring styled HTML
Apache License 2.0
80 stars 16 forks source link

Don't store dark/light toggle if it matches the OS setting #73

Open odrotbohm opened 1 year ago

odrotbohm commented 1 year ago

It would be nice if the CSS could automatically detect whether to use dark or light mode based on the user theme (via media queries).

philwebb commented 1 year ago

We should already do this. See https://github.com/spring-io/spring-asciidoctor-backends/blob/6ce63903637ea570b62ad33c5761854db6765285/src/main/js/setup/switchtheme.js#L25 and https://github.com/spring-io/spring-asciidoctor-backends/blob/6ce63903637ea570b62ad33c5761854db6765285/src/main/js/setup/switchtheme.js#L50.

The problem might be that the theme has been toggled in the past and saved to local storage.

@odrotbohm What does an incognito window do?

odrotbohm commented 1 year ago

You're right. An incognito window brings up the dark theme on a dark OS. I guess I've clicked on the button just to test the switch at some point. A localStorage.removeItem("theme") did the trick. Wonder if that could be made a bit more convient to reset? Additional icon next to the switch in case a value is set and a click on it removing the value?

philwebb commented 1 year ago

Perhaps we just shouldn't save a local value if it matches the detected one.