{#- chirp-ui: Icon Button Square icon-only button for toolbars and dense UIs. Usage: from "chirpui/icon_btn.html" import icon_btn icon_btn("✕", aria_label="Close") icon_btn("⚙", variant="ghost", size="lg", href="/settings", aria_label="Settings") icon_btn("🗑", aria_label="Delete", hx={"delete": "/item/1", "target": "#list", "swap": "outerHTML"}) hx={"post": "/url", "target": "#id"} — preferred for htmx attributes. Individual hx_get/hx_post/hx_target/hx_swap kwargs override dict keys. -#} {% def icon_btn(icon, variant="", size="", href=none, aria_label="", disabled=false, type="button", cls="", hx=none, hx_get=none, hx_post=none, hx_target=none, hx_swap=none) %} {# @consumes _bar_density from: command_bar, filter_bar — falls back to "" #} {% set _bar_size = consume("_bar_density", "") %} {# @consumes _suspense_busy from: suspense_group — falls back to "" #} {% set _busy = consume("_suspense_busy", "") %} {% set _variant = variant | validate_variant(("", "default", "primary", "ghost", "danger"), "") %} {% set _size = (size or _bar_size or "") | validate_variant(("", "sm", "md", "lg"), "") %} {% set _disabled = disabled or (_busy == "true") %} {% set variant_class = " chirpui-icon-btn--" ~ _variant if _variant else "" %} {% set size_class = " chirpui-icon-btn--" ~ _size if _size else "" %} {% set base = "chirpui-icon-btn" ~ variant_class ~ size_class ~ (" " ~ cls if cls else "") %} {% set _hx_dict = build_hx_attrs(hx=hx, hx_get=hx_get, hx_post=hx_post, hx_target=hx_target, hx_swap=hx_swap) %} {% set _link_has_hx_request = _hx_dict.get("hx-get") or _hx_dict.get("hx-post") %} {% set _link_has_hx_config = _hx_dict | length > 0 %} {% set _route_attrs = route_link_attrs(href) if href and not _link_has_hx_config and not _disabled else {} %} {% if href %} {{ icon | icon }} {% else %} {% end %} {% end %}