-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathHeaderRow.tsx
More file actions
105 lines (94 loc) · 2.84 KB
/
HeaderRow.tsx
File metadata and controls
105 lines (94 loc) · 2.84 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { memo, useState } from 'react';
import { css } from 'ecij';
import { classnames } from './utils';
import type {
CalculatedColumn,
Direction,
IterateOverViewportColumnsForRow,
Maybe,
Position,
ResizedWidth
} from './types';
import type { DataGridProps } from './DataGrid';
import HeaderCell from './HeaderCell';
import { cell, cellFrozen } from './style/cell';
type SharedDataGridProps<R, SR, K extends React.Key> = Pick<
DataGridProps<R, SR, K>,
'sortColumns' | 'onSortColumnsChange' | 'onColumnsReorder'
>;
export interface HeaderRowProps<R, SR, K extends React.Key> extends SharedDataGridProps<R, SR, K> {
rowIdx: number;
iterateOverViewportColumnsForRow: IterateOverViewportColumnsForRow<R, SR>;
onColumnResize: (column: CalculatedColumn<R, SR>, width: ResizedWidth) => void;
onColumnResizeEnd: () => void;
activeCellIdx: number | undefined;
setPosition: (position: Position) => void;
shouldFocusGrid: boolean;
direction: Direction;
headerRowClass: Maybe<string>;
}
const headerRow = css`
@layer rdg.HeaderRow {
display: contents;
background-color: var(--rdg-header-background-color);
font-weight: bold;
& > .${cell} {
/* Should have a higher value than 1 to show up above regular cells and the focus sink */
z-index: 2;
position: sticky;
}
& > .${cellFrozen} {
z-index: 3;
}
}
`;
export const headerRowClassname = `rdg-header-row ${headerRow}`;
function HeaderRow<R, SR, K extends React.Key>({
headerRowClass,
rowIdx,
iterateOverViewportColumnsForRow,
onColumnResize,
onColumnResizeEnd,
onColumnsReorder,
sortColumns,
onSortColumnsChange,
activeCellIdx,
setPosition,
shouldFocusGrid,
direction
}: HeaderRowProps<R, SR, K>) {
const [draggedColumnKey, setDraggedColumnKey] = useState<string>();
const cells = iterateOverViewportColumnsForRow(activeCellIdx, { type: 'HEADER' })
.map(([column, isCellActive, colSpan], index) => (
<HeaderCell<R, SR>
key={column.key}
column={column}
colSpan={colSpan}
rowIdx={rowIdx}
isCellActive={isCellActive}
onColumnResize={onColumnResize}
onColumnResizeEnd={onColumnResizeEnd}
onColumnsReorder={onColumnsReorder}
onSortColumnsChange={onSortColumnsChange}
sortColumns={sortColumns}
setPosition={setPosition}
shouldFocusGrid={shouldFocusGrid && index === 0}
direction={direction}
draggedColumnKey={draggedColumnKey}
setDraggedColumnKey={setDraggedColumnKey}
/>
))
.toArray();
return (
<div
role="row"
aria-rowindex={rowIdx} // aria-rowindex is 1 based
className={classnames(headerRowClassname, headerRowClass)}
>
{cells}
</div>
);
}
export default memo(HeaderRow) as <R, SR, K extends React.Key>(
props: HeaderRowProps<R, SR, K>
) => React.JSX.Element;