-
Notifications
You must be signed in to change notification settings - Fork 138
/
RenderBodyRow.tsx
60 lines (54 loc) 路 1.86 KB
/
RenderBodyRow.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @license
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/
import type { TableColumnMergedExpandable } from '../../composables/useColumns'
import type { FlattedData } from '../../composables/useDataSource'
import type { TableBodyRowProps, TableColumnExpandable } from '../../types'
import type { Slots, VNodeChild } from 'vue'
import { isFunction, isString } from 'lodash-es'
import BodyRow from './BodyRow'
import BodyRowSingle from './BodyRowSingle'
export function renderBodyRow(
item: FlattedData,
rowIndex: number,
slots: Slots,
expandable: TableColumnMergedExpandable | undefined,
prefixCls: string,
): VNodeChild {
const { children, expanded, level, hasPrevSibling, hasNextSibling, showLineIndentIndexList, record, rowKey } = item
const rowProps = {
key: rowKey,
expanded,
level,
hasPrevSibling,
hasNextSibling,
showLineIndentIndexList,
hasChildren: !!children?.length,
record,
rowData: item,
rowIndex,
rowKey,
}
const rowNode = <BodyRow {...rowProps} />
const expandedNode = expanded && renderExpandedContext(rowProps, slots, expandable, prefixCls)
return expandedNode ? [rowNode, expandedNode] : rowNode
}
function renderExpandedContext(
props: TableBodyRowProps,
slots: Slots,
expandable: TableColumnExpandable | undefined,
prefixCls: string,
) {
const { customExpand } = expandable || {}
const { record, rowIndex } = props
let expandedContext: VNodeChild
if (isFunction(customExpand)) {
expandedContext = customExpand({ record, rowIndex })
} else if (isString(customExpand) && slots[customExpand]) {
expandedContext = slots[customExpand]!({ record, rowIndex })
}
return expandedContext && <BodyRowSingle class={`${prefixCls}-expanded-row`}>{expandedContext}</BodyRowSingle>
}