From 3ed8b4dc587b644b9964d48e9322b8b147193e62 Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Tue, 27 Oct 2026 19:46:51 +0000 Subject: [PATCH] Rename `CalculatedColumnParent` to `CalculatedColumnGroup` and the `*Event` arg types to `*Args`, and order `RenderSummaryCellContentProps` type parameters like the other types - `CalculatedColumnParent` -> `CalculatedColumnGroup`, with `headerCellClass` declared as always set - `FillEvent`, `SelectRowEvent`, `SelectHeaderRowEvent` -> `FillArgs`, `SelectRowArgs`, `SelectHeaderRowArgs` - `RenderSummaryCellContentProps` -> `RenderSummaryCellContentProps` Co-Authored-By: Claude Opus 5.5 --- README.md | 56 +++++++++---------- src/DataGrid.tsx | 12 ++-- src/GroupedColumnHeaderCell.tsx | 4 +- src/GroupedColumnHeaderRow.tsx | 4 +- src/hooks/useCalculatedColumns.ts | 20 +++---- src/hooks/useRowSelection.ts | 6 +- src/index.ts | 8 +-- src/types.ts | 20 +++---- src/utils/activePositionUtils.ts | 4 +- .../browser/column/renderSummaryCell.test.tsx | 3 +- test/browser/dragFill.test.tsx | 4 +- website/routes/AllFeatures.tsx | 4 +- 12 files changed, 73 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index e1b7436198..40db485e42 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ Control column widths using the [`width`](#width-maybenumber--string), [`minWidt ### Custom Renderers -Replace default components with custom implementations using the [`renderers`](#renderers-mayberenderersr-sr) prop. Columns can also have custom renderers using the [`renderCell`](#rendercell-maybeprops-rendercellcontentpropstrow-tsummaryrow--reactnode), [`renderHeaderCell`](#renderheadercell-maybeprops-renderheadercellcontentpropstrow-tsummaryrow--reactnode), [`renderSummaryCell`](#rendersummarycell-maybeprops-rendersummarycellcontentpropstsummaryrow-trow--reactnode), [`renderGroupCell`](#rendergroupcell-maybeprops-rendergroupcellcontentpropstrow-tsummaryrow--reactnode), and [`renderEditCell`](#rendereditcell-maybeprops-rendereditcellcontentpropstrow-tsummaryrow--reactnode) properties. +Replace default components with custom implementations using the [`renderers`](#renderers-mayberenderersr-sr) prop. Columns can also have custom renderers using the [`renderCell`](#rendercell-maybeprops-rendercellcontentpropstrow-tsummaryrow--reactnode), [`renderHeaderCell`](#renderheadercell-maybeprops-renderheadercellcontentpropstrow-tsummaryrow--reactnode), [`renderSummaryCell`](#rendersummarycell-maybeprops-rendersummarycellcontentpropstrow-tsummaryrow--reactnode), [`renderGroupCell`](#rendergroupcell-maybeprops-rendergroupcellcontentpropstrow-tsummaryrow--reactnode), and [`renderEditCell`](#rendereditcell-maybeprops-rendereditcellcontentpropstrow-tsummaryrow--reactnode) properties. ## Keyboard Shortcuts @@ -648,14 +648,14 @@ Return the updated row; the grid will call `onRowsChange` with it. Callback triggered when the active position changes. See the [`PositionChangeArgs`](#positionchangeargstrow-tsummaryrow) type. -###### `onFill?: Maybe<(event: FillEvent) => R>` +###### `onFill?: Maybe<(args: FillArgs) => R>` Callback triggered when the value of the active cell is dragged to fill other cells. When this prop is set, a drag handle is shown on the active cell if it is editable. Drag the handle up or down to fill the cells it passes over, or double-click it to fill all the cells below. -The grid calls `onFill` for each editable target cell. Return the updated target row; the grid will call `onRowsChange` with the updated rows. See the [`FillEvent`](#filleventtrow) type. +The grid calls `onFill` for each editable target cell. Return the updated target row; the grid will call `onRowsChange` with the updated rows. See the [`FillArgs`](#fillargstrow) type. ```tsx -function onFill({ columnKey, sourceRow, targetRow }: FillEvent): Row { +function onFill({ columnKey, sourceRow, targetRow }: FillArgs): Row { return { ...targetRow, [columnKey]: sourceRow[columnKey as keyof Row] }; } @@ -1007,7 +1007,7 @@ Hook for managing header row selection state. Used within custom header cell ren - `isIndeterminate: boolean` - Whether some (but not all) rows are selected - `isRowSelected: boolean` - Whether all rows are selected -- `onRowSelectionChange: (event: SelectHeaderRowEvent) => void` - Callback to change selection state +- `onRowSelectionChange: (args: SelectHeaderRowArgs) => void` - Callback to change selection state **Example:** @@ -1043,7 +1043,7 @@ Hook for managing row selection state. Used within custom cell renderers to impl - `isRowSelectionDisabled: boolean` - Whether selection is disabled for this row - `isRowSelected: boolean` - Whether this row is selected -- `onRowSelectionChange: (event: SelectRowEvent) => void` - Callback to change selection state +- `onRowSelectionChange: (args: SelectRowArgs) => void` - Callback to change selection state **Example:** @@ -1377,7 +1377,7 @@ Render function to render the content of cells. Render function to render the content of the header cell. -##### `renderSummaryCell?: Maybe<(props: RenderSummaryCellContentProps) => ReactNode>` +##### `renderSummaryCell?: Maybe<(props: RenderSummaryCellContentProps) => ReactNode>` Render function to render the content of summary cells. @@ -1526,7 +1526,7 @@ Extends `Column` with additional computed properties used internally by the grid ```tsx interface CalculatedColumn extends Column { /** The column group that contains the column, or `undefined` if the column is not in a group */ - readonly parent: CalculatedColumnParent | undefined; + readonly parent: CalculatedColumnGroup | undefined; /** The index of the column in the grid. Column groups are flattened and frozen columns are moved to their edge, so it can differ from the column's index in `columns` */ readonly idx: number; /** Header row level, counted from the bottom header row: always `0` for columns, and negative for column groups */ @@ -1558,18 +1558,18 @@ interface CalculatedColumn extends Column` -#### `CalculatedColumnParent` +#### `CalculatedColumnGroup` Represents a parent column group in the calculated column structure. ```tsx -interface CalculatedColumnParent { +interface CalculatedColumnGroup { readonly name: string | ReactElement; - readonly parent: CalculatedColumnParent | undefined; + readonly parent: CalculatedColumnGroup | undefined; readonly idx: number; readonly colSpan: number; readonly level: number; - readonly headerCellClass?: Maybe; + readonly headerCellClass: Maybe; } ``` @@ -1577,13 +1577,13 @@ interface CalculatedColumnParent { #### `CalculatedColumnOrColumnGroup` -Union type representing either a `CalculatedColumnParent` or a `CalculatedColumn`. +Union type representing either a `CalculatedColumnGroup` or a `CalculatedColumn`. ```tsx -type CalculatedColumnOrColumnGroup = CalculatedColumnParent | CalculatedColumn; +type CalculatedColumnOrColumnGroup = CalculatedColumnGroup | CalculatedColumn; ``` -**See also:** [`CalculatedColumn`](#calculatedcolumntrow-tsummaryrow), [`CalculatedColumnParent`](#calculatedcolumnparenttrow-tsummaryrow) +**See also:** [`CalculatedColumn`](#calculatedcolumntrow-tsummaryrow), [`CalculatedColumnGroup`](#calculatedcolumngrouptrow-tsummaryrow) #### `DefaultColumnOptions` @@ -1695,19 +1695,19 @@ function renderEditor({ row, column, onRowChange, onClose }: RenderEditCellConte **See also:** [`column.renderEditCell`](#rendereditcell-maybeprops-rendereditcellcontentpropstrow-tsummaryrow--reactnode), [`renderTextEditor`](#rendertexteditortrow-tsummaryrowprops-rendereditcellcontentpropstrow-tsummaryrow) function -#### `RenderSummaryCellContentProps` +#### `RenderSummaryCellContentProps` Props passed to summary cell content renderers (`column.renderSummaryCell`). ```tsx -interface RenderSummaryCellContentProps { +interface RenderSummaryCellContentProps { column: CalculatedColumn; row: TSummaryRow; tabIndex: number; } ``` -**See also:** [`column.renderSummaryCell`](#rendersummarycell-maybeprops-rendersummarycellcontentpropstsummaryrow-trow--reactnode) +**See also:** [`column.renderSummaryCell`](#rendersummarycell-maybeprops-rendersummarycellcontentpropstrow-tsummaryrow--reactnode) #### `RenderGroupCellContentProps` @@ -2160,12 +2160,12 @@ interface RowsChangeData { **See also:** [`onRowsChange`](#onrowschange-mayberows-r-data-rowschangedatar-sr--void) prop on `` -#### `SelectRowEvent` +#### `SelectRowArgs` -Event object for row selection changes. +Arguments for row selection changes. ```tsx -interface SelectRowEvent { +interface SelectRowArgs { row: TRow; checked: boolean; isShiftClick: boolean; @@ -2174,31 +2174,31 @@ interface SelectRowEvent { **See also:** [`useRowSelection`](#userowselection) hook -#### `SelectHeaderRowEvent` +#### `SelectHeaderRowArgs` -Event object for header row selection changes. +Arguments for header row selection changes. ```tsx -interface SelectHeaderRowEvent { +interface SelectHeaderRowArgs { checked: boolean; } ``` **See also:** [`useHeaderRowSelection`](#useheaderrowselection) hook -#### `FillEvent` +#### `FillArgs` -Event object for drag-fill operations. +Arguments for drag-fill operations. ```tsx -interface FillEvent { +interface FillArgs { columnKey: string; sourceRow: TRow; targetRow: TRow; } ``` -**See also:** [`onFill`](#onfill-maybeevent-filleventr--r) prop on `` +**See also:** [`onFill`](#onfill-maybeargs-fillargsr--r) prop on `` #### `DataGridHandle` diff --git a/src/DataGrid.tsx b/src/DataGrid.tsx index ff9127fab8..62fac62f86 100644 --- a/src/DataGrid.tsx +++ b/src/DataGrid.tsx @@ -50,14 +50,14 @@ import type { ColumnOrColumnGroup, ColumnWidths, Direction, - FillEvent, + FillArgs, Maybe, Position, Renderers, RowsChangeData, SetActivePositionOptions, - SelectHeaderRowEvent, - SelectRowEvent, + SelectHeaderRowArgs, + SelectRowArgs, SortColumn } from './types'; import { defaultRenderCell } from './Cell'; @@ -197,7 +197,7 @@ export interface DataGridProps extends Sha /** Callback triggered when columns are reordered */ onColumnsReorder?: Maybe<(sourceColumnKey: string, targetColumnKey: string) => void>; /** Callback triggered when the value of the active cell is dragged to fill other cells */ - onFill?: Maybe<(event: FillEvent>) => NoInfer>; + onFill?: Maybe<(args: FillArgs>) => NoInfer>; /** * Toggles and modes @@ -537,7 +537,7 @@ export function DataGrid(props: DataGridPr /** * event handlers */ - function selectHeaderRow(args: SelectHeaderRowEvent) { + function selectHeaderRow(args: SelectHeaderRowArgs) { if (!onSelectedRowsChange) return; assertIsValidKeyGetter(rowKeyGetter); @@ -555,7 +555,7 @@ export function DataGrid(props: DataGridPr onSelectedRowsChange(newSelectedRows); } - function selectRow(args: SelectRowEvent) { + function selectRow(args: SelectRowArgs) { if (!onSelectedRowsChange) return; assertIsValidKeyGetter(rowKeyGetter); diff --git a/src/GroupedColumnHeaderCell.tsx b/src/GroupedColumnHeaderCell.tsx index 0cb549ff5f..e425cca974 100644 --- a/src/GroupedColumnHeaderCell.tsx +++ b/src/GroupedColumnHeaderCell.tsx @@ -1,6 +1,6 @@ import { useRovingTabIndex } from './hooks'; import { classnames, getHeaderCellRowSpan, getHeaderCellStyle } from './utils'; -import type { CalculatedColumnParent } from './types'; +import type { CalculatedColumnGroup } from './types'; import type { GroupedColumnHeaderRowProps } from './GroupedColumnHeaderRow'; import { cellClassname } from './style/cell'; @@ -10,7 +10,7 @@ type SharedGroupedColumnHeaderRowProps = Pick< >; interface GroupedColumnHeaderCellProps extends SharedGroupedColumnHeaderRowProps { - column: CalculatedColumnParent; + column: CalculatedColumnGroup; isCellActive: boolean; } diff --git a/src/GroupedColumnHeaderRow.tsx b/src/GroupedColumnHeaderRow.tsx index 8ddd62a6a9..12f20abff7 100644 --- a/src/GroupedColumnHeaderRow.tsx +++ b/src/GroupedColumnHeaderRow.tsx @@ -1,6 +1,6 @@ import { memo } from 'react'; -import type { CalculatedColumnParent, MapViewportColumns, Position } from './types'; +import type { CalculatedColumnGroup, MapViewportColumns, Position } from './types'; import GroupedColumnHeaderCell from './GroupedColumnHeaderCell'; import { headerRowClassname } from './HeaderRow'; @@ -19,7 +19,7 @@ function GroupedColumnHeaderRow({ activeCellIdx, setPosition }: GroupedColumnHeaderRowProps) { - const renderedParents = new Set>(); + const renderedParents = new Set>(); const cells = mapViewportColumns(activeCellIdx, undefined, (column, isCellActive) => { if (column.parent === undefined) return null; diff --git a/src/hooks/useCalculatedColumns.ts b/src/hooks/useCalculatedColumns.ts index eadfa7b7a6..180ce9f783 100644 --- a/src/hooks/useCalculatedColumns.ts +++ b/src/hooks/useCalculatedColumns.ts @@ -3,7 +3,7 @@ import { useMemo } from 'react'; import { clampColumnWidth, max, min } from '../utils'; import type { CalculatedColumn, - CalculatedColumnParent, + CalculatedColumnGroup, ColSpanArgs, ColumnFrozen, ColumnOrColumnGroup, @@ -19,10 +19,10 @@ type Mutable = { }; interface WithParent { - readonly parent: MutableCalculatedColumnParent | undefined; + readonly parent: MutableCalculatedColumnGroup | undefined; } -type MutableCalculatedColumnParent = Omit>, 'parent'> & +type MutableCalculatedColumnGroup = Omit>, 'parent'> & WithParent; type MutableCalculatedColumn = Omit>, 'parent'> & WithParent; @@ -109,11 +109,11 @@ export function useCalculatedColumns({ function collectColumns( rawColumns: readonly ColumnOrColumnGroup[], level: number, - parent?: MutableCalculatedColumnParent + parent?: MutableCalculatedColumnGroup ) { for (const rawColumn of rawColumns) { if ('children' in rawColumn) { - const calculatedColumnParent: MutableCalculatedColumnParent = { + const calculatedColumnGroup: MutableCalculatedColumnGroup = { name: rawColumn.name, parent, idx: -1, @@ -122,7 +122,7 @@ export function useCalculatedColumns({ headerCellClass: rawColumn.headerCellClass }; - collectColumns(rawColumn.children, level + 1, calculatedColumnParent); + collectColumns(rawColumn.children, level + 1, calculatedColumnGroup); continue; } @@ -193,7 +193,7 @@ export function useCalculatedColumns({ for (let idx = 0; idx < columns.length; idx++) { const column = columns[idx]; column.idx = idx; - updateColumnParent(column, idx, 0); + updateColumnGroups(column, idx, 0); if (column.colSpan != null) { colSpanColumns.push(column); @@ -367,8 +367,8 @@ function getDefaultColSpan() { return 1; } -function updateColumnParent( - column: MutableCalculatedColumn | MutableCalculatedColumnParent, +function updateColumnGroups( + column: MutableCalculatedColumn | MutableCalculatedColumnGroup, index: number, level: number ) { @@ -382,6 +382,6 @@ function updateColumnParent( parent.idx = index; } parent.colSpan += 1; - updateColumnParent(parent, index, level - 1); + updateColumnGroups(parent, index, level - 1); } } diff --git a/src/hooks/useRowSelection.ts b/src/hooks/useRowSelection.ts index 64f02778bc..9c93024be6 100644 --- a/src/hooks/useRowSelection.ts +++ b/src/hooks/useRowSelection.ts @@ -1,6 +1,6 @@ import { createContext, use } from 'react'; -import type { SelectHeaderRowEvent, SelectRowEvent } from '../types'; +import type { SelectHeaderRowArgs, SelectRowArgs } from '../types'; export interface RowSelectionContextValue { readonly isRowSelected: boolean; @@ -12,7 +12,7 @@ RowSelectionContext.displayName = 'RowSelectionContext'; export const RowSelectionChangeContext = createContext< // oxlint-disable-next-line typescript/no-explicit-any - ((selectRowEvent: SelectRowEvent) => void) | undefined + ((args: SelectRowArgs) => void) | undefined >(undefined); RowSelectionChangeContext.displayName = 'RowSelectionChangeContext'; @@ -42,7 +42,7 @@ export const HeaderRowSelectionContext = createContext void) | undefined + ((args: SelectHeaderRowArgs) => void) | undefined >(undefined); HeaderRowSelectionChangeContext.displayName = 'HeaderRowSelectionChangeContext'; diff --git a/src/index.ts b/src/index.ts index 6b999c11b0..2188ba8a07 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,8 +18,8 @@ export { renderSortIcon, renderSortPriority } from './sortStatus'; export { useHeaderRowSelection, useRowSelection } from './hooks'; export type { CalculatedColumn, + CalculatedColumnGroup, CalculatedColumnOrColumnGroup, - CalculatedColumnParent, CellCopyArgs, CellKeyboardEvent, CellKeyDownArgs, @@ -34,7 +34,7 @@ export type { ColumnWidth, ColumnWidths, Direction, - FillEvent, + FillArgs, PositionChangeArgs, RenderCellContentProps, RenderCellProps, @@ -50,8 +50,8 @@ export type { RenderSummaryCellContentProps, RowHeightArgs, RowsChangeData, - SelectHeaderRowEvent, - SelectRowEvent, + SelectHeaderRowArgs, + SelectRowArgs, SetActivePositionOptions, SortColumn, SortDirection diff --git a/src/types.ts b/src/types.ts index 59afb0a4fa..767a75fe5f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -39,7 +39,7 @@ export interface Column { >; /** Render function to render the content of summary cells */ readonly renderSummaryCell?: Maybe< - (props: RenderSummaryCellContentProps) => ReactNode + (props: RenderSummaryCellContentProps) => ReactNode >; /** Render function to render the content of group cells */ readonly renderGroupCell?: Maybe< @@ -91,7 +91,7 @@ export interface Column { export interface CalculatedColumn extends Column { /** The column group that contains the column, or `undefined` if the column is not in a group */ - readonly parent: CalculatedColumnParent | undefined; + readonly parent: CalculatedColumnGroup | undefined; /** The index of the column in the grid. Column groups are flattened and frozen columns are moved to their edge, so it can differ from the column's index in `columns` */ readonly idx: number; /** Header row level, counted from the bottom header row: always `0` for columns, and negative for column groups */ @@ -127,19 +127,19 @@ export interface ColumnGroup { readonly children: readonly ColumnOrColumnGroup[]; } -export interface CalculatedColumnParent { +export interface CalculatedColumnGroup { readonly name: string | ReactElement; - readonly parent: CalculatedColumnParent | undefined; + readonly parent: CalculatedColumnGroup | undefined; readonly idx: number; readonly colSpan: number; readonly level: number; - readonly headerCellClass?: Maybe; + readonly headerCellClass: Maybe; } export type ColumnOrColumnGroup = Column | ColumnGroup; export type CalculatedColumnOrColumnGroup = - | CalculatedColumnParent + | CalculatedColumnGroup | CalculatedColumn; export interface Position { @@ -158,7 +158,7 @@ export interface RenderCellContentProps { onRowChange: (row: TRow) => void; } -export interface RenderSummaryCellContentProps { +export interface RenderSummaryCellContentProps { column: CalculatedColumn; row: TSummaryRow; tabIndex: number; @@ -336,17 +336,17 @@ export interface RowsChangeData { column: CalculatedColumn; } -export interface SelectRowEvent { +export interface SelectRowArgs { row: TRow; checked: boolean; isShiftClick: boolean; } -export interface SelectHeaderRowEvent { +export interface SelectHeaderRowArgs { checked: boolean; } -export interface FillEvent { +export interface FillArgs { columnKey: string; sourceRow: TRow; targetRow: TRow; diff --git a/src/utils/activePositionUtils.ts b/src/utils/activePositionUtils.ts index b18df077d5..526879ea6f 100644 --- a/src/utils/activePositionUtils.ts +++ b/src/utils/activePositionUtils.ts @@ -1,6 +1,6 @@ import type { CalculatedColumn, - CalculatedColumnParent, + CalculatedColumnGroup, CellNavigationMode, Maybe, Position @@ -124,7 +124,7 @@ export function getNextActivePosition({ } }; - const getParentRowIdx = (parent: CalculatedColumnParent) => { + const getParentRowIdx = (parent: CalculatedColumnGroup) => { return parent.level + mainHeaderRowIdx; }; diff --git a/test/browser/column/renderSummaryCell.test.tsx b/test/browser/column/renderSummaryCell.test.tsx index 540d57c82a..bd3527fb69 100644 --- a/test/browser/column/renderSummaryCell.test.tsx +++ b/test/browser/column/renderSummaryCell.test.tsx @@ -1,6 +1,6 @@ import { page } from 'vite-plus/test/browser'; -import type { Column } from '../../../src'; +import type { Column, RenderSummaryCellContentProps } from '../../../src'; import { setup } from '../utils'; const cells = page.getCell(); @@ -16,6 +16,7 @@ const columns: readonly Column[] = [ key: 'col1', name: 'Col1', renderSummaryCell(props) { + expectTypeOf(props).toEqualTypeOf>(); return `Summary: ${props.row.id}`; } }, diff --git a/test/browser/dragFill.test.tsx b/test/browser/dragFill.test.tsx index 2388be7794..cc5d641170 100644 --- a/test/browser/dragFill.test.tsx +++ b/test/browser/dragFill.test.tsx @@ -2,7 +2,7 @@ import { useState } from 'react'; import { commands, page, userEvent, type Locator } from 'vite-plus/test/browser'; import { DataGrid } from '../../src'; -import type { Column, FillEvent } from '../../src'; +import type { Column, FillArgs } from '../../src'; import { getCellsAtRowIndex, scrollGrid } from './utils'; const dragHandle = page.getDragHandle(); @@ -31,7 +31,7 @@ function setup(allowDragFill = true) { function DragFillTest({ allowDragFill = true }: { allowDragFill?: boolean }) { const [rows, setRows] = useState(initialRows); - function onFill({ columnKey, sourceRow, targetRow }: FillEvent): Row { + function onFill({ columnKey, sourceRow, targetRow }: FillArgs): Row { return { ...targetRow, [columnKey]: sourceRow[columnKey as keyof Row] }; } diff --git a/website/routes/AllFeatures.tsx b/website/routes/AllFeatures.tsx index 29d0cae346..834b055c38 100644 --- a/website/routes/AllFeatures.tsx +++ b/website/routes/AllFeatures.tsx @@ -5,7 +5,7 @@ import { css } from 'ecij'; import clsx from 'clsx'; import { DataGrid, renderTextEditor, SelectColumn } from '../../src'; -import type { CalculatedColumn, CellCopyArgs, CellPasteArgs, Column, FillEvent } from '../../src'; +import type { CalculatedColumn, CellCopyArgs, CellPasteArgs, Column, FillArgs } from '../../src'; import { textEditorClassname } from '../../src/editors/renderTextEditor'; import { useDirection } from '../directionContext'; @@ -206,7 +206,7 @@ function AllFeatures() { readonly column: CalculatedColumn; } | null>(null); - function handleFill({ columnKey, sourceRow, targetRow }: FillEvent): Row { + function handleFill({ columnKey, sourceRow, targetRow }: FillArgs): Row { return { ...targetRow, [columnKey]: sourceRow[columnKey as keyof Row] }; }