Skip to content

Commit fd8586f

Browse files
authored
Add command methods and CSS variable types (#3858)
* Add command methods and CSS variable types * Remove extra fields
1 parent 7a7aaaf commit fd8586f

File tree

8 files changed

+46
-35
lines changed

8 files changed

+46
-35
lines changed

src/DataGrid.tsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,28 +1192,26 @@ export function DataGrid<R, SR = unknown, K extends Key = Key>(props: DataGridPr
11921192
},
11931193
className
11941194
)}
1195-
style={
1196-
{
1197-
...style,
1198-
// set scrollPadding to correctly position non-sticky cells after scrolling
1199-
scrollPaddingInlineStart:
1200-
selectedPosition.idx > lastFrozenColumnIndex || scrollToPosition?.idx !== undefined
1201-
? `${totalFrozenColumnWidth}px`
1202-
: undefined,
1203-
scrollPaddingBlock:
1204-
isRowIdxWithinViewportBounds(selectedPosition.rowIdx) ||
1205-
scrollToPosition?.rowIdx !== undefined
1206-
? `${headerRowsHeight + topSummaryRowsCount * summaryRowHeight}px ${
1207-
bottomSummaryRowsCount * summaryRowHeight
1208-
}px`
1209-
: undefined,
1210-
gridTemplateColumns,
1211-
gridTemplateRows: templateRows,
1212-
'--rdg-header-row-height': `${headerRowHeight}px`,
1213-
'--rdg-scroll-height': `${scrollHeight}px`,
1214-
...layoutCssVars
1215-
} as unknown as React.CSSProperties
1216-
}
1195+
style={{
1196+
...style,
1197+
// set scrollPadding to correctly position non-sticky cells after scrolling
1198+
scrollPaddingInlineStart:
1199+
selectedPosition.idx > lastFrozenColumnIndex || scrollToPosition?.idx !== undefined
1200+
? `${totalFrozenColumnWidth}px`
1201+
: undefined,
1202+
scrollPaddingBlock:
1203+
isRowIdxWithinViewportBounds(selectedPosition.rowIdx) ||
1204+
scrollToPosition?.rowIdx !== undefined
1205+
? `${headerRowsHeight + topSummaryRowsCount * summaryRowHeight}px ${
1206+
bottomSummaryRowsCount * summaryRowHeight
1207+
}px`
1208+
: undefined,
1209+
gridTemplateColumns,
1210+
gridTemplateRows: templateRows,
1211+
'--rdg-header-row-height': `${headerRowHeight}px`,
1212+
'--rdg-scroll-height': `${scrollHeight}px`,
1213+
...layoutCssVars
1214+
}}
12171215
dir={direction}
12181216
ref={gridRef}
12191217
onScroll={handleScroll}

src/SummaryRow.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,11 @@ function SummaryRow<R, SR>({
100100
[bottomSummaryRowClassname]: !isTop
101101
}
102102
)}
103-
style={
104-
{
105-
...getRowStyle(gridRowStart),
106-
'--rdg-summary-row-top': top !== undefined ? `${top}px` : undefined,
107-
'--rdg-summary-row-bottom': bottom !== undefined ? `${bottom}px` : undefined
108-
} as unknown as React.CSSProperties
109-
}
103+
style={{
104+
...getRowStyle(gridRowStart),
105+
'--rdg-summary-row-top': top !== undefined ? `${top}px` : undefined,
106+
'--rdg-summary-row-bottom': bottom !== undefined ? `${bottom}px` : undefined
107+
}}
110108
>
111109
{cells}
112110
</div>

src/globals.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module 'react' {
2+
// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
3+
interface CSSProperties {
4+
[key: `--${string}`]: string | number | undefined;
5+
}
6+
}
7+
8+
// somehow required to make `declare global` work
9+
export {};

src/utils/styleUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { CalculatedColumn, CalculatedColumnOrColumnGroup } from '../types';
55
import { cellClassname, cellFrozenClassname } from '../style/cell';
66

77
export function getRowStyle(rowIdx: number): CSSProperties {
8-
return { '--rdg-grid-row-start': rowIdx } as unknown as CSSProperties;
8+
return { '--rdg-grid-row-start': rowIdx };
99
}
1010

1111
export function getHeaderCellStyle<R, SR>(

test/browser/column/resizable.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ interface ResizeArgs {
3131
async function resize({ column, resizeBy }: ResizeArgs) {
3232
expect(getResizeHandle(column)).toBeInTheDocument();
3333

34-
// @ts-expect-error
3534
await commands.resizeColumn(resizeBy);
3635
}
3736

test/browser/dragFill.test.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ test('should allow dragFill if onFill is specified', async () => {
6666

6767
test('should update single row using mouse', async () => {
6868
setup();
69-
// @ts-expect-error
7069
await commands.dragFill('a1', 'a2');
7170
await expect.element(getCellsAtRowIndex(1)[0]).toHaveTextContent('a1');
7271
await expect.element(getCellsAtRowIndex(2)[0]).toHaveTextContent('a3');
@@ -75,7 +74,6 @@ test('should update single row using mouse', async () => {
7574

7675
test('should update multiple rows using mouse', async () => {
7776
setup();
78-
// @ts-expect-error
7977
await commands.dragFill('a1', 'a4');
8078
await expect.element(getCellsAtRowIndex(1)[0]).toHaveTextContent('a1');
8179
await expect.element(getCellsAtRowIndex(2)[0]).toHaveTextContent('a1');
@@ -84,7 +82,6 @@ test('should update multiple rows using mouse', async () => {
8482

8583
test('should allow drag up using mouse', async () => {
8684
setup();
87-
// @ts-expect-error
8885
await commands.dragFill('a4', 'a1');
8986
await expect.element(getCellsAtRowIndex(0)[0]).toHaveTextContent('a4');
9087
await expect.element(getCellsAtRowIndex(1)[0]).toHaveTextContent('a4');

test/globals.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module '@vitest/browser/context' {
2+
interface BrowserCommands {
3+
resizeColumn: (resizeBy: number | readonly number[]) => Promise<void>;
4+
dragFill: (from: string, to: string) => Promise<void>;
5+
}
6+
}
7+
8+
// somehow required to make `declare global` work
9+
export {};

tsconfig.lib.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"lib": ["ESNext", "DOM", "DOM.Iterable", "DOM.AsyncIterable"],
77
"noCheck": true
88
},
9-
"files": ["src/index.ts"]
9+
"files": ["src/index.ts"],
10+
"include": ["src/globals.d.ts"]
1011
}

0 commit comments

Comments
 (0)