{#- 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_put=none, hx_patch=none, hx_delete=none,
hx_target=none, hx_swap=none, hx_sync=none, hx_disabled_elt=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_put=hx_put, hx_patch=hx_patch,
hx_delete=hx_delete, hx_target=hx_target, hx_swap=hx_swap) %}
{% set _link_has_hx_request = _hx_dict.get("hx-get") or _hx_dict.get("hx-post") or _hx_dict.get("hx-put") or _hx_dict.get("hx-patch") or _hx_dict.get("hx-delete") %}
{% set _link_has_hx_mutation = _hx_dict.get("hx-post") or _hx_dict.get("hx-put") or _hx_dict.get("hx-patch") or _hx_dict.get("hx-delete") %}
{% set _link_has_hx_config = _hx_dict | length > 0 %}
{% set _explicit_hx_select = _hx_dict.get("hx-select") %}
{% set _hx_sync_from_dict = _hx_dict.get("hx-sync") %}
{% set _hx_disabled_from_dict = _hx_dict.get("hx-disabled-elt") %}
{% set _default_hx_select = "unset" if _link_has_hx_request and not _explicit_hx_select else none %}
{% set _default_hx_sync = hx_sync if hx_sync is not none else ("this:drop" if _link_has_hx_mutation and not _hx_sync_from_dict else none) %}
{% set _default_hx_disabled = hx_disabled_elt if hx_disabled_elt is not none else ("this" if _link_has_hx_mutation and not href and not _hx_disabled_from_dict else none) %}
{% 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 %}