2019-01-09 20:38:09 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
2019-10-21 12:01:33 +08:00
|
|
|
import { ConfigConsumerProps } from '../config-provider';
|
|
|
|
import { withConfigConsumer } from '../config-provider/context';
|
2019-01-09 20:38:09 +08:00
|
|
|
import StatisticNumber from './Number';
|
|
|
|
import Countdown from './Countdown';
|
|
|
|
import { valueType, FormatConfig } from './utils';
|
|
|
|
|
|
|
|
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-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-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-01-02 19:10:16 +08:00
|
|
|
const cls = classNames(prefixCls, className, {
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
|
|
});
|
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>}
|
|
|
|
<div style={valueStyle} className={`${prefixCls}-content`}>
|
|
|
|
{prefix && <span className={`${prefixCls}-content-prefix`}>{prefix}</span>}
|
2020-06-06 15:25:47 +08:00
|
|
|
{valueRender ? valueRender(valueNode) : valueNode}
|
2019-01-09 20:38:09 +08:00
|
|
|
{suffix && <span className={`${prefixCls}-content-suffix`}>{suffix}</span>}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Statistic.defaultProps = {
|
|
|
|
decimalSeparator: '.',
|
2019-01-10 17:04:14 +08:00
|
|
|
groupSeparator: ',',
|
2019-01-09 20:38:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const WrapperStatistic = withConfigConsumer<StatisticProps>({
|
|
|
|
prefixCls: 'statistic',
|
|
|
|
})<StatisticComponent>(Statistic);
|
|
|
|
|
|
|
|
export default WrapperStatistic;
|