-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathSummaryRow.tsx
More file actions
91 lines (80 loc) · 2.03 KB
/
SummaryRow.tsx
File metadata and controls
91 lines (80 loc) · 2.03 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import { memo } from 'react';
import { css } from 'ecij';
import { classnames, getColSpan } from './utils';
import type { RenderSummaryRowProps } from './types';
import { bottomSummaryRowClassname, rowClassname, topSummaryRowClassname } from './style/row';
import SummaryCell from './SummaryCell';
const summaryRow = css`
@layer rdg.SummaryRow {
position: sticky;
z-index: 2;
}
`;
const summaryRowClassname = `rdg-summary-row ${summaryRow}`;
function SummaryRow<R, SR>({
tabIndex,
className,
rowIdx,
gridRowStart,
row,
viewportColumns,
top,
bottom,
lastFrozenColumnIndex,
selectedCellIdx,
isTop,
selectCell,
'aria-rowindex': ariaRowIndex
}: RenderSummaryRowProps<R, SR>) {
const cells = [];
for (let index = 0; index < viewportColumns.length; index++) {
const column = viewportColumns[index];
const colSpan = getColSpan(column, lastFrozenColumnIndex, { type: 'SUMMARY', row });
if (colSpan !== undefined) {
index += colSpan - 1;
}
const isCellSelected = selectedCellIdx === column.idx;
cells.push(
<SummaryCell<R, SR>
key={column.key}
column={column}
colSpan={colSpan}
row={row}
rowIdx={rowIdx}
isCellSelected={isCellSelected}
selectCell={selectCell}
/>
);
}
return (
<div
role="row"
aria-rowindex={ariaRowIndex}
tabIndex={tabIndex}
className={classnames(
rowClassname,
`rdg-row-${rowIdx % 2 === 0 ? 'even' : 'odd'}`,
summaryRowClassname,
isTop ? topSummaryRowClassname : bottomSummaryRowClassname,
className
)}
style={{
gridRowStart,
top,
bottom
}}
>
{cells}
</div>
);
}
const SummaryRowComponent = memo(SummaryRow) as <R, SR>(
props: RenderSummaryRowProps<R, SR>
) => React.JSX.Element;
export default SummaryRowComponent;
export function defaultRenderSummaryRow<R, SR>(
key: React.Key,
props: RenderSummaryRowProps<R, SR>
) {
return <SummaryRowComponent key={key} {...props} />;
}