feat(ui): status_badge, status_dot, stat_tile, empty_state, page_header, icon_button and form classes (#5094)
#5094 "Status and layout macros, and form classes". - formatting.STATES: one state -> (tone, label) map for up, down, stale, firing, pending, acknowledged, no_data, ok, warn, crit, resolved and inactive; status_info() reads it (an unmapped state is drawn dim under its own name). required() lets a macro refuse a missing argument. - _macros.html: status_badge and status_dot (a dot always carries its label, sr-only unless shown), stat_tile, empty_state, page_header (actions via a call block) and icon_button, which raises without a label. - steward.css: tone classes (badge-/dot-/stat- ok, warn, crit, info, dim), .sr-only, .page-header, .stat-tile, .empty-state, .btn-icon and the form classes .field, .field-label, .field-hint and .input. Info text is a 40% mix (--blue): the house --fs-info-fg falls to 4.18:1 on its tint over a hovered row, 40% holds 5.09:1. - First users: the Alerts list, history and maintenance pages (headers, state badges, empty states) and the alert forms' hints; the inline inp/lbl style sets on the monitor and host forms become .input / .field-label. - tests/core/test_macros.py renders each macro through the app environment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -95,3 +95,37 @@ def status_class(value: Any, kind: str, thresholds: dict) -> str:
|
||||
if th.get("dir", "high") == "low":
|
||||
return "crit" if value < crit else "warn" if value < warn else "ok"
|
||||
return "crit" if value >= crit else "warn" if value >= warn else "ok"
|
||||
|
||||
|
||||
# Every state a page shows, and the tone it is drawn in: ok (green), warn
|
||||
# (amber), crit (red), info (blue) or dim. The status_badge and status_dot
|
||||
# macros read this, so one state looks the same on every page.
|
||||
STATES: dict[str, tuple[str, str]] = {
|
||||
"up": ("ok", "Up"),
|
||||
"ok": ("ok", "OK"),
|
||||
"resolved": ("ok", "Resolved"),
|
||||
"down": ("crit", "Down"),
|
||||
"firing": ("crit", "Firing"),
|
||||
"crit": ("crit", "Critical"),
|
||||
"warn": ("warn", "Warning"),
|
||||
"pending": ("warn", "Pending"),
|
||||
"stale": ("warn", "Stale"),
|
||||
"no_data": ("warn", "No data"),
|
||||
"acknowledged": ("info", "Acknowledged"),
|
||||
"inactive": ("dim", "Inactive"),
|
||||
"unknown": ("dim", "Unknown"),
|
||||
}
|
||||
|
||||
|
||||
def status_info(state: Any) -> tuple[str, str]:
|
||||
"""(tone, label) for a state name or enum. A state the map doesn't know
|
||||
is drawn dim under its own name rather than breaking the page."""
|
||||
key = str(getattr(state, "value", state) or "unknown").lower()
|
||||
return STATES.get(key, ("dim", key.replace("_", " ").capitalize()))
|
||||
|
||||
|
||||
def required(value: Any, what: str) -> Any:
|
||||
"""For a macro argument that must be given: raise if it is empty."""
|
||||
if value is None or not str(value).strip():
|
||||
raise ValueError(f"{what} is required")
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user