import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
// import { is, fromJS } from 'immutable'
|
import { Switch } from 'antd'
|
|
import './index.scss'
|
|
class ColorSketch extends Component {
|
static propTpyes = {
|
defaultValue: PropTypes.any,
|
autoFocus: PropTypes.any,
|
config: PropTypes.object,
|
onChange: PropTypes.func
|
}
|
state = {
|
status: false
|
}
|
|
UNSAFE_componentWillMount () {
|
const { defaultValue, config } = this.props
|
|
let status = false
|
|
if (defaultValue === config.openVal) {
|
status = true
|
}
|
|
this.setState({status})
|
}
|
|
changeStatus = (val) => {
|
const { config } = this.props
|
this.setState({ status: val }, () => {
|
let _val = val ? config.openVal : config.closeVal
|
this.props.onChange(_val)
|
})
|
}
|
|
render() {
|
const { config, autoFocus } = this.props
|
const { status } = this.state
|
return (
|
<Switch checkedChildren={config.openText} autoFocus={autoFocus} onBlur={this.props.onBlur} unCheckedChildren={config.closeText} checked={status} onChange={this.changeStatus} />
|
)
|
}
|
}
|
|
export default ColorSketch
|