Skip to content

Fully dynamic attributes #452

@untitaker

Description

@untitaker

#444 from @BadMannersXYZ got me thinking. I currently use maud like JSX, in that I define components like this:

fn my_custom_form(...) -> Markup { html! { form { .. } } }

// later

fn main_view() -> Markup {
    html! {
        (my_custom_form())
    }
}

In React-land, I'd write:

<MyCustomForm />

Now my problem is that I'd like to add custom classes and attributes to my "component" from the caller side. <form class="foobar"> for example. In JSX, I'd write:

<MyCustomForm className="foobar" />

And the MyCustomForm would forward all props to the underlying form element.

How about this API in Rust?

fn my_custom_form(attrs: maud::Attributes) -> Markup {
    html! {
        form (..attrs) { .. }
    }
}

fn main_view() -> Markup {
    html! {
        (my_custom_form(maud::attributes!(.foobar)))
    }
}

maud could expose alternative ways to construct maud::Attributes as well, and solve usecases related to #444 as well in one go.

Metadata

Metadata

Assignees

No one assigned

    Labels

    context aware escapingThis feature depends on Maud treating certain elements and attributes in a special way

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions