1use crate::prelude::*;
2use crate::{v_stack, ButtonGroup};
3
4#[derive(Component)]
5pub struct Details<V: 'static> {
6 text: &'static str,
7 meta: Option<&'static str>,
8 actions: Option<ButtonGroup<V>>,
9}
10
11impl<V: 'static> Details<V> {
12 pub fn new(text: &'static str) -> Self {
13 Self {
14 text,
15 meta: None,
16 actions: None,
17 }
18 }
19
20 pub fn meta_text(mut self, meta: &'static str) -> Self {
21 self.meta = Some(meta);
22 self
23 }
24
25 pub fn actions(mut self, actions: ButtonGroup<V>) -> Self {
26 self.actions = Some(actions);
27 self
28 }
29
30 fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
31 v_stack()
32 .p_1()
33 .gap_0p5()
34 .text_xs()
35 .text_color(cx.theme().colors().text)
36 .size_full()
37 .child(self.text)
38 .children(self.meta.map(|m| m))
39 .children(self.actions.map(|a| a))
40 }
41}
42
43#[cfg(feature = "stories")]
44pub use stories::*;
45
46#[cfg(feature = "stories")]
47mod stories {
48 use super::*;
49 use crate::{Button, Story};
50 use gpui::{Div, Render};
51
52 pub struct DetailsStory;
53
54 impl Render for DetailsStory {
55 type Element = Div<Self>;
56
57 fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
58 Story::container(cx)
59 .child(Story::title_for::<_, Details<Self>>(cx))
60 .child(Story::label(cx, "Default"))
61 .child(Details::new("The quick brown fox jumps over the lazy dog"))
62 .child(Story::label(cx, "With meta"))
63 .child(
64 Details::new("The quick brown fox jumps over the lazy dog")
65 .meta_text("Sphinx of black quartz, judge my vow."),
66 )
67 .child(Story::label(cx, "With meta and actions"))
68 .child(
69 Details::new("The quick brown fox jumps over the lazy dog")
70 .meta_text("Sphinx of black quartz, judge my vow.")
71 .actions(ButtonGroup::new(vec![
72 Button::new("Decline"),
73 Button::new("Accept").variant(crate::ButtonVariant::Filled),
74 ])),
75 )
76 }
77 }
78}