1
- import { defineComponent , inject , PropType } from 'vue' ;
1
+ import { defineComponent , PropType } from 'vue' ;
2
2
import PropTypes from '../_util/vue-types' ;
3
- import { getComponent } from '../_util/props-util' ;
4
3
import initDefaultProps from '../_util/props-util/initDefaultProps' ;
5
- import { defaultConfigProvider } from '../config-provider' ;
6
4
import StatisticNumber from './Number' ;
7
5
import { countdownValueType } from './utils' ;
6
+ import Skeleton from '../skeleton/Skeleton' ;
7
+ import useConfigInject from '../_util/hooks/useConfigInject' ;
8
8
9
9
export const StatisticProps = {
10
10
prefixCls : PropTypes . string ,
@@ -22,52 +22,49 @@ export const StatisticProps = {
22
22
suffix : PropTypes . VNodeChild ,
23
23
title : PropTypes . VNodeChild ,
24
24
onFinish : PropTypes . func ,
25
+ loading : PropTypes . looseBool ,
25
26
} ;
26
27
27
28
export default defineComponent ( {
28
29
name : 'AStatistic' ,
29
30
props : initDefaultProps ( StatisticProps , {
30
31
decimalSeparator : '.' ,
31
32
groupSeparator : ',' ,
33
+ loading : false ,
32
34
} ) ,
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 >
69
66
</ div >
70
- </ div >
71
- ) ;
67
+ ) ;
68
+ } ;
72
69
} ,
73
70
} ) ;
0 commit comments