Merge pull request #128 from DioxusLabs/jk/optional-tag
feat: add "optional" flag for props
This commit is contained in:
2 files changed
+23
-1
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
//! Example: README.md showcase
|
//! Example: README.md showcase
|
||||||
//!
|
//!
|
||||||
//! The example from the README.md.
|
//! The example from the README.md.
|
||||||
@@ -14,6 +16,7 @@ fn app(cx: Scope) -> Element {
|
|||||||
a: "asd".to_string(),
|
a: "asd".to_string(),
|
||||||
c: Some("asd".to_string()),
|
c: Some("asd".to_string()),
|
||||||
d: "asd".to_string(),
|
d: "asd".to_string(),
|
||||||
|
e: "asd".to_string(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -30,8 +33,19 @@ struct ButtonProps {
|
|||||||
|
|
||||||
#[props(default, strip_option)]
|
#[props(default, strip_option)]
|
||||||
d: Option<String>,
|
d: Option<String>,
|
||||||
|
|
||||||
|
#[props(optional)]
|
||||||
|
e: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn Button(cx: Scope<ButtonProps>) -> Element {
|
fn Button(cx: Scope<ButtonProps>) -> Element {
|
||||||
todo!()
|
cx.render(rsx! {
|
||||||
|
button {
|
||||||
|
"{cx.props.a}"
|
||||||
|
"{cx.props.b:?}"
|
||||||
|
"{cx.props.c:?}"
|
||||||
|
"{cx.props.d:?}"
|
||||||
|
"{cx.props.e:?}"
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
@@ -364,6 +364,14 @@ mod field_info {
|
|||||||
Some(syn::parse(quote!(Default::default()).into()).unwrap());
|
Some(syn::parse(quote!(Default::default()).into()).unwrap());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"optional" => {
|
||||||
|
self.default =
|
||||||
|
Some(syn::parse(quote!(Default::default()).into()).unwrap());
|
||||||
|
self.strip_option = true;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
macro_rules! handle_fields {
|
macro_rules! handle_fields {
|
||||||
( $( $flag:expr, $field:ident, $already:expr; )* ) => {
|
( $( $flag:expr, $field:ident, $already:expr; )* ) => {
|
||||||
|
|||||||
Reference in new issue
Block a user