king
2022-06-02 6ae85d25c2e5773a07fdaf3ad477fbdbb61c9165
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Checkbox } from 'antd'
 
class MKCheckbox extends Component {
  static propTpyes = {
    config: PropTypes.object,
    onChange: PropTypes.func
  }
 
  state = {
    value: this.props.config.initval,
    config: fromJS(this.props.config).toJS(),
    options: fromJS(this.props.config.options).toJS(),
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  onChange = (value) => {
    this.setState({value})
    this.props.onChange(value)
  }
 
  render() {
    const { value, options } = this.state
 
    return (
      <Checkbox.Group style={{whiteSpace: 'nowrap'}} defaultValue={value} onChange={this.onChange}>
        {options.map(option => <Checkbox key={option.value} title={option.label} disabled={option.disabled} value={option.value}>{option.label}</Checkbox>)}
      </Checkbox.Group>
    )
  }
}
 
export default MKCheckbox