@@ -15,9 +15,31 @@ const NuGrid = ({ data }) => {
1515 Visible,
1616 Posn,
1717 Values,
18+ ColTitles,
19+ RowTitles,
20+ TitleWidth = 50 ,
21+ TitleHeight = 24 ,
22+ CellWidths = 100 ,
23+ CellHeights = 24 ,
1824 CSS ,
1925 } = data ?. Properties || { } ;
2026
27+ // Helper to get width for a column (scalar or per-column array)
28+ const getCellWidth = ( colIndex ) => {
29+ if ( Array . isArray ( CellWidths ) ) {
30+ return CellWidths [ colIndex ] ?? CellWidths [ 0 ] ?? 100 ;
31+ }
32+ return CellWidths || 100 ;
33+ } ;
34+
35+ // Helper to get height for a row (scalar or per-row array)
36+ const getCellHeight = ( rowIndex ) => {
37+ if ( Array . isArray ( CellHeights ) ) {
38+ return CellHeights [ rowIndex ] ?? CellHeights [ 0 ] ?? 24 ;
39+ }
40+ return CellHeights || 24 ;
41+ } ;
42+
2143 const customStyles = parseFlexStyles ( CSS ) ;
2244 const baseStyles = setStyle ( data ?. Properties ) ;
2345
@@ -32,6 +54,12 @@ const NuGrid = ({ data }) => {
3254 ...customStyles ,
3355 } ;
3456
57+ // Normalize titles to arrays
58+ const colTitlesArray = ColTitles ? ( Array . isArray ( ColTitles ) ? ColTitles : [ ColTitles ] ) : [ ] ;
59+ const rowTitlesArray = RowTitles ? ( Array . isArray ( RowTitles ) ? RowTitles : [ RowTitles ] ) : [ ] ;
60+ const hasColTitles = colTitlesArray . length > 0 ;
61+ const hasRowTitles = rowTitlesArray . length > 0 ;
62+
3563 return (
3664 < div
3765 id = { data ?. ID }
@@ -41,21 +69,52 @@ const NuGrid = ({ data }) => {
4169 < div className = "nugrid-container" >
4270 { Values && Values . length > 0 ? (
4371 < table className = "nugrid-table" >
72+ { hasColTitles && (
73+ < thead >
74+ < tr className = "nugrid-header-row" style = { { height : TitleHeight } } >
75+ { hasRowTitles && (
76+ < th
77+ className = "nugrid-corner-cell"
78+ style = { { width : TitleWidth , height : TitleHeight } }
79+ />
80+ ) }
81+ { colTitlesArray . map ( ( title , colIndex ) => (
82+ < th
83+ key = { colIndex }
84+ className = "nugrid-col-header"
85+ style = { { width : getCellWidth ( colIndex ) , height : TitleHeight } }
86+ >
87+ { title !== null && title !== undefined ? String ( title ) : '' }
88+ </ th >
89+ ) ) }
90+ </ tr >
91+ </ thead >
92+ ) }
4493 < tbody >
4594 { Values . map ( ( row , rowIndex ) => (
46- < tr key = { rowIndex } className = "nugrid-row" >
95+ < tr key = { rowIndex } className = "nugrid-row" style = { { height : getCellHeight ( rowIndex ) } } >
96+ { hasRowTitles && (
97+ < th
98+ className = "nugrid-row-header"
99+ style = { { width : TitleWidth , height : getCellHeight ( rowIndex ) } }
100+ >
101+ { rowTitlesArray [ rowIndex ] !== null && rowTitlesArray [ rowIndex ] !== undefined
102+ ? String ( rowTitlesArray [ rowIndex ] )
103+ : '' }
104+ </ th >
105+ ) }
47106 { Array . isArray ( row ) ? (
48107 row . map ( ( cell , colIndex ) => (
49108 < td
50109 key = { colIndex }
51110 className = "nugrid-cell"
111+ style = { { width : getCellWidth ( colIndex ) , height : getCellHeight ( rowIndex ) } }
52112 >
53113 { cell !== null && cell !== undefined ? String ( cell ) : '' }
54114 </ td >
55115 ) )
56116 ) : (
57- // Handle case where row is a single value (1-column grid)
58- < td className = "nugrid-cell" >
117+ < td className = "nugrid-cell" style = { { width : getCellWidth ( 0 ) , height : getCellHeight ( rowIndex ) } } >
59118 { row !== null && row !== undefined ? String ( row ) : '' }
60119 </ td >
61120 ) }
0 commit comments