Skip to content

Commit 438fedc

Browse files
committed
Refactor navset_bar panels into reusable function
1 parent 797e5c9 commit 438fedc

File tree

1 file changed

+42
-14
lines changed
  • tests/playwright/shiny/components/nav/navset_bar_kitchensink

1 file changed

+42
-14
lines changed

tests/playwright/shiny/components/nav/navset_bar_kitchensink/app.py

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from shiny.express import ui
1+
from typing import Any
2+
3+
from shiny.express import expressify, ui
24

35

46
def navset_sidebar():
@@ -52,24 +54,50 @@ def navset_sidebar():
5254
),
5355
]
5456

57+
58+
@expressify
59+
def navset_bar_panel(tab_name: str, navset_args: dict[str, Any]) -> None:
60+
with ui.nav_panel(tab_name):
61+
with ui.card(style="position: relative;"):
62+
navset_kwargs = navset_args.copy()
63+
navbar_options_keys = (
64+
"position",
65+
"bg",
66+
"theme",
67+
"inverse",
68+
"collapsible",
69+
"underline",
70+
)
71+
navbar_options_kwargs: dict[str, Any] = {}
72+
for key in navbar_options_keys:
73+
if key not in navset_kwargs:
74+
continue
75+
76+
value = navset_kwargs.pop(key)
77+
78+
if key == "inverse":
79+
navbar_options_kwargs["theme"] = "dark" if value else "light"
80+
else:
81+
navbar_options_kwargs[key] = value
82+
if navbar_options_kwargs:
83+
navset_kwargs["navbar_options"] = ui.navbar_options(
84+
**navbar_options_kwargs
85+
)
86+
87+
with ui.navset_bar(**navset_kwargs):
88+
with ui.nav_panel("A"):
89+
"Panel A content"
90+
91+
with ui.nav_panel("B"):
92+
"Panel B content"
93+
94+
5595
# Add extra spaces so that the navset_tab is below the fixed-top navset_bar
5696
ui.br()
5797
ui.br()
5898
ui.br()
5999
ui.br()
60100

61-
# TODO-karan; Put each navset_bar into a navpanel within a navset_tab (similar to the navsets_kitchensink app)
62101
with ui.navset_tab(id="navsets_collection"):
63102
for tab_name, navset_args in navset_bar_infos:
64-
with ui.nav_panel(tab_name):
65-
66-
with ui.card(style="position: relative;"):
67-
68-
with ui.navset_bar(
69-
**navset_args # pyright: ignore[reportArgumentType]
70-
):
71-
with ui.nav_panel("A"):
72-
"Panel A content"
73-
74-
with ui.nav_panel("B"):
75-
"Panel B content"
103+
navset_bar_panel(tab_name, navset_args)

0 commit comments

Comments
 (0)