data: add pinned strip overlay for sidebar custom content

This commit is contained in:
2026-11-12 05:00:40 +07:00
parent 97106b7a3a
commit 72118bdd6c
2 changed files with 79 additions and 42 deletions
+25 -2
View File
@@ -1,7 +1,7 @@
//! The sidebar: a controlled list with section headers — the Finder
//! sidebar's model of rows grouped under non-selectable labels. Custom content
//! replaces the list and takes the whole container; the header and footer
//! slots apply only to the entry list.
//! replaces the list and takes the whole container, sliding under a pinned
//! strip; the header and footer slots apply only to the entry list.
use std::rc::Rc;
@@ -124,6 +124,7 @@ pub struct Sidebar {
header: Option<AnyElement>,
content: Option<AnyElement>,
footer: Option<AnyElement>,
strip: Option<AnyElement>,
}
impl Sidebar {
@@ -142,6 +143,7 @@ impl Sidebar {
header: None,
content: None,
footer: None,
strip: None,
}
}
@@ -207,6 +209,15 @@ impl Sidebar {
self
}
/// Pins a titlebar strip at the sidebar's top, custom content renders behind it.
pub fn strip<E>(mut self, strip: E) -> Self
where
E: IntoElement,
{
self.strip = Some(strip.into_any_element());
self
}
/// Overrides the accessibility label, which defaults to the id.
pub fn accessibility_label<L>(mut self, label: L) -> Self
where
@@ -229,6 +240,7 @@ impl RenderOnce for Sidebar {
header,
content,
footer,
strip,
} = self;
let custom = content.is_some();
@@ -344,6 +356,15 @@ impl RenderOnce for Sidebar {
let theme = cx.theme();
let (leading_strip, overlay_strip) = match strip {
Some(strip) if custom => (
None,
Some(div().absolute().top_0().left_0().right_0().child(strip)),
),
Some(strip) => (Some(strip), None),
None => (None, None),
};
div()
.id(id.clone())
.debug_selector(move || format!("sidebar-{debug_id}"))
@@ -355,9 +376,11 @@ impl RenderOnce for Sidebar {
.when(custom, |sidebar| {
sidebar.role(Role::Group).aria_label(label)
})
.when_some(leading_strip, |sidebar, strip| sidebar.child(strip))
.when_some(header, |sidebar, header| sidebar.child(header))
.child(body)
.when_some(footer, |sidebar, footer| sidebar.child(footer))
.when_some(overlay_strip, |sidebar, strip| sidebar.child(strip))
}
}