@@ -29,16 +29,18 @@ export interface TableProps<Column, Value = unknown> {
2929 columns : Column [ ]
3030 /** The number of rows. */
3131 numRows : number
32- /** Whether columns can be inserted, removed, modified and re-ordered. */
33- columnsEditable ?: boolean
34- /** Whether rows can be inserted, removed and re-ordered. */
35- rowsEditable ?: boolean
3632 /** Whether columns can be resized. */
3733 columnsResizeable ?: boolean
34+ /** Whether columns can be renamed. */
35+ columnsRenameable ?: boolean
36+ /** Whether to render an "add column" button. */
37+ addColumnButton ?: boolean
38+ /** Whether to render an "add column" button. */
39+ addRowButton ?: boolean
3840 /** Height of cells in pixels. */
3941 cellHeight ?: number
4042 /** Component used to render the content of cells for a particular column. */
41- cellContent ?: ( column : Column ) => Component < CellContentProps < Value > > | undefined
43+ getCellContent ?: ( column : Column ) => Component < CellContentProps < Value > > | undefined
4244 /** Gets the icon for a particular column. */
4345 getColumnIcon ?: ( column : Column ) => Component | undefined
4446 /** The state of the selected cell or cells in the table. */
@@ -60,13 +62,9 @@ export interface TableProps<Column, Value = unknown> {
6062 /** Sets the name of the given column. */
6163 setColumnName ?: ( column : Column , name : string ) => void
6264 /** Inserts a numer of columns into the table. */
63- insertColumns ?: ( index : number , count : number ) => void
65+ onInsertColumns ?: ( index : number , count : number ) => void
6466 /** Inserts a number of rows into the table. */
65- insertRows ?: ( index : number , count : number ) => void
66- /** Removes a number of columns from the table. */
67- removeColumns ?: ( index : number , count : number ) => void
68- /** Removes a number of rows from the table. */
69- removeRows ?: ( index : number , count : number ) => void
67+ onInsertRows ?: ( index : number , count : number ) => void
7068 /** Called whenever the range of rows visible in the viewport changes. */
7169 onViewportChanged ?: ( start : number , end : number ) => void
7270 /** Fired when a cell context menu is opened. */
@@ -83,7 +81,7 @@ export interface TableProps<Column, Value = unknown> {
8381 onScrollPositionChange ?: ( scrollLeft : number , scrollTop : number ) => void
8482}
8583
86- export default function Table < Column , Value = unknown > ( props : TableProps < Column , Value > ) {
84+ export function Table < Column , Value = unknown > ( props : TableProps < Column , Value > ) {
8785 // The root DOM element of the table
8886 let tableEl : HTMLDivElement | undefined
8987
@@ -237,7 +235,7 @@ export default function Table<Column, Value = unknown>(props: TableProps<Column,
237235 return props . getColumnName ?.( column ) ?? String ( column )
238236 } ,
239237 get component ( ) {
240- return props . cellContent ?.( column ) ?? DEFAULT_CELL_CONTENT
238+ return props . getCellContent ?.( column ) ?? DEFAULT_CELL_CONTENT
241239 } ,
242240 get icon ( ) {
243241 return props . getColumnIcon ?.( column )
@@ -538,8 +536,8 @@ export default function Table<Column, Value = unknown>(props: TableProps<Column,
538536
539537 // Append row button
540538 const appendRow = ( ) => {
541- if ( ! props . insertRows ) return
542- props . insertRows ( numRows ( ) , 1 )
539+ if ( ! props . onInsertRows ) return
540+ props . onInsertRows ( numRows ( ) , 1 )
543541
544542 // Scroll to the last row
545543 scrollToCell ( props . numRows , undefined )
@@ -612,7 +610,7 @@ export default function Table<Column, Value = unknown>(props: TableProps<Column,
612610 < ColumnHeader
613611 column = { column }
614612 height = { colHeaderHeight ( ) }
615- columnsEditable = { props . columnsEditable }
613+ columnsRenameable = { props . columnsRenameable }
616614 columnsResizeable = { props . columnsResizeable }
617615 setColumnName = { props . setColumnName }
618616 setColumnSize = { props . setColumnSize }
@@ -622,12 +620,12 @@ export default function Table<Column, Value = unknown>(props: TableProps<Column,
622620 ) }
623621 </ For >
624622
625- < Show when = { props . columnsEditable } >
623+ < Show when = { props . addColumnButton } >
626624 < AddColumnButton
627625 tableWidth = { tableWidth ( ) }
628626 width = { DEFAULT_COLUMN_SIZE }
629627 height = { colHeaderHeight ( ) }
630- onPointerDown = { ( ) => props . insertColumns ?.( numCols ( ) , 1 ) }
628+ onPointerDown = { ( ) => props . onInsertColumns ?.( numCols ( ) , 1 ) }
631629 />
632630 </ Show >
633631
@@ -672,7 +670,7 @@ export default function Table<Column, Value = unknown>(props: TableProps<Column,
672670 < Show when = { activeCellData ( ) } keyed >
673671 { ( { row, column } ) => (
674672 < CellInputContainer
675- component = { props . cellContent ?.( column ) ?? DEFAULT_CELL_CONTENT }
673+ component = { props . getCellContent ?.( column ) ?? DEFAULT_CELL_CONTENT }
676674 rect = { activeCellOutline ( ) ! }
677675 value = { props . getCellValue ( row , column ) }
678676 setValue = { value => props . setCellValue ?.( row , column , value ) }
@@ -686,7 +684,7 @@ export default function Table<Column, Value = unknown>(props: TableProps<Column,
686684 </ div >
687685
688686 { /* Add row button */ }
689- < Show when = { props . rowsEditable } >
687+ < Show when = { props . addRowButton } >
690688 < AddRowButton
691689 tableWidth = { tableWidth ( ) }
692690 cellHeight = { cellHeight ( ) }
0 commit comments