Embedded sidebar #978
Replies: 5 comments 3 replies
-
@solara.component
def Sidebar(children=[]):
"""Puts its children in the sidebar of the AppLayout (or any layout that supports it).
This component does not need to be a direct child of the AppLayout, it can be at any level in your component tree."""
...
|
Beta Was this translation helpful? Give feedback.
-
Further reading into the docs: Nested LayoutsEach subdirectory (or subpackage) can define a This is useful for larger apps where each subdirectory may add a bit of layout/chrome around your page. This sounds like what I'm looking for, but it doesn't work as expected.
routes = [
solara.Route(
path="root",
children=[
solara.Route(path="workbench", component=Workbench),
],
layout=Layout,
),
] Then my workbench component
@solara.component
def Layout(children=[]):
with solara.Sidebar():
with rv.ListGroup():
with rv.ListItem():
solara.Text("1")
with rv.ListItem():
solara.Text("2")
with rv.ListItem():
solara.Text("3")
with rv.ListItem():
solara.Text("4")
solara.Div(children=children) and @solara.component
def Workbench():
with rv.Container(class_="mt-5"):
Wizard() My end goal is that the workbench route comes with a sidebar that acts as a set of vertical tabs. A click on a tab will render the body of the Workbench (right of the sidebar) with the corresponding wizard component. |
Beta Was this translation helpful? Give feedback.
-
Defining a |
Beta Was this translation helpful? Give feedback.
-
I'm trying to slowly build a nested layout (great if you could provide an example 🙏). Considering that by itself, def Tester():
with solara.Sidebar():
solara.Text("I'm in the sidebar")
solara.Text("I'm in the body") Looking into the code of the ...
children_without_portal_sources = [c for c in children if c.component != AppBar]
use_drawer = len(children_without_portal_sources) > 1
children_content = children
children_sidebar = []
if use_drawer:
child_sidebar = children_without_portal_sources.pop(0)
children_sidebar = [child_sidebar]
children_content = [c for c in children if c is not child_sidebar]
children_sidebar = children_sidebar + sidebar_portal.use_portal()
children_appbar = appbar_portal.use_portal()
if children_sidebar:
use_drawer = True
... I assume that @solara.component
def TesterLayout(children=[]):
print(children)
sidebar_open, set_sidebar_open = solara.use_state_or_update(False)
children_without_portal_sources = [
c for c in children if c.component != solara.applayout.AppBar
]
use_drawer = len(children_without_portal_sources) > 1
children_content = children
children_sidebar = []
if use_drawer:
child_sidebar = children_without_portal_sources.pop(0)
children_sidebar = [child_sidebar]
children_content = [c for c in children if c is not child_sidebar]
print(children_sidebar)
solara.Div(children=children)
[Div(classes = ['solara-autorouter-content'], children = ...)] On inspection of the DOM, it seems the sidebar children (as well as the content children) are somewhere in the children of this
Note that replacing the code of @iisakkirotko any advice here would be greatly appreciated. I am trying to understand the intended usage of |
Beta Was this translation helpful? Give feedback.
-
That the contents of the sidebar should be used in the layout in question. For children_sidebar = children_sidebar + sidebar_portal.use_portal()
...
if embedded_mode and not fullscreen:
...
else:
with v.Html(tag="div", style_="height: 100vh") as main:
with solara.HBox():
if use_drawer:
with v.NavigationDrawer(
...
):
if not show_app_bar:
AppIcon(sidebar_open, on_click=lambda: set_sidebar_open(not sidebar_open))
v.Html(tag="div", children=children_sidebar, style_="...").meta(ref="sidebar-content") Where we first get the children that have been injected into the portal, and then render them.
That being said, I don't think I follow what you mean with embed in this context?
I think your minimal layout @solara.component
def TesterLayout(children=[]):
print(children)
sidebar_open, set_sidebar_open = solara.use_state_or_update(False)
children_without_portal_sources = [
c for c in children if c.component != solara.applayout.AppBar
]
use_drawer = len(children_without_portal_sources) > 1
children_content = children
children_sidebar = []
if use_drawer:
child_sidebar = children_without_portal_sources.pop(0)
children_sidebar = [child_sidebar]
children_content = [c for c in children if c is not child_sidebar]
print(children_sidebar)
solara.Div(children=children) Is missing the line children_sidebar += sidebar_portal.use_portal() which actually fetches all the children that should be injected into the global Sidebar element. This is needed because instead of being a conventional component, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
My app has several pages. I manage my own app bar navigation component. One of my pages could use a sidebar. But it appears that the sidebar cannot be embedded. If I am mistaken, please let me know how I can do this.
Beta Was this translation helpful? Give feedback.
All reactions