-
Notifications
You must be signed in to change notification settings - Fork 58
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!: Introduce navbar_options()
#1141
Conversation
…-related options in `navset_bar()`
collapsible = collapsible, | ||
underline = underline, | ||
.fn_caller = "page_navbar", | ||
.warn_deprecated = !was_called_by_shiny |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would really really like to decouple shiny::navbarPage()
from bslib::page_navbar()
. I'm thinking it'd be an update to add page_navbar_legacy()
that we'd export but mark as internal so it doesn't show up in docs and indices.
What I want out of that change is to have a clear line around what parts of the navbar API we shouldn't touch without thinking carefully about backwards compatibility or API changes and which parts are owned by bslib. Currently it feels too entangled and over time entropy wins leading to more entanglement.
Do you have any immediate/near-term plans to do this? |
Yeah, I'm planning to immediately use this to introduce |
Sounds good, thanks. FWIW, I do want to be conservative about adding more to the |
Here is the idea I had earlier, but had a hard time articulating. It does drop the extra warning about |
Thanks for the suggestion. I also tried something similar this morning, but I think it's important that I also think it's important to consider that the code is currently a little complicated to give the best transition experience. In a year or so we could delete most of it and hard-deprecate the direct arguments (once we deal with |
Another way to go to fulfill this constraint would be attach the "present" arguments as a character vector attribute on the list.
I won't insist on following my suggestion, but part of why I'm pushing back is that, in my experience, complicated code tends to not get touched/deleted because it's painful to load up all the context. |
Good idea, done in ee683e7 |
R/navs-legacy.R
Outdated
is_default <- attr(options_user, "is_default") %||% list() | ||
for (opt in names(options_old)) { | ||
can_use_direct <- | ||
!opt %in% names(options_user) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is here to account for the fact that we might in the future have deprecated options that aren't available in navbar_options()
? It's not clear to me why we need to account for that situation here, but then silently drop them later in rlang::exec(navbar_options, !!!options_user)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you referring specifically to the !opt %in% names(options_user)
line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it says that NULL
values in navbar_options()
can be overridden by non-null direct values, but I've changed this in the latest commit.
I've reworked this so that navbar_options(bg = NULL)
wins in the presence of a direct use of bg
, since the signal is that the user put bg
in navbar_options()
. The implicit bg = NULL
in navbar_options()
is (still) overridden by a direct bg = "red"
or similar.
The end result is that navbar_options_resolve_deprecated()
returns an object that is completely equivalent to one that would be created by directly calling navbar_options()
. This means that when we elevate to deprecation errors instead of warnings, the only code we need to delete is the unreachable branch inside navbar_options_resolve_deprecated()
and some easy-to-identify test code.
This PR consolidates the
position
,bg
,collapse
,inverse
andunderline
arguments ofnavset_bar()
andpage_navbar()
into anavbar_options()
helper and replaces their use in the parent functions with a singlenavbar_options
argument.Before
After
Using the direct arguments results in a lifecycle deprecation warning
and another warning is emitted if the same argument is used in both places
Background
The reason for this PR is two-fold:
The arguments of
page_navbar()
andnavset_bar()
are applied in several different contexts, but there are clear groupings. This change makes it clearer which arguments apply to the navbar appearance and style by separating them from the remaining arguments.This change makes it easier to introduce new navbar options to
page_navbar()
andnavset_bar()
. Bootstrap 5 has moved away from the default/inverse terminology and has improved the terminology around the navbar colors. (Isinverse = TRUE
for light on dark background or dark text on light background? I can never remember.)Bootstrap 5 now uses
data-bs-theme="dark"
and the color mode terminology, where"light"
is like a light color mode, i.e. dark text on a light background. It'd be nice to make the navbar functions consistent with this new language in a backwards-compatible way.However, if we were to introduce
mode
ortype
as a top-level argument, it'd be far too confusing with the other arguments. If we introducenavbar_mode
ornavbar_type
, it's equally confusing -- why is onlymode
ortype
prefixed withnavbar_
? Introducing anavbar_options()
helper gives us the space to have better named arguments. It also creates space to have Bootstrap version-aware options and defaults.