@@ -2,25 +2,28 @@ import { FunctionComponent } from 'react';
22import { CSSGrid } from './CSSGrid' ;
33import { RowCol } from './RowCol' ;
44import { Table } from './Table' ;
5- import { GridRendererProps , GridRenderingType } from './types' ;
5+ import { GridPositionnable , GridRendererProps , GridRenderingType } from './types' ;
66
77const getTotalGridDimensions = ( rows : any [ ] ) : number => {
88 const totalColSpan = rows [ 0 ] . columns . reduce ( ( acc : number , col : any ) => acc + col . layout . colspan , 0 ) ;
99 return totalColSpan ;
1010} ;
1111
12- export function getPositionnableCellClassNames (
13- rowIndex : number ,
14- colIndex : number ,
15- rowLength : number ,
16- colLength : number ,
17- ) : string {
12+ export function getPositionnableCellClassNames ( {
13+ rowIndex,
14+ colIndex,
15+ rowLength,
16+ colLength,
17+ } : GridPositionnable ) : string {
1818 return `cell-${ rowIndex } -${ colIndex } ${ rowIndex == 0 ? 'first-row' : '' } ${ colIndex == 0 ? 'first-col' : '' } ${
1919 rowIndex === rowLength - 1 ? 'last-row' : ''
2020 } ${ colIndex === colLength - 1 ? 'last-col' : '' } `. replace ( / \s + / g, ' ' ) ;
2121}
2222
23- export function getPositionnablRowClassNames ( rowIndex : number , rowLength : number ) : string {
23+ export function getPositionnablRowClassNames ( {
24+ rowIndex,
25+ rowLength,
26+ } : Omit < GridPositionnable , 'colIndex' | 'colLength' > ) : string {
2427 return `row-${ rowIndex } ${ rowIndex == 0 ? 'first-row' : '' } ${ rowIndex == rowLength - 1 ? 'last-row' : '' } ` . replace (
2528 / \s + / g,
2629 ' ' ,
@@ -32,6 +35,7 @@ export const GridRenderer: FunctionComponent<GridRendererProps> = ({
3235 children,
3336 grid,
3437 type = GridRenderingType . Div ,
38+ styleForCell,
3539 ...props
3640} ) => {
3741 if ( ! cellComponent && ! children ) {
@@ -44,14 +48,26 @@ export const GridRenderer: FunctionComponent<GridRendererProps> = ({
4448 const totalColSpan = getTotalGridDimensions ( rows ) ;
4549 if ( type === GridRenderingType . Table ) {
4650 return (
47- < Table cellComponent = { cellComponent } rows = { rows } totalColSpan = { totalColSpan } { ...props } >
51+ < Table
52+ cellComponent = { cellComponent }
53+ rows = { rows }
54+ totalColSpan = { totalColSpan }
55+ styleForCell = { styleForCell }
56+ { ...props }
57+ >
4858 { children }
4959 </ Table >
5060 ) ;
5161 }
5262 if ( type === GridRenderingType . RowCol ) {
5363 return (
54- < RowCol cellComponent = { cellComponent } rows = { rows } totalColSpan = { totalColSpan } { ...props } >
64+ < RowCol
65+ cellComponent = { cellComponent }
66+ rows = { rows }
67+ totalColSpan = { totalColSpan }
68+ styleForCell = { styleForCell }
69+ { ...props }
70+ >
5571 { children }
5672 </ RowCol >
5773 ) ;
@@ -66,7 +82,13 @@ export const GridRenderer: FunctionComponent<GridRendererProps> = ({
6682 return accumulator ;
6783 } , [ ] ) ;
6884 return (
69- < CSSGrid cellComponent = { cellComponent } cells = { cells } totalColSpan = { totalColSpan } { ...props } >
85+ < CSSGrid
86+ cellComponent = { cellComponent }
87+ cells = { cells }
88+ totalColSpan = { totalColSpan }
89+ styleForCell = { styleForCell }
90+ { ...props }
91+ >
7092 { children }
7193 </ CSSGrid >
7294 ) ;
0 commit comments