patternfly_yew/utils/
styled.rs

1use yew::{html::IntoPropValue, prelude::*, virtual_dom::VNode};
2
3/// Wrap an element with style.
4pub struct Styled<T>
5where
6    T: Into<Html>,
7{
8    pub content: T,
9    pub style: Option<AttrValue>,
10}
11
12impl<T> Styled<T>
13where
14    T: Into<Html>,
15{
16    pub fn into_html(self) -> Html {
17        html! (
18            <span style={&self.style}>
19                { self.content.into() }
20            </span>
21        )
22    }
23}
24
25impl<T> From<Styled<T>> for VNode
26where
27    T: Into<Html>,
28{
29    fn from(value: Styled<T>) -> Self {
30        value.into_html()
31    }
32}
33
34impl<T> IntoPropValue<Html> for Styled<T>
35where
36    T: Into<Html>,
37{
38    fn into_prop_value(self) -> Html {
39        self.into_html()
40    }
41}
42
43impl<T> IntoPropValue<Option<Html>> for Styled<T>
44where
45    T: Into<Html>,
46{
47    fn into_prop_value(self) -> Option<Html> {
48        Some(self.into_html())
49    }
50}