/
TableViewCol.js
114 lines (107 loc) · 3.21 KB
/
TableViewCol.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React from 'react';
import PropTypes from 'prop-types';
import Checkbox from '@mui/material/Checkbox';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import FormControl from '@mui/material/FormControl';
import FormGroup from '@mui/material/FormGroup';
import FormControlLabel from '@mui/material/FormControlLabel';
import { makeStyles } from "tss-react/mui";
const useStyles = makeStyles()(
theme => ({
root: {
padding: '16px 24px 16px 24px',
fontFamily: 'Roboto',
},
title: {
marginLeft: '-7px',
marginRight: '24px',
fontSize: '14px',
color: theme.palette.text.secondary,
textAlign: 'left',
fontWeight: 500,
},
formGroup: {
marginTop: '8px',
},
formControl: {},
checkbox: {
padding: '0px',
width: '32px',
height: '32px',
},
checkboxRoot: {},
checked: {},
label: {
fontSize: '15px',
marginLeft: '8px',
color: theme.palette.text.primary,
},
}),
{ name: 'MUIDataTableViewCol' },
);
const TableViewCol = ({ columns, options, components = {}, onColumnUpdate, updateColumns }) => {
const { classes } = useStyles();
const textLabels = options.textLabels.viewColumns;
const CheckboxComponent = components.Checkbox || Checkbox;
const handleColChange = index => {
onColumnUpdate(index);
};
const selectAll = () => {
var newColumns = columns.map(col => {
var newCol = Object.assign({}, col);
newCol.display = "true";
return newCol;
});
updateColumns(newColumns);
};
return (
<FormControl component={'fieldset'} className={classes.root} aria-label={textLabels.titleAria}>
<Typography variant="caption" className={classes.title}>
{textLabels.title}
</Typography>
<FormGroup className={classes.formGroup}>
<Button onClick={selectAll}>Show All</Button>
{columns.map((column, index) => {
return (
column.display !== 'excluded' &&
column.viewColumns !== false && (
<FormControlLabel
key={index}
classes={{
root: classes.formControl,
label: classes.label,
}}
control={
<CheckboxComponent
color="primary"
className={classes.checkbox}
classes={{
root: classes.checkboxRoot,
checked: classes.checked,
}}
onChange={() => handleColChange(index)}
checked={column.display === 'true'}
value={column.name}
/>
}
label={column.label}
/>
)
);
})}
</FormGroup>
</FormControl>
);
};
TableViewCol.propTypes = {
/** Columns used to describe table */
columns: PropTypes.array.isRequired,
/** Options used to describe table */
options: PropTypes.object.isRequired,
/** Callback to trigger View column update */
onColumnUpdate: PropTypes.func,
/** Extend the style applied to components */
classes: PropTypes.object,
};
export default TableViewCol;