Skip to content

[Idea] allow repeated attribute extension! #6

Closed
@bessey

Description

@bessey

Hey guys, saw your pip package in an HN thread and it really scratched an itch for me. I've been playing around with it and Tailwind to see if I can build a Python native UI framework.

This script:

import htpy as h

button = h.button(".btn")

submit_input = h.input(".btn", type="submit")

checkbox_input = h.input(".checkbox", type="checkbox")

print(
    h.div[
        h.p["Hello, World!"],
        button(".bottom")["Click me!"],
        checkbox_input(name="test"),
        submit_input(value="Submit"),
    ]
)

Outputs: (I'm adding newlines for readability)

<div>
<p>Hello, World!</p>
<button class="bottom">Click me!</button>
<input name="test"><input value="Submit">
</div>

Where as I would have expected successive Element() calls to accumulate attributes, and intelligently merge accumulated classes, e.g.

<div>
<p>Hello, World!</p>
<button class="btn bottom">Click me!</button>
<input class="checkbox" type="checkbox" name="test">
<input class="btn" type="submit" value="Submit">
</div>

For what its worth, with just one line change I was able to get the attribute accumulation by prepending **self._attrs, here.

Thoughts? I appreciate this can be worked around with the UI Component pattern you mention, but applying that at such a low level makes composition quite painful. Presumably you would end up almost never being able to use the clever element()[] syntax since its all wrapped in method calls.

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