pkgdown icon indicating copy to clipboard operation
pkgdown copied to clipboard

Thinking about dark mode

Open maelle opened this issue 3 years ago • 12 comments

There will be two CSS files, one light and one dark.

I am wondering how users could provide variables especially for dark mode (bslib-dark in YAML?).

bslib:
  variable1: bla
  variable2: blabla
bslib-dark:
  variable1: blop

now what should be the value for variable2 in dark mode: the Bootstrap/pkgdown default, or variable2 as defined under bslib:?

The former seems more logical if this variable is a colour, but if it's a font for instance, it would be a bit annoying to define it twice.

maelle avatar May 20 '21 14:05 maelle

or probably pkgdown itself should only pick a few variables to make the dark mode CSS.

maelle avatar May 20 '21 15:05 maelle

Note to self:

  • Use as many BS variables as possible in the syntax highlighting sass;
  • For all Pandoc classes, use new variables (I've just tried, it works just by adding variables to pkgdown_bslib_defaults() even if they are not BS variables) and document them.

maelle avatar May 20 '21 16:05 maelle

I wonder how to name the variables for colours of code. E.g. the color for fu, should it be "$fu-color". CC @apreshill as you might have an opinion.

maelle avatar May 20 '21 16:05 maelle

Dark mode example https://solutions.rstudio.com/ (except I can't find code thus no syntax highlighting theme)

maelle avatar Jun 04 '21 07:06 maelle

Re-surfacing a link shared by @apreshill https://marketplace.visualstudio.com/items?itemName=liviuschera.noctis

maelle avatar Jun 04 '21 12:06 maelle

Customization logic https://github.com/r-lib/pkgdown/pull/1707/files#r645567663

maelle avatar Jun 04 '21 13:06 maelle

Just noting that it could be one CSS file with all the rules (and different classes for dark/light) as it is something I saw recently.

maelle avatar Jul 22 '21 11:07 maelle

There a good general guide at https://css-tricks.com/a-complete-guide-to-dark-mode-on-the-web/

I think we'll probably need to have two separate style sheets (one for light and one for dark), unless there's some hack to generate only the changed rules with bslib (which seems unlikely). We could probably figure out how to combine all the rules into one, but that would double the size of the css.

hadley avatar Oct 17 '21 21:10 hadley

Things would be easier if the navbar colours only depended on CSS, not HTML, but that's not Bootstrap/Bootswatch logic.

maelle avatar Oct 18 '21 06:10 maelle

bslib now has a dark mode toggle on its pkgdown site (top right):: https://rstudio.github.io/bslib/

jayhesselberth avatar Sep 03 '23 10:09 jayhesselberth

@cpsievert can you explain how it works?

hadley avatar Sep 03 '23 21:09 hadley

Here's the PR were we added it https://github.com/rstudio/bslib/pull/768

I think it's mostly self-explanatory from the PR and Bootstrap color mode docs, but happy to answer any more specific questions. Also, keep in mind that you'll need the development version of bslib because it requires Bootstrap 5.3 which we only recently updated to.

cpsievert avatar Sep 04 '23 00:09 cpsievert