Skip to content

Better bslib usage#1735

Closed
maelle wants to merge 2 commits intocupcakefrom
bslib-cleaner
Closed

Better bslib usage#1735
maelle wants to merge 2 commits intocupcakefrom
bslib-cleaner

Conversation

@maelle
Copy link
Collaborator

@maelle maelle commented Jul 14, 2021

Thanks to @cpsievert's feedback

Cc @apreshill

`fu-color` = "#4758AB !default",
`border-radius` = "1rem !default",
`navbar-light-color` = "rgba($fg, 0.8) !default",
`navbar-light-hover-color` = "rgba($fg, 0.9) !default"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't use $body-color here as I get the error that it's not defined, but it's actually what I'd want to do.

Copy link

@cpsievert cpsievert Jul 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems more correct to me:

`navbar-light-color` = "rgba(color-contrast($navbar-bg), 0.8) !default",
`navbar-light-hover-color` = "rgba(color-contrast($navbar-bg), 0.9) !default",

@maelle
Copy link
Collaborator Author

maelle commented Jul 14, 2021

Questions

  • is this the general idea?
  • For component-active-bg we had
  # map either secondary OR fg, bg to component-active-bg
  # and also dropdown-link-active-bg
  # unless a value was set by the user

I am guessing from the convo that we might change this logic. Now, if we didn't change that logic, how would that work with this new code? I.e. the current code differentiated between "secondary from BS defaults" and "secondary from user settings".

@cpsievert
Copy link

cpsievert commented Jul 14, 2021

is this the general idea?

Yes! And you should be able to avoid all the if (is.null()) checking using this approach that embraces the !default flag (but you may have to use the pattern oulined below for setting new Bootstrap variable defaults that are based on other, possibly user defined, Bootstrap variables)

For component-active-bg we had

I'm currently thinking #1682 (comment) which could be done by adding another default with a "hard coded" color

pkgdown_bslib_defaults <- function() {
  list(
    ...,
    "list-group-active-bg" = "gray !default"
  )
}

As for other defaults that may want to know what the "final" bg, fg, etc. is, you may have to use a pattern like:

theme <- bslib::bs_theme(
  version = bs_version,
  bootswatch = bootswatch_theme
)

# if pkgdown wants to set new Bootstrap variable defaults based on other Bootstrap variables, you should pass the theme with user defaults added at this point
vars <- pkgdown_bslib_defaults(
  bslib::bs_add_variables(theme, !!!pkg$meta$template$bslib)
)
# but still add _your_ defaults first before the user's
theme <- bslib::bs_add_variables(theme, !!!vars)
theme <- bslib::bs_add_variables(theme, !!!pkg$meta$template$bslib)

...

pkgdown_bslib_defaults <- function(theme) {
  vars <- bs_get_variables(theme, "fg")
  list(
    ...,
    "foo" = vars[["fg"]]
  )
}

@maelle maelle closed this Jul 28, 2021
@hadley hadley deleted the bslib-cleaner branch November 1, 2023 13:02
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

Successfully merging this pull request may close these issues.

2 participants