{# BPJudge UI Contract v1 macros. Import with: {% import "components/ui/v1.html" as ui_v1 %} Do not use `ui` as the alias: Hydro exposes its navigation registry through that global template name, and shadowing it breaks shared layout rendering. Text is escaped by the template environment. Translate user-facing copy at the call site so these primitives remain independent from business logic. #} {% macro help(text, label='使用说明') -%} {{ text }} {%- endmacro %} {% macro badge(text, tone='neutral', extra_class='') -%} {{ text }} {%- endmacro %} {% macro category_label(text, category=0) -%} {% set category = category if category in [0, 1, 2, 3, 4, 5, 6, 7, 8] else 0 -%} {{ text }} {%- endmacro %} {% macro stat(value, label, detail=none, extra_class='', trend=none) -%}
{{ label }}
{% if trend and trend.text %}
{{ trend.text }}
{% endif %}
{{ value }}
{% if detail %}
{{ detail }}
{% endif %}
{%- endmacro %} {% macro empty_state(title, description=none, icon_class=none, extra_class='') -%}
{{ title }}
{% if description %}
{{ description }}
{% endif %} {% if caller %}
{{ caller() }}
{% endif %}
{%- endmacro %} {% macro panel(title=none, description=none, extra_class='', body_class='') -%}
{% if title or description %}
{% if title %}

{{ title }}

{% endif %} {% if description %}
{{ description }}
{% endif %}
{% endif %}
{% if caller %}{{ caller() }}{% endif %}
{%- endmacro %} {% macro page_header(title, description=none, extra_class='') -%}

{{ title }}

{% if description %}
{{ description }}
{% endif %}
{% if caller %}
{{ caller() }}
{% endif %}
{%- endmacro %} {% macro alert(title, description=none, tone='neutral', extra_class='', icon=true) -%}
{% if icon %} {% endif %}
{{ title }}
{% if description %}
{{ description }}
{% endif %}
{%- endmacro %} {% macro sortable_handle(label, described_by=none, enabled=true, extra_class='') -%} {%- endmacro %} {% macro sortable_index(value, label=none, extra_class='') -%} {{ value }} {%- endmacro %} {% macro sortable_action(text, label, action=none, disabled=false, href=none, button_type='button', name=none, value=none, icon_class=none, tone='neutral', extra_class='') -%} {% if href and disabled %} {% elif href %} {% else %} {% endif %} {%- endmacro %} {% macro tab_link(text, href, active=false, count=none, extra_class='') -%} {{ text }} {% if count is not none %}({{ count }}){% endif %} {%- endmacro %} {% macro toolbar(flush=false, filter=false, extra_class='') -%}
{% if caller %}{{ caller() }}{% endif %}
{%- endmacro %} {% macro field(label, help=none, error=none, extra_class='') -%} {%- endmacro %} {% macro card(title=none, description=none, muted=false, extra_class='', body_class='') -%}
{% if title or description %}
{% if title %}

{{ title }}

{% endif %} {% if description %}
{{ description }}
{% endif %}
{% endif %}
{% if caller %}{{ caller() }}{% endif %}
{%- endmacro %} {% macro item_row(title=none, href=none, description=none, extra_class='') -%}
  • {% if title %}

    {% if href %}{{ title }}{% else %}{{ title }}{% endif %}

    {% endif %} {% if description %}

    {{ description }}

    {% endif %} {% if caller %}{{ caller() }}{% endif %}
  • {%- endmacro %} {% macro disclosure(title, meta=none, open=false, extra_class='') -%}
    {{ title }}{% if meta %} {{ meta }}{% endif %}
    {% if caller %}{{ caller() }}{% endif %}
    {%- endmacro %} {% macro table_scroll(label, extra_class='') -%}
    {% if caller %}{{ caller() }}{% endif %}
    {%- endmacro %} {% macro kv_item(term, detail=none, extra_class='') -%}
    {{ term }}
    {% if detail is not none %}{{ detail }}{% elif caller %}{{ caller() }}{% endif %}
    {%- endmacro %} {% macro progress_bar(percent, label, tone=none, extra_class='') -%} {% set numeric_text = r/^\s*[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\s*$/ -%} {% set progress = percent | float(none) if percent is number or (percent is string and numeric_text.test(percent)) else none -%} {% if progress is not none and (progress | string) not in ['Infinity', '-Infinity'] -%} {% set progress = 0 if progress < 0 else (100 if progress > 100 else progress) -%} {% else -%} {% set progress = none -%} {% endif -%} {% if progress is not none %}{{ progress }}%{% else %}{{ label }}{% endif %} {%- endmacro %}