{# Form components — every field is a `.field` (studio-redesign.css): label, control, optional hint. Buttons use `.btn` variants from tusk-app.css. Plain macros render name/value for classic forms and HTMX; the alpine_* variants bind to Alpine state with x-model instead. Macros: text_input, textarea, select_input, checkbox, toggle, button, icon_button, alpine_input, alpine_select, alpine_textarea, form_group #} {% macro text_input(name, label="", value="", placeholder="", type="text", required=false, disabled=false, help="") %}
{% if label %}{% endif %} {% if help %}{{ help }}{% endif %}
{% endmacro %} {% macro textarea(name, label="", value="", placeholder="", rows=4, required=false, disabled=false, mono=false) %}
{% if label %}{% endif %}
{% endmacro %} {% macro select_input(name, options, label="", selected="", required=false, disabled=false) %} {# options: list of {value, label} dicts or plain strings #}
{% if label %}{% endif %}
{% endmacro %} {% macro checkbox(name, label, checked=false, disabled=false) %} {% endmacro %} {% macro toggle(name, label, checked=false, disabled=false) %} {# On/off switch (`.switch`). The input stays in the form as a normal checkbox. #} {% endmacro %} {% macro button(text, type="button", variant="primary", icon="", disabled=false, size="md", full_width=false) %} {# variant: primary (ink) | brand (coral) | secondary (outline) | danger | ghost #} {% set variants = {"primary": "btn-primary", "brand": "btn-brand", "secondary": "", "danger": "btn-danger", "ghost": "btn-ghost"} %} {% endmacro %} {% macro icon_button(icon, title="", variant="ghost", size="md", disabled=false) %} {# Square icon-only button (`.icon-btn`). variant danger tints it red on hover. #} {% endmacro %} {% macro alpine_input(model, label="", type="text", placeholder="", mono=false, help="") %} {# Input bound to Alpine state: model is the x-model expression (e.g. "form.name"). #}
{% if label %}{% endif %} {% if help %}{{ help }}{% endif %}
{% endmacro %} {% macro alpine_select(model, options, label="") %}
{% if label %}{% endif %}
{% endmacro %} {% macro alpine_textarea(model, label="", placeholder="", rows=4, mono=false) %}
{% if label %}{% endif %}
{% endmacro %} {% macro form_group(label="", help="", error="") %} {# Wrap a custom control so it lines up with the other fields. Use with {% call %}. #}
{% if label %}{% endif %} {{ caller() }} {% if error %} {{ error }} {% elif help %} {{ help }} {% endif %}
{% endmacro %}