-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Row.tsx
67 lines (62 loc) · 1.58 KB
/
Row.tsx
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
import React, { memo } from 'react';
import clsx from 'clsx';
import Cell from './Cell';
import { RowRendererProps } from './common/types';
import { wrapEvent } from './utils';
function Row<R, SR = unknown>({
cellRenderer: CellRenderer = Cell,
className,
eventBus,
rowIdx,
isRowSelected,
lastFrozenColumnIndex,
selectedCellIdx,
copiedCellIdx,
draggedOverCellIdx,
row,
viewportColumns,
dragHandle,
onRowClick,
rowClass,
setDraggedOverRowIdx,
onMouseEnter,
top,
...props
}: RowRendererProps<R, SR>) {
function handleDragEnter() {
setDraggedOverRowIdx?.(rowIdx);
}
className = clsx(
'rdg-row',
`rdg-row-${rowIdx % 2 === 0 ? 'even' : 'odd'}`,
{ 'rdg-row-selected': isRowSelected },
rowClass?.(row),
className
);
return (
<div
className={className}
onMouseEnter={wrapEvent(handleDragEnter, onMouseEnter)}
style={{ top }}
{...props}
>
{viewportColumns.map(column => (
<CellRenderer
key={column.key}
rowIdx={rowIdx}
column={column}
lastFrozenColumnIndex={lastFrozenColumnIndex}
row={row}
isSelected={selectedCellIdx === column.idx}
isCopied={copiedCellIdx === column.idx}
isDraggedOver={draggedOverCellIdx === column.idx}
isRowSelected={isRowSelected}
eventBus={eventBus}
dragHandle={selectedCellIdx === column.idx ? dragHandle : undefined}
onRowClick={onRowClick}
/>
))}
</div>
);
}
export default memo(Row) as <R, SR>(props: RowRendererProps<R, SR>) => JSX.Element;