-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathVirtualListRow.tsx
61 lines (47 loc) · 1.54 KB
/
VirtualListRow.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 React, { Component, CSSProperties } from 'react';
import { ColumnProps } from './Column';
import CellWrapper from './CellWrapper';
import TreeState from '../model/tree-state';
import Row, { RowModel } from '../model/row';
import { createRow } from '../util/row-creator';
export type VirtualListRowProps<TData> = {
data: Readonly<TreeState<TData>>;
model: RowModel<TData>;
columns: Array<ColumnProps<TData>>;
onChange: (value: Readonly<TreeState<TData>>) => void;
index: number;
relIndex: number;
}
export default class VirtualListRow<TData> extends Component<VirtualListRowProps<TData>, {}> {
render() {
const { model, columns, data, index, relIndex } = this.props;
const row: Row<TData> = createRow<TData>(model, data, this.handleChange);
return (
<div className={`cp_tree-table_row`}
style={{ ...STYLE_ROW, height: `${row.metadata.height}px` }}
data-index={index}
data-relindex={relIndex}>
{columns.map((column: ColumnProps<TData>, indexKey) => {
return (
<CellWrapper key={indexKey}
row={row}
renderCell={column.renderCell}
grow={column.grow}
basis={column.basis}/>
);
})}
</div>
);
}
private handleChange = (value: Readonly<TreeState<TData>>): void => {
const { onChange } = this.props;
onChange(value);
}
}
const STYLE_ROW: CSSProperties = {
display: 'flex',
boxSizing: 'border-box',
position: 'relative',
overflow: 'hidden',
width: '100%',
};