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 ToHtml for OptionalHtml {
24 fn to_html(&self) -> Html {
25 self.0.to_html()
26 }
27
28 fn into_html(self) -> Html
29 where
30 Self: Sized,
31 {
32 self.0.into_html()
33 }
34}
35
36impl From<Html> for OptionalHtml {
37 fn from(value: Html) -> Self {
38 Self(Some(value))
39 }
40}
41
42impl From<Option<Html>> for OptionalHtml {
43 fn from(value: Option<Html>) -> Self {
44 Self(value)
45 }
46}
47
48impl From<&str> for OptionalHtml {
49 fn from(value: &str) -> Self {
50 Self(Some(Html::from(value)))
51 }
52}
53
54impl From<String> for OptionalHtml {
55 fn from(value: String) -> Self {
56 Self(Some(Html::from(value)))
57 }
58}
59
60impl IntoPropValue<OptionalHtml> for &str {
61 fn into_prop_value(self) -> OptionalHtml {
62 self.into()
63 }
64}
65
66impl IntoPropValue<OptionalHtml> for String {
67 fn into_prop_value(self) -> OptionalHtml {
68 self.into()
69 }
70}
71
72impl IntoPropValue<OptionalHtml> for Html {
73 fn into_prop_value(self) -> OptionalHtml {
74 self.into()
75 }
76}
77
78impl IntoPropValue<OptionalHtml> for Option<Html> {
79 fn into_prop_value(self) -> OptionalHtml {
80 self.into()
81 }
82}
83
84impl<COMP: BaseComponent> IntoPropValue<OptionalHtml> for yew::virtual_dom::VChild<COMP> {
85 fn into_prop_value(self) -> OptionalHtml {
86 let html: Html = self.into();
87 html.into()
88 }
89}