{#- chirp-ui: Description list component Key-value pairs for settings, profile info, metadata. Usage: from "chirpui/description_list.html" import description_list, description_item description_list(items=[{"term": "Name", "detail": "Alice"}, {"term": "Email", "detail": "alice@example.com"}]) Or with slot: call description_list() description_item("Name", "Alice") description_item("Email", "alice@example.com") end description_list(items=..., variant="horizontal") for term left, detail right layout. Modifiers: hoverable=true (row highlight on hover), divided=true (border between rows), relaxed=true (more vertical spacing). Icon support: description_item("Name", "Alice", icon="◇") Slots: header (content above the list). -#} {% def description_list(items=none, variant="stacked", compact=false, relaxed=false, hoverable=false, divided=false, term_width="", detail_align="", cls="") %} {% set variant = variant | validate_variant(("stacked","horizontal"), "stacked") %} {% set compact_class = " chirpui-dl--compact" if compact else "" %} {% set relaxed_class = " chirpui-dl--relaxed" if relaxed else "" %} {% set hover_class = " chirpui-dl--hoverable" if hoverable else "" %} {% set divided_class = " chirpui-dl--divided" if divided else "" %} {% set align_class = " chirpui-dl--detail-" ~ detail_align if detail_align in ("left", "center", "right") else "" %} {% set style_attr = "" %} {% if term_width %}{% set style_attr = " style=\"--chirpui-dl-term-width: " ~ term_width ~ "\"" %}{% end %}
{% slot header %}
{% if items %} {% for item in items %} {% set item_type = item.get('type') or (item.detail | value_type) %}
{{ item.term }}
{% if item_type == "bool" %} {% from "chirpui/badge.html" import badge %} {{ badge("Yes" if item.detail else "No", variant="success" if item.detail else "muted") }} {% elif item_type == "unset" %} {{ item.detail }} {% else %} {{ item.detail }} {% end %}
{% end %} {% else %} {% slot %} {% end %}
{% end %} {% def description_item(term, detail, type=none, icon=none, cls="") %} {% set resolved_type = type if type else (detail | value_type) %} {% set type_class = " chirpui-dl__detail--" ~ resolved_type if resolved_type else "" %} {% set type_valid = (resolved_type or "") | validate_variant(("", "bool", "url", "path", "number", "unset"), "") %}
{% if icon %}{{ term }}{% else %}{{ term }}{% end %}
{% if type_valid == "bool" %} {% from "chirpui/badge.html" import badge %} {{ badge("Yes" if detail else "No", variant="success" if detail else "muted") }} {% elif type_valid == "unset" %} {{ detail }} {% else %} {{ detail }} {% end %}
{% end %}