1
1
import type { App , Plugin , ExtractPropTypes , PropType , HTMLAttributes } from 'vue' ;
2
2
import { provide , defineComponent , ref , watch , computed , toRef } from 'vue' ;
3
- import PropTypes from '../_util/vue-types' ;
4
3
import classNames from '../_util/classNames' ;
5
4
6
5
import type { SpinProps } from '../spin' ;
@@ -13,6 +12,14 @@ import Item from './Item';
13
12
import { flattenChildren } from '../_util/props-util' ;
14
13
import initDefaultProps from '../_util/props-util/initDefaultProps' ;
15
14
import type { Key } from '../_util/type' ;
15
+ import {
16
+ arrayType ,
17
+ someType ,
18
+ booleanType ,
19
+ objectType ,
20
+ vNodeType ,
21
+ functionType ,
22
+ } from '../_util/type' ;
16
23
import ItemMeta from './ItemMeta' ;
17
24
import useConfigInject from '../config-provider/hooks/useConfigInject' ;
18
25
import useBreakpoint from '../_util/hooks/useBreakpoint' ;
@@ -45,30 +52,22 @@ export type ListSize = 'small' | 'default' | 'large';
45
52
export type ListItemLayout = 'horizontal' | 'vertical' ;
46
53
47
54
export const listProps = ( ) => ( {
48
- bordered : { type : Boolean , default : undefined } ,
49
- dataSource : PropTypes . array ,
50
- extra : PropTypes . any ,
51
- grid : { type : Object as PropType < ListGridType > , default : undefined as ListGridType } ,
55
+ bordered : booleanType ( ) ,
56
+ dataSource : arrayType ( ) ,
57
+ extra : vNodeType ( ) ,
58
+ grid : objectType < ListGridType > ( ) ,
52
59
itemLayout : String as PropType < ListItemLayout > ,
53
- loading : {
54
- type : [ Boolean , Object ] as PropType < boolean | ( SpinProps & HTMLAttributes ) > ,
55
- default : undefined as boolean | ( SpinProps & HTMLAttributes ) ,
56
- } ,
57
- loadMore : PropTypes . any ,
58
- pagination : {
59
- type : [ Boolean , Object ] as PropType < false | PaginationConfig > ,
60
- default : undefined as false | PaginationConfig ,
61
- } ,
60
+ loading : someType < boolean | ( SpinProps & HTMLAttributes ) > ( [ Boolean , Object ] ) ,
61
+ loadMore : vNodeType ( ) ,
62
+ pagination : someType < false | PaginationConfig > ( [ Boolean , Object ] ) ,
62
63
prefixCls : String ,
63
- rowKey : [ String , Number , Function ] as PropType < Key | ( ( item : any ) => Key ) > ,
64
- renderItem : Function as PropType < ( opt : { item : any ; index : number } ) => any > ,
64
+ rowKey : someType < Key | ( ( item : any ) => Key ) > ( [ String , Number , Function ] ) ,
65
+ renderItem : functionType < ( opt : { item : any ; index : number } ) => any > ( ) ,
65
66
size : String as PropType < ListSize > ,
66
- split : { type : Boolean , default : undefined } ,
67
- header : PropTypes . any ,
68
- footer : PropTypes . any ,
69
- locale : {
70
- type : Object as PropType < ListLocale > ,
71
- } ,
67
+ split : booleanType ( ) ,
68
+ header : vNodeType ( ) ,
69
+ footer : vNodeType ( ) ,
70
+ locale : objectType < ListLocale > ( ) ,
72
71
} ) ;
73
72
74
73
export interface ListLocale {
@@ -78,7 +77,6 @@ export interface ListLocale {
78
77
export type ListProps = Partial < ExtractPropTypes < ReturnType < typeof listProps > > > ;
79
78
80
79
import { ListContextKey } from './contextKey' ;
81
- import type { RenderEmptyHandler } from '../config-provider/renderEmpty' ;
82
80
83
81
const List = defineComponent ( {
84
82
compatConfig : { MODE : 3 } ,
@@ -135,12 +133,6 @@ const List = defineComponent({
135
133
136
134
const onPaginationShowSizeChange = triggerPaginationEvent ( 'onShowSizeChange' ) ;
137
135
138
- const renderEmptyFunc = ( renderEmptyHandler : RenderEmptyHandler ) => (
139
- < div class = { `${ prefixCls . value } -empty-text` } >
140
- { props . locale ?. emptyText || renderEmptyHandler ( 'List' ) }
141
- </ div >
142
- ) ;
143
-
144
136
const loadingProp = computed ( ( ) => {
145
137
if ( typeof props . loading === 'boolean' ) {
146
138
return {
@@ -304,7 +296,11 @@ const List = defineComponent({
304
296
< ul class = { `${ prefixCls . value } -items` } > { items } </ ul >
305
297
) ;
306
298
} else if ( ! children . length && ! isLoading . value ) {
307
- childrenContent = renderEmptyFunc ( renderEmpty ) ;
299
+ childrenContent = (
300
+ < div class = { `${ prefixCls . value } -empty-text` } >
301
+ { props . locale ?. emptyText || renderEmpty ( 'List' ) }
302
+ </ div >
303
+ ) ;
308
304
}
309
305
310
306
const paginationPosition = paginationProps . value . position || 'bottom' ;
0 commit comments