1use crate::prelude::*;
2use crate::{h_flex, Icon, IconName, IconSize, Label};
3
4#[derive(IntoElement)]
5pub struct ListSubHeader {
6 label: SharedString,
7 start_slot: Option<IconName>,
8 inset: bool,
9}
10
11impl ListSubHeader {
12 pub fn new(label: impl Into<SharedString>) -> Self {
13 Self {
14 label: label.into(),
15 start_slot: None,
16 inset: false,
17 }
18 }
19
20 pub fn left_icon(mut self, left_icon: Option<IconName>) -> Self {
21 self.start_slot = left_icon;
22 self
23 }
24
25 pub fn inset(mut self, inset: bool) -> Self {
26 self.inset = inset;
27 self
28 }
29}
30
31impl RenderOnce for ListSubHeader {
32 fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
33 h_flex().flex_1().w_full().relative().py_1().child(
34 div()
35 .h_6()
36 .when(self.inset, |this| this.px_2())
37 .flex()
38 .flex_1()
39 .w_full()
40 .gap_1()
41 .items_center()
42 .justify_between()
43 .child(
44 div()
45 .flex()
46 .gap_1()
47 .items_center()
48 .children(
49 self.start_slot
50 .map(|i| Icon::new(i).color(Color::Muted).size(IconSize::Small)),
51 )
52 .child(Label::new(self.label.clone()).color(Color::Muted)),
53 ),
54 )
55 }
56}