callout_row.rs

 1use component::{example_group_with_title, single_example};
 2use gpui::{AnyElement, App, IntoElement, RenderOnce, Window};
 3use smallvec::SmallVec;
 4use ui::{Label, prelude::*};
 5
 6#[derive(IntoElement, RegisterComponent)]
 7pub struct CalloutRow {
 8    title: SharedString,
 9    lines: SmallVec<[SharedString; 4]>,
10}
11
12impl CalloutRow {
13    pub fn new(title: impl Into<SharedString>) -> Self {
14        Self {
15            title: title.into(),
16            lines: SmallVec::new(),
17        }
18    }
19
20    pub fn line(mut self, line: impl Into<SharedString>) -> Self {
21        self.lines.push(line.into());
22        self
23    }
24}
25
26impl RenderOnce for CalloutRow {
27    fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
28        div().px_2().child(
29            v_flex()
30                .p_3()
31                .gap_1()
32                .bg(cx.theme().colors().surface_background)
33                .border_1()
34                .border_color(cx.theme().colors().border_variant)
35                .rounded_md()
36                .child(Label::new(self.title).weight(gpui::FontWeight::MEDIUM))
37                .children(
38                    self.lines
39                        .into_iter()
40                        .map(|line| Label::new(line).size(LabelSize::Small).color(Color::Muted)),
41                ),
42        )
43    }
44}
45
46impl Component for CalloutRow {
47    fn scope() -> ComponentScope {
48        ComponentScope::Layout
49    }
50
51    fn sort_name() -> &'static str {
52        "RowCallout"
53    }
54
55    fn preview(_window: &mut Window, _cx: &mut App) -> Option<AnyElement> {
56        let examples = example_group_with_title(
57            "CalloutRow Examples",
58            vec![
59                single_example(
60                    "Privacy Notice",
61                    CalloutRow::new("We don't use your code to train AI models")
62                        .line("You choose which providers you enable, and they have their own privacy policies.")
63                        .line("Read more about our privacy practices in our Privacy Policy.")
64                        .into_any_element(),
65                ),
66                single_example(
67                    "Single Line",
68                    CalloutRow::new("Important Notice")
69                        .line("This is a single line of information.")
70                        .into_any_element(),
71                ),
72                single_example(
73                    "Multi Line",
74                    CalloutRow::new("Getting Started")
75                        .line("Welcome to Zed! Here are some things to know:")
76                        .line("• Use Cmd+P to quickly open files")
77                        .line("• Use Cmd+Shift+P to access the command palette")
78                        .line("• Check out the documentation for more tips")
79                        .into_any_element(),
80                ),
81            ],
82        );
83
84        Some(v_flex().p_4().gap_4().child(examples).into_any_element())
85    }
86}