Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fully dynamic attributes #452

Open
untitaker opened this issue Nov 17, 2024 · 0 comments
Open

Fully dynamic attributes #452

untitaker opened this issue Nov 17, 2024 · 0 comments
Labels
context aware escaping This feature depends on Maud treating certain elements and attributes in a special way

Comments

@untitaker
Copy link

#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.

@lambda-fairy lambda-fairy added the context aware escaping This feature depends on Maud treating certain elements and attributes in a special way label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
context aware escaping This feature depends on Maud treating certain elements and attributes in a special way
Projects
None yet
Development

No branches or pull requests

2 participants