thomasborgen / hypermedia

Composable HTML rendering in pure python with FastAPI and HTMX in mind
MIT License
18 stars 0 forks source link

Components #42

Open thomasborgen opened 1 month ago

thomasborgen commented 1 month ago

I think I'm going to add some components for layouts.

For example a Stack class that renders a Div with display: flex and other convenient attributes like direction: Literal["horizontal", "vertical"] = "horizontal" to handle flex direction. align_items etc. maybe fluid: bool = True for a full width/auto switch as well.

We can do this, and it is typed and autocompleted in the styles attribute. But theres something nice about having a named component that just speaks to me.

Stack(Div(), Div(), direction="vertical")
thomasborgen commented 1 month ago
HButton(
    variant: Literal["primary", "secondary"] = "primary"
    disabled: bool = False
    size: Literal["big", "medium", "small"] = "medium"
    fluid: bool = True  # causes button to fill available space
) -> Element
thomasborgen commented 1 month ago

If we add components, we might need to add css with some simple classes and variables to override.

thomasborgen commented 4 weeks ago
Counter()

Should render as 3 elements, a plus and minus button and a input element in the middle with type number and optional min/max values set.