LedgerUI.Components.KpiCard (LedgerUI v0.2.0)

Copy Markdown View Source

Indicator card: a big tabular figure, its unit in subtle and a coloured delta in the footer.

<.kpi_card label="MRR" value="184,320" prefix="$" delta="8.8%" compare="vs $169,460 in Sep"
  live spark={@mrr_series} open_label="Open" on_open="open_report" />

<.kpi_card label="Churn rate" value="2.1" unit="%" delta="0.4 pts" trend="up" delta_tone="error" />

The colour of the delta follows the meaning, not the direction: churn going up is error (a red arrow pointing up). trend draws the arrow (up, down, flat), delta_tone colours it and defaults from trend (up success, down error, flat neutral).

Variants

  • canvas (default): the reference card. The sparkline sits at the right (spark), the delta is a lu-delta and the arrow an icon.
  • badge: the compact card of the dashboards, with the delta in a lu-badge and the arrow as a glyph (↗, ↘, →); pair it with count for a figure that counts up (CSS only).

With an <:icon>, layout="stack" puts the icon chip before the label and "inline" puts it beside the label and the figure.

The sparkline is drawn on the server (see LedgerUI.Components.Sparkline). The gradient of its fill takes its id from id (derived from the card's content when not given).

Summary

Functions

kpi_card(assigns)

Attributes

  • id (:string) - Defaults to nil.
  • label (:string) - Defaults to nil.
  • value (:string) - The figure, already formatted. Defaults to nil.
  • prefix (:string) - A small prefix before the figure ($, R$). Defaults to nil.
  • unit (:string) - A smaller suffix beside the figure (mil, %, dias). Defaults to nil.
  • delta (:string) - The change since the last period, already formatted. Defaults to nil.
  • compare (:string) - What the change is measured against (vs Sep). Defaults to nil.
  • trend (:string) - Defaults to "up". Must be one of "up", "down", or "flat".
  • delta_tone (:string) - Defaults to nil.Must be one of nil, "success", "error", or "neutral".
  • spark (:list) - Numbers for the sparkline. Defaults to [].
  • color (:string) - Defaults to "primary". Must be one of "neutral", "primary", "secondary", "info", "success", "warning", or "error".
  • variant (:string) - Defaults to "canvas". Must be one of "canvas", or "badge".
  • layout (:string) - Defaults to "inline". Must be one of "stack", or "inline".
  • count (:integer) - badge variant: the figure counts up to this number, in CSS. Defaults to nil.
  • progress (:integer) - 0 to 100: a meter under the figure, in place of the sparkline. Defaults to nil.
  • caption (:string) - A faint line under the figure or the meter. Defaults to nil.
  • icon_tone (:string) - Defaults to "acc". Must be one of "acc", "pos", "neg", "warn", or "info".
  • value_id (:string) - The id of the figure element. Defaults to nil.
  • gap (:boolean) - Defaults to true.
  • loading (:boolean) - Defaults to false.
  • live (:boolean) - A Live chip beside the label. Defaults to false.
  • live_label (:string) - Defaults to "Live".
  • open_label (:string) - aria-label of the round button at the footer's right; no button without it. Defaults to nil.
  • on_open (:any) - Event name or %JS{} of the round button. Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • icon - An icon shown in a tinted chip before the label.