UNPKG

731 BJavaScriptView Raw
1import countRowSpan from './count_row_span';
2
3function resolveHeaderRows(columns = []) {
4 let resolvedChildren = [];
5
6 const ret = columns.map(column => {
7 const { children, ...col } = column;
8
9 if (children && children.length) {
10 resolvedChildren = resolvedChildren.concat(
11 resolveHeaderRows(children)[0]
12 );
13
14 return {
15 ...col,
16 props: {
17 ...col.props,
18 colSpan: children.length
19 }
20 };
21 }
22
23 return {
24 ...col,
25 props: {
26 ...col.props,
27 rowSpan: countRowSpan(columns)
28 }
29 };
30 });
31
32 if (resolvedChildren.length) {
33 return [ret].concat([resolvedChildren]);
34 }
35
36 return [ret];
37}
38
39export default resolveHeaderRows;