Add Details component
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
pub mod avatar;
|
pub mod avatar;
|
||||||
pub mod button;
|
pub mod button;
|
||||||
|
pub mod details;
|
||||||
pub mod icon;
|
pub mod icon;
|
||||||
pub mod input;
|
pub mod input;
|
||||||
pub mod label;
|
pub mod label;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
use ui::prelude::*;
|
||||||
|
use ui::Details;
|
||||||
|
|
||||||
|
use crate::story::Story;
|
||||||
|
|
||||||
|
#[derive(Element)]
|
||||||
|
pub struct DetailsStory<S: 'static + Send + Sync + Clone> {
|
||||||
|
state_type: PhantomData<S>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: 'static + Send + Sync + Clone> DetailsStory<S> {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
state_type: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
|
||||||
|
Story::container(cx)
|
||||||
|
.child(Story::title_for::<_, Details<S>>(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."),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ use ui::prelude::*;
|
|||||||
pub enum ElementStory {
|
pub enum ElementStory {
|
||||||
Avatar,
|
Avatar,
|
||||||
Button,
|
Button,
|
||||||
|
Details,
|
||||||
Icon,
|
Icon,
|
||||||
Input,
|
Input,
|
||||||
Label,
|
Label,
|
||||||
@@ -26,6 +27,7 @@ impl ElementStory {
|
|||||||
match self {
|
match self {
|
||||||
Self::Avatar => elements::avatar::AvatarStory::new().into_any(),
|
Self::Avatar => elements::avatar::AvatarStory::new().into_any(),
|
||||||
Self::Button => elements::button::ButtonStory::new().into_any(),
|
Self::Button => elements::button::ButtonStory::new().into_any(),
|
||||||
|
Self::Details => elements::details::DetailsStory::new().into_any(),
|
||||||
Self::Icon => elements::icon::IconStory::new().into_any(),
|
Self::Icon => elements::icon::IconStory::new().into_any(),
|
||||||
Self::Input => elements::input::InputStory::new().into_any(),
|
Self::Input => elements::input::InputStory::new().into_any(),
|
||||||
Self::Label => elements::label::LabelStory::new().into_any(),
|
Self::Label => elements::label::LabelStory::new().into_any(),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
mod avatar;
|
mod avatar;
|
||||||
mod button;
|
mod button;
|
||||||
|
mod details;
|
||||||
mod icon;
|
mod icon;
|
||||||
mod input;
|
mod input;
|
||||||
mod label;
|
mod label;
|
||||||
@@ -9,6 +10,7 @@ mod tool_divider;
|
|||||||
|
|
||||||
pub use avatar::*;
|
pub use avatar::*;
|
||||||
pub use button::*;
|
pub use button::*;
|
||||||
|
pub use details::*;
|
||||||
pub use icon::*;
|
pub use icon::*;
|
||||||
pub use input::*;
|
pub use input::*;
|
||||||
pub use label::*;
|
pub use label::*;
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
use crate::theme;
|
||||||
|
|
||||||
|
#[derive(Element, Clone)]
|
||||||
|
pub struct Details<S: 'static + Send + Sync + Clone> {
|
||||||
|
state_type: PhantomData<S>,
|
||||||
|
text: &'static str,
|
||||||
|
meta: Option<&'static str>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: 'static + Send + Sync + Clone> Details<S> {
|
||||||
|
pub fn new(text: &'static str) -> Self {
|
||||||
|
Self {
|
||||||
|
state_type: PhantomData,
|
||||||
|
text,
|
||||||
|
meta: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn meta_text(mut self, meta: &'static str) -> Self {
|
||||||
|
self.meta = Some(meta);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render(&mut self, cx: &mut ViewContext<S>) -> impl Element<State = S> {
|
||||||
|
let theme = theme(cx);
|
||||||
|
|
||||||
|
div()
|
||||||
|
// .flex()
|
||||||
|
// .w_full()
|
||||||
|
.p_1()
|
||||||
|
.gap_0p5()
|
||||||
|
.text_xs()
|
||||||
|
.text_color(theme.lowest.base.default.foreground)
|
||||||
|
.child(self.text)
|
||||||
|
.children(self.meta.map(|m| m))
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user