Skip to content

Commit 289e509

Browse files
committed
refactor!: streamline and improve applayout api
1 parent 4ce4cf2 commit 289e509

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

solara/components/applayout.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ def AppLayout(
196196
children=[],
197197
sidebar_open=True,
198198
title=None,
199+
show_app_bar: Optional[bool] = None,
199200
navigation=True,
200-
toolbar_dark=True,
201-
color: Optional[str] = "primary",
201+
toolbar_dark: Optional[bool] = None,
202+
color: Optional[str] = None,
202203
classes: List[str] = [],
203204
style: Optional[Union[str, Dict[str, str]]] = None,
204205
):
@@ -222,9 +223,14 @@ def AppLayout(
222223
223224
# Arguments
224225
225-
* `children`: The children of the AppLayout. The first child is used as the sidebar content, the rest as the main content.
226+
* `children`: The children of the AppLayout. Note: Since Solara 2.0, the first child is no longer placed in the sidebar.
227+
Use [Sidebar](/documentation/components/layout/sidebar) instead.
226228
* `sidebar_open`: Whether the sidebar is open or not.
227229
* `title`: The title of the app shown in the app bar, can also be set using the [Title](/documentation/components/page/title) component.
230+
* `show_app_bar`: Whether the app bar should be shown. If `None` (the default), `AppBar` is shown if:
231+
* There are one or more sibling routes to the current page.
232+
* **OR**: There are one or more children of the `AppBar` component.
233+
* **OR**: There are one or more children of the `AppBarTitle` component.
228234
* `toolbar_dark`: Whether the toolbar should be dark or not.
229235
* `navigation`: Whether the navigation tabs based on routing should be shown.
230236
* `color`: The color of the toolbar.
@@ -243,18 +249,10 @@ def AppLayout(
243249

244250
sidebar_open, set_sidebar_open = solara.use_state_or_update(sidebar_open)
245251
# remove the appbar from the children
246-
children_without_portal_sources = [c for c in children if c.component != AppBar]
247-
use_drawer = len(children_without_portal_sources) > 1
248-
children_content = children
249-
children_sidebar = []
250-
if use_drawer:
251-
child_sidebar = children_without_portal_sources.pop(0)
252-
children_sidebar = [child_sidebar]
253-
children_content = [c for c in children if c is not child_sidebar]
254-
children_sidebar = children_sidebar + sidebar_portal.use_portal()
252+
children_content = [c for c in children if c.component != AppBar]
253+
children_sidebar = sidebar_portal.use_portal()
254+
use_drawer = len(children_sidebar) > 0
255255
children_appbar = appbar_portal.use_portal()
256-
if children_sidebar:
257-
use_drawer = True
258256
title = t.use_title_get() or title
259257
children_appbartitle = apptitle_portal.use_portal()
260258
v_slots = []
@@ -269,7 +267,8 @@ def AppLayout(
269267
children_appbar.remove(tabs)
270268
tabs_to_render = tabs
271269

272-
show_app_bar = (title and (len(routes) > 1 and navigation)) or bool(children_appbar) or bool(use_drawer) or bool(children_appbartitle) or bool(tabs)
270+
if show_app_bar is None:
271+
show_app_bar = (len(routes) > 1) or bool(children_appbar) or bool(use_drawer) or bool(children_appbartitle) or bool(tabs)
273272

274273
if style is None:
275274
style = {"height": "100%", "max-height": "100%", "overflow": "auto"}
@@ -284,7 +283,7 @@ def set_path(index):
284283
if (tabs_to_render is None) and routes and navigation and (len(routes) > 1):
285284
with solara.lab.Tabs(value=index, on_value=set_path, align="center") as tabs_to_render:
286285
for route in routes:
287-
name = route.path if route.path != "/" else "Home"
286+
name = route.label if route.label is not None else (route.path if route.path != "/" else "Home")
288287
solara.lab.Tab(name)
289288
# with v.Tabs(v_model=index, on_v_model=set_path, centered=True) as tabs:
290289
# for route in routes:
@@ -296,7 +295,7 @@ def set_path(index):
296295
# this version doesn't need to run fullscreen
297296
# also ideal in jupyter notebooks
298297
with v.Html(tag="div") as main:
299-
if show_app_bar or use_drawer:
298+
if show_app_bar:
300299
with v.AppBar(color=color, dark=toolbar_dark, v_slots=v_slots):
301300
if use_drawer:
302301
icon = AppIcon(sidebar_open, on_click=lambda: set_sidebar_open(not sidebar_open), v_on="x.on")

0 commit comments

Comments
 (0)