{# A figure tile, as a macro: components/stat.html (the Python Stat) and any template that heads a page with its figures. {% from "components/_stat.html" import stat, stat_row %} {% call stat_row(label="This week") %} {{ stat("Planned", "32 h", "danger", icon_name="warning", tip="Past capacity", item=true) }} {{ stat("Behind", "3", url="#work", target=none, compact=true, item=true) }} {% endcall %} label is the name over the value, value the figure (shown as given; pass the formatted text). tone is neutral / info / success / warning / danger (an accent on the edge), anything else none. icon_name is an icon() name before the label. url makes the label a link whose ::after covers the tile; target is its Unpoly target (none: a plain link, as for an anchor on the page). help is a muted line under the value. tip is a tooltip — the browser's title with JavaScript off, the library's on hover, and on keyboard focus (an unlinked tile then takes focus; a linked one has its link). dashed draws the edge dashed: a provisional figure (an estimate, a forecast, a draft). compact is the small tile for a summary row. delta and spark are the dicts StatComponent builds (text, tone, icon, word, label; points, width, height, summary). stat_row is a list of tiles that wraps, named by its label; a tile in it takes item=true, so it is the list's item. #} {% macro stat(label, value, tone=none, icon_name=none, url=none, target="#main-content", help=none, tip=none, dashed=false, compact=false, delta=none, spark=none, item=false, id=none, css_class=none) -%} {%- set tag = "li" if item else "div" -%} <{{ tag }} class="fcu-stat {%- if url %} fcu-stat--linked{% endif %} {%- if tone in ("neutral", "info", "success", "warning", "danger") %} fcu-stat--{{ tone }}{% endif %} {%- if dashed %} fcu-stat--dashed{% endif %} {%- if compact %} fcu-stat--compact{% endif %} {%- if css_class %} {{ css_class }}{% endif %}" {%- if id %} id="{{ id }}"{% endif %} {%- if tip %} title="{{ tip }}" data-fcu-tip=""{% if not url %} tabindex="0"{% endif %}{% endif %}>
{%- if icon_name %}{{ icon(icon_name, size="sm" if compact else "md") }}{% endif %} {%- if url %}{{ label }} {%- else %}{{ label }}{% endif -%}
{{ "—" if value is none or value == "" else value }}
{% if delta %}{%- if delta.icon %}{{ icon(delta.icon, size="sm", label=delta.word) }}{% endif %} {{ delta.text }} {%- if delta.label %} {{ delta.label }}{% endif -%}
{% endif %} {% if spark %} {% endif %} {% if help %}{{ help }}
{% endif %} {{ tag }}> {%- endmacro %} {% macro stat_row(label=none, id=none, css_class=none) -%}