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
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
Stat("Orders today", value: 1284, format: .integer, count: "600ms")
Money in its own currency
Stat("Average order", value: €42.50, change: 0.08)
A figure written as text
Stat("Uptime", value: "99.98%")
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label | String (positional) | — | What the figure is, small and muted above it |
value: | Number or Money or String (required) | — | The figure, large; |
format: | one of its cases | none: as | How the figure is written, as
|
change: | Number | none | How it moved, as a fraction ( |
trend: | [Number] | none | Its recent values, drawn as a 120×28 sparkline under it when the page is built ( |
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)
| Prop | Type | Unset | Meaning |
|---|---|---|---|
text | String (positional) | none | The label |
Stat.Value
Its figure.
Stat.Value(_ text: String or Number)
| Prop | Type | Unset | Meaning |
|---|---|---|---|
text | String or Number (positional) | none | The figure |
Stat.Change
How it moved, with its direction.
Stat.Change(_ text: String)
| Prop | Type | Unset | Meaning |
|---|---|---|---|
text | String (positional) | none | The change |
Renders with the class wf-stat, stable across releases, so a stylesheet may target it.