Trait review::ElementBuilder
source · [−]pub trait ElementBuilder {
fn with_child<T: Into<VNode>>(self, child: T) -> VElement;
fn with_children(self, children: Vec<VNode>) -> VElement;
fn with_attribute(self, key: &str, value: &str) -> VElement;
fn with_attributes(self, attributes: Vec<(&str, &str)>) -> VElement;
fn with_event(self, event: EventType, callback: Event) -> VElement;
}
Expand description
This is the API to declare VNode in reView
reView doesn’t implement any macro to mimic JSX syntax (too much effort to develop, test, and maintain such macro)
Instead it define a fluent API to declare VNode from a Tag or a VElement. Then the obtained VElement can be converted in a VNode calling into()
Example
let vnode: VNode = Main
.with_children(children!(
Img.with_attribute("class", "logo")
.with_attribute("src", "/assets/logo.png")
.with_attribute("alt", "reView logo"),
H1.with_child("Hello World!"),
Span.with_attribute("class", "subtitle")
.with_children(children!(
"from reView with ",
I.with_attribute("class", "heart")
))
))
.into();