Skip to content

Commit 5f50b5a

Browse files
committed
chore(navbar_options): Add docs, rename type -> theme
1 parent 0309d76 commit 5f50b5a

File tree

3 files changed

+112
-38
lines changed

3 files changed

+112
-38
lines changed

shiny/ui/_navs.py

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -998,13 +998,13 @@ def __init__(self, value: T):
998998
NavbarOptionsPositionT = Literal[
999999
"static-top", "fixed-top", "fixed-bottom", "sticky-top"
10001000
]
1001-
NavbarOptionsTypeT = Literal["auto", "light", "dark"]
1001+
NavbarOptionsThemeT = Literal["auto", "light", "dark"]
10021002

10031003

10041004
class NavbarOptions:
10051005
position: NavbarOptionsPositionT
10061006
bg: Optional[str]
1007-
type: NavbarOptionsTypeT
1007+
theme: NavbarOptionsThemeT
10081008
underline: bool
10091009
collapsible: bool
10101010
attrs: dict[str, Any]
@@ -1015,7 +1015,7 @@ def __init__(
10151015
*,
10161016
position: MaybeMissing[NavbarOptionsPositionT] = MISSING,
10171017
bg: MaybeMissing[str | None] = MISSING,
1018-
type: MaybeMissing[NavbarOptionsTypeT] = MISSING,
1018+
theme: MaybeMissing[NavbarOptionsThemeT] = MISSING,
10191019
underline: MaybeMissing[bool] = MISSING,
10201020
collapsible: MaybeMissing[bool] = MISSING,
10211021
**attrs: TagAttrValue,
@@ -1024,13 +1024,13 @@ def __init__(
10241024

10251025
self.position = self._maybe_default("position", position, default="static-top")
10261026
self.bg = self._maybe_default("bg", bg, default=None)
1027-
self.type = self._maybe_default("type", type, default="auto")
1027+
self.theme = self._maybe_default("theme", theme, default="auto")
10281028
self.underline = self._maybe_default("underline", underline, default=True)
10291029
self.collapsible = self._maybe_default("collapsible", collapsible, default=True)
10301030

10311031
if "inverse" in attrs:
10321032
warn_deprecated(
1033-
"`navbar_options()` does not support `inverse`, please use `type_` instead."
1033+
"`navbar_options()` does not support `inverse`, please use `theme` instead."
10341034
)
10351035
del attrs["inverse"]
10361036

@@ -1049,7 +1049,7 @@ def __eq__(self, other: Any):
10491049
return (
10501050
self.position == other.position
10511051
and self.bg == other.bg
1052-
and self.type == other.type
1052+
and self.theme == other.theme
10531053
and self.underline == other.underline
10541054
and self.collapsible == other.collapsible
10551055
and self.attrs == other.attrs
@@ -1071,15 +1071,51 @@ def __repr__(self):
10711071
def navbar_options(
10721072
position: MaybeMissing[NavbarOptionsPositionT] = MISSING,
10731073
bg: MaybeMissing[str | None] = MISSING,
1074-
type: MaybeMissing[NavbarOptionsTypeT] = MISSING,
1074+
theme: MaybeMissing[NavbarOptionsThemeT] = MISSING,
10751075
underline: MaybeMissing[bool] = MISSING,
10761076
collapsible: MaybeMissing[bool] = MISSING,
10771077
**attrs: TagAttrValue,
10781078
) -> NavbarOptions:
1079+
"""
1080+
Configure the appearance and behavior of the navbar.
1081+
1082+
Parameters:
1083+
-----------
1084+
position
1085+
Determines whether the navbar should be displayed at the top of the page with
1086+
normal scrolling behavior (`"static-top"`), pinned at the top (`"fixed-top"`),
1087+
or pinned at the bottom (`"fixed-bottom"`). Note that using `"fixed-top"` or
1088+
`"fixed-bottom"` will cause the navbar to overlay your body content, unless you
1089+
add padding (e.g., `tags.style("body {padding-top: 70px;}")`)
1090+
1091+
bg
1092+
Background color of the navbar (a CSS color).
1093+
1094+
theme
1095+
The navbar theme: either `"dark"` for a light text color (on a **dark**
1096+
background) or `"light"` for a dark text color (on a **light** background). If
1097+
`"auto"` (the default) and `bg` is provided, the best contrast to `bg` is
1098+
chosen.
1099+
1100+
underline
1101+
If `True`, adds an underline effect to the navbar.
1102+
1103+
collapsible
1104+
If `True`, automatically collapses the elements into an expandable menu on
1105+
mobile devices or narrow window widths.
1106+
1107+
**attrs : dict
1108+
Additional HTML attributes to apply to the navbar container element.
1109+
1110+
Returns:
1111+
--------
1112+
NavbarOptions
1113+
A NavbarOptions object configured with the specified options.
1114+
"""
10791115
return NavbarOptions(
10801116
position=position,
10811117
bg=bg,
1082-
type=type,
1118+
theme=theme,
10831119
underline=underline,
10841120
collapsible=collapsible,
10851121
**attrs,
@@ -1121,7 +1157,7 @@ def navbar_options_resolve_deprecated(
11211157
if not isinstance(inverse_old, bool):
11221158
raise ValueError(f"Invalid `inverse` value: {inverse}")
11231159

1124-
options_old["type"] = "dark" if inverse_old else "light"
1160+
options_old["theme"] = "dark" if inverse_old else "light"
11251161

11261162
options_user = options_user if options_user is not None else navbar_options()
11271163

@@ -1136,7 +1172,7 @@ def navbar_options_resolve_deprecated(
11361172
if opt not in options_resolved:
11371173
options_resolved[opt] = options_old[opt]
11381174
elif options_old[opt] != options_resolved[opt]:
1139-
ignored.append("inverse" if opt == "type" else opt)
1175+
ignored.append("inverse" if opt == "theme" else opt)
11401176

11411177
if ignored:
11421178
warn_deprecated(
@@ -1237,7 +1273,7 @@ def layout(self, nav: Tag, content: Tag) -> TagList:
12371273
# bslib supports navbar-default/navbar-inverse (which is no longer
12381274
# a thing in Bootstrap 5) in a way that's still useful, especially Bootswatch.
12391275
nav_final.add_class(
1240-
"navbar-inverse" if self.navbar_options.type == "dark" else "navbar-default"
1276+
"navbar-inverse" if self.navbar_options.theme == "dark" else "navbar-default"
12411277
)
12421278

12431279
if self.navbar_options.bg:
@@ -1347,8 +1383,8 @@ def navset_bar(
13471383
padding: Optional[CssUnit | list[CssUnit]] = None,
13481384
header: TagChild = None,
13491385
footer: TagChild = None,
1350-
fluid: bool = True,
13511386
navbar_options: Optional[NavbarOptions] = None,
1387+
fluid: bool = True,
13521388
# Deprecated ----
13531389
position: MaybeMissing[NavbarOptionsPositionT] = DEPRECATED,
13541390
bg: MaybeMissing[str | None] = DEPRECATED,
@@ -1390,24 +1426,43 @@ def navset_bar(
13901426
be used for top, the second will be left and right, and the third will be
13911427
bottom. If four, then the values will be interpreted as top, right, bottom, and
13921428
left respectively. This value is only used when the navbar is `fillable`.
1429+
header
1430+
UI to display above the selected content.
1431+
footer
1432+
UI to display below the selected content.
1433+
fluid
1434+
``True`` to use fluid layout; ``False`` to use fixed layout.
1435+
navbar_options
1436+
Configure the appearance and behavior of the navbar using
1437+
:func:`~shiny.ui.navbar_options` to set properties like position, background
1438+
color, and more.
1439+
1440+
`navbar_options` was added in v1.3.0 and replaces deprecated arguments
1441+
`position`, `bg`, `inverse`, `collapsible`, and `underline`.
13931442
position
1443+
Deprecated in v1.3.0. Please use `navbar_options` instead; see
1444+
:func:`~shiny.ui.navbar_options` for details.
1445+
13941446
Determines whether the navbar should be displayed at the top of the page with
13951447
normal scrolling behavior ("static-top"), pinned at the top ("fixed-top"), or
13961448
pinned at the bottom ("fixed-bottom"). Note that using "fixed-top" or
13971449
"fixed-bottom" will cause the navbar to overlay your body content, unless you
13981450
add padding (e.g., ``tags.style("body {padding-top: 70px;}")``).
1399-
header
1400-
UI to display above the selected content.
1401-
footer
1402-
UI to display below the selected content.
14031451
bg
1452+
Deprecated in v1.3.0. Please use `navbar_options` instead; see
1453+
:func:`~shiny.ui.navbar_options` for details.
1454+
14041455
Background color of the navbar (a CSS color).
14051456
inverse
1457+
Deprecated in v1.3.0. Please use `navbar_options` instead; see
1458+
:func:`~shiny.ui.navbar_options` for details.
1459+
14061460
Either ``True`` for a light text color or ``False`` for a dark text color.
14071461
collapsible
1408-
``True`` to automatically collapse the navigation elements into an expandable menu on mobile devices or narrow window widths.
1409-
fluid
1410-
``True`` to use fluid layout; ``False`` to use fixed layout.
1462+
Deprecated in v1.3.0. Please use `navbar_options` instead; see
1463+
:func:`~shiny.ui.navbar_options` for details.
1464+
1465+
``True`` to automatically collapse the elements into an expandable menu on mobile devices or narrow window widths.
14111466
14121467
See Also
14131468
--------

shiny/ui/_page.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,10 @@ def page_navbar(
218218
be used for top, the second will be left and right, and the third will be
219219
bottom. If four, then the values will be interpreted as top, right, bottom, and
220220
left respectively. This value is only used when the navbar is _fillable_.
221-
position
222-
Determines whether the navbar should be displayed at the top of the page with
223-
normal scrolling behavior ("static-top"), pinned at the top ("fixed-top"), or
224-
pinned at the bottom ("fixed-bottom"). Note that using "fixed-top" or
225-
"fixed-bottom" will cause the navbar to overlay your body content, unless you
226-
add padding (e.g., ``tags.style("body {padding-top: 70px;}")``).
227221
header
228222
UI to display above the selected content.
229223
footer
230224
UI to display below the selected content.
231-
bg
232-
Background color of the navbar (a CSS color).
233-
inverse
234-
Either ``True`` for a light text color or ``False`` for a dark text color.
235-
collapsible
236-
``True`` to automatically collapse the elements into an expandable menu on mobile devices or narrow window widths.
237-
fluid
238-
``True`` to use fluid layout; ``False`` to use fixed layout.
239225
window_title
240226
The browser's window title (defaults to the host URL of the page). Can also be
241227
set as a side effect via :func:`~shiny.ui.panel_title`.
@@ -254,6 +240,39 @@ def page_navbar(
254240
255241
To modify the theme of an app without replacing the Bootstrap CSS entirely, use
256242
:func:`~shiny.ui.include_css` to add custom CSS.
243+
fluid
244+
``True`` to use fluid layout; ``False`` to use fixed layout.
245+
navbar_options
246+
Configure the appearance and behavior of the navbar using
247+
:func:`~shiny.ui.navbar_options` to set properties like position, background
248+
color, and more.
249+
250+
`navbar_options` was added in v1.3.0 and replaces deprecated arguments
251+
`position`, `bg`, `inverse`, `collapsible`, and `underline`.
252+
position
253+
Deprecated in v1.3.0. Please use `navbar_options` instead; see
254+
:func:`~shiny.ui.navbar_options` for details.
255+
256+
Determines whether the navbar should be displayed at the top of the page with
257+
normal scrolling behavior ("static-top"), pinned at the top ("fixed-top"), or
258+
pinned at the bottom ("fixed-bottom"). Note that using "fixed-top" or
259+
"fixed-bottom" will cause the navbar to overlay your body content, unless you
260+
add padding (e.g., ``tags.style("body {padding-top: 70px;}")``).
261+
bg
262+
Deprecated in v1.3.0. Please use `navbar_options` instead; see
263+
:func:`~shiny.ui.navbar_options` for details.
264+
265+
Background color of the navbar (a CSS color).
266+
inverse
267+
Deprecated in v1.3.0. Please use `navbar_options` instead; see
268+
:func:`~shiny.ui.navbar_options` for details.
269+
270+
Either ``True`` for a light text color or ``False`` for a dark text color.
271+
collapsible
272+
Deprecated in v1.3.0. Please use `navbar_options` instead; see
273+
:func:`~shiny.ui.navbar_options` for details.
274+
275+
``True`` to automatically collapse the elements into an expandable menu on mobile devices or narrow window widths.
257276
258277
Returns
259278
-------

tests/pytest/test_navs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,15 @@ def test_navbar_options_inverse_true():
216216
with pytest.warns(ShinyDeprecationWarning, match="`inverse`"):
217217
result = navbar_options_resolve_deprecated(options_user, inverse=True)
218218
assert isinstance(result, NavbarOptions)
219-
assert result.type == "dark"
219+
assert result.theme == "dark"
220220

221221

222222
def test_navbar_options_inverse_false():
223223
options_user = navbar_options()
224224
with pytest.warns(ShinyDeprecationWarning, match="`inverse`"):
225225
result = navbar_options_resolve_deprecated(options_user, inverse=False)
226226
assert isinstance(result, NavbarOptions)
227-
assert result.type == "light"
227+
assert result.theme == "light"
228228

229229

230230
def test_navbar_options_inverse_invalid():
@@ -272,7 +272,7 @@ def test_navbar_options_all_deprecated_arguments():
272272
options_user = navbar_options()
273273
with pytest.warns(
274274
ShinyDeprecationWarning,
275-
match="The arguments of `navset_bar\\(\\)` for navbar options",
275+
match="arguments of `navset_bar\\(\\)` for navbar options",
276276
):
277277
result = navbar_options_resolve_deprecated(
278278
options_user,
@@ -283,14 +283,14 @@ def test_navbar_options_all_deprecated_arguments():
283283
underline=True,
284284
)
285285
assert isinstance(result, NavbarOptions)
286-
assert result.type == "dark"
286+
assert result.theme == "dark"
287287

288288

289289
def test_navbar_options_fn_caller_custom():
290290
options_user = navbar_options()
291291
with pytest.warns(
292292
ShinyDeprecationWarning,
293-
match="The arguments of `custom_caller\\(\\)` for navbar options",
293+
match="arguments of `custom_caller\\(\\)` for navbar options",
294294
):
295295
result = navbar_options_resolve_deprecated(
296296
options_user,

0 commit comments

Comments
 (0)