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

Dynamic theme #19

Closed
jrappen opened this issue Feb 21, 2019 · 2 comments
Closed

Dynamic theme #19

jrappen opened this issue Feb 21, 2019 · 2 comments

Comments

@jrappen
Copy link

jrappen commented Feb 21, 2019

Compare https://www.macstories.net/news/safari-technology-preview-allows-websites-to-switch-themes-based-on-mojaves-dark-mode/.

Maybe this would make sense? Haven't checked for how to check on newer Win10.

@jhildenbiddle
Copy link
Owner

jhildenbiddle commented Feb 21, 2019

OS theme detection is made possible by the prefers-color-scheme media query:

Specifying a separate stylesheet for light/dark OS themes can be done as follows:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple-dark.css" media="(prefers-color-scheme: dark)">

I have made this change to the docsify-themeable site. View it with the latest Safari Technical Preview and toggle your macOS Mohave's light/dark color scheme to see the effect.

FWIW, this solutions is less-than-ideal because it requires both stylesheets to be downloaded, but it makes it very easy to specify separate stylesheets for light and dark color schemes. I could also offer a new stylesheet that contains the CSS custom property values from both the "Simple" and "Simple Dark" themes which would remove the additional stylesheet request and handle all of this automatically, but this approach prevents users from specifying their own light and dark themes. For now, it seems easiest to just recommend the approach above, favoring flexibility over the slight performance hit taken from downloading two stylesheets.

Be aware that while Firefox Nightly supports the prefers-color-scheme media query, it requires a browser restart to detect color scheme changes. A bug has been filed, so hopefully this will be addressed before Firefox 67 is released.

@jrappen
Copy link
Author

jrappen commented May 7, 2019

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

No branches or pull requests

2 participants