vuepress icon indicating copy to clipboard operation
vuepress copied to clipboard

Add dark mode

Open manuales opened this issue 6 years ago β€’ 38 comments

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 Docu

manuales avatar Sep 17 '19 16:09 manuales

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

flozero avatar Sep 19 '19 20:09 flozero

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.

vinayakkulkarni avatar Sep 22 '19 09:09 vinayakkulkarni

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

tolking avatar Sep 23 '19 03:09 tolking

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

vinayakkulkarni avatar Sep 26 '19 09:09 vinayakkulkarni

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.

songololo avatar Oct 04 '19 15:10 songololo

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.

Mister-Hope avatar Oct 09 '19 09:10 Mister-Hope

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).

Mister-Hope avatar Oct 09 '19 10:10 Mister-Hope

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 avatar Oct 09 '19 10:10 Mister-Hope

@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.

vinayakkulkarni avatar Oct 09 '19 10:10 vinayakkulkarni

I checked this, so I am saying I did not see any changes on the style file.

So Akruym is dealing with the style?

Mister-Hope avatar Oct 09 '19 10:10 Mister-Hope

image 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

Mister-Hope avatar Oct 09 '19 10:10 Mister-Hope

@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.

Mister-Hope avatar Oct 15 '19 01:10 Mister-Hope

I make a plugin here You can check this out. If it is okey, I will make a PR

Mister-Hope avatar Nov 22 '19 12:11 Mister-Hope

any news on this issue? assuming the offer from Mister-Hope still stands

superusercode avatar Mar 14 '20 22:03 superusercode

Love this feature <3. Still looking forward to it.

quantrung9 avatar Mar 18 '20 07:03 quantrung9

@kefranabg I can open a PR for this. If you need it, just call me.

Mister-Hope avatar Mar 18 '20 11:03 Mister-Hope

@kefranabg check this https://github.com/vuejs/vuepress/pull/2232

Mister-Hope avatar Mar 18 '20 13:03 Mister-Hope

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-scheme approach.
    • 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.
  • @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?

KieranHunt avatar Mar 18 '20 14:03 KieranHunt

  • @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.

Mister-Hope avatar Mar 18 '20 14:03 Mister-Hope

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.

Mister-Hope avatar Mar 18 '20 15:03 Mister-Hope

  • I really like the prefers-color-scheme approach.

I really like the prefers-color-scheme approach. Switch light and dark modes according to system settings.

tolking avatar Mar 21 '20 03:03 tolking

@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

Mister-Hope avatar Mar 22 '20 04:03 Mister-Hope

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?

sudoappel avatar Apr 02 '20 14:04 sudoappel

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 !

Dorson avatar Apr 09 '20 06:04 Dorson

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.

Mister-Hope avatar Apr 10 '20 02:04 Mister-Hope

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-shadow instead 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. πŸ˜ƒ

Mister-Hope avatar Apr 13 '20 16:04 Mister-Hope

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.

Mister-Hope avatar Apr 14 '20 01:04 Mister-Hope

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.

Dorson avatar Apr 14 '20 20:04 Dorson

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.

Mister-Hope avatar Apr 15 '20 00:04 Mister-Hope

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.

Dorson avatar Apr 15 '20 01:04 Dorson