implement spreading props in the rsx macro

This commit is contained in:
Evan Almloff committed 2023-09-22 10:04:34 -05:00
1 parent 9e167dfdb7
commit 5b65c4cfb4
7 files changed
+208 -102

No files matched your search

+8 -8
View File
@@ -1,6 +1,7 @@
use convert_case::{Case, Casing};
use dioxus_rsx::{
BodyNode, CallBody, Component, Element, ElementAttr, ElementAttrNamed, ElementName, IfmtInput,
AttributeType, BodyNode, CallBody, Component, Element, ElementAttr, ElementAttrNamed,
ElementName, IfmtInput,
};
pub use html_parser::{Dom, Node};
use proc_macro2::{Ident, Span};
@@ -34,7 +35,7 @@ pub fn rsx_node_from_html(node: &Node) -> Option<BodyNode> {
Ident::new(new_name.as_str(), Span::call_site())
};
ElementAttrNamed {
AttributeType::Named(ElementAttrNamed {
el_name: el_name.clone(),
attr: ElementAttr {
value: dioxus_rsx::ElementAttrValue::AttrLiteral(ifmt_from_text(
@@ -42,13 +43,13 @@ pub fn rsx_node_from_html(node: &Node) -> Option<BodyNode> {
)),
name: dioxus_rsx::ElementAttrName::BuiltIn(ident),
},
}
})
})
.collect();
let class = el.classes.join(" ");
if !class.is_empty() {
attributes.push(ElementAttrNamed {
attributes.push(AttributeType::Named(ElementAttrNamed {
el_name: el_name.clone(),
attr: ElementAttr {
name: dioxus_rsx::ElementAttrName::BuiltIn(Ident::new(
@@ -57,11 +58,11 @@ pub fn rsx_node_from_html(node: &Node) -> Option<BodyNode> {
)),
value: dioxus_rsx::ElementAttrValue::AttrLiteral(ifmt_from_text(&class)),
},
});
}));
}
if let Some(id) = &el.id {
attributes.push(ElementAttrNamed {
attributes.push(AttributeType::Named(ElementAttrNamed {
el_name: el_name.clone(),
attr: ElementAttr {
name: dioxus_rsx::ElementAttrName::BuiltIn(Ident::new(
@@ -70,7 +71,7 @@ pub fn rsx_node_from_html(node: &Node) -> Option<BodyNode> {
)),
value: dioxus_rsx::ElementAttrValue::AttrLiteral(ifmt_from_text(id)),
},
});
}));
}
let children = el.children.iter().filter_map(rsx_node_from_html).collect();
@@ -82,7 +83,6 @@ pub fn rsx_node_from_html(node: &Node) -> Option<BodyNode> {
merged_attributes: Default::default(),
key: None,
brace: Default::default(),
extra_attributes: None,
}))
}