forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRow.tsx
138 lines (129 loc) · 3.66 KB
/
Row.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import Cell from './Cell';
import { getOptionProps, getSlot, getClass, getStyle, getComponent } from '../_util/props-util';
import { FunctionalComponent, VNode, inject } from 'vue';
import { descriptionsContext, DescriptionsContextProp } from './index';
interface CellConfig {
component: string | [string, string];
type: string;
showLabel?: boolean;
showContent?: boolean;
}
export interface RowProps {
prefixCls: string;
vertical: boolean;
row: any[];
bordered: boolean;
colon: boolean;
index: number;
}
const Row: FunctionalComponent<RowProps> = props => {
const renderCells = (
items: VNode[],
{ colon, prefixCls, bordered },
{
component,
type,
showLabel,
showContent,
labelStyle: rootLabelStyle,
contentStyle: rootContentStyle,
}: CellConfig & DescriptionsContextProp,
) => {
return items.map((item, index) => {
const {
prefixCls: itemPrefixCls = prefixCls,
span = 1,
labelStyle,
contentStyle,
} = getOptionProps(item);
const label = getComponent(item, 'label');
const children = getSlot(item);
const className = getClass(item);
const style = getStyle(item);
const { key } = item;
if (typeof component === 'string') {
return (
<Cell
key={`${type}-${key || index}`}
class={className}
style={style}
labelStyle={{ ...rootLabelStyle, ...labelStyle }}
contentStyle={{ ...rootContentStyle, ...contentStyle }}
span={span}
colon={colon}
component={component}
itemPrefixCls={itemPrefixCls}
bordered={bordered}
label={showLabel ? label : null}
content={showContent ? children : null}
/>
);
}
return [
<Cell
key={`label-${key || index}`}
class={className}
style={{ ...rootLabelStyle, ...style, ...labelStyle }}
span={1}
colon={colon}
component={component[0]}
itemPrefixCls={itemPrefixCls}
bordered={bordered}
label={label}
/>,
<Cell
key={`content-${key || index}`}
class={className}
style={{ ...rootContentStyle, ...style, ...contentStyle }}
span={span * 2 - 1}
component={component[1]}
itemPrefixCls={itemPrefixCls}
bordered={bordered}
content={children}
/>,
];
});
};
const { prefixCls, vertical, row, index, bordered } = props;
const { labelStyle, contentStyle } = inject(descriptionsContext, {
labelStyle: undefined,
contentStyle: undefined,
});
if (vertical) {
return (
<>
<tr key={`label-${index}`} class={`${prefixCls}-row`}>
{renderCells(row, props, {
component: 'th',
type: 'label',
showLabel: true,
labelStyle: labelStyle.value,
contentStyle: contentStyle.value,
})}
</tr>
<tr key={`content-${index}`} class={`${prefixCls}-row`}>
{renderCells(row, props, {
component: 'td',
type: 'content',
showContent: true,
labelStyle: labelStyle.value,
contentStyle: contentStyle.value,
})}
</tr>
</>
);
}
return (
<tr key={index} class={`${prefixCls}-row`}>
{renderCells(row, props, {
component: bordered ? ['th', 'td'] : 'td',
type: 'item',
showLabel: true,
showContent: true,
labelStyle: labelStyle.value,
contentStyle: contentStyle.value,
})}
</tr>
);
};
export default Row;