Skip to content

feat: Move navbar_options into single argument with helper navbar_options() #1822

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

Merged
merged 20 commits into from
Feb 27, 2025

Conversation

gadenbuie
Copy link
Collaborator

@gadenbuie gadenbuie commented Jan 16, 2025

Moves navbar options position, bg, inverse, underline and collapsibe into a navbar_options argument in ui.page_navbar() and ui.navset_bar(). These options can be prepared with a new helper ui.navbar_options(). Further, inverse is replaced with theme in ui.navber_options().

Reflects changes in

The top-level direct arguments are now deprecated, but users can continue to use them (with a deprecation warning).

@gadenbuie gadenbuie changed the title feat: Move navbar_options() into single argument with helper feat: Move navbar_options into single argument with helper navbar_options() Jan 16, 2025
@gadenbuie gadenbuie marked this pull request as ready for review January 16, 2025 22:17
inverse: bool = False,
underline: bool = True,
collapsible: bool = True,
navbar_options: Optional[NavbarOptions] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel somewhat on the fence about this, but would you be open to having types.NavbarOptions inherit from TypedDict? The benefit being that we wouldn't need ui.navbar_options(). FWIW, the animate argument of input_slider() follows that pattern.

Copy link
Collaborator Author

@gadenbuie gadenbuie Jan 21, 2025

Choose a reason for hiding this comment

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

Totally open to it and it's certainly a route I thought about taking. It's a little more complicated because there are methods on NavbarOptions, so we'd need a user-facing NavbarOptions that inherits from TypedDict and a counterpart NavbarOptionsResolved (or similar name) class that resolves the user-facing options.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It turns out it's a bit more complicated because, unlike AnimationOptions, the navbar options are not a closed set, which means we can't just call NavbarOptionsResolved(**navbar_options) without making the type checker angry.

Code sample in pyright playground

from typing import TypedDict

class NavbarOptions(TypedDict, total = False):
    underline: bool
    __extra_items__: str

def test(x: NavbarOptions) -> bool:
    return x.get("underline", False)


test({"underline": True})
test({"class": "my-class"}) # we want this to be okay
#> Argument of type "dict[str, str]" cannot be assigned to parameter "x" of type "NavbarOptions" in function "test"
#>  "class" is an undefined item in type "NavbarOptions"  (reportArgumentType)

test({"underline": True, "class": "my-class"})
#> Argument of type "dict[str, bool | str]" cannot be assigned to parameter "x" of type "NavbarOptions" in function "test"
#>  "class" is an undefined item in type "NavbarOptions"  (reportArgumentType)

It turns out there's a PEP for this but it's still in draft mode: https://peps.python.org/pep-0728/

@gadenbuie gadenbuie added this to the Next Release milestone Feb 19, 2025
Comment on lines +10 to +14
### Breaking changes

* The navbar-related style options of `ui.page_navbar()` and `ui.navset_bar()` have been consolidated into a single `navbar_options` argument that pairs with a new `ui.navbar_options()` helper. Using the direct `position`, `bg`, `inverse`, `collapsible`, and `underline` arguments will continue to work with a deprecation message.

Related to this change, `ui.navset_bar()` now defaults to using `underline=True` so that it uses the same set of default `ui.navbar_options()` as the page variant. In `ui.navbar_options()`, `inverse` is replaced by `theme`, which takes values `"light"` (dark text on a **light** background), `"dark"` (light text on a **dark** background), or `"auto"` (follow page settings).
Copy link
Collaborator

@cpsievert cpsievert Feb 26, 2025

Choose a reason for hiding this comment

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

Since the "breaking" change here could be considered more of an improvement than a regression, I'd be in favor of renaming this section to ### Changes (or even ### Improvements and putting it just after ### New features.

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 had the same thought, but we do emit deprecation warnings that say, effectively, "your current code is being deprecated, please update it". I know it's not strictly breaking but I'd personally rather read a changelog that differentiates between "you might need to take action" and "you might want to know about this" items.

@gadenbuie gadenbuie merged commit 3fe8c64 into main Feb 27, 2025
41 checks passed
@gadenbuie gadenbuie deleted the feat/navbar-options branch February 27, 2025 19:52
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