File tree Expand file tree Collapse file tree 5 files changed +43
-2
lines changed Expand file tree Collapse file tree 5 files changed +43
-2
lines changed Original file line number Diff line number Diff line change
1
+ import * as React from 'react' ;
2
+
3
+ export const getPreviousColSpans = ( children : React . ReactNode , index : number ) => {
4
+ return React . Children . toArray ( children ) . reduce ( ( acc , value , key ) => {
5
+ if ( ! React . isValidElement ( value ) ) return acc ;
6
+ if ( key >= index ) return acc ;
7
+ if ( ! value . props . gridColumnStart && ! value . props . gridColumnEnd ) return acc ;
8
+
9
+ return acc + value . props . gridColumnEnd - value . props . gridColumnStart - 1 ;
10
+ } , 0 ) ;
11
+ } ;
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ export const Cell: React.FC<CellProps> = ({
16
16
pinLeft,
17
17
pinRight,
18
18
stiff,
19
+ includePreviousColSpan,
20
+ previousColSpans,
19
21
gridColumnStart,
20
22
gridColumnEnd,
21
23
onClick,
@@ -27,13 +29,24 @@ export const Cell: React.FC<CellProps> = ({
27
29
28
30
const hasColSpan = gridColumnStart && gridColumnEnd ;
29
31
const colSpan = hasColSpan ? gridColumnEnd - gridColumnStart - 1 : 0 ;
32
+ const computedGridColumnStart = includePreviousColSpan
33
+ ? gridColumnStart + previousColSpans
34
+ : gridColumnStart ;
35
+ const computedGridColumnEnd = includePreviousColSpan
36
+ ? gridColumnEnd + previousColSpans
37
+ : gridColumnEnd ;
30
38
31
39
return (
32
40
< >
33
41
< CellContainer
34
42
role = "gridcell"
35
43
data-table-library_td = ""
36
- style = { { ...( hasColSpan ? { gridColumnStart, gridColumnEnd } : { } ) , ...style } }
44
+ style = { {
45
+ ...( hasColSpan
46
+ ? { gridColumnStart : computedGridColumnStart , gridColumnEnd : computedGridColumnEnd }
47
+ : { } ) ,
48
+ ...style ,
49
+ } }
37
50
css = { css `
38
51
${ theme ?. BaseCell }
39
52
${ theme ?. Cell }
Original file line number Diff line number Diff line change @@ -76,6 +76,8 @@ export const HeaderCell: React.FC<HeaderCellProps> = ({
76
76
pinRight,
77
77
stiff,
78
78
isFooter,
79
+ includePreviousColSpan,
80
+ previousColSpans,
79
81
gridColumnStart,
80
82
gridColumnEnd,
81
83
resize,
@@ -92,6 +94,12 @@ export const HeaderCell: React.FC<HeaderCellProps> = ({
92
94
93
95
const hasColSpan = gridColumnStart && gridColumnEnd ;
94
96
const colSpan = hasColSpan ? gridColumnEnd - gridColumnStart - 1 : 0 ;
97
+ const computedGridColumnStart = includePreviousColSpan
98
+ ? gridColumnStart + previousColSpans
99
+ : gridColumnStart ;
100
+ const computedGridColumnEnd = includePreviousColSpan
101
+ ? gridColumnEnd + previousColSpans
102
+ : gridColumnEnd ;
95
103
96
104
return (
97
105
< >
@@ -102,7 +110,12 @@ export const HeaderCell: React.FC<HeaderCellProps> = ({
102
110
data-resize-min-width = {
103
111
typeof resize === 'boolean' || resize ?. minWidth == null ? 75 : resize . minWidth
104
112
}
105
- style = { { ...( hasColSpan ? { gridColumnStart, gridColumnEnd } : { } ) , ...style } }
113
+ style = { {
114
+ ...( hasColSpan
115
+ ? { gridColumnStart : computedGridColumnStart , gridColumnEnd : computedGridColumnEnd }
116
+ : { } ) ,
117
+ ...style ,
118
+ } }
106
119
css = { css `
107
120
${ theme ?. BaseCell }
108
121
${ isFooter ? theme ?. FooterCell : theme ?. HeaderCell }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import {
16
16
getHeaderColumns ,
17
17
} from '@table-library/react-table-library/common/util/columns' ;
18
18
import { isReactFragment } from '@table-library/react-table-library/common/util/isFragment' ;
19
+ import { getPreviousColSpans } from '@table-library/react-table-library/common/util/getPreviousColSpans' ;
19
20
20
21
import { HeaderRowProps } from '@table-library/react-table-library/types/table' ;
21
22
@@ -96,6 +97,7 @@ export const HeaderRow: React.FC<HeaderRowProps> = ({
96
97
extraProps = {
97
98
...extraProps ,
98
99
index,
100
+ previousColSpans : getPreviousColSpans ( children , index ) ,
99
101
} ;
100
102
}
101
103
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { RowContainer } from '@table-library/react-table-library/common/componen
10
10
import { ThemeContext } from '@table-library/react-table-library/common/context/Theme' ;
11
11
import { useFeatures } from '@table-library/react-table-library/common/context/Feature' ;
12
12
import { isReactFragment } from '@table-library/react-table-library/common/util/isFragment' ;
13
+ import { getPreviousColSpans } from '@table-library/react-table-library/common/util/getPreviousColSpans' ;
13
14
14
15
import { Nullish } from '@table-library/react-table-library/types/common' ;
15
16
import {
@@ -126,6 +127,7 @@ export const Row: React.FC<RowProps> = (props: RowProps) => {
126
127
extraProps = {
127
128
...extraProps ,
128
129
index,
130
+ previousColSpans : getPreviousColSpans ( children , index ) ,
129
131
} ;
130
132
}
131
133
You can’t perform that action at this time.
0 commit comments