mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-05 05:28:20 +08:00
1fc374495f
* chore: init test * test: rootClassName inject * test: part of test * chore: patch qrcode rootCls * chore: part rootClassName * chore: part rootClassName * test: more test * test: more test * test: more test * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * test: more test * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: part rootClassName * chore: fix lint * chore: fix lint * chore: ignore part of lint * test: update snapshot * test: fix test case * chore: fix node test * chore: adjust render logic * fix: test * test: update snapshot * test: update * refactor * chore: fix require module logic
97 lines
2.6 KiB
TypeScript
97 lines
2.6 KiB
TypeScript
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<HTMLDivElement>;
|
|
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
|
|
}
|
|
|
|
type CompoundedComponent = {
|
|
Countdown: typeof Countdown;
|
|
};
|
|
|
|
const Statistic: React.FC<StatisticProps> & 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<ConfigConsumerProps>(ConfigContext);
|
|
|
|
const prefixCls = getPrefixCls('statistic', customizePrefixCls);
|
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
|
|
|
const valueNode: React.ReactNode = (
|
|
<StatisticNumber
|
|
decimalSeparator={decimalSeparator}
|
|
groupSeparator={groupSeparator}
|
|
prefixCls={prefixCls}
|
|
{...props}
|
|
value={value}
|
|
/>
|
|
);
|
|
|
|
const cls = classNames(
|
|
prefixCls,
|
|
{
|
|
[`${prefixCls}-rtl`]: direction === 'rtl',
|
|
},
|
|
className,
|
|
rootClassName,
|
|
hashId,
|
|
);
|
|
|
|
return wrapSSR(
|
|
<div className={cls} style={style} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
|
|
{title && <div className={`${prefixCls}-title`}>{title}</div>}
|
|
<Skeleton paragraph={false} loading={loading} className={`${prefixCls}-skeleton`}>
|
|
<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>
|
|
</div>,
|
|
);
|
|
};
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
Statistic.displayName = 'Statistic';
|
|
}
|
|
|
|
Statistic.Countdown = Countdown;
|
|
|
|
export default Statistic;
|