-
-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathtr.tsx
61 lines (50 loc) · 1.43 KB
/
tr.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
import { h, JSX, ComponentChildren } from 'preact';
import Row from '../../row';
import Cell from '../../cell';
import { classJoin, className } from '../../util/className';
import { TColumn } from '../../types';
import { TD } from './td';
import Header from '../../header';
import { useConfig } from '../../hooks/useConfig';
import useSelector from '../../hooks/useSelector';
export function TR(props: {
row?: Row;
messageRow?: boolean;
children?: ComponentChildren;
}) {
const config = useConfig();
const header = useSelector((state) => state.header);
const getColumn = (cellIndex: number): TColumn => {
if (header) {
const cols = Header.leafColumns(header.columns);
if (cols) {
return cols[cellIndex];
}
}
return null;
};
const handleClick = (
e: JSX.TargetedMouseEvent<HTMLTableRowElement>,
): void => {
if (props.messageRow) return;
config.eventEmitter.emit('rowClick', e, props.row);
};
const getChildren = (): ComponentChildren => {
if (props.children) {
return props.children;
}
return props.row.cells.map((cell: Cell, i) => {
const column = getColumn(i);
if (column && column.hidden) return null;
return <TD key={cell.id} cell={cell} row={props.row} column={column} />;
});
};
return (
<tr
className={classJoin(className('tr'), config.className.tr)}
onClick={handleClick}
>
{getChildren()}
</tr>
);
}