import * as React from 'react'; import classNames from 'classnames'; import pickAttrs from 'rc-util/lib/pickAttrs'; import type { HTMLAriaDataAttributes } from '../_util/aria-data-attrs'; import type { ConfigConsumerProps } from '../config-provider'; import { ConfigContext } from '../config-provider'; import Skeleton from '../skeleton'; import StatisticNumber from './Number'; import useStyle from './style'; import type { FormatConfig, valueType } from './utils'; interface StatisticReactProps extends FormatConfig { prefixCls?: string; className?: string; rootClassName?: string; style?: React.CSSProperties; value?: valueType; valueStyle?: React.CSSProperties; valueRender?: (node: React.ReactNode) => React.ReactNode; title?: React.ReactNode; prefix?: React.ReactNode; suffix?: React.ReactNode; loading?: boolean; onMouseEnter?: React.MouseEventHandler; onMouseLeave?: React.MouseEventHandler; } export type StatisticProps = HTMLAriaDataAttributes & StatisticReactProps; const Statistic: React.FC = (props) => { const { prefixCls: customizePrefixCls, className, rootClassName, style, valueStyle, value = 0, title, valueRender, prefix, suffix, loading = false, /* --- FormatConfig starts --- */ formatter, precision, decimalSeparator = '.', groupSeparator = ',', /* --- FormatConfig starts --- */ onMouseEnter, onMouseLeave, ...rest } = props; const { getPrefixCls, direction, statistic } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('statistic', customizePrefixCls); const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls); const valueNode: React.ReactNode = ( ); const cls = classNames( prefixCls, { [`${prefixCls}-rtl`]: direction === 'rtl', }, statistic?.className, className, rootClassName, hashId, cssVarCls, ); const restProps = pickAttrs(rest, { aria: true, data: true }); return wrapCSSVar(
{title &&
{title}
}
{prefix && {prefix}} {valueRender ? valueRender(valueNode) : valueNode} {suffix && {suffix}}
, ); }; if (process.env.NODE_ENV !== 'production') { Statistic.displayName = 'Statistic'; } export default Statistic;