thomasborgen / hypermedia

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

Let attributes be `None`, and if they are ommit them from output. #11

Closed thomasborgen closed 4 months ago

thomasborgen commented 4 months ago

It should be convenient to be able to have a value and if it is none the attribute is ommited like:

def input_element(
    label: str,
    name: str,
    value: str,
    placeholder: str | None = None,
) -> Element:
    """Create an input element with a label."""
    return Div(
        Label(text=label),
        Input(
            name=name,
            value=value,
            placeholder=placeholder,
        ),
        classes=["input_container"],
    )

Then things like this would work where placeholder would just be ommited if they aren't provided.