Statistic
Headless Statistic; covers Ant Design Statistic, shadcn/ui, Adobe Spectrum.
| Package | @vizejs/ui/statistic |
| Maturity | stable |
| Quality gates | behavior contract, mounted dom, type inference, tree shaking, bundle size, ssr, hydration, dom compile, ssr compile, vapor compile |
| Bundle budget | 4,000 B JS gzip / 0 B CSS gzip |
| Own the source | vize lib pull statistic |
| Requires | — |
| Aliases | stat, metric, kpi, number display |
| Covers | Ant Design Statistic, shadcn/ui, Adobe Spectrum |
Minimal setup
Use a Vue 3.5+ project with Vue SFC compilation configured (see Vite+ integration).
vp install @vizejs/ui
Add the public import below to <script setup lang="ts">. Components provide behavior without styles; the preview uses optional Paper styles.
import { Statistic } from "@vizejs/ui/statistic";
Or copy the source into your project with vize lib pull statistic (see Source Distribution).
Try it
This is the basic example maintained with the component source, using the public package imports. The preview adds the optional Paper styles.
Open the interactive example · Styling these components
Copy the example
<!-- Revenue and request-volume statistics, including a negative amount and compact notation. -->
<script setup lang="ts">
import { Statistic } from "@vizejs/ui/statistic";
</script>
<template>
<div>
<Statistic title="Revenue" :value="1280" prefix="$" suffix="/mo" />
<Statistic title="Refunds" :value="-240" prefix="$" />
<Statistic title="Requests" :value="1200" notation="compact" :maximum-fraction-digits="1" />
</div>
</template>
Lead with the number, keep the sign honest
Statistic formats one number with Intl.NumberFormat and publishes the title
as the accessible name. The minus sign is placed before the prefix, so a
negative amount reads -$1,280 rather than $-1,280.
<script setup lang="ts">
import { Statistic } from "@vizejs/ui/statistic";
</script>
<template>
<Statistic title="Revenue" :value="1280" prefix="$" suffix="/mo" />
<Statistic title="Requests" :value="1200" notation="compact" :maximum-fraction-digits="1" />
</template>
notation="compact" uses the locale's short form (1.2K in en-US). Grouping
and decimal marks follow locale. The component renders no stylesheet. Style
[data-vize-ui="statistic"] and [data-part="title"|"value"].
API
Statistic
Source: src/components/statistic/statistic.vue
Props
| Prop | Type | Default | Description |
|---|---|---|---|
title (required) |
string |
— | Accessible name and visible title of the figure. |
value (required) |
number |
— | Numeric value. The sign is rendered before prefix. |
prefix |
string |
"" |
Text placed immediately before the formatted number. |
suffix |
string |
"" |
Text placed immediately after the formatted number. |
locale |
string |
"en-US" |
BCP 47 locale passed to Intl.NumberFormat. |
maximumFractionDigits |
number |
0 |
Maximum fraction digits. Grouping follows locale. |
notation |
StatisticNotation |
"standard" |
compact renders short forms such as 1.2K. |
Behavior
Normative state × input → outcome table for src/components/statistic/statistic.vue.
Every row is proven by src/components/statistic/tests/behavior.test.ts.
| # | State | Input | Outcome | Proven by |
|---|---|---|---|---|
| S1 | value 1280, prefix $ |
render | group named from the title; value $1,280 |
formats a prefixed value and names the group from its title |
| S2 | value -1280, prefix $ |
render | sign stays in front of the prefix: -$1,280 |
puts the minus sign before the prefix |
| S3 | value 1200, compact, 1 fraction | render | 1.2K |
formats compact notation |
| S4 | omitted format props | render | en-US, 0 fraction digits, standard notation |
defaults locale, fraction digits, and notation |