|
@ -1,18 +1,12 @@ |
|
|
import classNames from 'classnames'; |
|
|
import classNames from 'classnames'; |
|
|
import * as React from 'react'; |
|
|
import * as React from 'react'; |
|
|
|
|
|
|
|
|
import type { ConfigConsumerProps } from '../config-provider'; |
|
|
import type { ConfigConsumerProps } from '../config-provider'; |
|
|
import { withConfigConsumer } from '../config-provider/context'; |
|
|
import { ConfigContext } from '../config-provider'; |
|
|
import Skeleton from '../skeleton'; |
|
|
import Skeleton from '../skeleton'; |
|
|
import type Countdown from './Countdown'; |
|
|
|
|
|
import StatisticNumber from './Number'; |
|
|
import StatisticNumber from './Number'; |
|
|
import type { FormatConfig, valueType } from './utils'; |
|
|
import type { FormatConfig, valueType } from './utils'; |
|
|
|
|
|
|
|
|
import useStyle from './style'; |
|
|
import useStyle from './style'; |
|
|
|
|
|
import Countdown from './Countdown'; |
|
|
type CompoundedComponent = { |
|
|
|
|
|
Countdown: typeof Countdown; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export interface StatisticProps extends FormatConfig { |
|
|
export interface StatisticProps extends FormatConfig { |
|
|
prefixCls?: string; |
|
|
prefixCls?: string; |
|
@ -29,9 +23,13 @@ export interface StatisticProps extends FormatConfig { |
|
|
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>; |
|
|
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = (props) => { |
|
|
type CompoundedComponent = { |
|
|
|
|
|
Countdown: typeof Countdown; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const Statistic: React.FC<StatisticProps> & CompoundedComponent = (props) => { |
|
|
const { |
|
|
const { |
|
|
prefixCls, |
|
|
prefixCls: customizePrefixCls, |
|
|
className, |
|
|
className, |
|
|
style, |
|
|
style, |
|
|
valueStyle, |
|
|
valueStyle, |
|
@ -41,22 +39,28 @@ const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = (props) => { |
|
|
prefix, |
|
|
prefix, |
|
|
suffix, |
|
|
suffix, |
|
|
loading = false, |
|
|
loading = false, |
|
|
direction, |
|
|
|
|
|
onMouseEnter, |
|
|
onMouseEnter, |
|
|
onMouseLeave, |
|
|
onMouseLeave, |
|
|
decimalSeparator = '.', |
|
|
decimalSeparator = '.', |
|
|
groupSeparator = ',', |
|
|
groupSeparator = ',', |
|
|
} = props; |
|
|
} = props; |
|
|
const valueNode = ( |
|
|
|
|
|
|
|
|
const { getPrefixCls, direction } = React.useContext<ConfigConsumerProps>(ConfigContext); |
|
|
|
|
|
|
|
|
|
|
|
const prefixCls = getPrefixCls('statistic', customizePrefixCls); |
|
|
|
|
|
|
|
|
|
|
|
const [wrapSSR, hashId] = useStyle(prefixCls); |
|
|
|
|
|
|
|
|
|
|
|
const valueNode: React.ReactNode = ( |
|
|
<StatisticNumber |
|
|
<StatisticNumber |
|
|
decimalSeparator={decimalSeparator} |
|
|
decimalSeparator={decimalSeparator} |
|
|
groupSeparator={groupSeparator} |
|
|
groupSeparator={groupSeparator} |
|
|
|
|
|
prefixCls={prefixCls} |
|
|
{...props} |
|
|
{...props} |
|
|
value={value} |
|
|
value={value} |
|
|
/> |
|
|
/> |
|
|
); |
|
|
); |
|
|
// Style
|
|
|
|
|
|
const [wrapSSR, hashId] = useStyle(String(prefixCls)); |
|
|
|
|
|
const cls = classNames( |
|
|
const cls = classNames( |
|
|
prefixCls, |
|
|
prefixCls, |
|
|
{ |
|
|
{ |
|
@ -65,6 +69,7 @@ const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = (props) => { |
|
|
className, |
|
|
className, |
|
|
hashId, |
|
|
hashId, |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
return wrapSSR( |
|
|
return wrapSSR( |
|
|
<div className={cls} style={style} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}> |
|
|
<div className={cls} style={style} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}> |
|
|
{title && <div className={`${prefixCls}-title`}>{title}</div>} |
|
|
{title && <div className={`${prefixCls}-title`}>{title}</div>} |
|
@ -79,8 +84,6 @@ const Statistic: React.FC<StatisticProps & ConfigConsumerProps> = (props) => { |
|
|
); |
|
|
); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const WrapperStatistic = withConfigConsumer<StatisticProps>({ |
|
|
Statistic.Countdown = Countdown; |
|
|
prefixCls: 'statistic', |
|
|
|
|
|
})<CompoundedComponent>(Statistic); |
|
|
|
|
|
|
|
|
|
|
|
export default WrapperStatistic; |
|
|
export default Statistic; |
|
|