use std::marker::PhantomData; use crate::{prelude::*, v_stack, ButtonGroup}; #[derive(Element)] pub struct Details { state_type: PhantomData, text: &'static str, meta: Option<&'static str>, actions: Option>, } impl Details { pub fn new(text: &'static str) -> Self { Self { state_type: PhantomData, text, meta: None, actions: None, } } pub fn meta_text(mut self, meta: &'static str) -> Self { self.meta = Some(meta); self } pub fn actions(mut self, actions: ButtonGroup) -> Self { self.actions = Some(actions); self } fn render(&mut self, _view: &mut S, cx: &mut ViewContext) -> impl Element { let theme = theme(cx); v_stack() .p_1() .gap_0p5() .text_xs() .text_color(theme.text) .size_full() .child(self.text) .children(self.meta.map(|m| m)) .children(self.actions.take().map(|a| a)) } } #[cfg(feature = "stories")] pub use stories::*; #[cfg(feature = "stories")] mod stories { use crate::{Button, Story}; use super::*; #[derive(Element)] pub struct DetailsStory { state_type: PhantomData, } impl DetailsStory { pub fn new() -> Self { Self { state_type: PhantomData, } } fn render( &mut self, _view: &mut S, cx: &mut ViewContext, ) -> impl Element { Story::container(cx) .child(Story::title_for::<_, Details>(cx)) .child(Story::label(cx, "Default")) .child(Details::new("The quick brown fox jumps over the lazy dog")) .child(Story::label(cx, "With meta")) .child( Details::new("The quick brown fox jumps over the lazy dog") .meta_text("Sphinx of black quartz, judge my vow."), ) .child(Story::label(cx, "With meta and actions")) .child( Details::new("The quick brown fox jumps over the lazy dog") .meta_text("Sphinx of black quartz, judge my vow.") .actions(ButtonGroup::new(vec![ Button::new("Decline"), Button::new("Accept").variant(crate::ButtonVariant::Filled), ])), ) } } }