Vitral 0.2.18
Data

Stat

A figure worth a glance — what it is, how much, and which way it went — formatted for the locale, with the change read out in words.

Import

main.ts
import { Stat } from '@vitral/vue';

A row of figures

`delta` is a ratio: `0.125` is +12.5%. The arrow and the colour are not read out, so the change is said in words.

Revenue
$48,250Up 12.4%vs last month
Active users
18KUp 3.1%vs last month
Churn
2.4%0%no change
Orders
<script setup lang="ts">import { banknote, receipt, users } from '@vitral/icons';import { Card, Stat } from '@vitral/vue';</script> <template>    <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem; width: 100%">        <Card><Stat label="Revenue" :icon="banknote" :value="48250" :format="{ style: 'currency', currency: 'USD', maximumFractionDigits: 0 }" :delta="0.124" caption="vs last month" /></Card>        <Card><Stat label="Active users" :icon="users" :value="18400" :format="{ notation: 'compact' }" :delta="0.031" caption="vs last month" /></Card>        <Card><Stat label="Churn" icon="trendingDown" :value="2.4" suffix="%" :delta="0" caption="no change" /></Card>        <Card><Stat label="Orders" :icon="receipt" loading /></Card>    </div></template>

When down is good

`invert` for costs, errors and load times: a fall is shown in the good colour, still pointing down.

Median load time
1.18sDown 21%after the image change
Cloud costs
$3,120Up 8%this week
<script setup lang="ts">import { Stat } from '@vitral/vue';</script> <template>    <div style="display: flex; flex-wrap: wrap; gap: 2.5rem">        <Stat label="Median load time" :value="1.18" suffix="s" :delta="-0.21" invert caption="after the image change" />        <Stat label="Cloud costs" :value="3120" prefix="$" :delta="0.08" invert caption="this week" />    </div></template>

With a sparkline

The `chart` slot sits under the figure.

Visits today
9,512Up 18%
<script setup lang="ts">import { Chart, Stat } from '@vitral/vue'; const visits = [{ name: 'Visits', data: [31, 40, 28, 51, 42, 60, 74, 68, 80, 95] }];</script> <template>    <div style="width: min(100%, 18rem)">        <Stat label="Visits today" :value="9512" :delta="0.18">            <template #chart>                <Chart type="area" :series="visits" :options="{ chart: { sparkline: { enabled: true } } }" height="3rem" aria-label="Visits over the last ten hours" />            </template>        </Stat>    </div></template>

API

Read from packages/vue/src/components/Stat/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
label string—
value number | stringA number is formatted for the locale with `format`; a string is shown as it is.
format Intl.NumberFormatOptions`Intl.NumberFormat` options for `value`: `{ style: 'currency', currency: 'BRL' }`, `{ notation: 'compact' }`.
prefix string—
suffix string—
delta number | stringThe change, as a ratio: `0.125` is +12.5%. A string is shown as it is, and then `trend` says which way it went.
deltaFormat Intl.NumberFormatOptions`Intl.NumberFormat` options for `delta`. Defaults to a signed percentage with one decimal.
trend 'up' | 'down' | 'neutral'Which way it went; worked out from the sign of a numeric `delta` otherwise.
invert booleanA fall is the good news: costs, errors, time to load.
caption stringBeside the change: `'vs last month'`.
icon IconProp—
loading booleanKeeps the layout and shows a placeholder for the figure.
size Size—

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Slots

NameSlot propsDescription
label ——
value (context: { value: string })Replaces the formatted figure.
icon ——
caption ——
chart —Below everything: a sparkline, a meter.