8 releases

0.2.4 Aug 21, 2024
0.2.3 Aug 21, 2024
0.1.2 Aug 17, 2024

#1568 in Web programming

Download history 745/week @ 2024-08-17 61/week @ 2024-08-24 13/week @ 2024-08-31 16/week @ 2024-09-14 22/week @ 2024-09-21 21/week @ 2024-09-28

193 downloads per month
Used in yew-attrs-macro

MIT license

11KB
200 lines

yew-attrs

Dynamic attributes for Yew.

Documentation

Documentation for the crates is available on Docs.rs:


lib.rs:

Dynamic attributes for Yew.

Example

use yew::{prelude::*, virtual_dom::VTag};
use yew_attrs::{attrs, Attrs};

#[derive(PartialEq, Properties)]
struct ButtonProps {
    #[prop_or_default]
    pub node_ref: NodeRef,
    #[prop_or_default]
    pub attrs: Attrs,
    #[prop_or_default]
    pub children: Html,
}

#[function_component]
fn Button(props: &ButtonProps) -> Html {
    props
        .attrs
        .clone()
        .new_vtag(
            "button",
            props.node_ref.clone(),
            Default::default(),
            props.children.clone(),
        )
        .into()
}

#[function_component]
fn App() -> Html {
    let on_click = use_callback((), |_, _| {});

    html! {
        <Button attrs={attrs! {class="text-red" disabled=false onclick={on_click}}}>
            {"Click"}
        </Button>
    }
}

Dependencies

~11–20MB
~266K SLoC