-
Notifications
You must be signed in to change notification settings - Fork 26
Description
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.