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