Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/bound-aggregated-cell-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'@tanstack/angular-table': patch
'@tanstack/lit-table': patch
'@tanstack/octane-table': patch
'@tanstack/preact-table': patch
'@tanstack/react-table': patch
'@tanstack/solid-table': patch
'@tanstack/svelte-table': patch
'@tanstack/vue-table': patch
---

Type `aggregatedCell` against bound `cellComponents` in `createAppColumnHelper`, matching `cell`.
18 changes: 14 additions & 4 deletions packages/angular-table/src/helpers/createTableHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export type AppColumnDefTemplate<TProps extends object> =
string | ((props: TProps) => any)

/**
* Enhanced column definition base with pre-bound components in cell/header/footer contexts.
* Enhanced column definition base with pre-bound components in
* cell/aggregatedCell/header/footer contexts.
*/
export type AppColumnDefBase<
TFeatures extends TableFeatures,
Expand All @@ -95,11 +96,14 @@ export type AppColumnDefBase<
THeaderComponents extends Record<string, RenderableComponent>,
> = Omit<
IdentifiedColumnDef<TFeatures, TData, TValue>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>
>
Expand All @@ -118,11 +122,14 @@ export type AppDisplayColumnDef<
THeaderComponents extends Record<string, RenderableComponent>,
> = Omit<
DisplayColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand All @@ -141,11 +148,14 @@ export type AppGroupColumnDef<
THeaderComponents extends Record<string, RenderableComponent>,
> = Omit<
GroupColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer' | 'columns'
'cell' | 'aggregatedCell' | 'header' | 'footer' | 'columns'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand Down
18 changes: 14 additions & 4 deletions packages/lit-table/src/createTableHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ export type AppColumnDefTemplate<TProps extends object> =
string | ((props: TProps) => any)

/**
* Enhanced column definition base with pre-bound components in cell/header/footer contexts.
* Enhanced column definition base with pre-bound components in
* cell/aggregatedCell/header/footer contexts.
*/
export type AppColumnDefBase<
TFeatures extends TableFeatures,
Expand All @@ -102,11 +103,14 @@ export type AppColumnDefBase<
THeaderComponents extends Record<string, ComponentType<any>>,
> = Omit<
IdentifiedColumnDef<TFeatures, TData, TValue>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>
>
Expand All @@ -125,11 +129,14 @@ export type AppDisplayColumnDef<
THeaderComponents extends Record<string, ComponentType<any>>,
> = Omit<
DisplayColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand All @@ -148,11 +155,14 @@ export type AppGroupColumnDef<
THeaderComponents extends Record<string, ComponentType<any>>,
> = Omit<
GroupColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer' | 'columns'
'cell' | 'aggregatedCell' | 'header' | 'footer' | 'columns'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand Down
17 changes: 13 additions & 4 deletions packages/octane-table/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export type AppColumnDefTemplate<TProps extends object> =

/**
* Enhanced column definition base with pre-bound components in
* cell/header/footer contexts.
* cell/aggregatedCell/header/footer contexts.
*/
export type AppColumnDefBase<
TFeatures extends TableFeatures,
Expand All @@ -387,11 +387,14 @@ export type AppColumnDefBase<
THeaderComponents extends Record<string, TableComponentType>,
> = Omit<
IdentifiedColumnDef<TFeatures, TData, TValue>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>
>
Expand All @@ -410,11 +413,14 @@ export type AppDisplayColumnDef<
THeaderComponents extends Record<string, TableComponentType>,
> = Omit<
DisplayColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand All @@ -433,11 +439,14 @@ export type AppGroupColumnDef<
THeaderComponents extends Record<string, TableComponentType>,
> = Omit<
GroupColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer' | 'columns'
'cell' | 'aggregatedCell' | 'header' | 'footer' | 'columns'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand Down
18 changes: 14 additions & 4 deletions packages/preact-table/src/createTableHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export type AppColumnDefTemplate<TProps extends object> =
string | ((props: TProps) => any)

/**
* Enhanced column definition base with pre-bound components in cell/header/footer contexts.
* Enhanced column definition base with pre-bound components in
* cell/aggregatedCell/header/footer contexts.
*/
export type AppColumnDefBase<
TFeatures extends TableFeatures,
Expand All @@ -94,11 +95,14 @@ export type AppColumnDefBase<
THeaderComponents extends Record<string, ComponentType<any>>,
> = Omit<
IdentifiedColumnDef<TFeatures, TData, TValue>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>
>
Expand All @@ -117,11 +121,14 @@ export type AppDisplayColumnDef<
THeaderComponents extends Record<string, ComponentType<any>>,
> = Omit<
DisplayColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand All @@ -140,11 +147,14 @@ export type AppGroupColumnDef<
THeaderComponents extends Record<string, ComponentType<any>>,
> = Omit<
GroupColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer' | 'columns'
'cell' | 'aggregatedCell' | 'header' | 'footer' | 'columns'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand Down
18 changes: 14 additions & 4 deletions packages/react-table/src/createTableHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export type AppColumnDefTemplate<TProps extends object> =
string | ((props: TProps) => any)

/**
* Enhanced column definition base with pre-bound components in cell/header/footer contexts.
* Enhanced column definition base with pre-bound components in
* cell/aggregatedCell/header/footer contexts.
*/
export type AppColumnDefBase<
TFeatures extends TableFeatures,
Expand All @@ -97,11 +98,14 @@ export type AppColumnDefBase<
THeaderComponents extends Record<string, ComponentType<any>>,
> = Omit<
IdentifiedColumnDef<TFeatures, TData, TValue>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, TValue, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, TValue, THeaderComponents>
>
Expand All @@ -120,11 +124,14 @@ export type AppDisplayColumnDef<
THeaderComponents extends Record<string, ComponentType<any>>,
> = Omit<
DisplayColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer'
'cell' | 'aggregatedCell' | 'header' | 'footer'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand All @@ -143,11 +150,14 @@ export type AppGroupColumnDef<
THeaderComponents extends Record<string, ComponentType<any>>,
> = Omit<
GroupColumnDef<TFeatures, TData, unknown>,
'cell' | 'header' | 'footer' | 'columns'
'cell' | 'aggregatedCell' | 'header' | 'footer' | 'columns'
> & {
cell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
aggregatedCell?: AppColumnDefTemplate<
AppCellContext<TFeatures, TData, unknown, TCellComponents>
>
header?: AppColumnDefTemplate<
AppHeaderContext<TFeatures, TData, unknown, THeaderComponents>
>
Expand Down
57 changes: 57 additions & 0 deletions packages/react-table/tests/createAppColumnHelper.test-d.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Type-level tests for `createAppColumnHelper`, checked by `test:types` (tsc).
// Not executed by vitest (the `.test-d.` name is excluded from its run glob).

import * as React from 'react'
import { rowAggregationFeature, tableFeatures } from '@tanstack/table-core'
import { createTableHook, createTableHookContexts } from '../src'

type Person = {
id: string
name: string
}

const features = tableFeatures({
rowAggregationFeature,
})
const contexts = createTableHookContexts<typeof features, Person>()

function NameCell() {
const cell = contexts.useCellContext<string>()

return <span>{cell.getValue().toUpperCase()}</span>
}

const appTable = createTableHook({
features,
tableContext: contexts.tableContext,
cellContext: contexts.cellContext,
headerContext: contexts.headerContext,
cellComponents: { NameCell },
})
const columnHelper = appTable.createAppColumnHelper<Person>()

columnHelper.accessor('name', {
id: 'name',
// The bound `cellComponents` are available on the cell context here...
cell: ({ cell }) => <cell.NameCell />,
// ...and must be equally available on the aggregatedCell context.
aggregatedCell: ({ cell }) => <cell.NameCell />,
})

columnHelper.display({
id: 'display',
cell: ({ cell }) => <cell.NameCell />,
aggregatedCell: ({ cell }) => <cell.NameCell />,
})

columnHelper.group({
id: 'group',
aggregatedCell: ({ cell }) => <cell.NameCell />,
columns: [],
})

columnHelper.accessor('name', {
id: 'guard',
// @ts-expect-error a component that was not registered is not bound
aggregatedCell: ({ cell }) => <cell.NotRegistered />,
})
Loading