Statistic
A display component for statistical figures, with decimal precision, thousands grouping and affixes.
Basic usage
Basic usage
Active users
98,800
Transaction amount
¥12,600.50
Total views
99 999 999 999 999 999 999
Completion rate
87%
import { LhStatistic } from '@lh-ui/react'
export default function Demo() {
return (
<>
<LhStatistic title="Active users" value={98800} />
<LhStatistic title="Transaction amount" value={12600.5} precision={2} prefix="¥" />
<LhStatistic title="Total views" value="99999999999999999999" separator=" " />
<LhStatistic title="Completion rate" value={87} suffix="%" />
</>
)
}
Statistic Props
| Prop | Description | Type | Options | Default |
|---|---|---|---|---|
| title | Figure caption (rendered above the value) | ReactNode | — | — |
| value | Statistical figure; a string can carry very large numbers or signed text | string | number | — | — |
| precision | Decimal places (sanitized internally, dirty values never throw) | number | — | 0 |
| separator | Thousands separator; an empty string disables grouping | string | — | ',' |
| prefix | Value prefix, e.g. a currency symbol | ReactNode | — | — |
| suffix | Value suffix, e.g. a unit | ReactNode | — | — |
| sx | Layout shorthand | SxProps | — | — |
Vue equivalent
value / precision / separator match lh-ui-plus's LhStatistic props; React has no slots,
so the #title / #prefix / #suffix slots become same-named ReactNode props.
Very large and non-finite values
Pass value as a string to carry numbers beyond Number.MAX_SAFE_INTEGER: the formatting runs
entirely on the string, so precision and grouping are never lost. Non-finite numbers such as
NaN / Infinity render verbatim.
Accessibility
The value element carries aria-live="polite", so screen readers announce value updates.
Styles
import '@lh-ui/react/style/statistic'