Add Details
component
This commit is contained in:
parent
d956bd3743
commit
42e9800bde
5 changed files with 76 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
mod avatar;
|
||||
mod button;
|
||||
mod details;
|
||||
mod icon;
|
||||
mod input;
|
||||
mod label;
|
||||
|
@ -9,6 +10,7 @@ mod tool_divider;
|
|||
|
||||
pub use avatar::*;
|
||||
pub use button::*;
|
||||
pub use details::*;
|
||||
pub use icon::*;
|
||||
pub use input::*;
|
||||
pub use label::*;
|
||||
|
|
40
crates/ui2/src/elements/details.rs
Normal file
40
crates/ui2/src/elements/details.rs
Normal file
|
@ -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))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue