yew_bs/components/
text.rs

1use yew::prelude::*;
2use crate::components::common::{
3    TextAlign, TextWrap, TextTransform, FontWeight, FontStyle, TextDecoration, LineHeight,
4};
5#[derive(Properties, PartialEq)]
6pub struct TextProps {
7    #[prop_or_default]
8    pub align: Option<TextAlign>,
9    #[prop_or_default]
10    pub wrap: Option<TextWrap>,
11    #[prop_or_default]
12    pub transform: Option<TextTransform>,
13    #[prop_or_default]
14    pub weight: Option<FontWeight>,
15    #[prop_or_default]
16    pub style: Option<FontStyle>,
17    #[prop_or_default]
18    pub decoration: Option<TextDecoration>,
19    #[prop_or_default]
20    pub line_height: Option<LineHeight>,
21    #[prop_or_default]
22    pub children: Children,
23    #[prop_or_default]
24    pub class: Option<AttrValue>,
25}
26#[function_component(TextUtility)]
27pub fn text_utility(props: &TextProps) -> Html {
28    let mut classes = Classes::new();
29    if let Some(align) = &props.align {
30        classes.push(align.as_str());
31    }
32    if let Some(wrap) = &props.wrap {
33        classes.push(wrap.as_str());
34    }
35    if let Some(transform) = &props.transform {
36        classes.push(transform.as_str());
37    }
38    if let Some(weight) = &props.weight {
39        classes.push(weight.as_str());
40    }
41    if let Some(style) = &props.style {
42        classes.push(style.as_str());
43    }
44    if let Some(decoration) = &props.decoration {
45        classes.push(decoration.as_str());
46    }
47    if let Some(line_height) = &props.line_height {
48        classes.push(line_height.as_str());
49    }
50    if let Some(custom_class) = &props.class {
51        classes.push(custom_class.to_string());
52    }
53    html! {
54        < div class = { classes } > { for props.children.iter() } </ div >
55    }
56}