Struct ElementBuilder

Source
pub struct ElementBuilder { /* private fields */ }
Expand description

Build an HTML element.

Implementations§

Source§

impl ElementBuilder

Source

pub fn new(tag: impl AsRef<str>) -> Self

Source

pub fn attribute<T>( self, name: impl AsRef<str>, value: impl AttributeValue<T>, ) -> Self

Set an attribute. Attribute values can be reactive.

Source

pub fn child(self, child: impl Into<Element>) -> Self

Add a child element after existing children. The child element can be reactive.

Source

pub fn text(self, child: impl Text) -> Self

Add a text node after existing children. The text node can be reactive.

Source

pub fn effect<T>(self, child: impl Effect<T>) -> Self

Apply an effect after the next render. For example, to set the focus of an element:

element.effect(|elem: &HtmlInputElement| elem.focus().unwrap());

Effects can be reactive. For example, to set the visibibilty of an item based on a hidden boolean signal:

let hidden = Signal::new(false);
let is_hidden = hidden.read();

element.effect(is_hidden.map(|&hidden| move |elem: &HtmlInputElement| elem.set_hidden(hidden)));
Source

pub fn on(self, name: &'static str, f: impl 'static + FnMut(JsValue)) -> Self

Register an event handler.

name is the name of the event. See the MDN Events page for a list.

f is the callback when the event fires and will be passed the javascript Event object.

Trait Implementations§

Source§

impl Builder for ElementBuilder

Source§

impl DomElement for ElementBuilder

Source§

impl From<ElementBuilder> for Element

Source§

fn from(builder: ElementBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.