Newer
Older
import React from 'react'
import { withStyles } from '@material-ui/core/styles'
import { Draggable } from 'react-beautiful-dnd'
import DragHandleIcon from '@material-ui/icons/DragHandle'
import CheckboxField from '@src/js/components/common/form/CheckboxField.jsx'
piotr.kupczyk@id.ethz.ch
committed
import logger from '@src/js/common/logger.js'
row: {
display: 'flex',
piotr.kupczyk@id.ethz.ch
committed
padding: `${theme.spacing(1) / 2}px 0px`,
'&:first-child': {
paddingTop: 0
},
'&:last-child': {
paddingBottom: 0
}
},
label: {
marginLeft: 0
},
drag: {
display: 'flex',
cursor: 'grab'
}
})
piotr.kupczyk@id.ethz.ch
committed
class GridColumnsConfigRow extends React.PureComponent {
constructor(props) {
super(props)
this.handleVisibleChange = this.handleVisibleChange.bind(this)
}
handleVisibleChange() {
piotr.kupczyk@id.ethz.ch
committed
this.props.onVisibleChange({
[this.props.column.name]: !this.props.visible
})
}
render() {
piotr.kupczyk@id.ethz.ch
committed
logger.log(logger.DEBUG, 'GridConfigRow.render')
const { classes, column, visible, index } = this.props
return (
piotr.kupczyk@id.ethz.ch
committed
<Draggable draggableId={column.name} index={index}>
{provided => (
<div
ref={provided.innerRef}
{...provided.draggableProps}
className={classes.row}
>
<div {...provided.dragHandleProps} className={classes.drag}>
<DragHandleIcon fontSize='small' />
</div>
piotr.kupczyk@id.ethz.ch
committed
label={column.label || column.name}
value={visible}
disabled={!column.configurable}
onChange={this.handleVisibleChange}
/>
</div>
)}
</Draggable>
)
}
}
piotr.kupczyk@id.ethz.ch
committed
export default withStyles(styles)(GridColumnsConfigRow)