Skip to content

Commit 60c55ff

Browse files
committed
fix custom features example
1 parent 7a46b6c commit 60c55ff

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

examples/react/custom-features/src/main.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ export interface Table_Density {
4747
toggleDensity: (value?: DensityState) => void
4848
}
4949

50-
// Here is all of the actual javascript code for our new feature
51-
export const densityPlugin: TableFeature<{
50+
interface DensityPluginConstructors {
5251
Table: Table_Density
5352
TableOptions: TableOptions_Density
5453
TableState: TableState_Density
55-
}> = {
54+
}
55+
56+
// Here is all of the actual javascript code for our new feature
57+
export const densityPlugin: TableFeature<DensityPluginConstructors> = {
5658
// define the new feature's initial state
5759
getInitialState: (initialState) => {
5860
return {
@@ -69,9 +71,7 @@ export const densityPlugin: TableFeature<{
6971
}
7072
},
7173
// if you need to add a default column definition...
72-
// getDefaultColumnDef: <TFeatures extends TableFeatures, TData extends RowData>(): Partial<ColumnDef<TFeatures, TData>> => {
73-
// return { meta: {} } //use meta instead of directly adding to the columnDef to avoid typescript stuff that's hard to workaround
74-
// },
74+
// getDefaultColumnDef: () => {},
7575

7676
// define the new feature's table instance methods
7777
constructTableAPIs: (table) => {
@@ -83,21 +83,24 @@ export const densityPlugin: TableFeature<{
8383
return table.options.onDensityChange?.(safeUpdater)
8484
}
8585
table.toggleDensity = (value) => {
86-
table.setDensity((old) => {
86+
table.setDensity?.((old) => {
8787
if (value) return value
8888
return old === 'lg' ? 'md' : old === 'md' ? 'sm' : 'lg' // cycle through the 3 options
8989
})
9090
}
9191
},
9292

93-
// // if you need to add row instance APIs...
94-
// constructRowAPIs: <TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData>, table: Table<TFeatures, TData>): void => {},
95-
// // if you need to add cell instance APIs...
96-
// constructCellAPIs: <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(cell: Cell<TFeatures, TData, TValue>): void => {},
97-
// // if you need to add column instance APIs...
98-
// constructColumnAPIs: <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): void => {},
99-
// // if you need to add header instance APIs...
100-
// constructHeaderAPIs: <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(header: Header<TFeatures, TData, TValue>): void => {},
93+
// if you need to add row instance APIs...
94+
// constructRowAPIs: (row) => {},
95+
96+
// if you need to add cell instance APIs...
97+
// constructCellAPIs: (cell) => {},
98+
99+
// if you need to add column instance APIs...
100+
// constructColumnAPIs: (column) => {},
101+
102+
// if you need to add header instance APIs...
103+
// constructHeaderAPIs: (header) => {},
101104
}
102105
// end of custom feature code
103106

packages/table-core/src/types/TableFeatures.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,39 @@ export type ConstructCellAPIs<TConstructors extends FeatureConstructors> = <
5252
TData extends RowData,
5353
TValue extends CellData = CellData,
5454
>(
55-
cell: Cell<TFeatures, TData, TValue> & TConstructors['Cell'],
55+
cell: Cell<TFeatures, TData, TValue> &
56+
TConstructors['Cell'] & {
57+
row: Row<TFeatures, TData> & TConstructors['Row']
58+
column: Column<TFeatures, TData, TValue> &
59+
TConstructors['Column'] & {
60+
columnDef: Partial<TConstructors['ColumnDef']>
61+
}
62+
},
5663
) => void
5764

5865
export type ConstructColumnAPIs<TConstructors extends FeatureConstructors> = <
5966
TFeatures extends TableFeatures,
6067
TData extends RowData,
6168
TValue extends CellData = CellData,
6269
>(
63-
column: Column<TFeatures, TData, TValue> & TConstructors['Column'],
70+
column: Column<TFeatures, TData, TValue> &
71+
TConstructors['Column'] & {
72+
columnDef: Partial<TConstructors['ColumnDef']>
73+
},
6474
) => void
6575

6676
export type ConstructHeaderAPIs<TConstructors extends FeatureConstructors> = <
6777
TFeatures extends TableFeatures,
6878
TData extends RowData,
6979
TValue extends CellData = CellData,
7080
>(
71-
header: Header<TFeatures, TData, TValue> & TConstructors['Header'],
81+
header: Header<TFeatures, TData, TValue> &
82+
TConstructors['Header'] & {
83+
column: Column<TFeatures, TData, TValue> &
84+
TConstructors['Column'] & {
85+
columnDef: Partial<TConstructors['ColumnDef']>
86+
}
87+
},
7288
) => void
7389

7490
export type ConstructRowAPIs<TConstructors extends FeatureConstructors> = <
@@ -82,7 +98,10 @@ export type ConstructTableAPIs<TConstructors extends FeatureConstructors> = <
8298
TFeatures extends TableFeatures,
8399
TData extends RowData,
84100
>(
85-
table: Table_Internal<TFeatures, TData> & Partial<TConstructors['Table']>,
101+
table: Table_Internal<TFeatures, TData> &
102+
Partial<TConstructors['Table']> & {
103+
options: Partial<TConstructors['TableOptions']>
104+
},
86105
) => void
87106

88107
export type GetDefaultColumnDef<TConstructors extends FeatureConstructors> = <

0 commit comments

Comments
 (0)