{# Feedback components — built on the v0.4 classes in tusk-app.css (.chip, .alert, .empty, .modal-*). No colours live here: every macro maps to a token class, so light and dark themes come for free. Macros: badge, severity_badge, status_badge, alert, empty_state, modal #} {% macro badge(text, variant="info") %} {# Small label. variant: critical|error|danger → rose, high|medium|warning → amber, low → violet, safe|success|ok → green, primary|brand → brand, anything else → neutral. #} {% set chips = { "critical": "chip-rose", "error": "chip-rose", "danger": "chip-rose", "high": "chip-amber", "medium": "chip-amber", "warning": "chip-amber", "low": "chip-violet", "safe": "chip-green", "success": "chip-green", "ok": "chip-green", "primary": "chip-brand", "brand": "chip-brand", "info": "chip-neutral", "neutral": "chip-neutral" } %} {{ text }} {% endmacro %} {% macro severity_badge(severity) %} {# CRITICAL / HIGH / MEDIUM / LOW / SAFE, upper-cased. #} {% set s = severity | lower %} {% if s in ["critical", "high", "medium", "low"] %} {{ badge(severity | upper, s) }} {% elif s in ["safe", "ok", "good"] %} {{ badge(severity | upper, "safe") }} {% else %} {{ badge(severity, "info") }} {% endif %} {% endmacro %} {% macro status_badge(status) %} {# active/running/online → green, pending/queued → amber, failed/offline → rose, else neutral. #} {% set s = status | lower %} {% if s in ["active", "running", "online", "connected", "healthy", "success", "passed"] %} {{ badge(status, "success") }} {% elif s in ["pending", "waiting", "queued", "warning"] %} {{ badge(status, "warning") }} {% elif s in ["error", "failed", "offline", "disconnected", "unhealthy"] %} {{ badge(status, "error") }} {% else %} {{ badge(status, "info") }} {% endif %} {% endmacro %} {% macro alert(message, variant="info", dismissible=false, icon="") %} {# Inline notice. variant: info | success | warning | error #} {% set default_icons = {"info": "info", "success": "check-circle", "warning": "alert-triangle", "error": "circle-x"} %}
{{ message }} {% if dismissible %} {% endif %}
{% endmacro %} {% macro empty_state(message, icon="inbox", action_text="", action_url="", action_onclick="", title="") %} {# Centered placeholder for lists with nothing in them. #}
{% if title %}
{{ title }}
{% endif %}
{{ message }}
{% if action_text %}
{% if action_url %} {{ action_text }} {% elif action_onclick %} {% endif %}
{% endif %}
{% endmacro %} {% macro modal(id, title, event="", max_width="max-w-lg", icon="", danger=false, close_event="") %} {# Generic modal for arbitrary content. Use with {% call %}. Opens on `$dispatch('open-{id}')` (or `event`), closes on Escape, backdrop click, the × button or `close_event`. Usage: {% call modal(id="edit-user", title="Edit user", icon="user") %}
...
{% endcall %} #} {% set open_event = event or ("open-" ~ id) %} {% endmacro %}