[][src]Struct valerie::Tag

pub struct Tag<T> { /* fields omitted */ }

An HTML Tag

Macros are defined for easier use of few tags. Can also be used to make other tags also.

Implementations

impl<T> Tag<T> where
    T: JsCast,
    T: AsRef<Element>, 
[src]

pub fn new(tag: &'static str) -> Self[src]

Make a new Tag. You have to specify the Element type i.e. Element or HtmlDivElement etc.

Examples

Tag::<web_sys::Element>::new("div").push("Hello, World!")

impl<T> Tag<T> where
    T: AsRef<Node>, 
[src]

pub fn push<U>(self, component: U) -> Self where
    U: Component
[src]

Push components inside the Tag.

Examples

div!().push("Hello, World!")

pub fn push_multiple<U>(self, components: &[U]) -> Self where
    U: AsRef<Node>, 
[src]

Push multiple components. Rarely used. Use push preferably.

Examples

div!().push_multiple(&[Node::from("Hello, "), Node::from("World!")])

pub fn push_loop<F, U>(self, n: usize, func: F) -> Self where
    F: Fn(usize) -> U,
    U: Component
[src]

Push components as a loop from 0 to n (exclusive).

Examples

div!().push_loop(5, |x| h3!(x))

impl<T> Tag<T> where
    T: AsRef<Node> + Clone + 'static, 
[src]

pub fn on_event<F, U>(self, event: impl AsRef<str>, var: U, func: F) -> Self where
    U: 'static,
    F: FnMut(&mut U, &mut T) + 'static, 
[src]

Attach an event to the Tag.

Examples

let message = StateMutex::new(String::new());
button!(message.clone())
    .on_event("mouseover", message.clone(), |x, _| {
        x.put("Mouse pointer is in me".to_string())
    })
    .on_event("mouseout", message.clone(), |x, _| {
        x.put("Mouse pointer is outside".to_string())
    })
    .on_event("mousedown", message.clone(), |x, _| {
        x.put("Mouse button pressed".to_string())
    })

impl<T> Tag<T> where
    T: AsRef<Element>, 
[src]

pub fn id(self, id: impl AsRef<str>) -> Self[src]

Set the id of the Tag.

Examples

div!("Hello, World!")
    .id("hello-world")

pub fn get_id(&self) -> String[src]

Get the id of the Tag.

Examples

let heading = h1!("Hello, World!").id("hello-world-id");
div!(heading.clone(), br!(), "id ", heading.get_id())

pub fn class(self, class: impl AsRef<str>) -> Self[src]

Set the class of the Tag.

Examples

div!("Hello, World!")
    .class("heading")

pub fn get_class(&self) -> String[src]

Get the class of the Tag.

Examples

let heading = h1!("Hello, World!").class("heading");
div!(heading.clone(), br!(), "class ", heading.get_class())

pub fn attr(self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self[src]

Set the attribute of the Tag by key and value.

Examples

div!("Hello, World!")
    .attr("id", "hello-world")

pub fn get_attr(&self, key: impl AsRef<str>) -> Option<String>[src]

Get the attribute of the Tag by key.

Examples

let heading = h1!("Hello, World!").attr("id", "hello-world");
div!(
    heading.clone(),
    br!(),
    "attr ",
    heading.get_attr("id").unwrap()
)

impl Tag<HtmlInputElement>[src]

pub fn bind<T>(self, var: T) -> Self where
    T: StateTrait + 'static,
    T::Value: FromStr + Default
[src]

One way bind to the input element. Any change in the state variable won't be reflected back to the input element.

Examples

let state = StateMutex::new(String::new());
div!(
    state.clone(),
    br!(),
    input!("text").bind(state.clone()),
    input!("text").bind(state)
)

pub fn double_bind<T>(self, var: T) -> Self where
    T: StateTrait + 'static,
    T::Value: FromStr + Default,
    T::Channel: Deref<Target = String>, 
[src]

Two way bind to the input element. Any change in the state variable will be reflected back to the input element.

Examples

let state = StateMutex::new(String::new());
div!(
    state.clone(),
    br!(),
    input!("text").double_bind(state.clone()),
    input!("text").double_bind(state)
)

pub fn bind_func<T, F>(self, var: T, func: F) -> Self where
    T: StateTrait + 'static,
    F: FnOnce(String) -> T::Value,
    F: 'static + Copy
[src]

A function to bind to the input element. This function gets called every time the event input fires i.e. when the user enters and input.

Examples

let state = StateAtomic::new(0usize);
div!(
    state.clone(),
    br!(),
    input!("text").bind_func(state, |x| x.len())
)

pub fn placeholder(self, text: impl AsRef<str>) -> Self[src]

To add placeholder for the input element.

Examples

input!("text")
    .placeholder("Enter something...")

Trait Implementations

impl<T> AsRef<Node> for Tag<T> where
    T: JsCast
[src]

impl<T: Clone> Clone for Tag<T>[src]

impl<T> Component for Tag<T> where
    T: JsCast
[src]

impl<T> Deref for Tag<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T> DerefMut for Tag<T>[src]

impl<T> From<Tag<T>> for Node where
    T: JsCast
[src]

impl<T> From<Tag<T>> for Node where
    T: JsCast
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Tag<T> where
    T: RefUnwindSafe

impl<T> Send for Tag<T> where
    T: Send

impl<T> Sync for Tag<T> where
    T: Sync

impl<T> Unpin for Tag<T> where
    T: Unpin

impl<T> UnwindSafe for Tag<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.