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,
|
value: PropTypes.any,
|
onChange: PropTypes.func
|
}
|
state = {
|
status: true,
|
}
|
|
UNSAFE_componentWillMount () {
|
const { defaultValue, value } = this.props
|
let initVal = 'true'
|
|
if (this.props['data-__meta']) {
|
initVal = this.props['data-__meta'].initialValue
|
} else if (defaultValue) {
|
initVal = defaultValue
|
} else if (value) {
|
initVal = value
|
}
|
|
if (initVal === 'false') {
|
initVal = false
|
} else {
|
initVal = true
|
}
|
|
this.setState({status: initVal})
|
}
|
|
changeStatus = (val) => {
|
this.setState({ status: val }, () => {
|
let _val = val ? 'true' : 'false'
|
this.props.onChange && this.props.onChange(_val)
|
})
|
}
|
|
render() {
|
const { status } = this.state
|
return (
|
<Switch checkedChildren="是" unCheckedChildren="否" checked={status} onChange={this.changeStatus} />
|
)
|
}
|
}
|
|
export default ColorSketch
|