-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathstyleUtils.ts
More file actions
61 lines (54 loc) · 1.66 KB
/
styleUtils.ts
File metadata and controls
61 lines (54 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import type { CSSProperties } from 'react';
import clsx from 'clsx';
import type { CalculatedColumn, CalculatedColumnOrColumnGroup } from '../types';
import { cellClassname, cellFrozenClassname, cellRightFrozenClassname } from '../style/cell';
export function getRowStyle(rowIdx: number): CSSProperties {
return { '--rdg-grid-row-start': rowIdx } as unknown as CSSProperties;
}
export function getHeaderCellStyle<R, SR>(
column: CalculatedColumnOrColumnGroup<R, SR>,
rowIdx: number,
rowSpan: number
): React.CSSProperties {
const gridRowEnd = rowIdx + 1;
const paddingBlockStart = `calc(${rowSpan - 1} * var(--rdg-header-row-height))`;
if (column.parent === undefined) {
return {
insetBlockStart: 0,
gridRowStart: 1,
gridRowEnd,
paddingBlockStart
};
}
return {
insetBlockStart: `calc(${rowIdx - rowSpan} * var(--rdg-header-row-height))`,
gridRowStart: gridRowEnd - rowSpan,
gridRowEnd,
paddingBlockStart
};
}
export function getCellStyle<R, SR>(
column: CalculatedColumn<R, SR>,
colSpan = 1
): React.CSSProperties {
const index = column.idx + 1;
return {
gridColumnStart: index,
gridColumnEnd: index + colSpan,
insetInlineStart: column.frozen ? `var(--rdg-frozen-left-${column.idx})` : undefined,
insetInlineEnd: column.rightFrozen? `var(--rdg-frozen-right-${column.idx})` : undefined,
};
}
export function getCellClassname<R, SR>(
column: CalculatedColumn<R, SR>,
...extraClasses: Parameters<typeof clsx>
): string {
return clsx(
cellClassname,
{
[cellFrozenClassname]: column.frozen,
[cellRightFrozenClassname]: column.rightFrozen,
},
...extraClasses
);
}