|
1 | 1 | import _ from 'lodash'; |
2 | 2 | import META from 'src/utils/Meta'; |
| 3 | +import getUnhandledProps from 'src/utils/getUnhandledProps'; |
3 | 4 | import React, {Component, PropTypes} from 'react'; |
4 | 5 | import classNames from 'classnames'; |
5 | 6 | import $ from 'jquery'; |
6 | 7 |
|
7 | 8 | export default class Checkbox extends Component { |
8 | 9 | static propTypes = { |
9 | | - beforeChecked: PropTypes.func, |
10 | | - beforeDeterminate: PropTypes.func, |
11 | | - beforeIndeterminate: PropTypes.func, |
12 | | - beforeUnchecked: PropTypes.func, |
13 | | - className: PropTypes.oneOfType([ |
14 | | - PropTypes.string, |
15 | | - PropTypes.array, |
16 | | - PropTypes.object, |
17 | | - ]), |
18 | | - defaultChecked: PropTypes.bool, |
| 10 | + className: PropTypes.string, |
19 | 11 | label: PropTypes.string, |
20 | 12 | name: PropTypes.string, |
21 | | - onChange: PropTypes.func, |
22 | | - onChecked: PropTypes.func, |
23 | | - onDeterminate: PropTypes.func, |
24 | | - onDisable: PropTypes.func, |
25 | | - onEnable: PropTypes.func, |
26 | | - onIndeterminate: PropTypes.func, |
27 | | - onUnchecked: PropTypes.func, |
| 13 | + settings: PropTypes.object, |
28 | 14 | type: PropTypes.string, |
29 | 15 | }; |
30 | 16 |
|
31 | 17 | componentDidMount() { |
32 | | - this.container = $(this.refs.container); |
33 | | - this.input = $(this.refs.input); |
34 | | - |
35 | | - this.container.checkbox({ |
36 | | - onChange: this.props.onChange, |
37 | | - onChecked: this.props.onChecked, |
38 | | - onIndeterminate: this.props.onIndeterminate, |
39 | | - onDeterminate: this.props.onDeterminate, |
40 | | - onUnchecked: this.props.onUnchecked, |
41 | | - beforeChecked: this.props.beforeChecked, |
42 | | - beforeIndeterminate: this.props.beforeIndeterminate, |
43 | | - beforeDeterminate: this.props.beforeDeterminate, |
44 | | - beforeUnchecked: this.props.beforeUnchecked, |
45 | | - onEnable: this.props.onEnable, |
46 | | - onDisable: this.props.onDisable, |
47 | | - }); |
| 18 | + this.element = $(this.refs.element); |
| 19 | + this.element.checkbox(this.props.settings); |
48 | 20 | } |
49 | 21 |
|
50 | 22 | componentWillUnmount() { |
51 | | - this.container.off(); |
| 23 | + this.element.off(); |
52 | 24 | } |
53 | 25 |
|
54 | 26 | static _meta = { |
@@ -77,11 +49,11 @@ export default class Checkbox extends Component { |
77 | 49 | 'checkbox' |
78 | 50 | ); |
79 | 51 |
|
80 | | - const checkboxProps = _.clone(this.props); |
81 | | - delete checkboxProps.className; |
| 52 | + const props = getUnhandledProps(this); |
| 53 | + |
82 | 54 | return ( |
83 | | - <div className={classes} ref='container'> |
84 | | - <input {...checkboxProps} type={type} ref='checkbox' /> |
| 55 | + <div className={classes} ref='element'> |
| 56 | + <input {...props} type={type} /> |
85 | 57 | <label>{this.props.label}</label> |
86 | 58 | </div> |
87 | 59 | ); |
|
0 commit comments