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 pub fn new() -> Self {
58 Self
59 }
60
61 fn render<V: 'static>(self, _view: &mut V, cx: &mut ViewContext<V>) -> impl Component<V> {
62 Story::container(cx)
63 .child(Story::title_for::<_, Details<V>>(cx))
64 .child(Story::label(cx, "Default"))
65 .child(Details::new("The quick brown fox jumps over the lazy dog"))
66 .child(Story::label(cx, "With meta"))
67 .child(
68 Details::new("The quick brown fox jumps over the lazy dog")
69 .meta_text("Sphinx of black quartz, judge my vow."),
70 )
71 .child(Story::label(cx, "With meta and actions"))
72 .child(
73 Details::new("The quick brown fox jumps over the lazy dog")
74 .meta_text("Sphinx of black quartz, judge my vow.")
75 .actions(ButtonGroup::new(vec![
76 Button::new("Decline"),
77 Button::new("Accept").variant(crate::ButtonVariant::Filled),
78 ])),
79 )
80 }
81 }
82}