1use std::marker::PhantomData;
2
3use crate::prelude::*;
4
5#[derive(Element, Clone)]
6pub struct Details<S: 'static + Send + Sync + Clone> {
7 state_type: PhantomData<S>,
8 text: &'static str,
9 meta: Option<&'static str>,
10}
11
12impl<S: 'static + Send + Sync + Clone> Details<S> {
13 pub fn new(text: &'static str) -> Self {
14 Self {
15 state_type: PhantomData,
16 text,
17 meta: None,
18 }
19 }
20
21 pub fn meta_text(mut self, meta: &'static str) -> Self {
22 self.meta = Some(meta);
23 self
24 }
25
26 fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
27 let color = ThemeColor::new(cx);
28
29 div()
30 // .flex()
31 // .w_full()
32 .p_1()
33 .gap_0p5()
34 .text_xs()
35 .text_color(color.text)
36 .child(self.text)
37 .children(self.meta.map(|m| m))
38 }
39}
40
41#[cfg(feature = "stories")]
42pub use stories::*;
43
44#[cfg(feature = "stories")]
45mod stories {
46 use crate::Story;
47
48 use super::*;
49
50 #[derive(Element)]
51 pub struct DetailsStory<S: 'static + Send + Sync + Clone> {
52 state_type: PhantomData<S>,
53 }
54
55 impl<S: 'static + Send + Sync + Clone> DetailsStory<S> {
56 pub fn new() -> Self {
57 Self {
58 state_type: PhantomData,
59 }
60 }
61
62 fn render(
63 &mut self,
64 _view: &mut S,
65 cx: &mut ViewContext<S>,
66 ) -> impl Element<ViewState = S> {
67 Story::container(cx)
68 .child(Story::title_for::<_, Details<S>>(cx))
69 .child(Story::label(cx, "Default"))
70 .child(Details::new("The quick brown fox jumps over the lazy dog"))
71 .child(Story::label(cx, "With meta"))
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 )
76 }
77 }
78}