patternfly_yew/core/
content.rs1use std::ops::{Deref, DerefMut};
2use yew::html::IntoPropValue;
3use yew::prelude::*;
4
5#[derive(Clone, Debug, Default, PartialEq)]
7pub struct OptionalHtml(pub Option<Html>);
8
9impl Deref for OptionalHtml {
10 type Target = Option<Html>;
11
12 fn deref(&self) -> &Self::Target {
13 &self.0
14 }
15}
16
17impl DerefMut for OptionalHtml {
18 fn deref_mut(&mut self) -> &mut Self::Target {
19 &mut self.0
20 }
21}
22
23impl IntoPropValue<Option<Html>> for OptionalHtml {
24 fn into_prop_value(self) -> Option<Html> {
25 self.0
26 }
27}
28
29impl From<Html> for OptionalHtml {
30 fn from(value: Html) -> Self {
31 Self(Some(value))
32 }
33}
34
35impl From<Option<Html>> for OptionalHtml {
36 fn from(value: Option<Html>) -> Self {
37 Self(value)
38 }
39}
40
41impl From<&str> for OptionalHtml {
42 fn from(value: &str) -> Self {
43 Self(Some(Html::from(value)))
44 }
45}
46
47impl From<String> for OptionalHtml {
48 fn from(value: String) -> Self {
49 Self(Some(Html::from(value)))
50 }
51}
52
53impl IntoPropValue<OptionalHtml> for &str {
54 fn into_prop_value(self) -> OptionalHtml {
55 self.into()
56 }
57}
58
59impl IntoPropValue<OptionalHtml> for String {
60 fn into_prop_value(self) -> OptionalHtml {
61 self.into()
62 }
63}
64
65impl IntoPropValue<OptionalHtml> for Html {
66 fn into_prop_value(self) -> OptionalHtml {
67 self.into()
68 }
69}
70
71impl IntoPropValue<OptionalHtml> for Option<Html> {
72 fn into_prop_value(self) -> OptionalHtml {
73 self.into()
74 }
75}
76
77impl<COMP: BaseComponent> IntoPropValue<OptionalHtml> for yew::virtual_dom::VChild<COMP> {
78 fn into_prop_value(self) -> OptionalHtml {
79 let html: Html = self.into();
80 html.into()
81 }
82}