1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use yew::{html::IntoPropValue, prelude::*, virtual_dom::VNode};

/// Wrap an element with style.
pub struct Styled<T>
where
    T: Into<Html>,
{
    pub content: T,
    pub style: Option<AttrValue>,
}

impl<T> Styled<T>
where
    T: Into<Html>,
{
    pub fn into_html(self) -> Html {
        html! (
            <span style={&self.style}>
                { self.content.into() }
            </span>
        )
    }
}

impl<T> From<Styled<T>> for VNode
where
    T: Into<Html>,
{
    fn from(value: Styled<T>) -> Self {
        value.into_html()
    }
}

impl<T> IntoPropValue<Html> for Styled<T>
where
    T: Into<Html>,
{
    fn into_prop_value(self) -> Html {
        self.into_html()
    }
}

impl<T> IntoPropValue<Option<Html>> for Styled<T>
where
    T: Into<Html>,
{
    fn into_prop_value(self) -> Option<Html> {
        Some(self.into_html())
    }
}