Reference

Stat

A figure with its label — revenue, sign-ups — and how it moved: Stat("Revenue", value: total, format: .currency, change: 0.124). count: counts to a new value.

Stat(_ label: String, value: Number or Money or String, format: Enum, change: Number, …) { … }

Since 6.2.0

label

format

number

integer

currency

percent

compact

change

Revenue

$48,210.00

Up 12.4%

Active users

18K

Up 3.1%

Churn

2%

Down 0.4%

Example

wf

Grid(columns: { base: 1, md: 3 }, gap: .md) { Stat("Revenue", value: 48210, format: .currency, change: 0.124, trend: [31, 40, 28, 44, 52, 48]) Stat("Active users", value: 18400, format: .compact, change: 0.031, trend: [15, 16, 16, 17, 18, 18]) Stat("Churn", value: 0.021, format: .percent, change: -0.004) }

Counting up as it arrives

wf

Stat("Orders today", value: 1284, format: .integer, count: "600ms")

Money in its own currency

wf

Stat("Average order", value: €42.50, change: 0.08)

A figure written as text

wf

Stat("Uptime", value: "99.98%")

Props

Props of Stat
PropTypeUnsetMeaning

label

String (positional)

—

What the figure is, small and muted above it

value:

Number or Money or String (required)

—

The figure, large; format: says how it is written

format:

one of its cases

none: as format(value) writes it — grouped digits, a Money in its currency

How the figure is written, as format(value, .style) writes it in the page's locale. Written as a flag, .number, or by name, format: .number.

  • .number: Grouped digits: 1,234.5
  • .integer: A whole number: 1,235
  • .currency: Money, in the page's currency (a Money in its own)
  • .percent: A fraction as a percentage: 0.25 is 25%
  • .compact: Short: 1.2K

change:

Number

none

How it moved, as a fraction (0.124 is ▲ 12.4%, green; a negative one ▼, red), read "Up" or "Down" by a screen reader

trend:

[Number]

none

Its recent values, drawn as a 120×28 sparkline under it when the page is built (E109 when not known then): [31, 40, 28, 51]

Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

.number

.integer

.currency

.percent

.compact

Events

Every element also takes the props, the events and the attribute families listed on every element.

Slots

children

Parts

The parts of Stat are written under its name, inside it. Each is described here, with what it takes.

Stat.Label

Its label.

Stat.Label(_ text: String)
Props of Stat.Label
PropTypeUnsetMeaning

text

String (positional)

none

The label

Stat.Value

Its figure.

Stat.Value(_ text: String or Number)
Props of Stat.Value
PropTypeUnsetMeaning

text

String or Number (positional)

none

The figure

Stat.Change

How it moved, with its direction.

Stat.Change(_ text: String)
Props of Stat.Change
PropTypeUnsetMeaning

text

String (positional)

none

The change

Renders with the class wf-stat, stable across releases, so a stylesheet may target it.