Skip to content

UI kit

The pieces every page shares, so the core and every plugin read alike: the stat tile, the status badge and the tag, the alert banner and the notification. The debug_tools plugin's UI kit page (/ui-kit under its mount) shows each one in the current theme: a tool for who writes a plugin page, so it is not in the core's admin.

On a page with its own <head>

A page of the core's layout (base.html.j2, public_base.html.j2) has the kit already. A page that writes its own <head>, like a plugin's public site, loads the kit alone: the tokens and the kit's rules, nothing of the admin layout.

<html lang="en" data-bs-theme-base="neutral" data-fp-status-tones='{{ status_tones | tojson }}'>
<head>
  <script src="/static/js/fp-helpers.js"></script>  {# fp.statusBadge, fp.tag, fp.notify #}
  <link rel="stylesheet" href="/static/vendor/tabler-1.4.0/css/tabler.min.css">
  <link rel="stylesheet" href="/static/vendor/tabler-1.4.0/css/tabler-themes.min.css">
  <link rel="stylesheet" href="/static/css/ui-kit.css">

data-fp-status-tones gives fp.statusBadge the shared status words; status_tones is a template global. fp.notify makes its corner on first use, so it needs nothing in the page. The kit's surfaces are the core's neutral greys; data-bs-theme-base="neutral" and Tabler's tabler-themes.min.css make the page's own background neutral too. ui-kit.css is built by scripts/build-css.sh from 01-tokens.css and 10-ui-kit.css, the kit's source.

Rules

  • Colour says a state, or tells categories apart; never both.
  • State colours say good or bad news: green done, blue in progress, yellow waiting or partly wrong, red failed, grey off or unknown. Use one only when the value is news: a "Failed 0" tile stays neutral.
  • Category colours (blue, teal, violet) only tell tiles apart. They are discreet, one category keeps its hue everywhere, and never a state hue (no green or red category).
  • Neutral is the default.
  • Colour is never the only signal: a state also has a word or an icon.
  • Readable in both themes: text at least 4.5:1, icons and outlines at least 3:1. Never force text-white or text-dark on a coloured background: Bootstrap's !important beats the core's readable colour, and white on yellow, green or cyan is 2 to 3:1.
  • No effect without a function: a hover effect only on what is clickable; no gradients, glows or emoji; sentence case, normal weight, no letter-spaced capitals; Tabler icons only. The data (the number, the value) is the most visible thing.

Stat tile

{% from "components/ui.html.j2" import stat_tile %}
{{ stat_tile("Failed", failed, "alert-triangle", "danger" if failed else "") }}

stat_tile(label, value, icon=None, tone="", sub=None, url=None, id=None)

tone Draws Use for
"" no colour a count that is neither news nor a category
blue, teal, violet a thin bar on top, the value neutral telling categories apart
success, warning, danger the value in that colour a number that is good or bad news

icon is a Tabler icon name, drawn large and faint behind the value in the tone's colour. sub adds a line under the value; a body ({% call stat_tile(...) %}...{% endcall %}) adds a line of your own markup instead. url makes the whole tile a link. Every argument is escaped.

StatsWidget and StatusWidget draw this tile: their color / status (a Tabler colour) is mapped to a tone (success/green to success, primary/blue/info to blue, purple to violet, ..., anything else neutral).

Status badge and tag

A status is a soft filled badge whose colour says the state; a tag (a topic, a kind, a flag) is outlined and colourless. They differ by shape, so a blue "Running" never reads like a topic.

{{ task.status | status_badge }}                       {# failed -> red "Failed" #}
{{ worker.state | status_badge({"draining": "yellow"}) }}
{{ topic | tag }}
cell.innerHTML = fp.statusBadge(row.status) + ' ' + fp.tag(row.topic);
cell.innerHTML = fp.statusBadge(row.state, {draining: 'yellow'});

The colour comes from the colours you pass for your own words, then from the core's shared words (fastpluggy.core.widgets.render_field_tools.STATUS_TONES: sent, ok, enabled... are green, running blue, pending, partial... yellow, failed, error... red, disabled, unknown... grey), else grey. fp.statusBadge reads the same table from the page (<html data-fp-status-tones>), so a script never carries a second copy. The label is the value in sentence case (load_failed reads "Load failed") unless label= is given; it is escaped.

Alert banner

A message that stays on the page: something wrong with what you see, or a hint.

{% from "components/ui.html.j2" import alert %}
{{ alert("warning", "Worker draining", "No new task starts on it until it restarts.") }}
{% call alert("error", "Two workers do not hear task ends") %}
  Install the notification plugin on <a class="alert-link" href="{{ url }}">these workers</a>.
{% endcall %}

alert(level="info", title=None, text=None, icon=None), level one of info, success, warning, error. The title and text are escaped; a body is your own markup. Every .alert (Tabler markup, AlertWidget, flash messages) draws the same soft tint, so existing pages need no change.

Notification

fp.notify('The ntfy server answered 500.', 'error', {title: 'Send failed', link: url});

fp.notify(message, level, {title, link, linkLabel, action: {label, onClick}, sticky}), level one of info, success, warning, error (danger is read as error). It floats in the corner with the banner's look on an opaque background, and goes away after 5 seconds unless sticky. The message is inserted as text.