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();

Required Methods

This function is used to append a child that implements Into to a Tag or a VElement and return a VElement

Example
let mut velement = Div.with_child(Button);
velement.with_child(Span.with_child("hello!!"));

This function is used to append a list of children VNode to a Tag or a VElement and return a VElement

Example
let velement = Div.with_children(vec!(Button.into(), Div.into(), A.into()));

or to avoid the .into() calls

Example
let velement = Div.with_children(children!(Button, Div, A));

This function is used to append an attribute to a Tag or a VElement and return a VElement

Example
let mut velement = A.with_attribute("href", "https://malpenzibo.github.io/review/");
velement.with_attribute("target", "_blank");

This function is used to append a list of attributes to a Tag or a VElement and return a VElement

Example
let velement = Div.with_attributes(vec!(
    ("href", "https://malpenzibo.github.io/review/"),
    ("target", "_blank")
));

This function is used to append an event to a Tag or a VElement and return a VElement

Example
let mut velement = Div.with_event(OnClick, callback!(move || log::info!("hello!!")));
velement.with_event(OnMouseEnter, callback!(move || log::info!("mouseEnter!!")));

Implementors