sidebar: add header, footer, and custom content slots
This commit is contained in:
@@ -3852,6 +3852,7 @@ struct SidebarDemo {
|
||||
impl Render for SidebarDemo {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let view = cx.entity();
|
||||
let view_slots = view.clone();
|
||||
let theme = cx.theme();
|
||||
let colors = theme.colors;
|
||||
let radius = theme.radius;
|
||||
@@ -3909,6 +3910,93 @@ impl Render for SidebarDemo {
|
||||
}),
|
||||
),
|
||||
))
|
||||
.child(demo_section(
|
||||
"header and footer slots stay pinned around the list",
|
||||
colors,
|
||||
div()
|
||||
.w(rems(17.5))
|
||||
.h(rems(22.5))
|
||||
.rounded(radius.control)
|
||||
.border_1()
|
||||
.border_color(colors.border)
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
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(|_, _| {
|
||||
vec![
|
||||
SidebarEntry::header("Favorites"),
|
||||
SidebarEntry::row("Documents", "Documents"),
|
||||
SidebarEntry::row("Pictures", "Pictures").detail("24"),
|
||||
SidebarEntry::header("Locations"),
|
||||
SidebarEntry::row("Trash", "Trash"),
|
||||
]
|
||||
}),
|
||||
),
|
||||
))
|
||||
.child(demo_section(
|
||||
"custom content replaces the list; the sidebar is a bare container",
|
||||
colors,
|
||||
div()
|
||||
.w(rems(17.5))
|
||||
.h(rems(13.))
|
||||
.rounded(radius.control)
|
||||
.border_1()
|
||||
.border_color(colors.border)
|
||||
.overflow_hidden()
|
||||
.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"),
|
||||
),
|
||||
),
|
||||
))
|
||||
.child(
|
||||
div()
|
||||
.text_xs()
|
||||
|
||||
Reference in New Issue
Block a user