Making UI components #29
-
Hello, and thanks so much for both htmy and fasthx, I'm using both of them on a small exploration project at EdgeDB, integrating our authentication extension with FastAPI. I'm primarily a React/TypeScript developer and I have a few questions about how to create reusable UI components, in a similar way to something like shadcn is React/Radix components with Tailwind styling. I've attempted to intuit this by making something like a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi, Thanks for giving these projects a try! I find your feedback very interesting and useful. I'll start with my two takeaways:
Back to your code and the original question. Since you don't use from typing import Literal
from htmy import ComponentType, PropertyValue
ButtonVariant = Literal["primary", "secondary", "link"]
_button_classes: dict[ButtonVariant, str] = {
"primary": "...",
"secondary": "...",
"link": "..."
}
def button(*args: ComponentType, variant: ButtonVariant, **kwargs: PropertyValue) -> html.button:
return html.button(*args, class_=_button_classes[variant], **kwargs) Notes:
Let me know if I can help you with anything else. And I'm also curious about what you think about my thoughts at the beginning of this comment. |
Beta Was this translation helpful? Give feedback.
Hi,
Thanks for giving these projects a try! I find your feedback very interesting and useful. I'll start with my two takeaways:
Formatter
should by default skip properties whose value isNone
. I already prototyped the implementation, I still need to add some tests. We should create an issue for it, the feature could be included in the next release.functools.partial
. Although it's not trivial, because"_property"
,"property"
, and"property_"
patterns must be treat together.Back to your code and the original question. Since you don't use
context
in…