forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableRowWrapperDemo.tsx
More file actions
71 lines (67 loc) · 2.42 KB
/
TableRowWrapperDemo.tsx
File metadata and controls
71 lines (67 loc) · 2.42 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
import { Component } from 'react';
import { RowWrapperProps, ICell, IRow } from '@patternfly/react-table';
import { Table, TableHeader, TableBody, TableProps } from '@patternfly/react-table/deprecated';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Table/table';
import t_global_color_brand_default from '@patternfly/react-tokens/dist/esm/t_global_color_brand_default';
interface ITableRowWrapperDemoState {
rows: IRow[];
columns: (ICell | string)[];
}
export class TableRowWrapperDemo extends Component<TableProps, ITableRowWrapperDemoState> {
static displayName = 'TableRowWrapperDemo';
customRowWrapper: (props: RowWrapperProps) => React.JSX.Element;
constructor(props: TableProps) {
super(props);
this.state = {
columns: [{ title: 'Repositories' }, 'Branches', { title: 'Pull requests' }, 'Workspaces'],
rows: [
{
cells: ['Repositories one', 'Branches one', 'Pull requests one', 'Workspaces one']
},
{
cells: ['Repositories two', 'Branches two', 'Pull requests two', 'Workspaces two']
},
{
cells: ['Repositories three', 'Branches three', 'Pull requests three', 'Workspaces three']
}
]
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
this.customRowWrapper = ({ trRef, className, rowProps = { rowIndex: 0, rowKey: '' }, onResize, ...rest }) => {
const isExpanded = rest.row ? rest.row.isExpanded : false;
const isOddRow = (rowProps.rowIndex + 1) % 2;
const customStyle = {
borderLeft: `3px solid ${t_global_color_brand_default.var}`
};
return (
<tr
ref={trRef as React.Ref<any>}
className={css(
className,
isOddRow ? 'odd-row-class' : 'even-row-class',
'custom-static-class',
isExpanded !== undefined && styles.tableExpandableRow,
isExpanded && styles.modifiers.expanded
)}
hidden={isExpanded !== undefined && !isExpanded}
style={isOddRow ? customStyle : {}}
/>
);
};
}
render() {
const { columns, rows } = this.state;
return (
<Table
caption="Table with custom row wrapper that styles odd rows"
cells={columns}
rows={rows}
rowWrapper={this.customRowWrapper}
>
<TableHeader />
<TableBody />
</Table>
);
}
}