Statistic
Numerical indicators, formatting, animation and countdown and countdown timers.
When to use
Statistic highlights a numerical indicator: quantity, balance or percentage. StatisticTimer shows the duration from the starting point or to the target time. These components display data; obtaining indicators, rounding and application validity remain the logic of the application.
Number and formatting
value accepts a number or a string; without a value, 0 is displayed. title signs the indicator, prefix/suffix adds an icon or unit. precision pads and trims the decimal string without performing monetary rounding.
| Problem | Setting | Example |
|---|---|---|
| Show indicator | value, title |
Basic values |
| Add units and icons | prefix, suffix |
Units |
| Set up fractional part | precision, separators |
Number format |
| Use your own format | formatter, valueRender |
Rendering |
| Show duration | StatisticTimer |
Timers |
| Replace value with expectation | loading |
Loading |
Pass large exact values as a string before formatting so as not to lose Number precision. For rounding, use your own formatter, for example Intl.NumberFormat with the necessary rules. decimalSeparator/groupSeparator specify built-in format symbols.
The formatter receives the initial value and can return text or a snippet. valueRender wraps a ready-made snippet value. The animation in example uses Svelte Tween; it is not a built-in Statistic animation. Reduced motion sets the target immediately, cleanup stops Tween.
Timer and duration format
StatisticTimer requires type:countdown/countup. value — timestamp in milliseconds: the target of the countdown or the beginning of the countdown. This is not the duration in seconds. Default format is HH:mm:ss.
onChange reports the current duration in milliseconds. onFinish is called when countdown completes; countup runs until stopped or unmounted. The last countdown callback may contain a negative remainder, although the display is limited to zero.
D shows full days, SSS shows milliseconds, literals are enclosed in square brackets. Without D, the hours include a full day. Y and M use fixed 365 and 30 days: this is a duration format, not a calendar addition of dates.
On the server, the timer is independent of the current time and displays an initial representation; the countdown is connected after mount. The examples create a label on a button click and stop the intervals by removing the component. An expired UI timer in itself is not a server-side check for the operation's expiration date.
Design and availability
loading replaces the value with Skeleton, keeping the title. The value and unit must be read together; do not convey the meaning of growth or decline with one arrow color. Constant timer updates are not worth it without having to announce via aria-live every fraction of a second.
Semantic root/header/title/content/value/prefix/suffix are configured by an object or callback. styles - CSS strings. Component Statistic design tokens set titleFontSize/contentFontSize, local styles allow you to override the desired node. RTL is inherited from ConfigProvider, native root is available after mount.
ConfigProvider.statistic accepts StatisticConfig: class, style, classNames and styles. The setting applies to Statistic and StatisticTimer. Semantic defaults can be an object or a callback with the current props. The provider and component classes are additive; styles are applied in the order styles provider, provider style for root, local styles, local style. A nested statistic={} replaces the entire record, maintaining the overall theme. General settings show each level.
Local prefixCls changes the CSS classes of Statistic and its nodes; a non-empty value takes precedence over ConfigProvider.prefixCls. The empty string and undefined inherit the provider's base prefix with the -statistic suffix, defaulting to ant-statistic. This is different from prefix, which adds content before the number. The setting is also available for StatisticTimer. Local example retains the design and standard neighbor; common prefix shows inheritance of both components. When loading, Skeleton separately inherits the general prefix of the provider, and not the local Statistic.prefixCls.
Examples
Basic example
Number of users, balance with precision and default value.
<script lang="ts">
import { Button, Statistic } from '@woodger/antd';
let balance = $state(112893);
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
align-items: start;
gap: 32px;
}
.balance {
display: grid;
justify-items: start;
gap: 16px;
}
</style>
<div class="examples">
<Statistic title={("Active users")} value={112893} />
<div class="balance">
<Statistic title={("Account balance")} value={balance} precision={2} />
<Button
type="primary"
onclick={() => { balance += 100; }}
>{("Top up by 100")}</Button>
</div>
<Statistic title={("Default value")} />
</div>
Units of measurement
Text units, fraction and SVG prefix.
<script lang="ts">
import { Statistic } from '@woodger/antd';
</script>
<style>
.examples {
display: flex;
flex-wrap: wrap;
gap: 32px;
}
</style>
{#snippet arrow()}
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="M5 17 18 4M5 4h13v13" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round" />
</svg>
{/snippet}
<div class="examples">
<Statistic title={("Responses")} value={1128} suffix={("pcs.")} />
<Statistic title={("Plan completed")} value={93} suffix="/ 100" />
<Statistic title={("Growth")} value={11.28} precision={2} prefix={arrow} suffix="%"
styles={{ content: 'color: var(--ant-color-success)' }} />
</div>
Precision and separators
Padding with zeros, trimming without rounding and a large exact number with a string.
<script lang="ts">
import { Statistic } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
justify-items: start;
gap: 24px;
}
</style>
<div class="examples">
<Statistic title={("Separators")} value="123456.789" precision={2}
groupSeparator=" " decimalSeparator="," suffix="₽" />
<Statistic title={("Zero padding")} value="12.3" precision={4} />
<Statistic
title={("Large number in a string")}
value="9007199254740993.129"
precision={2}
groupSeparator=" "
decimalSeparator=","
styles={{ content: 'font-size: 18px' }}
/>
</div>
Animated value
formatter and Svelte Tween; changes by button, reduced motion and cleanup.
AnimatedStatistic.svelte<script lang="ts"> import { untrack } from 'svelte'; import { Tween, prefersReducedMotion } from 'svelte/motion'; import { Statistic } from '@woodger/antd'; let { title, value, precision = 0 }: { title: string; value: number; precision?: number; } = $props(); const tween = new Tween(untrack(() => value)); const numberFormat = $derived(new Intl.NumberFormat('en-US', { minimumFractionDigits: precision, maximumFractionDigits: precision })); $effect(() => { const target = value; const duration = prefersReducedMotion.current ? 0 : 800; if (untrack(() => tween.current === target)) { return; } void tween.set(target, { duration }); return () => { void tween.set(tween.current, { duration: 0 }); }; }); </script> <Statistic title={(title)} {value} formatter={() => numberFormat.format(tween.current)} styles={{ content: 'font-variant-numeric: tabular-nums' }} />Animated.svelte<script lang="ts"> import { Button } from '@woodger/antd'; import AnimatedStatistic from './AnimatedStatistic.svelte'; let users = $state(112893); let balance = $state(112893); </script> <style> .example { display: grid; justify-items: start; gap: 20px; } .values, .actions { display: flex; flex-wrap: wrap; gap: 24px; } </style> <div class="example"> <div class="values"> <AnimatedStatistic title={("Users with animation")} value={users} /> <AnimatedStatistic title={("Balance with animation")} value={balance} precision={2} /> </div> <div class="actions"> <Button onclick={() => { users += 1000; balance += 1000; }}>{("Increase performance")}</Button> <Button onclick={() => { users = 112893; balance = 112893; }}>{("Reset indicators")}</Button> </div> </div>
Indicators in Card
Cards with activity percentages and their own value color.
<script lang="ts">
import { Card, Statistic } from '@woodger/antd';
</script>
<style>
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
gap: 16px;
padding: 16px;
border-radius: 8px;
background: var(--ant-color-fill-alter);
}
</style>
<div class="cards">
<Card size="small">
<Statistic title={("Active")} value={11.28} precision={2} suffix="%"
styles={{ content: 'color: var(--ant-color-success)' }} />
</Card>
<Card size="small">
<Statistic title={("Inactive")} value={9.3} precision={2} suffix="%"
styles={{ content: 'color: var(--ant-color-error)' }} />
</Card>
</div>
Countdown and forward countdown
StatisticTimer with countup/countdown, events, restart and stop.
<script lang="ts">
import { Button, StatisticTimer } from '@woodger/antd';
let started = $state<number>();
let remaining = $state(10);
let completions = $state(0);
function start() {
remaining = 10;
started = Date.now();
}
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
.actions, .values {
display: flex;
flex-wrap: wrap;
gap: 16px;
}
output { color: var(--ant-color-text-secondary); }
</style>
<div class="example">
<div class="actions">
<Button type="primary" onclick={start}>{("Start timers")}</Button>
<Button disabled={started === undefined} onclick={() => { started = undefined; }}>
{("\n Stop timers\n ")}
</Button>
</div>
{#if started !== undefined}
<div class="values">
<StatisticTimer title={("Countdown")} type="countdown" value={started
+ 10000}
onChange={next => { remaining = Math.max(0, Math.ceil(next / 1000)); }}
onFinish={() => { completions++; }} />
<StatisticTimer title={("Time has passed")} type="countup" value={started} />
</div>
{/if}
<output
aria-label={("Timer events")}
>{("Seconds left: ")}{remaining}{("; completions: ")}{completions}</output>
</div>
Duration formats
Milliseconds, full days and literals in square brackets.
<script lang="ts">
import { Button, StatisticTimer } from '@woodger/antd';
let started = $state<number>();
const duration = 2 * 24 * 60 * 60 * 1000 + 30000;
</script>
<style>
.example {
display: grid;
justify-items: start;
gap: 20px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 16px;
}
.values {
display: grid;
gap: 24px;
}
</style>
<div class="example">
<div class="actions">
<Button onclick={() => { started = Date.now(); }}>{("Launch formats")}</Button>
<Button disabled={started === undefined} onclick={() => { started = undefined; }}>
{("\n Stop formats\n ")}
</Button>
</div>
{#if started !== undefined}
<div class="values">
<StatisticTimer title={("With milliseconds")} type="countdown" value={started
+ duration}
format="HH:mm:ss.SSS" />
<StatisticTimer title={("Days to completion")} type="countdown" value={started
+ duration}
format={("D [d] HH:mm:ss")} />
<StatisticTimer title={("Days after start")} type="countup" value={started
- duration}
format={("D [d] HH:mm:ss")} />
</div>
{/if}
</div>
<script lang="ts">
import { Checkbox, Statistic } from '@woodger/antd';
let loading = $state(true);
</script>
<style>
.example {
display: grid;
gap: 20px;
}
.value {
min-width: 0;
max-width: 240px;
}
</style>
<div class="example">
<Checkbox bind:checked={loading}>{("Loading indicator")}</Checkbox>
<div class="value">
<Statistic title={("Confirmed orders")} value={1128} {loading} />
</div>
</div>
formatter and snippets
Intl.NumberFormat, valueRender wrapper and Snippet instead of number.
<script lang="ts">
import type { Snippet } from 'svelte';
import { Statistic } from '@woodger/antd';
const currency = new Intl.NumberFormat("en", {
style: 'currency', currency: 'RUB', maximumFractionDigits: 0
});
</script>
<style>
.examples {
display: grid;
justify-items: start;
gap: 24px;
}
.highlight {
padding: 2px 6px;
border-radius: 4px;
color: var(--ant-color-primary);
background: var(--ant-color-primary-bg);
}
</style>
{#snippet title()}
<span>{("Revenue ")}<small>
{("per month")}
</small></span>
{/snippet}
{#snippet wrapped(original: Snippet)}
<span class="highlight">{@render original()}</span>
{/snippet}
{#snippet customValue()}<strong>{("Ready")}</strong>{/snippet}
<div class="examples">
<Statistic title={(title)} value={12345.67} formatter={value => currency.format(
Number(value)
)} />
<Statistic
title={("Original value wrapper")}
value={12345.67}
precision={2}
valueRender={wrapped}
/>
<Statistic
title={("Snippet instead of a number")}
value="done"
formatter={() => customValue}
/>
</div>
Semantic DOM
Designing seven slots with an object and a function from props.
<script lang="ts">
import { Statistic } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
justify-items: stretch;
gap: 24px;
}
</style>
<div class="examples">
<Statistic
title={("Users per month")}
value={93241}
prefix="+"
suffix={("persons")}
classNames={{ root: 'statistic-semantic-object', value: 'statistic-object-value' }}
styles={{
root:
`
padding: 16px;
border: 1px solid var(--ant-color-border-secondary);
border-radius: 8px;
`,
header: 'padding-bottom: 12px',
title: 'font-weight: 600',
content: 'font-variant-numeric: tabular-nums',
value: 'color: var(--ant-color-primary)',
prefix: 'margin-inline-end: 8px',
suffix: 'font-size: 14px'
}}
/>
<Statistic title={("Change over the year")} value={-18.7} suffix="%"
classNames={() => ({ root: 'statistic-semantic-function' })}
styles={({ props }) => ({
value: `color: var(--ant-color-${Number(props.value) < 0 ? 'error' : 'success'})`,
title: 'font-weight: 600'
})} />
</div>
Component tokens
titleFontSize/contentFontSize, compact theme and priority styles.
<script lang="ts">
import { ConfigProvider, Statistic } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
justify-items: start;
gap: 24px;
}
</style>
<ConfigProvider theme={{ components: { Statistic: { titleFontSize: 16, contentFontSize: 32 } } }}>
<div class="examples">
<Statistic title={("Local topic")} value={4256} />
<ConfigProvider theme={{ compact: true }}>
<Statistic title={("Compact theme")} value={4256} />
</ConfigProvider>
<Statistic title={("Local style")} value={4256} styles={{
content: 'font-size: 28px'
}} />
</div>
</ConfigProvider>
Right to left
ConfigProvider.direction and order of prefix, value and unit.
<script lang="ts">
import { ConfigProvider, Statistic } from '@woodger/antd';
</script>
<ConfigProvider direction="rtl">
<Statistic
title={("Indicator from right to left")}
value={1234.5}
precision={2}
prefix="$"
suffix="USD"
/>
</ConfigProvider>
Indicators from the review
Participants, balance, plan and user-triggered countdown.
<script lang="ts">
import { Button, Flex, Statistic, StatisticTimer } from '@woodger/antd';
let users = $state(112893);
let loading = $state(false);
let deadline = $state<number>();
let finished = $state(false);
</script>
<Flex gap="large" wrap>
<Statistic title={("Members")} value={users} loading={loading} />
<Statistic
title={("Project balance")}
value="123456.789"
precision={2}
suffix="₽"
loading={loading}
/>
<Statistic
title={("Execution of plan")}
value={93}
suffix="/ 100"
loading={loading}
/>
</Flex>
<div style="margin-top:16px">
<Button
onclick={() => {
finished = false;
deadline = Date.now() + 10000;
}}
>{("Start countdown")}</Button>
{#if deadline !== undefined}<div style="margin-top:16px"><StatisticTimer
title={("Until completion")}
type="countdown"
value={deadline}
onFinish={() => { finished = true; }}
/></div>{/if}
{#if finished}<p role="status">{("Countdown completed")}</p>{/if}
</div>
<Flex gap="small" wrap style="margin-top:16px">
<Button onclick={() => { users++; }}>{("Add member")}</Button>
<Button onclick={() => { loading = !loading; }}>{(loading ? "Show values" : "Show loading")}</Button>
</Flex>
General settings Statistic
ConfigProvider.statistic, local styles, nested record and timer design.
<script lang="ts">
import { Button, Checkbox, ConfigProvider, Statistic, StatisticTimer } from '@woodger/antd';
let emphasized = $state(true);
let started = $state<number>();
</script>
<style>
.example, .metrics {
display: grid;
gap: 24px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
</style>
<div class="example">
<Checkbox bind:checked={emphasized}>{("Accent indicators")}</Checkbox>
<ConfigProvider statistic={{
class: 'shared-statistic', style: 'padding: 12px',
classNames: { value: 'shared-statistic-value' },
styles: ({ props }) => ({
title: 'font-weight: 600',
value: emphasized && Number(props.value) > 0
? 'color: #389e0d'
: 'color: var(--ant-color-text)'
})
}}>
<div class="metrics">
<Statistic title={("Setting up a provider")} value={2400} aria-label={("General indicator")} />
<Statistic title={("Local design")} value={1200} aria-label={("Local indicator")}
classNames={{ value: 'local-statistic-value' }} styles={{ value: 'color: #d46b08' }}
style="padding: 20px" />
<ConfigProvider statistic={{}}>
<Statistic title={("Independent region")} value={600} aria-label={("Indicator without defaults")} />
</ConfigProvider>
{#if started !== undefined}
<StatisticTimer
title={("Timer with general design")}
type="countup"
value={started}
aria-label={("Timer with defaults")}
/>
{/if}
</div>
</ConfigProvider>
<div class="actions">
<Button
onclick={() => { started = Date.now(); }}
>{("Show timer with defaults")}</Button>
<Button disabled={started === undefined} onclick={() => { started = undefined; }}>
{("Remove timer from defaults")}
</Button>
</div>
</div>
Local CSS prefix
Reactive prefixCls and standard neighbor without changing geometry.
<script lang="ts">
import { Checkbox, Statistic } from '@woodger/antd';
let alternate = $state(false);
</script>
<style>
.example {
display: grid;
gap: 24px;
}
</style>
<div class="example">
<Checkbox bind:checked={alternate}>{("Other prefix Statistic")}</Checkbox>
<Statistic prefixCls={alternate ? 'woodger-metric' : 'woodger-statistic'}
title={("With local prefix")} value={1234.5} precision={2} suffix="₽"
aria-label={("Indicator with prefix")} />
<Statistic title={("Standard neighbor")} value={1234.5} precision={2} suffix="₽"
aria-label={("Standard indicator")} />
</div>
API
Verified against six ant.design 6.7.0 themes and public Svelte API based on 6.6.8. For timers, a separate StatisticTimer import is used. Full definitions of Props are in the package.
| Theme | Example |
|---|---|
| Basic | Indicators, accuracy and balance replenishment. |
| Unit | Units and Snippet of the prefix. |
| Animated number | Svelte Tween via formatter instead of React CountUp; reduced motion and cleanup. |
| In Card | Indicators inside Card. |
| Timer | Countup/countdown, events; days and milliseconds are listed on a separate card. |
| Custom semantic dom styling | styles/classNames object and function for seven slots. |
| Component config | Common class/style and semantic defaults Statistic, including Timer. |
| Local CSS prefix | Isolated prefixCls without changing the contents of the prefix. |
Statistic
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full local CSS prefix for the root and Statistic/Timer nodes. The empty string inherits the common prefix; ant-statistic is used without configuration. theme/semantic slots are preserved. | string | ConfigProvider + -statistic |
value | Number or string. The string retains its exact decimal representation. | StatisticValue | 0 |
title | Header; supports Snippet. | StatisticContent | — |
precision | Pads or truncates a fractional string without rounding. | number | original fractional part |
decimalSeparator | Fractional separator of the built-in formatter. | string | . |
groupSeparator | Group separator of an integer part. | string | , |
prefix | Content before value; string, number or Snippet. | StatisticContent | — |
suffix | Unit of measure or content after the value. | StatisticContent | — |
formatter | Own display. With the function, precision and delimiters are processed by the owner. | (value: StatisticValue) => StatisticContent | built-in |
valueRender | A wrapper around the original value that preserves the inline formatting. | Snippet<[original: Snippet]> | — |
loading | Skeleton instead of value; the header is retained. | boolean | false |
classNames | Classes by semantic slots; the function gets the allowed props. | StatisticSemanticSlots | callback | ConfigProvider.statistic |
styles | CSS lines by semantic slots; object or function. | StatisticSemanticSlots | callback | ConfigProvider.statistic |
nativeElement | bind:nativeElement provides root after mount and is cleared upon unmount. | HTMLDivElement | undefined | — |
StatisticTimer
| Property | Description | Type | Default |
|---|---|---|---|
type | Countdown or forward countdown. | 'countdown' | 'countup' | is required |
value | In the examples - timestamp in milliseconds: countdown target or countup start. | StatisticValue | — |
format | Duration units Y/M/D/H/m/s/S; text in square brackets is a literal. | string | HH:mm:ss |
onChange | Duration in milliseconds, updated more than once per second. | (value: number) => void | — |
onFinish | End countdown; countup is not called. | () => void | — |
ConfigProvider.statistic accepts StatisticConfig: class, style, classNames and styles for Statistic and StatisticTimer. Semantic defaults support an object or callback with the current props. Local styles take precedence; nested statistic={} replaces the entire record. Root style are applied after semantic root; The provider and component classes are added together.
Semantic DOM
Title and value are plain text, not an input field. Specify the name of the indicator and the unit of measurement. Frequent timer updates are not advertised as a live region; the result of the operation in the examples is displayed as a separate output.
| Slot | Purpose |
|---|---|
root | Indicator container. |
header | Header area and its bottom margin. |
title | Title text. |
content | Prefix, value and unit string. |
value | Formatted value. |
prefix | Content before value. |
suffix | Content after the value. |
title, prefix and suffix accept values or Snippet. formatter can return Snippet; valueRender gets the original value as a Snippet for the wrapper. The decorative SVG arrow is hidden from the accessibility tree.
Registration tokens
theme.components.Statistic sets the titleFontSize and contentFontSize for the entire family. Local semantic styles retain priority. The example checks both sizes in the standard and compact theme.
| Token | Purpose |
|---|---|
titleFontSize | Header size; standard 14px. |
contentFontSize | Value size; standard 24px, compact - 20px. |
| Token | Meaning |
|---|---|
colorText | rgba(0,0,0,0.88) |
colorTextDescription | rgba(0,0,0,0.45) |
colorTextHeading | rgba(0,0,0,0.88) |
fontFamily | -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
'Noto Color Emoji' |
fontSize | 14 |
lineHeight | 1.5714285714285714 |
marginXXS | 4 |
padding | 16 |
FAQ
Why doesn't precision round?
Built-in format pads and truncates a string. For rounding, specify a formatter with the necessary rules.
Who controls the animation of the number?
The example uses Svelte Tween and passes the result through formatter. Statistic itself does not run Tween.
Why does the timer start with a button?
So the timestamp appears in the browser after the user action, and the SSR remains stable. Removing a component clears the interval.
How to show days and milliseconds?
Use D and SSS, enclose text in square brackets. This is a duration, not a calendar date format.