1- import { defineComponent , inject , PropType } from 'vue' ;
1+ import { defineComponent , PropType } from 'vue' ;
22import PropTypes from '../_util/vue-types' ;
3- import { getComponent } from '../_util/props-util' ;
43import initDefaultProps from '../_util/props-util/initDefaultProps' ;
5- import { defaultConfigProvider } from '../config-provider' ;
64import StatisticNumber from './Number' ;
75import { countdownValueType } from './utils' ;
6+ import Skeleton from '../skeleton/Skeleton' ;
7+ import useConfigInject from '../_util/hooks/useConfigInject' ;
88
99export const StatisticProps = {
1010 prefixCls : PropTypes . string ,
@@ -22,52 +22,49 @@ export const StatisticProps = {
2222 suffix : PropTypes . VNodeChild ,
2323 title : PropTypes . VNodeChild ,
2424 onFinish : PropTypes . func ,
25+ loading : PropTypes . looseBool ,
2526} ;
2627
2728export default defineComponent ( {
2829 name : 'AStatistic' ,
2930 props : initDefaultProps ( StatisticProps , {
3031 decimalSeparator : '.' ,
3132 groupSeparator : ',' ,
33+ loading : false ,
3234 } ) ,
33-
34- setup ( ) {
35- return {
36- configProvider : inject ( 'configProvider' , defaultConfigProvider ) ,
37- } ;
38- } ,
39-
40- render ( ) {
41- const { prefixCls : customizePrefixCls , value = 0 , valueStyle, valueRender } = this . $props ;
42- const { getPrefixCls } = this . configProvider ;
43- const prefixCls = getPrefixCls ( 'statistic' , customizePrefixCls ) ;
44-
45- const title = getComponent ( this , 'title' ) ;
46- const prefix = getComponent ( this , 'prefix' ) ;
47- const suffix = getComponent ( this , 'suffix' ) ;
48- const formatter = getComponent ( this , 'formatter' , { } , false ) ;
49- const props = {
50- ...this . $props ,
51- prefixCls,
52- value,
53- formatter,
54- } ;
55- // data-for-update just for update component
56- // https://github.com/vueComponent/ant-design-vue/pull/3170
57- let valueNode = < StatisticNumber data-for-update = { Date . now ( ) } { ...props } /> ;
58- if ( valueRender ) {
59- valueNode = valueRender ( valueNode ) ;
60- }
61-
62- return (
63- < div class = { prefixCls } >
64- { title && < div class = { `${ prefixCls } -title` } > { title } </ div > }
65- < div style = { valueStyle } class = { `${ prefixCls } -content` } >
66- { prefix && < span class = { `${ prefixCls } -content-prefix` } > { prefix } </ span > }
67- { valueNode }
68- { suffix && < span class = { `${ prefixCls } -content-suffix` } > { suffix } </ span > }
35+ slots : [ 'title' , 'prefix' , 'suffix' , 'formatter' ] ,
36+ setup ( props , { slots } ) {
37+ const { prefixCls, direction } = useConfigInject ( 'statistic' , props ) ;
38+ return ( ) => {
39+ const { value = 0 , valueStyle, valueRender } = props ;
40+ const pre = prefixCls . value ;
41+ const title = props . title ?? slots . title ?.( ) ;
42+ const prefix = props . prefix ?? slots . prefix ?.( ) ;
43+ const suffix = props . suffix ?? slots . suffix ?.( ) ;
44+ const formatter = props . formatter ?? slots . formatter ;
45+ // data-for-update just for update component
46+ // https://github.com/vueComponent/ant-design-vue/pull/3170
47+ let valueNode = (
48+ < StatisticNumber
49+ data-for-update = { Date . now ( ) }
50+ { ...{ ...props , prefixCls : pre , value, formatter } }
51+ />
52+ ) ;
53+ if ( valueRender ) {
54+ valueNode = valueRender ( valueNode ) ;
55+ }
56+ return (
57+ < div class = { [ pre , { [ `${ pre } -rtl` ] : direction . value === 'rtl' } ] } >
58+ { title && < div class = { `${ pre } -title` } > { title } </ div > }
59+ < Skeleton paragraph = { false } loading = { props . loading } >
60+ < div style = { valueStyle } class = { `${ pre } -content` } >
61+ { prefix && < span class = { `${ pre } -content-prefix` } > { prefix } </ span > }
62+ { valueNode }
63+ { suffix && < span class = { `${ pre } -content-suffix` } > { suffix } </ span > }
64+ </ div >
65+ </ Skeleton >
6966 </ div >
70- </ div >
71- ) ;
67+ ) ;
68+ } ;
7269 } ,
7370} ) ;
0 commit comments