2019-01-09 20:38:09 +08:00
|
|
|
import classNames from 'classnames';
|
2022-06-22 14:57:09 +08:00
|
|
|
import * as React from 'react';
|
2019-01-09 20:38:09 +08:00
|
|
|
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ConfigConsumerProps } from '../config-provider';
|
2019-10-21 12:01:33 +08:00
|
|
|
import { withConfigConsumer } from '../config-provider/context';
|
2020-10-23 10:09:31 +08:00
|
|
|
import Skeleton from '../skeleton';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type Countdown from './Countdown';
|
2022-06-22 14:57:09 +08:00
|
|
|
import StatisticNumber from './Number';
|
|
|
|
import type { FormatConfig, valueType } from './utils';
|
2019-01-09 20:38:09 +08:00
|
|
|
|
|
|
|
interface StatisticComponent {
|
|
|
|
Countdown: typeof Countdown;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface StatisticProps extends FormatConfig {
|
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
|
|
|
style?: React.CSSProperties;
|
|
|
|
value?: valueType;
|
|
|
|
valueStyle?: React.CSSProperties;
|
|
|
|
valueRender?: (node: React.ReactNode) => React.ReactNode;
|
|
|
|
title?: React.ReactNode;
|
|
|
|
prefix?: React.ReactNode;
|
|
|
|
suffix?: React.ReactNode;
|
2020-10-23 10:09:31 +08:00
|
|
|
loading?: boolean;
|
2020-06-06 15:25:47 +08:00
|
|
|
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
|
|
|
|
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
|
2019-01-09 20:38:09 +08:00
|
|
|
}
|
|
|
|
|
2020-03-28 11:56:57 +08:00
|
|
|
const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = props => {
|
2019-01-09 20:38:09 +08:00
|
|
|
const {
|
|
|
|
prefixCls,
|
|
|
|
className,
|
|
|
|
style,
|
|
|
|
valueStyle,
|
|
|
|
value = 0,
|
|
|
|
title,
|
|
|
|
valueRender,
|
|
|
|
prefix,
|
|
|
|
suffix,
|
2020-10-23 10:09:31 +08:00
|
|
|
loading,
|
2020-01-02 19:10:16 +08:00
|
|
|
direction,
|
2020-06-06 15:25:47 +08:00
|
|
|
onMouseEnter,
|
|
|
|
onMouseLeave,
|
2019-01-09 20:38:09 +08:00
|
|
|
} = props;
|
2020-06-06 15:25:47 +08:00
|
|
|
const valueNode = <StatisticNumber {...props} value={value} />;
|
2020-09-06 13:07:39 +08:00
|
|
|
const cls = classNames(
|
|
|
|
prefixCls,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
|
|
},
|
|
|
|
className,
|
|
|
|
);
|
2019-01-09 20:38:09 +08:00
|
|
|
return (
|
2020-06-06 15:25:47 +08:00
|
|
|
<div className={cls} style={style} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
|
2019-01-09 20:38:09 +08:00
|
|
|
{title && <div className={`${prefixCls}-title`}>{title}</div>}
|
2022-06-02 11:36:03 +08:00
|
|
|
<Skeleton paragraph={false} loading={loading} className={`${prefixCls}-skeleton`}>
|
2020-10-23 10:09:31 +08:00
|
|
|
<div style={valueStyle} className={`${prefixCls}-content`}>
|
|
|
|
{prefix && <span className={`${prefixCls}-content-prefix`}>{prefix}</span>}
|
|
|
|
{valueRender ? valueRender(valueNode) : valueNode}
|
|
|
|
{suffix && <span className={`${prefixCls}-content-suffix`}>{suffix}</span>}
|
|
|
|
</div>
|
|
|
|
</Skeleton>
|
2019-01-09 20:38:09 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Statistic.defaultProps = {
|
|
|
|
decimalSeparator: '.',
|
2019-01-10 17:04:14 +08:00
|
|
|
groupSeparator: ',',
|
2020-10-23 10:09:31 +08:00
|
|
|
loading: false,
|
2019-01-09 20:38:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const WrapperStatistic = withConfigConsumer<StatisticProps>({
|
|
|
|
prefixCls: 'statistic',
|
|
|
|
})<StatisticComponent>(Statistic);
|
|
|
|
|
|
|
|
export default WrapperStatistic;
|