sidebar: replace header/footer/content slots with custom entries

This commit is contained in:
2026-11-15 20:43:05 +07:00
parent fd6a8c0342
commit 0fda22caf7
2 changed files with 173 additions and 218 deletions
+33 -44
View File
@@ -4257,7 +4257,7 @@ impl Render for SidebarDemo {
),
))
.child(demo_section(
"header and footer slots stay pinned around the list",
"custom entries slot user content around the rows",
colors,
div()
.w(rems(17.5))
@@ -4270,41 +4270,41 @@ impl Render for SidebarDemo {
Sidebar::new("sidebar-demo-slots")
.selected(self.selected)
.transparent(true)
.header(
div()
.px_2()
.py_2()
.text_sm()
.font_weight(FontWeight::MEDIUM)
.child("Library"),
)
.footer(
div()
.px_2()
.py_2()
.text_xs()
.text_color(colors.muted_foreground)
.child("3 of 7 items"),
)
.on_change(move |selected, _, cx| {
view_slots.update(cx, |demo, cx| {
demo.selected = selected;
cx.notify();
});
})
.entries(|_, _| {
.entries(move |_, _| {
vec![
SidebarEntry::custom(
div()
.px_2()
.py_2()
.text_sm()
.font_weight(FontWeight::MEDIUM)
.child("Library"),
),
SidebarEntry::header("Favorites"),
SidebarEntry::row("Documents", "Documents"),
SidebarEntry::row("Pictures", "Pictures").detail("24"),
SidebarEntry::header("Locations"),
SidebarEntry::row("Trash", "Trash"),
SidebarEntry::custom(
div()
.px_2()
.py_2()
.text_xs()
.text_color(colors.muted_foreground)
.child("3 of 7 items"),
),
]
}),
),
))
.child(demo_section(
"custom content replaces the list; the sidebar is a bare container",
"a custom entry fills the list; the right border is off",
colors,
div()
.w(rems(17.5))
@@ -4316,31 +4316,20 @@ impl Render for SidebarDemo {
.child(
Sidebar::new("sidebar-demo-custom")
.transparent(true)
.header(
div()
.px_2()
.py_2()
.text_sm()
.font_weight(FontWeight::MEDIUM)
.child("Welcome"),
)
.content(
div()
.size_full()
.flex()
.items_center()
.justify_center()
.text_color(colors.muted_foreground)
.child("Nothing here yet"),
)
.footer(
div()
.px_2()
.py_2()
.text_xs()
.text_color(colors.muted_foreground)
.child("v1.0"),
),
.border_right(false)
.entries(move |_, _| {
vec![SidebarEntry::custom(
div()
.w_full()
.px_2()
.py_6()
.flex()
.items_center()
.justify_center()
.text_color(colors.muted_foreground)
.child("Nothing here yet"),
)]
}),
),
))
.child(