import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Switch } from 'antd'
|
|
class MKSwitch extends Component {
|
static propTpyes = {
|
config: PropTypes.object,
|
onChange: PropTypes.func
|
}
|
|
state = {
|
defaultChecked: this.props.config.initval === this.props.config.openVal
|
}
|
|
onChange = (val) => {
|
const { config } = this.props
|
|
if (val) {
|
this.props.onChange(config.openVal)
|
} else {
|
this.props.onChange(config.closeVal)
|
}
|
}
|
|
componentWillUnmount () {
|
this.setState = () => {
|
return
|
}
|
}
|
|
render() {
|
const { config } = this.props
|
const { defaultChecked } = this.state
|
|
return (
|
<Switch checkedChildren={config.openText || ''} disabled={config.readonly} unCheckedChildren={config.closeText || ''} defaultChecked={defaultChecked} onChange={this.onChange}/>
|
)
|
}
|
}
|
|
export default MKSwitch
|