import classNames from 'classnames'; import * as React from 'react'; import type { ConfigConsumerProps } from '../config-provider'; import { ConfigContext } from '../config-provider'; import Skeleton from '../skeleton'; import StatisticNumber from './Number'; import type { FormatConfig, valueType } from './utils'; import useStyle from './style'; import Countdown from './Countdown'; export interface StatisticProps 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; } type CompoundedComponent = { Countdown: typeof Countdown; }; const Statistic: React.FC & CompoundedComponent = (props) => { const { prefixCls: customizePrefixCls, className, rootClassName, style, valueStyle, value = 0, title, valueRender, prefix, suffix, loading = false, onMouseEnter, onMouseLeave, decimalSeparator = '.', groupSeparator = ',', } = props; const { getPrefixCls, direction } = React.useContext(ConfigContext); const prefixCls = getPrefixCls('statistic', customizePrefixCls); const [wrapSSR, hashId] = useStyle(prefixCls); const valueNode: React.ReactNode = ( ); const cls = classNames( prefixCls, { [`${prefixCls}-rtl`]: direction === 'rtl', }, className, rootClassName, hashId, ); return wrapSSR(
{title &&
{title}
}
{prefix && {prefix}} {valueRender ? valueRender(valueNode) : valueNode} {suffix && {suffix}}
, ); }; if (process.env.NODE_ENV !== 'production') { Statistic.displayName = 'Statistic'; } Statistic.Countdown = Countdown; export default Statistic;