@@ -8,14 +8,9 @@ import Pagination, { PaginationConfig } from '../pagination';
8
8
import { Row } from '../grid' ;
9
9
10
10
import Item from './Item' ;
11
- import {
12
- initDefaultProps ,
13
- getComponentFromProp ,
14
- filterEmpty ,
15
- getListeners ,
16
- } from '../_util/props-util' ;
11
+ import { initDefaultProps , getComponent , getSlot } from '../_util/props-util' ;
17
12
import { cloneElement } from '../_util/vnode' ;
18
- import Base from '../base ' ;
13
+ import { provide , inject } from 'vue ' ;
19
14
20
15
export { ListItemProps , ListItemMetaProps } from './Item' ;
21
16
@@ -56,6 +51,7 @@ export const ListProps = () => ({
56
51
} ) ;
57
52
58
53
const List = {
54
+ inheritAttrs : false ,
59
55
Item,
60
56
name : 'AList' ,
61
57
props : initDefaultProps ( ListProps ( ) , {
@@ -65,14 +61,15 @@ const List = {
65
61
loading : false ,
66
62
pagination : false ,
67
63
} ) ,
68
- provide ( ) {
64
+ created ( ) {
65
+ provide ( 'listContext' , this ) ;
66
+ } ,
67
+ setup ( ) {
69
68
return {
70
- listContext : this ,
69
+ configProvider : inject ( 'configProvider' , ConfigConsumerProps ) ,
71
70
} ;
72
71
} ,
73
- inject : {
74
- configProvider : { default : ( ) => ConfigConsumerProps } ,
75
- } ,
72
+
76
73
data ( ) {
77
74
this . keys = [ ] ;
78
75
this . defaultPaginationProps = {
@@ -107,10 +104,13 @@ const List = {
107
104
}
108
105
} ;
109
106
} ,
110
- renderItem2 ( item , index ) {
111
- const { $scopedSlots, rowKey } = this ;
112
- const renderItem = this . renderItem || $scopedSlots . renderItem ;
113
- if ( ! renderItem ) return null ;
107
+ innerRenderItem ( item , index ) {
108
+ const {
109
+ $slots : { renderItem } ,
110
+ rowKey,
111
+ } = this ;
112
+ const renderer = this . renderItem || renderItem ;
113
+ if ( ! renderer ) return null ;
114
114
let key ;
115
115
if ( typeof rowKey === 'function' ) {
116
116
key = rowKey ( item ) ;
@@ -126,21 +126,21 @@ const List = {
126
126
127
127
this . keys [ index ] = key ;
128
128
129
- return renderItem ( item , index ) ;
129
+ return renderer ( item , index ) ;
130
130
} ,
131
131
132
132
isSomethingAfterLastItem ( ) {
133
133
const { pagination } = this ;
134
- const loadMore = getComponentFromProp ( this , 'loadMore' ) ;
135
- const footer = getComponentFromProp ( this , 'footer' ) ;
134
+ const loadMore = getComponent ( this , 'loadMore' ) ;
135
+ const footer = getComponent ( this , 'footer' ) ;
136
136
return ! ! ( loadMore || pagination || footer ) ;
137
137
} ,
138
138
139
139
renderEmpty ( prefixCls , renderEmpty ) {
140
140
const { locale } = this ;
141
141
return (
142
142
< div class = { `${ prefixCls } -empty-text` } >
143
- { ( locale && locale . emptyText ) || renderEmpty ( h , 'List' ) }
143
+ { ( locale && locale . emptyText ) || renderEmpty ( 'List' ) }
144
144
</ div >
145
145
) ;
146
146
} ,
@@ -157,17 +157,17 @@ const List = {
157
157
dataSource = [ ] ,
158
158
size,
159
159
loading,
160
- $slots,
161
160
paginationCurrent,
162
161
paginationSize,
162
+ $attrs,
163
163
} = this ;
164
164
const getPrefixCls = this . configProvider . getPrefixCls ;
165
165
const prefixCls = getPrefixCls ( 'list' , customizePrefixCls ) ;
166
-
167
- const loadMore = getComponentFromProp ( this , 'loadMore' ) ;
168
- const footer = getComponentFromProp ( this , 'footer' ) ;
169
- const header = getComponentFromProp ( this , 'header' ) ;
170
- const children = filterEmpty ( $slots . default || [ ] ) ;
166
+ const { class : _cls , ... restAttrs } = $attrs ;
167
+ const loadMore = getComponent ( this , 'loadMore' ) ;
168
+ const footer = getComponent ( this , 'footer' ) ;
169
+ const header = getComponent ( this , 'header' ) ;
170
+ const children = getSlot ( this ) ;
171
171
let loadingProp = loading ;
172
172
if ( typeof loadingProp === 'boolean' ) {
173
173
loadingProp = {
@@ -189,22 +189,27 @@ const List = {
189
189
default :
190
190
break ;
191
191
}
192
- const classString = classNames ( prefixCls , {
193
- [ `${ prefixCls } -vertical` ] : itemLayout === 'vertical' ,
194
- [ `${ prefixCls } -${ sizeCls } ` ] : sizeCls ,
195
- [ `${ prefixCls } -split` ] : split ,
196
- [ `${ prefixCls } -bordered` ] : bordered ,
197
- [ `${ prefixCls } -loading` ] : isLoading ,
198
- [ `${ prefixCls } -grid` ] : grid ,
199
- [ `${ prefixCls } -something-after-last-item` ] : this . isSomethingAfterLastItem ( ) ,
200
- } ) ;
192
+ const classString = classNames (
193
+ prefixCls ,
194
+ {
195
+ [ `${ prefixCls } -vertical` ] : itemLayout === 'vertical' ,
196
+ [ `${ prefixCls } -${ sizeCls } ` ] : sizeCls ,
197
+ [ `${ prefixCls } -split` ] : split ,
198
+ [ `${ prefixCls } -bordered` ] : bordered ,
199
+ [ `${ prefixCls } -loading` ] : isLoading ,
200
+ [ `${ prefixCls } -grid` ] : grid ,
201
+ [ `${ prefixCls } -something-after-last-item` ] : this . isSomethingAfterLastItem ( ) ,
202
+ } ,
203
+ $attrs . class ,
204
+ ) ;
201
205
const paginationProps = {
202
206
...this . defaultPaginationProps ,
203
207
total : dataSource . length ,
204
208
current : paginationCurrent ,
205
209
pageSize : paginationSize ,
206
210
...( pagination || { } ) ,
207
211
} ;
212
+ classString ;
208
213
const largestPage = Math . ceil ( paginationProps . total / paginationProps . pageSize ) ;
209
214
if ( paginationProps . current > largestPage ) {
210
215
paginationProps . current = largestPage ;
@@ -239,7 +244,7 @@ const List = {
239
244
let childrenContent ;
240
245
childrenContent = isLoading && < div style = { { minHeight : 53 } } /> ;
241
246
if ( splitDataSource . length > 0 ) {
242
- const items = splitDataSource . map ( ( item , index ) => this . renderItem2 ( item , index ) ) ;
247
+ const items = splitDataSource . map ( ( item , index ) => this . innerRenderItem ( item , index ) ) ;
243
248
const childrenList = items . map ( ( child , index ) =>
244
249
cloneElement ( child , {
245
250
key : this . keys [ index ] ,
@@ -258,10 +263,10 @@ const List = {
258
263
const paginationPosition = paginationProps . position || 'bottom' ;
259
264
260
265
return (
261
- < div class = { classString } { ...{ on : getListeners ( this ) } } >
266
+ < div class = { classString } { ...restAttrs } >
262
267
{ ( paginationPosition === 'top' || paginationPosition === 'both' ) && paginationContent }
263
268
{ header && < div class = { `${ prefixCls } -header` } > { header } </ div > }
264
- < Spin { ...{ props : loadingProp } } >
269
+ < Spin { ...loadingProp } >
265
270
{ childrenContent }
266
271
{ children }
267
272
</ Spin >
@@ -274,11 +279,10 @@ const List = {
274
279
} ;
275
280
276
281
/* istanbul ignore next */
277
- List . install = function ( Vue ) {
278
- Vue . use ( Base ) ;
279
- Vue . component ( List . name , List ) ;
280
- Vue . component ( List . Item . name , List . Item ) ;
281
- Vue . component ( List . Item . Meta . name , List . Item . Meta ) ;
282
+ List . install = function ( app ) {
283
+ app . component ( List . name , List ) ;
284
+ app . component ( List . Item . name , List . Item ) ;
285
+ app . component ( List . Item . Meta . name , List . Item . Meta ) ;
282
286
} ;
283
287
284
288
export default List ;
0 commit comments