vuepress
vuepress copied to clipboard
Add dark mode
Feature request
What problem does this feature solve?
What does the proposed API look like?
How should this be implemented in your opinion?
Are you willing to work on this yourself?
Integration of Dark mode in Vuepress
That's definitely a cool feature needed maybe it should be specific to the default theme plugin.
Can you work on it ? Do you need help some on boarding etc ?
Feel free to ask
just saw @f3ltron 's comment, I've managed to add a toggle button in the NavBar - reference, (https://github.com/vinayakkulkarni/vuepress/tree/feat/dark-theme), need some help regarding stylus as I've never used it before.
If create a plugin, you may need to add !important in the styles.
If the default theme can support prefers-color-scheme, it is best.
Or you need to create a new theme like vuepress-theme-default-prefers-color-scheme
If create a plugin, you may need to add !important in the styles.
Not really required, you can (should) use css variables var() to extend the theme imo
I think some sort of more comprehensive distillation of theming in VuePress would be really useful so that it is easier to override with custom theming (without a whole bunch of !important statements!)
css variables sound like a step in the right direction.
Wow, I just saw this, I built my own blog with this feature. My blog https://mrhope.site My source code: https://github.com/Mister-Hope/blog
I think it is not hard to make a plugin. If you need any help, just call me.
I did not see any changes on the styles file? Are you still working on with it? @vinayakkulkarni I can sperate my files to release a plugin. Since the plugin cannot access style files directly, my thought is to inject a style tag to the document when the switch component is mounted(or beforemount).
If you would like to make this feature with the default theme(I think many people would like to use it) rather than letting it become a plugin, then it's easier.
@Mister-Hope : Do check this out: https://github.com/vinayakkulkarni/vuepress/tree/feat/dark-theme, I am working on adding the dark theme. Need to integrate the colour palette used by Akruym in dev-tool dark theme.
I checked this, so I am saying I did not see any changes on the style file.
So Akruym is dealing with the style?
I think it is not a complex work, since the stylus file in Vuepress is very ordered.
Can't wait to see the feature offical supported
@vinayakkulkarni Could you check this stylus file? I think itβs good enough. You can just import it in index.styl and add a βtheme-nightβ class to
tag when dark mode is on.
I make a plugin here You can check this out. If it is okey, I will make a PR
any news on this issue? assuming the offer from Mister-Hope still stands
Love this feature <3. Still looking forward to it.
@kefranabg I can open a PR for this. If you need it, just call me.
@kefranabg check this https://github.com/vuejs/vuepress/pull/2232
I recently wanted to add dark mode to our own vuepress site, did a little survey around what was available, and wanted to report my findings:
- vuepress-theme-default-prefers-color-scheme by @tolking does basically what I'm looking for.
- I really like the
prefers-color-schemeapproach. - I just find the light mode code blocks to be a bit low-contrast
- I'd ideally like it if it were supported in the default theme.
- I really like the
- @Mister-Hope's pull request is cool.
- I do find it a little too dark (I don't think dark mode should be pitch black)
- It doesn't seem to use
prefers-color-scheme. - I swear I've seen that light/dark toggle around before. Does it come from somewhere else?
@Mister-Hope's pull request is cool.
- I do find it a little too dark (I don't think dark mode should be pitch black)
Maybe you are right, but all my device are AMOLED, and I work in pure dark. So a real dark fits me at least. Let's wait for vuepress team's opinion first. I can rebuild it to let it has a grey level
- It doesn't seem to use
prefers-color-scheme.
It's modified from @mr-hope/vuepress-plugin-theme-color, which is built for my theme vuepress-theme-hope
I will spend some time in the next few days to have a look at the plugin you provide.
- I swear I've seen that light/dark toggle around before. Does it come from somewhere else?
Yes, I got it from a switch collection with license MIT, but I am not sure if the collection owner built it. It's a nice remind, I will try to check it's license, if I cannot find it, I will change a new one.
I just find the light mode code blocks to be a bit low-contrast
I am thinking that too, but prism 's other theme usually have worse apprence. And I am not modifying it, it's color just remains which the theme-default provides.
- I really like the
prefers-color-schemeapproach.
I really like the prefers-color-scheme approach. Switch light and dark modes according to system settings.
@KieranHunt I change the apprence and the switch with some new commits.
I had a look at prefers-color-scheme. My first idea is to make a plugin, so I just cover some of the styles with higher order css selectors.And my PR actually is adding a new plugin called @vuepress/plugin-darkmode .
A plugin is hard to use prefers-color-scheme, unless I cover all the color styles.
We can switch to prefers-color-scheme actually, but that also means I have to modify styles in @vuepress/theme-default heavily, and place this function in theme-default so,
To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.
I shall first ask the team. @kefranabg @meteorlxy @vinayakkulkarni
Some very interesting take-aways from this writeup by Stackoverlow which we need to keep in mind: https://stackoverflow.blog/2020/03/31/building-dark-mode-on-stack-overflow/
And with that - is there an update on this?
Made a flexible solution for the Dark Mode or any CSS color theme:
https://dorson.github.io/CSS-Dark-Mode-and-color-switch/
Uses simple JS functions and CSS variables to set colors dynamically.
Have fun !
I rebuild my theme with prefers-color-scheme @KieranHunt , you can have a look at this.
I will ship this feature to the @vuepress/theme-default as a new feature instead of a plugin in a new PR.
I have opened a new PR #2301.
This new darkmode is using prefers-color-scheme with css vars, and will fall back to "6 - 18 lightmode; 18 - 6 darkmode" if the user's broswer does not support prefers-color-scheme.
Also:
- the code block apprearence in lightmode have been rebuilt with a lighter one
- Navbar style has been changed to
box-shadowinstead of a bottom border, which will bring better appearance on darkmode. - search bar styles has changed
- more variables are exposed to
palette.styl
Any suggestions are welcomed. π
I was wondering if I should put a switch with "light / auto / default" somewhere in the theme, and if you can give some opinions, it would be wonderful.
Besides, if you want to add this switch, please tell me where do you want to put it, because I have no idea about it.
I was wondering if I should put a switch with "light / auto / default" somewhere in the theme, and if you can give some opinions, it would be wonderful.
Besides, if you want to add this switch, please tell me where do you want to put it, because I have no idea about it.
Yes, such a toggle switch would be perfect in sunny conditions. Could be as minimal as possible, because most of the time we will not use it as the users. Maybe 3 times per day. In the sunshine on mobile screens, or when it's evening time.
White Unicode emoticon character with a dark background would work. π or π
or π or π or βοΈ (for white only) or β or π‘ or β―
Such a night / dark mode toggle switch could be placed near the top menu icon, or the search bar. Top right corner, or left right corner, or the bottom left corner. The bottom right corner is assumed to be used for the scroll up buttons, because the scroll bars end in that screen location.
Some websites place it on the lower left side. Most websites place it near the top right corner, or near the menu icon.
I put it in the navbar in the last PR, while I found it too narrow if I placed it there. Fixed it in a corner can be a good choice. i will try later. Thanks.
I put it in the navbar in the last PR, while I found it too narrow if I placed it there. Fixed it in a corner can be a good choice. i will try later. Thanks.
For the demo page, I put the Night / Light switch in the top right corner : https://dorson.github.io/CSS-Dark-Mode-and-color-switch/
It all depends on the other elements of the page and the text flow direction. Arabic and Hebrew is like a mirror position to the left to right text.