-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
Set CSS value in HTML to reflect current theme #192
Comments
Yeah, https://peps.python.org/ has a I'd welcome a PR to do something like this here too. |
Do you want it to match the |
We don't need to copy peps.python.org exactly. Checking a couple of others: Furo has a PyData Sphinx Theme has the same thing, but it only togges light and dark. It also has a Hmm, shall we follow Furo? |
I'd suggest following PyData Sphinx Theme honestly -- Furo's approach works because of the weird stacking it has due to the legacy of being a light-only theme that evolved a dark mode and requires... shenanigans (see https://github.com/pradyunsg/furo/blob/main/src/furo/assets/styles/base/_theme.sass which includes dark colors twice). PyData's approach allows content to only care about the current display theme, with keeping relevant "what mode is selected" state separately, which would work better for the usecases like showing the dark mode SVG when content is dark. |
See this page, where the anchor points to an SVG. If you ensure that there's no theme in local storage for this page, then if the browser settings are used to switch between dark and light modes (I'm using Firefox), the SVG is styled appropriately to display correctly. However, if I use the theme selector on the page to select dark mode when the browser is set to light mode, the SVG does not display correctly.
The reason is that I style for light mode and use a media query to override some styles, using
@media (prefers-color-scheme: dark)
. However, when the theme selector is used to select dark mode, then some dark-mode CSS is pulled in using theactivateTheme()
JS function, but from what I can tell this leaves no trace in the markup that we're now in dark mode. If there were e.g. adark-theme
class added to the<body>
tag when the page is in dark mode, then I could duplicate the styling using an appropriate selector. My complete styling of the SVG is:If there is another approach I could use to achieve the desired result (proper styling of the SVG in all cases), please let me know. Otherwise, would you consider adding
dark-theme
class to thebody
or other container tag so that I could try and achieve the desired result? Or have I missed somewhere where such a class has been added?The text was updated successfully, but these errors were encountered: