Skip to main content

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​

PropDescriptionTypeOptionsDefault
titleFigure caption (rendered above the value)ReactNode——
valueStatistical figure; a string can carry very large numbers or signed textstring | number——
precisionDecimal places (sanitized internally, dirty values never throw)number—0
separatorThousands separator; an empty string disables groupingstring—','
prefixValue prefix, e.g. a currency symbolReactNode——
suffixValue suffix, e.g. a unitReactNode——
sxLayout shorthandSxProps——
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'