import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Checkbox } from 'antd'
|
|
class MKCheckbox extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
onChange: PropTypes.func
|
}
|
|
state = {
|
value: this.props.config.initval,
|
config: fromJS(this.props.config).toJS(),
|
options: fromJS(this.props.config.options).toJS(),
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
onChange = (value) => {
|
this.setState({value})
|
this.props.onChange(value)
|
}
|
|
render() {
|
const { value, options } = this.state
|
|
return (
|
<Checkbox.Group style={{whiteSpace: 'nowrap'}} defaultValue={value} onChange={this.onChange}>
|
{options.map(option => <Checkbox key={option.value} title={option.label} disabled={option.disabled} value={option.value}>{option.label}</Checkbox>)}
|
</Checkbox.Group>
|
)
|
}
|
}
|
|
export default MKCheckbox
|