1use crate::{prelude::*, v_stack, ButtonGroup};
2
3#[derive(Component)]
4pub struct Details<V: 'static> {
5 text: &'static str,
6 meta: Option<&'static str>,
7 actions: Option<ButtonGroup<V>>,
8}
9
10impl<V: 'static> Details<V> {
11 pub fn new(text: &'static str) -> Self {
12 Self {
13 text,
14 meta: None,
15 actions: None,
16 }
17 }
18
19 pub fn meta_text(mut self, meta: &'static str) -> Self {
20 self.meta = Some(meta);
21 self
22 }
23
24 pub fn actions(mut self, actions: ButtonGroup<V>) -> Self {
25 self.actions = Some(actions);
26 self
27 }
28
29 fn render(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
30 let theme = theme(cx);
31
32 v_stack()
33 .p_1()
34 .gap_0p5()
35 .text_xs()
36 .text_color(theme.text)
37 .size_full()
38 .child(self.text)
39 .children(self.meta.map(|m| m))
40 .children(self.actions.map(|a| a))
41 }
42}
43
44#[cfg(feature = "stories")]
45pub use stories::*;
46
47#[cfg(feature = "stories")]
48mod stories {
49 use crate::{Button, Story};
50
51 use super::*;
52
53 #[derive(Component)]
54 pub struct DetailsStory;
55
56 impl DetailsStory {
57 fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
58 Story::container(cx)
59 .child(Story::title_for::<_, Details<V>>(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}