Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(navbar_options): Match Bootstrap 5 semantics #1146

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Dec 4, 2024

This PR was extracted from #1145 for easier review. The goal of this PR is:

  1. Replace inverse with type in navbar_options(). This replaces an overloaded binary option with an enum that currently accepts "auto" (default), "light" or "dark". There is still room for confusion around the meaning of light and dark, but it's easy to define and consistently used throughout bslib, Bootstrap, brand.yml, Quarto, etc. (light means light background, dark foreground, dark means dark background, light foreground).

  2. Include data-bs-theme in the navbar markup in a backwards-compatible way.

  3. Allow navbar_options(...) to include attributes that are passed to the nav container, making it possible to set class = "bg-primary" or other attributes, e.g. style. Users could also set data-bs-theme here directly, since that syntax appears in Bootstrap and Bootswatch docs.

Note that this PR does not change navbar appearance, so the scope of this PR is from R code to HTML markup.

FYI: In a follow-up PR I plan to move navbar_options() and related helpers from R/navs-legacy.R to R/navbar_options.R.

R/navs-legacy.R Outdated Show resolved Hide resolved
R/navs-legacy.R Outdated
Comment on lines 350 to 419
inverse <- TRUE
if (identical(theme_preset_info(theme)$name, "shiny")) {
inverse <- FALSE
if (is.null(theme) || theme_version(theme) < 5) {
inverse <- TRUE
Copy link
Collaborator

@cpsievert cpsievert Dec 4, 2024

Choose a reason for hiding this comment

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

I think I'm OK with this, but would you mind writing down the thought process behind it?

Also, this will change navbar appearance for Bootswatch themes (and vanilla Bootstrap), so assuming we're OK with that, let's make sure to call it out as a breaking change in the NEWS

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I think the code is easier to review with the smaller PRs, but the context is a bit spread out. The motivation is outlined in the first part of the description in #1145.

In short, in Bootstrap 5 inverse = type = "auto" now means "match the current light/dark mode". Before this, it "auto" meant "pick for me".

We could get into setting class and type attributes here to get navbar colors that match the current defaults. The continuity would be nice, but it'd add work and complexity that I'm not sure is worth the effort.

R/navs-legacy.R Outdated Show resolved Hide resolved
R/navs-legacy.R Outdated Show resolved Hide resolved
R/navs-legacy.R Outdated
collapsible = .navbar_options$collapsible,
underline = .navbar_options$underline,
# theme is only used to determine whether legacy style markup should be used
# (and, at least at the moment, we don't need legacy markup for this exported function)
theme = bs_theme()
)

navbar_options_apply_attribs(navbar, .navbar_options)
Copy link
Collaborator

@cpsievert cpsievert Dec 4, 2024

Choose a reason for hiding this comment

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

I think navbar_options_apply_attribs() could be easier to reason about if you assume that it gets passed a tag object and a list of attributes.

Suggested change
navbar_options_apply_attribs(navbar, .navbar_options)
navbar[[1]] <- navbar_options_apply_attribs(navbar[[1]], .navbar_options$attribs)
navbar

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, this hits on something I was noticing also, which is that navs_bar_() is not-quite legacy code, since it involves handling BS 5 styles. In this PR and others I was trying to hold a line where navs_bar_() was touched as little as possible for legacy reasons.

But this, and a few other changes, would be much better handled inside navs_bar_() than from the outside.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, yea, I see where you're coming from. Feel free to resolve this one

Copy link
Member Author

Choose a reason for hiding this comment

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

I moved all of the logic of navbar_options_apply_attribs() into navs_bar_(), which cleans up a lot of this logic and removed the need for a few other comments that I've resolved.

Copy link
Collaborator

@cpsievert cpsievert Dec 4, 2024

Choose a reason for hiding this comment

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

Nice, I like it, thanks!

R/navs-legacy.R Outdated Show resolved Hide resolved
R/navs-legacy.R Outdated Show resolved Hide resolved
R/navs-legacy.R Outdated Show resolved Hide resolved
R/navs-legacy.R Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this difference go away with #1145?

Copy link
Member Author

Choose a reason for hiding this comment

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

No probably not. It comes from the navbar having data-bs-theme="dark" ... which is how Bootstrap recommends doing this. I'll look into it more to see if there's something we're missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here's a stackblitz example based on the Bootstrap docs examples.

The way around that is to put make sure the dropdown menu resets to light.

<ul class="dropdown-menu" data-bs-theme="light">

R/navs-legacy.R Outdated Show resolved Hide resolved
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