summaryrefslogtreecommitdiffstats
path: root/front/odiparpack/app/components/Tables/tableParts/ToggleCell.js
blob: dc0af89e718a02f51601c084fcae3d7affca91b3 (plain)
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
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import css from 'ba-styles/Table.scss';

import { TableCell, FormControlLabel, Switch } from '@material-ui/core';

class ToggleCell extends React.Component {
  state = {
    isChecked: this.props.cellData.value
  };

  handleChange = event => {
    this.setState({ isChecked: event.target.checked });
    this.props.updateRow(event, this.props.branch);
  };

  render() {
    const {
      cellData,
      edited,
    } = this.props;
    return (
      <TableCell className={css.toggleCell} padding="none" textalign="center">
        <div className={classNames(css.coverReadonly, !edited ? css.show : '')} />
        <FormControlLabel
          control={(
            <Switch
              name={cellData.type}
              id={cellData.id.toString()}
              className={css.crudInput}
              checked={this.state.isChecked}
              onChange={this.handleChange}
              value={cellData.value.toString()}
            />
          )}
        />
      </TableCell>
    );
  }
}

ToggleCell.propTypes = {
  cellData: PropTypes.object.isRequired,
  updateRow: PropTypes.func.isRequired,
  edited: PropTypes.bool.isRequired,
  branch: PropTypes.string.isRequired,
};

export default ToggleCell;