-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbase-table.tsx
More file actions
70 lines (63 loc) · 1.7 KB
/
Copy pathbase-table.tsx
File metadata and controls
70 lines (63 loc) · 1.7 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
import React, { ReactNode } from 'react';
import styled from 'styled-components';
import TableHead from '../table-head/table-head';
import TableBody from '../table-body/table-body';
import BodyText from '../body-text/body-text';
export interface BaseTableProps {
renderHeader?: () => ReactNode;
renderDataHeaders?: () => ReactNode;
renderData?: () => ReactNode;
renderFooter?: () => ReactNode;
noData?: boolean;
noDataMessage?: string;
paddingBottom?: number;
}
export const TableContainer = styled.div<{ paddingBottom?: number }>(
({ theme, paddingBottom }) => ({
overflowX: 'auto',
...(paddingBottom && { paddingBottom }),
}),
);
const StyledTable = styled.table(({ theme }) => ({
width: '100%',
position: 'relative',
borderCollapse: 'collapse',
}));
const NoDataContainer = styled.div(({ theme }) => ({
position: 'absolute',
top: 0,
width: '100%',
height: '100%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}));
export function BaseTable(props: BaseTableProps) {
const {
renderHeader,
renderDataHeaders,
renderData,
renderFooter,
noData,
noDataMessage,
paddingBottom,
} = props;
return (
<>
{renderHeader && renderHeader()}
<TableContainer paddingBottom={paddingBottom}>
<StyledTable>
{renderDataHeaders && <TableHead>{renderDataHeaders()}</TableHead>}
{renderData && <TableBody>{renderData()}</TableBody>}
</StyledTable>
</TableContainer>
{renderFooter && renderFooter()}
{noDataMessage && noData && (
<NoDataContainer>
<BodyText size={1}>{noDataMessage}</BodyText>
</NoDataContainer>
)}
</>
);
}
export default BaseTable;