Closed apreshill closed 3 years ago
This is awesome @apreshill! I'll make fixes.
(so, thank you!!)
@apreshill the only variable I can't tackle is fg. Is it body-color
?
And I suppose it'd make sense indeed to add a few sentences in the vignette, if you want to make a small PR?
Ooh body-color
! I'm just getting the hang of these global bs4 variables too- fg
seems to be the bslib way of setting body color (https://rstudio.github.io/bslib/articles/bslib.html#main-colors), although I don't see it documented anywhere else on Bootstrap docs. This is the flexdashboard
theming vignette for more context: https://pkgs.rstudio.com/flexdashboard/articles/theme.html#custom-themes
Will do PR today š©āš³ Are you open to an R-based interactive table (i.e., a reactable, a DT like bslib), or prefer plain markdown?
(brainstorming here)
I think it would have helped me if I could have seen:
Also- I'm not sure if you noticed, but secondary
seems largely unused- only for the background of the version badge AFAIK (I've just realized I did not attempt footer elements, so it may cascade there). I was wondering if that variable might be made more useful? One idea I had (b/c it was difficult to tweak with CSS) was to make a variable that controls the hover+active states of the non-homepage TOC elements, and have that same variable affect the hover+active states of the copy button. What do you think?
So for pseudocode purposes, it is were secondary
:
/* Hover/Active/focus links */
nav[data-toggle="toc"] .nav > li > a:hover,
nav[data-toggle="toc"] .nav > li > a:focus,
nav[data-toggle="toc"] .nav-link.active,
nav[data-toggle="toc"] .nav-link.active:hover,
nav[data-toggle="toc"] .nav-link.active:focus {
background-color: var(--secondary);
}
/*----Copy Buttons ----*/
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active:hover {
background-color: var(--secondary);
}
Then I'd probably try to assign the background of the version badge to info
? It used to be danger
I believe, which didn't seem intuitive. Anyway, just spitballing!
(sorry I accidentally closed prematurely! sloppy keyboard skills :)
A reactable in https://pkgdown.r-lib.org/dev/articles/customization.html#bslib-variables-1 would be great.
We're also very receptive to any suggestions for moving logic out of pkgdown.css
and into bs variables.
Thanks so much @apreshill, super useful. Regarding CSS changes before the docs improvements,
secondary
?Some notes
I suppose making these changes will also make creating the dark mode much easier. I could look into making changes later this week.
Also related https://github.com/rstudio/bookdown/issues/1021
The syntax highlighting CSS would remain separate I suppose. :thinking:
Hi- sorry for the pause, I wanted to take some time yesterday to dig a bit deeper into both Bootstrap cascades, and how the Bootswatch themes make use of variables and the cascade too. I did find an interesting candidate variable that we could map $secondary
onto: $component-active-bg
. Seen here:
If we let $secondary
map onto this variable, I think we should make it affect four elements (see the first reactable table here; there are 3 total: one for theme variables, one for overriding theme variables, and one for navbar light/dark variables).
https://focused-snyder-9f2e47.netlify.app/articles/customization.html#bslib-variables-1
What do you both think? (I made these tables more for us- this is not intended as a draft of user-facing documentation-yet š )
Also in testing, I'm finding that the variable navbar-bg
needs to be explicitly set like:
navbar:
bg: navbar-bg
I wonder if that bslib variable should be the default navbar background, if set (i.e., you don't have to set the navbar bg
variable)?
Thanks again @apreshill! I'm digesting all your feedback into the open PR #1682
Regarding the version badge, after experimenting I think the current behavior makes sense: the badge is "danger" for the in development website but "default" (hence secondary-colored) for the release version.
I agree, "danger" definitely makes sense for in development- can you override the default cascade from $secondary
if you use a more specific variable?
I'm also still digesting as well! I'll continue getting some feedback internally about what variable cascades would be least surprising š¤
Btw @apreshill when you write " I did find an interesting candidate variable that we could map $secondary onto: $component-active-bg" do you have any example of how to do that with sass? I'm trying to use grey-200 for secondary, and am failing to do so.
I agree, "danger" definitely makes sense for in development- can you override the default cascade from $secondary if you use a more specific variable?
It didn't seem so so in my PR I now use badge-info for the release mode. It's $cyan
by default, but one can tweak $info
to get a different color just for the badge.
@apreshill actually fg works? I've created a monster with red fg and grey bg via the config:
One last thing (for today), reg the navbar the default is light at the moment
https://github.com/r-lib/pkgdown/blob/48d88cbb6dcfb10eb3ae5c6abec0cb7af5249e5f/R/navbar.R#L32-L33
Btw @apreshill when you write " I did find an interesting candidate variable that we could map $secondary onto: $component-active-bg" do you have any example of how to do that with sass? I'm trying to use grey-200 for secondary, and am failing to do so.
This is likely an oversimplification, as I've only used Sass via Hugo pipes. What I was thinking was that you could first do something like:
#pseudo-sass code
.navbar-light .navbar-nav .active > .nav-link {
@extend #{$component-active-bg};
}
I did something sort of like this here: https://github.com/hugo-apero/hugo-apero/blob/05497e6e4382f861c02a52fbdcbd1bdc60cee236/assets/scaffold.scss#L475-L487
This would force the component we want (the active background color for a nav link) "listen to" the variable $component-active-bg
.
Then, to make sure the that variable can be set with $secondary
...
#pseudo-sass code
$component-active-bg: '$secondary' !default;
Again, this is probably oversimplified, but was just working out an existing Bootstrap variable that might make sense!
Thank you! At the moment I'm trying, before running bslib::bs_theme_dependencies()
,
# map secondary to component-active-bg
secondary <- bslib::bs_get_variables(bs_theme, "secondary")
bs_theme <- bslib::bs_add_variables(
bs_theme,
"component-active-bg" = as.character(secondary)
)
which doesn't work yet.
Actually it does work for the button!
I had to keep the rules with $component-active-bg
in them, I wonder whether I missed something though I'm not too surprised regarding the rules of the TOC.
mmmh it was simpler actually. :woman_facepalming:
just waking up and excited to test your new branch out! šÆ
wait a bit then :see_no_evil:
Surprised this does not work hence my workaround:
library("bslib")
theme <- bs_theme(
"primary" = "#fff",
"component-active-bg" = "$primary !default"
)
bslib::bs_theme_dependencies(theme)
#> Error in compile_data(sass_input, options): Error: Undefined variable: "$primary".
#> on line 2:23 of stdin
#> >> $component-active-bg: $primary !default;
#>
#> ----------------------^
Created on 2021-05-20 by the reprex package (v2.0.0.9000)
ok now ready for testing @apreshill
Am I missing something?
Current workflow for replacing values in pkgdown.sass:
5b5fdff
(#1682)Does this make sense? (i.e. have I learnt my lesson? :sweat_smile: )
Starting off small and working my way up:
If I just use (woot!):
fg: "#982649"
bg: "white"
The footer color doesn't inherit fg
, maybe should?:
footer {
color: #666;
}
It looks like a nice alpha is added to fg
by default š
Is that right?
Adding primary
:
fg: "#ff0000"
bg: "white"
primary: "#9B5094"
Changed:
[x] link-color
[x] link-hover-color
(darken link-color
by 15% š )
[x] The background hover/active copy button and the border upon hover
[ ] And maybe other vars too? Maybe though - just a proposal! Maybe not- this may be too much š¼
Adding secondary
:
bg: "white"
fg: "#982649"
primary: "#60B2E5"
secondary: "#FBD989"
oh WOW- all that CSS pain taken away! This is lovely. Also changed background color for copy button when focus/active.
Narrator's voice After making more changes to navbar-bg
, I did notice that the hover background color for dropdowns can get lost, maybe both hover and focus of dropdowns should track with secondary
too?
Adding navbar-bg
bg: "white"
fg: "#982649"
primary: "#60B2E5"
secondary: "#FBD989"
navbar-bg: "#F7CCB6" # must set bg key in navbar
Works if I also set bg key in the navbar:
Adding heading-color
works āļø
bg: "white"
fg: "#982649"
primary: "#60B2E5"
secondary: "#FBD989"
navbar-bg: "#F7CCB6" # must set bg key in navbar
headings-color: "#006DAA" # inherits from fg if not set
Moving more quickly now as everything works! All the link coloring works š
side note: adding body-color
still works at this point! Still doesn't affect footer text color though.
I cannot seem to get component-active-color
to affect anything- I was expecting this to change the text color anywhere that component-active-bg
affected the background color (so text of active navbar links, text of active sidebar TOC links, and focus icon color for copy/paste button?)
bg: "white"
fg: "#982649"
primary: "#60B2E5"
secondary: "#FBD989"
navbar-bg: "#F7CCB6" # must set bg key in navbar
headings-color: "#006DAA" # inherits from fg if not set
link-color: "#B33C86" # inherit primary if not set
link-hover-color: "#EA638C" # darkens primary if not set
component-active-bg: "#AADACD" # yes!
component-active-color: "#9FFFF5" # nope
OK going to start hitting navbar with testing, but going to start new comment for that!!
Navbar! Here we go...
Starting from:
bg: "white"
fg: "#982649"
primary: "#60B2E5"
secondary: "#FBD989"
navbar-bg: "#F7CCB6" # must set bg key in navbar
headings-color: "#006DAA" # inherits from fg if not set
link-color: "#B33C86" # inherit primary if not set
link-hover-color: "#EA638C" # darkens primary if not set
component-active-bg: "#AADACD" # yes!
component-active-color: "#9FFFF5" # nope
OK everything light that I tried works! I tested:
# navbar
navbar-light-brand-color: "#476A6F" # pkgname color / inherits navbar-light-active-color if not set
navbar-light-brand-hover-color: "#B7094C" # pkgname hover / inherits navbar-light-hover-color if not set
navbar-light-active-color: "#B7094C" # active link
navbar-light-hover-color: "#1B998B" # hover link
navbar-light-color: "#2A9D8F" # link
info: "#EE92C2"
I'll pare down my reactable table for the vignette based on this. What do you think?
Pulling out some notes as a tl;dr:
component-active-color
affect all the text for elements that component-active-bg
affects now? primary
-> navbar-light-active-color
+ component-active-color
? Too much?secondary
if set? (dropdown variables here: https://github.com/rstudio/bslib/blob/e0503c6/inst/lib/bs/scss/_variables.scss#L781)fg
and then body-color
if set? Since Bootstrap doesn't have any specific footer variables, if we don't let an existing text color variable affect this, folks will have to use CSS to change.navbar-bg
without setting bg: navbar-bg
in the navbar
section?Thanks a ton for all of this!
Regarding the footer I've now gone with color: mix($body-color, $body-bg, 90%);
which means it'll automatically be lighter than normal text. The percentage could be tweaked if someone disagrees.
It looks like a nice alpha is added to fg by default nail_care Is that right?
Not by pkgdown.sass in any case. :thinking: It comes from bslib!
theme <- bslib::bs_theme(
fg = "#982649",
bg = "white"
)
bslib::bs_get_variables(theme, "body-color")
#> body-color
#> "#A23C5B"
Created on 2021-05-21 by the reprex package (v2.0.0.9000)
I've now made it possible to set the navbar bg via navbar-bg too.
I cannot seem to get component-active-color to affect anything- I was expecting this to change the text color anywhere that component-active-bg affected the background color (so text of active navbar links, text of active sidebar TOC links, and focus icon color for copy/paste button?)
pkgdown.sass fixed for this! Good catch!
what do you think about primary -> navbar-light-active-color + component-active-color? Too much?
I'd first like to have an answer on https://github.com/rstudio/bslib/issues/317 before I add more clunky code. :sweat_smile: would you mind opening a separate issue on this specific mapping? thank you!
what do you think about having the dropdown hover/focus follow secondary if set? (dropdown variables here: rstudio/bslib@e0503c6/inst/lib/bs/scss/_variables.scss#L781)
Could you also open an issue about this? I think it's a good idea but I'd like to add it in a tidy way.
Reg docs I think it'll be better to wait until @hadley reviews the PR, to not document a moving target. Thanks again for all the extremely useful hints & tips!
what do you think about primary -> navbar-light-active-color + component-active-color? Too much?
@apreshill this is now done thanks to @cderv :tada:
Last box checked :tada:
Now border-color too is by default a mix of body-bg and body-color.
A missing mapping is probably the color of text in the navbar. :thinking:
Yes- you mean the non-active/non-hover link color text? With bootswatch, it looks like it is white if dark: https://patchwork.data-imaginist.com/
Looking at bslib variable list I see:
variable | value | comment |
---|---|---|
navbar-light-contrast | if($navbar-light-bg, color-contrast($navbar-light-bg), $black) | Deepest contrasting color for navbarPage(inverse = FALSE). Defaults to $white or $black based on luminance of $navbar-light-bg |
navbar-light-color | rgba($navbar-light-contrast, .5) |
Looks like I cannot currently change anything with navbar-light-contrast
in my _pkgdown.yml
. If set, it looks like it provides a default for hover/active colors too?
@apreshill we've made component-active-bg
inherit from secondary
instead of primary
and now I'm wondering whether this is bad for using Bootswatch themes. :thinking:
Reg navbar-light-contrast
we can't use it because of
.navbar-light .navbar-nav .active > .nav-link {
background: $component-active-bg;
color: $component-active-color;
border-radius: 1rem;
}
navbar-light-color
and navbar-light-hover-color
that I don't want to remove as the default would be much too light (rgba($navbar-light-contrast, .5)
).I've however changed the default: now if navbar-light-color
and navbar-light-hover-color
aren't set in the configuration, they're a bit lighter than the body color. Does that seem correct? This still means navbar-light-contrast
is not usable.
Just some notes for myself. The different places where we are setting/changing things.
$primary
for link-color, and inheritance rules for variables e.g. $component-active-bg
inherits from $primary
. Variables also have default values (or not). This is all seen in https://rstudio.github.io/bslib/articles/bs4-variables.html.$primary
to #0054AD
. Nothing in pkgdown.sass should be hard-coded, except for the ORCID color..btn-copy-ex:active:hover {
background-color: $component-active-bg;
color: $component-active-color;
border-color: $component-active-bg;
}
$component-active-bg
inheriting from secondary instead of primary.$component-active-bg
only inherits from $secondary
if $component-active-bg
is not set in the configuration by the user.
Hi @maelle š
I've been working with the dev version of pkgdown for a bit, and wanted to share what I learned converting a previous CSS to a hybrid/frankenstein BS4 variable setup with additional CSS. I ran into a few issues with Bootstrap 4 variables and tried to annotate as I went.
Here are the variables I used that did seem to work:
And here are the variables that do not seem to work and require some brute-force CSS:
And here was the CSS I needed:
From looking at some of the commits and comments to the
pkgdown.css
file, it looks like some changes were made to improve accessibility (which is great!), but they seem to come at the cost of allowing users to use the Bootstrap variables. Anyway, I'm happy to funnel some of my notes above which variables affect what into your current vignette (https://pkgdown.r-lib.org/dev/articles/customization.html#bslib-variables), but was hoping you might have some ideas for making these 6 variables work šI'm really enjoying customizing this new template! Here is my repo for reference: https://github.com/apreshill/bakeoff
And the deployed site: https://bakeoff.netlify.app/