king
2022-04-26 5046d0d13dc6a8563b8e54e31913bc44cfa1072f
src/tabviews/custom/components/table/edit-table/normalTable/cusSwitch/index.jsx
New file
@@ -0,0 +1,49 @@
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
      let _text = val ? config.openText : config.closeText
      this.props.onChange(_val, _text)
    })
  }
  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