{#- chirp-ui: Badge component Small status indicators with semantic variants and optional icons. Usage: from "chirpui/badge.html" import badge badge("Active", variant="success") badge("Grass", color="#78c850") badge("Fire", color="fire", fill="solid") badge("Tag", href="/tags/x") -#} {% def badge(text, variant="primary", icon=none, cls="", color=none, fill="subtle", href=none) %} {% set fill = fill | validate_variant(("subtle", "solid"), "subtle") %} {% set resolved = color | resolve_color %} {% set use_variant = ("custom-solid" if (resolved and fill == "solid") else ("custom" if resolved else (variant | validate_variant_block("badge", "primary")))) %} {% set style_attr = ("--chirpui-badge-color: " ~ resolved ~ ("; --chirpui-badge-text: " ~ (resolved | contrast_text) if fill == "solid" else "")) if resolved else "" %} {% set badge_class = "badge" | bem(variant=use_variant, cls=cls) %} {% if href %} {% if icon %} {{ icon | icon }} {% end %} {{ text }} {% else %} {% if icon %} {{ icon | icon }} {% end %} {{ text }} {% end %} {% end %}