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';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ConfigConsumerProps } from '../config-provider';
|
2022-12-25 22:54:56 +08:00
|
|
|
import { ConfigContext } from '../config-provider';
|
2020-10-23 10:09:31 +08:00
|
|
|
import Skeleton from '../skeleton';
|
2019-01-09 20:38:09 +08:00
|
|
|
import StatisticNumber from './Number';
|
2022-06-22 14:57:09 +08:00
|
|
|
import type { FormatConfig, valueType } from './utils';
|
2022-03-16 12:02:52 +08:00
|
|
|
import useStyle from './style';
|
2022-12-25 22:54:56 +08:00
|
|
|
import Countdown from './Countdown';
|
2019-01-09 20:38:09 +08:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-12-25 22:54:56 +08:00
|
|
|
type CompoundedComponent = {
|
|
|
|
Countdown: typeof Countdown;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Statistic: React.FC<StatisticProps> & CompoundedComponent = (props) => {
|
2019-01-09 20:38:09 +08:00
|
|
|
const {
|
2022-12-25 22:54:56 +08:00
|
|
|
prefixCls: customizePrefixCls,
|
2019-01-09 20:38:09 +08:00
|
|
|
className,
|
|
|
|
style,
|
|
|
|
valueStyle,
|
|
|
|
value = 0,
|
|
|
|
title,
|
|
|
|
valueRender,
|
|
|
|
prefix,
|
|
|
|
suffix,
|
2022-09-30 17:44:24 +08:00
|
|
|
loading = false,
|
2020-06-06 15:25:47 +08:00
|
|
|
onMouseEnter,
|
|
|
|
onMouseLeave,
|
2022-09-30 17:44:24 +08:00
|
|
|
decimalSeparator = '.',
|
|
|
|
groupSeparator = ',',
|
2019-01-09 20:38:09 +08:00
|
|
|
} = props;
|
2022-12-25 22:54:56 +08:00
|
|
|
|
|
|
|
const { getPrefixCls, direction } = React.useContext<ConfigConsumerProps>(ConfigContext);
|
|
|
|
|
|
|
|
const prefixCls = getPrefixCls('statistic', customizePrefixCls);
|
|
|
|
|
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
|
|
|
|
|
|
|
const valueNode: React.ReactNode = (
|
2022-09-30 17:44:24 +08:00
|
|
|
<StatisticNumber
|
|
|
|
decimalSeparator={decimalSeparator}
|
|
|
|
groupSeparator={groupSeparator}
|
2022-12-25 22:54:56 +08:00
|
|
|
prefixCls={prefixCls}
|
2022-09-30 17:44:24 +08:00
|
|
|
{...props}
|
|
|
|
value={value}
|
|
|
|
/>
|
|
|
|
);
|
2022-12-25 22:54:56 +08:00
|
|
|
|
2020-09-06 13:07:39 +08:00
|
|
|
const cls = classNames(
|
|
|
|
prefixCls,
|
|
|
|
{
|
|
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
|
|
},
|
|
|
|
className,
|
2022-03-16 12:02:52 +08:00
|
|
|
hashId,
|
2020-09-06 13:07:39 +08:00
|
|
|
);
|
2022-12-25 22:54:56 +08:00
|
|
|
|
2022-03-16 12:02:52 +08:00
|
|
|
return wrapSSR(
|
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>
|
2022-03-16 12:02:52 +08:00
|
|
|
</div>,
|
2019-01-09 20:38:09 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-01-08 21:30:41 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
Statistic.displayName = 'Statistic';
|
|
|
|
}
|
|
|
|
|
2022-12-25 22:54:56 +08:00
|
|
|
Statistic.Countdown = Countdown;
|
2019-01-09 20:38:09 +08:00
|
|
|
|
2022-12-25 22:54:56 +08:00
|
|
|
export default Statistic;
|