king
2022-03-03 3fc643dea8f8c957a95a86d250b5d8b06fb740e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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