Skip to content
Draft
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
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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-tactiverow) type.

###### `onFill?: Maybe<(event: FillEvent<R>) => R>`
###### `onFill?: Maybe<(args: FillArgs<R>) => 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>): Row {
function onFill({ columnKey, sourceRow, targetRow }: FillArgs<Row>): Row {
return { ...targetRow, [columnKey]: sourceRow[columnKey as keyof Row] };
}

Expand Down Expand Up @@ -1032,7 +1032,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:**

Expand Down Expand Up @@ -1068,7 +1068,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<R>) => void` - Callback to change selection state
- `onRowSelectionChange: (args: SelectRowArgs<R>) => void` - Callback to change selection state

**Example:**

Expand Down Expand Up @@ -1419,7 +1419,7 @@ Render function to render the content of cells.

Render function to render the content of the header cell.

##### `renderSummaryCell?: Maybe<(props: RenderSummaryCellContentProps<TSummaryRow, TRow>) => ReactNode>`
##### `renderSummaryCell?: Maybe<(props: RenderSummaryCellContentProps<TRow, TSummaryRow>) => ReactNode>`

Render function to render the content of summary cells.

Expand Down Expand Up @@ -1580,7 +1580,7 @@ Extends `Column` with additional computed properties used internally by the grid
```tsx
interface CalculatedColumn<TRow, TSummaryRow = unknown> extends Column<TRow, TSummaryRow> {
/** The column group that contains the column, or `undefined` if the column is not in a group */
readonly parent: CalculatedColumnParent<TRow, TSummaryRow> | undefined;
readonly parent: CalculatedColumnGroup<TRow, TSummaryRow> | 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 */
Expand Down Expand Up @@ -1612,32 +1612,32 @@ interface CalculatedColumn<TRow, TSummaryRow = unknown> extends Column<TRow, TSu

**See also:** [`Column`](#columntrow-tsummaryrow), [`onColumnResize`](#oncolumnresize-maybecolumn-calculatedcolumnr-sr-width-number--void) prop on `<DataGrid />`

#### `CalculatedColumnParent<TRow, TSummaryRow>`
#### `CalculatedColumnGroup<TRow, TSummaryRow>`

Represents a parent column group in the calculated column structure.

```tsx
interface CalculatedColumnParent<R, SR> {
interface CalculatedColumnGroup<R, SR> {
readonly name: string | ReactElement;
readonly parent: CalculatedColumnParent<R, SR> | undefined;
readonly parent: CalculatedColumnGroup<R, SR> | undefined;
readonly idx: number;
readonly colSpan: number;
readonly level: number;
readonly headerCellClass?: Maybe<string>;
readonly headerCellClass: Maybe<string>;
}
```

**See also:** [`CalculatedColumn`](#calculatedcolumntrow-tsummaryrow)

#### `CalculatedColumnOrColumnGroup<TRow, TSummaryRow>`

Union type representing either a `CalculatedColumnParent` or a `CalculatedColumn`.
Union type representing either a `CalculatedColumnGroup` or a `CalculatedColumn`.

```tsx
type CalculatedColumnOrColumnGroup<R, SR> = CalculatedColumnParent<R, SR> | CalculatedColumn<R, SR>;
type CalculatedColumnOrColumnGroup<R, SR> = CalculatedColumnGroup<R, SR> | CalculatedColumn<R, SR>;
```

**See also:** [`CalculatedColumn`](#calculatedcolumntrow-tsummaryrow), [`CalculatedColumnParent`](#calculatedcolumnparenttrow-tsummaryrow)
**See also:** [`CalculatedColumn`](#calculatedcolumntrow-tsummaryrow), [`CalculatedColumnGroup`](#calculatedcolumngrouptrow-tsummaryrow)

#### `DefaultColumnOptions<TRow, TSummaryRow>`

Expand Down Expand Up @@ -1749,19 +1749,19 @@ function renderEditor({ row, column, onRowChange, onClose }: RenderEditCellConte

**See also:** [`column.renderEditCell`](#rendereditcell-maybeprops-rendereditcellcontentpropstrow-tsummaryrow--reactnode), [`renderTextEditor`](#rendertexteditortrow-tsummaryrowprops-rendereditcellcontentpropstrow-tsummaryrow) function

#### `RenderSummaryCellContentProps<TSummaryRow, TRow>`
#### `RenderSummaryCellContentProps<TRow, TSummaryRow>`

Props passed to summary cell content renderers (`column.renderSummaryCell`).

```tsx
interface RenderSummaryCellContentProps<TSummaryRow, TRow = unknown> {
interface RenderSummaryCellContentProps<TRow, TSummaryRow = unknown> {
column: CalculatedColumn<TRow, TSummaryRow>;
row: TSummaryRow;
tabIndex: number;
}
```

**See also:** [`column.renderSummaryCell`](#rendersummarycell-maybeprops-rendersummarycellcontentpropstsummaryrow-trow--reactnode)
**See also:** [`column.renderSummaryCell`](#rendersummarycell-maybeprops-rendersummarycellcontentpropstrow-tsummaryrow--reactnode)

#### `RenderGroupCellContentProps<TRow, TSummaryRow>`

Expand Down Expand Up @@ -2286,12 +2286,12 @@ interface RowsChangeData<R, SR = unknown> {

**See also:** [`onRowsChange`](#onrowschange-mayberows-r-data-rowschangedatar-sr--void) prop on `<DataGrid />`

#### `SelectRowEvent<TRow>`
#### `SelectRowArgs<TRow>`

Event object for row selection changes.
Arguments for row selection changes.

```tsx
interface SelectRowEvent<TRow> {
interface SelectRowArgs<TRow> {
row: TRow;
checked: boolean;
isShiftClick: boolean;
Expand All @@ -2300,31 +2300,31 @@ interface SelectRowEvent<TRow> {

**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<TRow>`
#### `FillArgs<TRow>`

Event object for drag-fill operations.
Arguments for drag-fill operations.

```tsx
interface FillEvent<TRow> {
interface FillArgs<TRow> {
columnKey: string;
sourceRow: TRow;
targetRow: TRow;
}
```

**See also:** [`onFill`](#onfill-maybeevent-filleventr--r) prop on `<DataGrid />`
**See also:** [`onFill`](#onfill-maybeargs-fillargsr--r) prop on `<DataGrid />`

#### `DataGridHandle`

Expand Down
12 changes: 6 additions & 6 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -202,7 +202,7 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> 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<R>>) => NoInfer<R>>;
onFill?: Maybe<(args: FillArgs<NoInfer<R>>) => NoInfer<R>>;

/**
* Toggles and modes
Expand Down Expand Up @@ -542,7 +542,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
/**
* event handlers
*/
function selectHeaderRow(args: SelectHeaderRowEvent) {
function selectHeaderRow(args: SelectHeaderRowArgs) {
if (!onSelectedRowsChange) return;

assertIsValidGetRowKey<R, K>(getRowKey);
Expand All @@ -560,7 +560,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
onSelectedRowsChange(newSelectedRows);
}

function selectRow(args: SelectRowEvent<R>) {
function selectRow(args: SelectRowArgs<R>) {
if (!onSelectedRowsChange) return;

assertIsValidGetRowKey<R, K>(getRowKey);
Expand Down
4 changes: 2 additions & 2 deletions src/GroupedColumnHeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -10,7 +10,7 @@ type SharedGroupedColumnHeaderRowProps<R, SR> = Pick<
>;

interface GroupedColumnHeaderCellProps<R, SR> extends SharedGroupedColumnHeaderRowProps<R, SR> {
column: CalculatedColumnParent<R, SR>;
column: CalculatedColumnGroup<R, SR>;
isCellActive: boolean;
}

Expand Down
4 changes: 2 additions & 2 deletions src/GroupedColumnHeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -19,7 +19,7 @@ function GroupedColumnHeaderRow<R, SR>({
activeCellIdx,
setPosition
}: GroupedColumnHeaderRowProps<R, SR>) {
const renderedParents = new Set<CalculatedColumnParent<R, SR>>();
const renderedParents = new Set<CalculatedColumnGroup<R, SR>>();

const cells = mapViewportColumns(activeCellIdx, undefined, (column, isCellActive) => {
if (column.parent === undefined) return null;
Expand Down
20 changes: 10 additions & 10 deletions src/hooks/useCalculatedColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMemo } from 'react';
import { clampColumnWidth, max, min } from '../utils';
import type {
CalculatedColumn,
CalculatedColumnParent,
CalculatedColumnGroup,
ColSpanArgs,
ColumnFrozen,
ColumnOrColumnGroup,
Expand All @@ -19,10 +19,10 @@ type Mutable<T> = {
};

interface WithParent<R, SR> {
readonly parent: MutableCalculatedColumnParent<R, SR> | undefined;
readonly parent: MutableCalculatedColumnGroup<R, SR> | undefined;
}

type MutableCalculatedColumnParent<R, SR> = Omit<Mutable<CalculatedColumnParent<R, SR>>, 'parent'> &
type MutableCalculatedColumnGroup<R, SR> = Omit<Mutable<CalculatedColumnGroup<R, SR>>, 'parent'> &
WithParent<R, SR>;
type MutableCalculatedColumn<R, SR> = Omit<Mutable<CalculatedColumn<R, SR>>, 'parent'> &
WithParent<R, SR>;
Expand Down Expand Up @@ -109,11 +109,11 @@ export function useCalculatedColumns<R, SR>({
function collectColumns(
rawColumns: readonly ColumnOrColumnGroup<R, SR>[],
level: number,
parent?: MutableCalculatedColumnParent<R, SR>
parent?: MutableCalculatedColumnGroup<R, SR>
) {
for (const rawColumn of rawColumns) {
if ('children' in rawColumn) {
const calculatedColumnParent: MutableCalculatedColumnParent<R, SR> = {
const calculatedColumnGroup: MutableCalculatedColumnGroup<R, SR> = {
name: rawColumn.name,
parent,
idx: -1,
Expand All @@ -122,7 +122,7 @@ export function useCalculatedColumns<R, SR>({
headerCellClass: rawColumn.headerCellClass
};

collectColumns(rawColumn.children, level + 1, calculatedColumnParent);
collectColumns(rawColumn.children, level + 1, calculatedColumnGroup);
continue;
}

Expand Down Expand Up @@ -193,7 +193,7 @@ export function useCalculatedColumns<R, SR>({
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);
Expand Down Expand Up @@ -367,8 +367,8 @@ function getDefaultColSpan() {
return 1;
}

function updateColumnParent<R, SR>(
column: MutableCalculatedColumn<R, SR> | MutableCalculatedColumnParent<R, SR>,
function updateColumnGroups<R, SR>(
column: MutableCalculatedColumn<R, SR> | MutableCalculatedColumnGroup<R, SR>,
index: number,
level: number
) {
Expand All @@ -382,6 +382,6 @@ function updateColumnParent<R, SR>(
parent.idx = index;
}
parent.colSpan += 1;
updateColumnParent(parent, index, level - 1);
updateColumnGroups(parent, index, level - 1);
}
}
6 changes: 3 additions & 3 deletions src/hooks/useRowSelection.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +12,7 @@ RowSelectionContext.displayName = 'RowSelectionContext';

export const RowSelectionChangeContext = createContext<
// oxlint-disable-next-line typescript/no-explicit-any
((selectRowEvent: SelectRowEvent<any>) => void) | undefined
((args: SelectRowArgs<any>) => void) | undefined
>(undefined);
RowSelectionChangeContext.displayName = 'RowSelectionChangeContext';

Expand Down Expand Up @@ -42,7 +42,7 @@ export const HeaderRowSelectionContext = createContext<HeaderRowSelectionContext
HeaderRowSelectionContext.displayName = 'HeaderRowSelectionContext';

export const HeaderRowSelectionChangeContext = createContext<
((selectRowEvent: SelectHeaderRowEvent) => void) | undefined
((args: SelectHeaderRowArgs) => void) | undefined
>(undefined);
HeaderRowSelectionChangeContext.displayName = 'HeaderRowSelectionChangeContext';

Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export { renderSortIcon, renderSortPriority } from './sortStatus';
export { useHeaderRowSelection, useRowSelection } from './hooks';
export type {
CalculatedColumn,
CalculatedColumnGroup,
CalculatedColumnOrColumnGroup,
CalculatedColumnParent,
CellCopyArgs,
CellKeyboardEvent,
CellKeyDownArgs,
Expand All @@ -34,7 +34,7 @@ export type {
ColumnWidth,
ColumnWidths,
Direction,
FillEvent,
FillArgs,
GroupRow,
PositionChangeArgs,
RenderCellContentProps,
Expand All @@ -51,8 +51,8 @@ export type {
RenderSummaryCellContentProps,
RowHeightArgs,
RowsChangeData,
SelectHeaderRowEvent,
SelectRowEvent,
SelectHeaderRowArgs,
SelectRowArgs,
SetActivePositionOptions,
SortColumn,
SortDirection,
Expand Down
Loading
Loading