8 releases

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

#253 in GUI

Download history 245/week @ 2024-08-12 547/week @ 2024-08-19 27/week @ 2024-08-26

819 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–19MB
~260K SLoC