Pass string types to Html props (#2872)

* Pass string types to Html props

* Not sure why passing None explicitly here...

* Update test stderr
This commit is contained in:
Cecile Tonglet 2023-02-02 12:00:51 +01:00 committed by GitHub
parent 9556266061
commit bff497e002
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 8 deletions

View File

@ -6,5 +6,5 @@ This is an example that demonstrates `<Suspense />` support.
## Concepts
This example shows that how `<Suspense />` works in Yew and how you can
This example shows how `<Suspense />` works in Yew and how you can
create hooks that utilises suspense.

View File

@ -375,4 +375,46 @@ fn compile_pass() {
::yew::html_nested! { 1 };
}
#[derive(
::std::clone::Clone, ::yew::Properties, ::std::default::Default, ::std::cmp::PartialEq,
)]
pub struct HtmlPassedAsPropProperties {
pub value: ::yew::Html,
}
pub struct HtmlPassedAsProp;
impl ::yew::Component for HtmlPassedAsProp {
type Message = ();
type Properties = HtmlPassedAsPropProperties;
fn create(_ctx: &::yew::Context<Self>) -> Self {
::std::unimplemented!()
}
fn view(&self, _ctx: &::yew::Context<Self>) -> ::yew::Html {
::std::unimplemented!()
}
}
pub struct HtmlPassedAsPropContainer;
impl ::yew::Component for HtmlPassedAsPropContainer {
type Message = ();
type Properties = ();
fn create(_ctx: &::yew::Context<Self>) -> Self {
::std::unimplemented!()
}
fn view(&self, _ctx: &::yew::Context<Self>) -> ::yew::Html {
::yew::html! {
<>
<HtmlPassedAsProp value={::yew::html!()} />
<HtmlPassedAsProp value="string literal" />
<HtmlPassedAsProp value={::std::format!("string")} />
<HtmlPassedAsProp value={::yew::AttrValue::Static("attr value")} />
</>
}
}
}
fn main() {}

View File

@ -480,10 +480,10 @@ error[E0277]: the trait bound `Option<NotToString>: IntoPropValue<Option<implici
|
= help: the following implementations were found:
<Option<&'static str> as IntoPropValue<Option<String>>>
<Option<&'static str> as IntoPropValue<Option<VNode>>>
<Option<&'static str> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<F> as IntoPropValue<Option<yew::Callback<I, O>>>>
<Option<Rc<str>> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
and 4 others
and 7 others
error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<implicit_clone::unsync::IString>>` is not satisfied
--> tests/html_macro/element-fail.rs:48:22
@ -496,10 +496,10 @@ error[E0277]: the trait bound `Option<{integer}>: IntoPropValue<Option<implicit_
|
= help: the following implementations were found:
<Option<&'static str> as IntoPropValue<Option<String>>>
<Option<&'static str> as IntoPropValue<Option<VNode>>>
<Option<&'static str> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<F> as IntoPropValue<Option<yew::Callback<I, O>>>>
<Option<Rc<str>> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
and 4 others
and 7 others
error[E0277]: expected a `Fn<(MouseEvent,)>` closure, found `{integer}`
--> tests/html_macro/element-fail.rs:51:28
@ -594,10 +594,10 @@ error[E0277]: the trait bound `Option<yew::NodeRef>: IntoPropValue<yew::NodeRef>
|
= help: the following implementations were found:
<Option<&'static str> as IntoPropValue<Option<String>>>
<Option<&'static str> as IntoPropValue<Option<VNode>>>
<Option<&'static str> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
<Option<F> as IntoPropValue<Option<yew::Callback<I, O>>>>
<Option<Rc<str>> as IntoPropValue<Option<implicit_clone::unsync::IString>>>
and 4 others
and 7 others
error[E0277]: expected a `Fn<(MouseEvent,)>` closure, found `yew::Callback<String>`
--> tests/html_macro/element-fail.rs:58:29

View File

@ -176,6 +176,9 @@ impl_into_prop!(|value: &'static str| -> AttrValue { AttrValue::Static(value) })
impl_into_prop!(|value: String| -> AttrValue { AttrValue::Rc(Rc::from(value)) });
impl_into_prop!(|value: Rc<str>| -> AttrValue { AttrValue::Rc(value) });
impl_into_prop!(|value: VNode| -> Children { Children::new(vec![value]) });
impl_into_prop!(|value: &'static str| -> VNode { crate::html!(value) });
impl_into_prop!(|value: String| -> VNode { crate::html!(value) });
impl_into_prop!(|value: AttrValue| -> VNode { crate::html!(value) });
impl<T: ImplicitClone + 'static> IntoPropValue<IArray<T>> for &'static [T] {
fn into_prop_value(self) -> IArray<T> {

View File

@ -151,7 +151,7 @@ mod feat_csr_ssr {
let SuspenseProps { children, fallback } = props.clone();
let fallback = html! {
<BaseSuspense fallback={None}>
<BaseSuspense>
{fallback}
</BaseSuspense>
};