Skip to content

Commit ef73ee3

Browse files
authored
Create mixin-tbody.js
1 parent 5d7c692 commit ef73ee3

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
export default {
2+
props: {
3+
tbodyClass: {
4+
type: [String, Array],
5+
default: null
6+
},
7+
tbodyTrClass: {
8+
type: [String, Array, Function],
9+
default: null
10+
},
11+
tbodyTransitionProps: {
12+
type: Object
13+
// default: undefined
14+
},
15+
tbodyTransitionHandlers: {
16+
type: Object
17+
// default: undefined
18+
}
19+
},
20+
methods: {
21+
renderTbody() {
22+
// Render the tbody element and children
23+
const h = this.$createElement
24+
const items = this.computedItems
25+
26+
// Prepare the tbody rows
27+
const $rows = []
28+
29+
// Add the item data rows or the busy slot
30+
const $busy = this.renderBusy()
31+
if ($busy) {
32+
// If table is busy and a busy slot, then return only the busy "row" indicator
33+
$rows.push($busy)
34+
} else {
35+
// Table isn't bsuy, or we don't have a busy slot
36+
37+
// Add static Top Row slot (hidden in visibly stacked mode as we can't control the data-label)
38+
$rows.push(this.renderTopRow())
39+
40+
// render the rows
41+
items.forEach((item, rowIndex) => {
42+
// Render the individual item row (rows if details slot)
43+
$rows.push(this.renderTbodyRow(item, rowIndex))
44+
})
45+
46+
// Empty Items / Empty Filtered Row slot (only shows if items.length < -
47+
$rows.push(this.renderEmpty())
48+
49+
// Static bottom row slot (hidden in visibly stacked mode as we can't control the data-label)
50+
$rows.push(this.renderBottomRow())
51+
}
52+
53+
// If tbody transition enabled
54+
const isTransGroup = this.tbodyTransitionProps || this.tbodyTransitionHandlers
55+
let tbodyProps = {}
56+
let tbodyOn = {}
57+
if (isTransGroup) {
58+
tbodyOn = this.tbodyTransitionHandlers || {}
59+
tbodyProps = {
60+
...(this.tbodyTransitionProps || {}),
61+
tag: 'tbody'
62+
}
63+
}
64+
65+
// Assemble rows into the tbody
66+
const $tbody = h(
67+
isTransGroup ? 'transition-group' : 'tbody',
68+
{
69+
props: tbodyProps,
70+
on: tbodyOn,
71+
class: this.bodyClasses,
72+
attrs: this.isStacked ? { role: 'rowgroup' } : {}
73+
},
74+
$rows
75+
)
76+
77+
return $tbody
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)