Skip to content

Allow accepting/passing arbitrary sets of attributes to components #181

@circuitsacul

Description

@circuitsacul

Say I have a component; for example, a wrapper around an <a> tag that adds commonly used HTMX attributes. I would like to also allow the caller to define the ID & classes, and other attributes on the tag, without having to list all possible attributes in the component definition.

#[component]
fn htmx_link<'a, R: Renderable>(url: &'a str, children: &R) -> impl Renderable {
    maud! {
        a
            /* how do I accept the id/classes here... */
            href=(url)
            hx-get=(url)
            hx-push-url=true
            hx-swap="none"
            hx-target={"#" (target)}
        { (children) }
    }
}

// elsewhere....
maud! {
    HtmxLink #i-still-want .to-customize[this == "stuff"] url="my/link" { "clicky" }
}

It would also be nice if I could use the native maud syntax for the IDs, classes, optional/conditional attributes, etc. (as I've done above), but having any way to pass in a list of "extra" attributes that are arbitrarily applied to the underlying tag would be wonderful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions