Skip to content

Commit 630378a

Browse files
committed
Support special style for item, wrapper, header and footer
1 parent 2e70fa3 commit 630378a

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

src/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ const VirtualList = Vue.component('virtual-list', {
221221
getRenderSlots (h) {
222222
const slots = []
223223
const { start, end } = this.range
224-
const { dataSources, dataKey, itemClass, itemTag, isHorizontal, extraProps, dataComponent } = this
224+
const { dataSources, dataKey, itemClass, itemTag, itemStyle, isHorizontal, extraProps, dataComponent } = this
225225
for (let index = start; index <= end; index++) {
226226
const dataSource = dataSources[index]
227227
if (dataSource) {
@@ -237,6 +237,7 @@ const VirtualList = Vue.component('virtual-list', {
237237
extraProps: extraProps,
238238
component: dataComponent
239239
},
240+
style: itemStyle,
240241
class: `${itemClass}${this.itemClassAdd ? ' ' + this.itemClassAdd(index) : ''}`
241242
}))
242243
} else {
@@ -255,8 +256,9 @@ const VirtualList = Vue.component('virtual-list', {
255256
render (h) {
256257
const { header, footer } = this.$slots
257258
const { padFront, padBehind } = this.range
258-
const { rootTag, headerClass, headerTag, wrapTag, wrapClass, footerClass, footerTag, isHorizontal } = this
259-
const padding = isHorizontal ? `0px ${padBehind}px 0px ${padFront}px` : `${padFront}px 0px ${padBehind}px`
259+
const { isHorizontal, rootTag, wrapTag, wrapClass, wrapStyle, headerTag, headerClass, headerStyle, footerTag, footerClass, footerStyle } = this
260+
const paddingStyle = { padding: isHorizontal ? `0px ${padBehind}px 0px ${padFront}px` : `${padFront}px 0px ${padBehind}px` }
261+
const wrapperStyle = wrapStyle ? Object.assign(wrapStyle, paddingStyle) : paddingStyle
260262

261263
return h(rootTag, {
262264
ref: 'root',
@@ -267,6 +269,7 @@ const VirtualList = Vue.component('virtual-list', {
267269
// header slot
268270
header ? h(Slot, {
269271
class: headerClass,
272+
style: headerStyle,
270273
props: {
271274
tag: headerTag,
272275
event: EVENT_TYPE.SLOT,
@@ -280,14 +283,13 @@ const VirtualList = Vue.component('virtual-list', {
280283
attrs: {
281284
role: 'group'
282285
},
283-
style: {
284-
padding: padding
285-
}
286+
style: wrapperStyle
286287
}, this.getRenderSlots(h)),
287288

288289
// footer slot
289290
footer ? h(Slot, {
290291
class: footerClass,
292+
style: footerStyle,
291293
props: {
292294
tag: footerTag,
293295
event: EVENT_TYPE.SLOT,

src/props.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,41 @@ export const VirtualProps = {
2828
default: 50
2929
},
3030

31-
rootTag: {
32-
type: String,
33-
default: 'div'
34-
},
35-
wrapTag: {
36-
type: String,
37-
default: 'div'
38-
},
39-
wrapClass: {
40-
type: String,
41-
default: ''
42-
},
4331
direction: {
4432
type: String,
4533
default: 'vertical' // the other value is horizontal
4634
},
47-
topThreshold: {
35+
start: {
4836
type: Number,
4937
default: 0
5038
},
51-
bottomThreshold: {
39+
offset: {
5240
type: Number,
5341
default: 0
5442
},
55-
start: {
43+
topThreshold: {
5644
type: Number,
5745
default: 0
5846
},
59-
offset: {
47+
bottomThreshold: {
6048
type: Number,
6149
default: 0
6250
},
51+
rootTag: {
52+
type: String,
53+
default: 'div'
54+
},
55+
wrapTag: {
56+
type: String,
57+
default: 'div'
58+
},
59+
wrapClass: {
60+
type: String,
61+
default: ''
62+
},
63+
wrapStyle: {
64+
type: Object
65+
},
6366
itemTag: {
6467
type: String,
6568
default: 'div'
@@ -71,6 +74,9 @@ export const VirtualProps = {
7174
itemClassAdd: {
7275
type: Function
7376
},
77+
itemStyle: {
78+
type: Object
79+
},
7480
headerTag: {
7581
type: String,
7682
default: 'div'
@@ -79,13 +85,19 @@ export const VirtualProps = {
7985
type: String,
8086
default: ''
8187
},
88+
headerStyle: {
89+
type: Object
90+
},
8291
footerTag: {
8392
type: String,
8493
default: 'div'
8594
},
8695
footerClass: {
8796
type: String,
8897
default: ''
98+
},
99+
footerStyle: {
100+
type: Object
89101
}
90102
}
91103

0 commit comments

Comments
 (0)