import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Checkbox } from 'antd'
|
|
class MKCheckbox extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
onChange: PropTypes.func
|
}
|
|
state = {
|
defaultValue: this.props.config.initval ? this.props.config.initval.split(',').filter(Boolean) : []
|
}
|
|
onChange = (values) => {
|
this.props.onChange(values.join(','))
|
}
|
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
render() {
|
const { config } = this.props
|
const { defaultValue } = this.state
|
|
return (
|
<Checkbox.Group defaultValue={defaultValue} disabled={config.readonly} onChange={this.onChange}>
|
{config.options.map(option => <Checkbox key={option.key} title={option.label} disabled={option.$disabled} value={option.value}>{option.label}</Checkbox>)}
|
</Checkbox.Group>
|
)
|
}
|
}
|
|
export default MKCheckbox
|