Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The DataGrid component is designed to handle large datasets efficiently while of

- [React 19.2+](package.json) support
- Evergreen browsers and server-side rendering support
- Tree-shaking support and only [one npm dependency](package.json) to keep your bundles slim
- Tree-shaking support with no external dependencies to keep your bundles slim
- Great performance thanks to virtualization: columns and rows outside the viewport are not rendered
- Strictly typed with TypeScript
- [Keyboard accessibility](https://comcast.github.io/react-data-grid/#/CommonFeatures)
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
"prepublishOnly": "npm install && node --run build",
"postpublish": "git push --follow-tags origin HEAD"
},
"dependencies": {
"clsx": "^2.0.0"
},
"devDependencies": {
"@babel/preset-typescript": "^7.27.1",
"@biomejs/biome": "2.2.5",
Expand All @@ -72,6 +69,7 @@
"@vitest/eslint-plugin": "^1.3.4",
"@wyw-in-js/rollup": "^0.7.0",
"@wyw-in-js/vite": "^0.7.0",
"clsx": "^2.1.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept this for website

"eslint": "^9.36.0",
"eslint-plugin-jest-dom": "^5.5.0",
"eslint-plugin-react": "^7.37.5",
Expand Down
11 changes: 7 additions & 4 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from 'react';
import type { Key, KeyboardEvent } from 'react';
import { flushSync } from 'react-dom';
import clsx from 'clsx';

import {
HeaderRowSelectionChangeContext,
Expand All @@ -26,6 +25,7 @@ import {
abs,
assertIsValidKeyGetter,
canExitGrid,
classnames,
createCellEvent,
getCellStyle,
getColSpan,
Expand Down Expand Up @@ -991,7 +991,10 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
return (
<div
style={dragHandleStyle}
className={clsx(cellDragHandleClassname, column.frozen && cellDragHandleFrozenClassname)}
className={classnames(
cellDragHandleClassname,
column.frozen && cellDragHandleFrozenClassname
)}
onPointerDown={handleDragHandlePointerDown}
onPointerMove={isDragging ? handleDragHandlePointerMove : undefined}
onLostPointerCapture={isDragging ? handleDragHandleLostPointerCapture : undefined}
Expand Down Expand Up @@ -1185,7 +1188,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
// Scrollable containers without tabIndex are keyboard focusable in Chrome only if there is no focusable element inside
// whereas they are always focusable in Firefox. We need to set tabIndex to have a consistent behavior across browsers.
tabIndex={-1}
className={clsx(
className={classnames(
rootClassname,
{
[viewportDraggingClassname]: isDragging
Expand Down Expand Up @@ -1329,7 +1332,7 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
<div
ref={focusSinkRef}
tabIndex={isGroupRowFocused ? 0 : -1}
className={clsx(focusSinkClassname, {
className={classnames(focusSinkClassname, {
[focusSinkHeaderAndSummaryClassname]: !isRowIdxWithinViewportBounds(
selectedPosition.rowIdx
),
Expand Down
5 changes: 2 additions & 3 deletions src/GroupRow.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { memo, useMemo } from 'react';
import { css } from '@linaria/core';
import clsx from 'clsx';

import { RowSelectionContext, type RowSelectionContextValue } from './hooks';
import { getRowStyle } from './utils';
import { classnames, getRowStyle } from './utils';
import type { BaseRenderRowProps, GroupRow } from './types';
import { SELECT_COLUMN_KEY } from './Columns';
import GroupCell from './GroupCell';
Expand Down Expand Up @@ -65,7 +64,7 @@ function GroupedRow<R, SR>({
aria-setsize={row.setSize}
aria-posinset={row.posInSet + 1} // aria-posinset is 1-based
aria-expanded={row.isExpanded}
className={clsx(
className={classnames(
rowClassname,
groupRowClassname,
`rdg-row-${rowIdx % 2 === 0 ? 'even' : 'odd'}`,
Expand Down
6 changes: 2 additions & 4 deletions src/GroupedColumnHeaderCell.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import clsx from 'clsx';

import { useRovingTabIndex } from './hooks';
import { getHeaderCellRowSpan, getHeaderCellStyle } from './utils';
import { classnames, getHeaderCellRowSpan, getHeaderCellStyle } from './utils';
import type { CalculatedColumnParent } from './types';
import type { GroupedColumnHeaderRowProps } from './GroupedColumnHeaderRow';
import { cellClassname } from './style/cell';
Expand Down Expand Up @@ -39,7 +37,7 @@ export default function GroupedColumnHeaderCell<R, SR>({
aria-rowspan={rowSpan}
aria-selected={isCellSelected}
tabIndex={tabIndex}
className={clsx(cellClassname, column.headerCellClass)}
className={classnames(cellClassname, column.headerCellClass)}
style={{
...getHeaderCellStyle(column, rowIdx, rowSpan),
gridColumnStart: index,
Expand Down
5 changes: 2 additions & 3 deletions src/HeaderRow.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { memo, useState } from 'react';
import { css } from '@linaria/core';
import clsx from 'clsx';

import { getColSpan } from './utils';
import { classnames, getColSpan } from './utils';
import type { CalculatedColumn, Direction, Maybe, Position, ResizedWidth } from './types';
import type { DataGridProps } from './DataGrid';
import HeaderCell from './HeaderCell';
Expand Down Expand Up @@ -97,7 +96,7 @@ function HeaderRow<R, SR, K extends React.Key>({
<div
role="row"
aria-rowindex={rowIdx} // aria-rowindex is 1 based
className={clsx(
className={classnames(
headerRowClassname,
{
[rowSelectedClassname]: selectedCellIdx === -1
Expand Down
5 changes: 2 additions & 3 deletions src/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { memo, useMemo } from 'react';
import clsx from 'clsx';

import { RowSelectionContext, useLatestFunc, type RowSelectionContextValue } from './hooks';
import { getColSpan, getRowStyle } from './utils';
import { classnames, getColSpan, getRowStyle } from './utils';
import type { CalculatedColumn, RenderRowProps } from './types';
import { useDefaultRenderers } from './DataGridDefaultRenderersContext';
import { rowClassname, rowSelectedClassname } from './style/row';
Expand Down Expand Up @@ -35,7 +34,7 @@ function Row<R, SR>({
onRowChange(column, rowIdx, newRow);
});

className = clsx(
className = classnames(
rowClassname,
`rdg-row-${rowIdx % 2 === 0 ? 'even' : 'odd'}`,
{
Expand Down
5 changes: 2 additions & 3 deletions src/SummaryRow.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { memo } from 'react';
import { css } from '@linaria/core';
import clsx from 'clsx';

import { getColSpan, getRowStyle } from './utils';
import { classnames, getColSpan, getRowStyle } from './utils';
import type { RenderRowProps } from './types';
import { cell, cellFrozen } from './style/cell';
import {
Expand Down Expand Up @@ -90,7 +89,7 @@ function SummaryRow<R, SR>({
<div
role="row"
aria-rowindex={ariaRowIndex}
className={clsx(
className={classnames(
rowClassname,
`rdg-row-${rowIdx % 2 === 0 ? 'even' : 'odd'}`,
summaryRowClassname,
Expand Down
29 changes: 25 additions & 4 deletions src/utils/styleUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { CSSProperties } from 'react';
import clsx from 'clsx';

import type { CalculatedColumn, CalculatedColumnOrColumnGroup } from '../types';
import type { CalculatedColumn, CalculatedColumnOrColumnGroup, Maybe } from '../types';
import { cellClassname, cellFrozenClassname } from '../style/cell';

export function getRowStyle(rowIdx: number): CSSProperties {
Expand Down Expand Up @@ -45,11 +44,33 @@ export function getCellStyle<R, SR>(
};
}

type ClassValue = Maybe<string> | Record<string, boolean> | false;

export function classnames(...args: readonly ClassValue[]) {
let classname = '';

for (const arg of args) {
if (arg) {
if (typeof arg === 'string') {
classname += ` ${arg}`;
} else if (typeof arg === 'object') {
for (const key in arg) {
if (arg[key]) {
classname += ` ${key}`;
}
}
}
}
}

return classname.trimStart();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also valid

Suggested change
return classname.trimStart();
return classname.slice(1);

}

export function getCellClassname<R, SR>(
column: CalculatedColumn<R, SR>,
...extraClasses: Parameters<typeof clsx>
...extraClasses: readonly ClassValue[]
): string {
return clsx(
return classnames(
cellClassname,
{
[cellFrozenClassname]: column.frozen
Expand Down