Skip to content

Commit b72f62d

Browse files
committed
update checkbox to expose element/plugin
1 parent 85deadb commit b72f62d

2 files changed

Lines changed: 11 additions & 39 deletions

File tree

src/modules/Checkbox/Checkbox.js

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,26 @@
11
import _ from 'lodash';
22
import META from 'src/utils/Meta';
3+
import getUnhandledProps from 'src/utils/getUnhandledProps';
34
import React, {Component, PropTypes} from 'react';
45
import classNames from 'classnames';
56
import $ from 'jquery';
67

78
export default class Checkbox extends Component {
89
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,
1911
label: PropTypes.string,
2012
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,
2814
type: PropTypes.string,
2915
};
3016

3117
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);
4820
}
4921

5022
componentWillUnmount() {
51-
this.container.off();
23+
this.element.off();
5224
}
5325

5426
static _meta = {
@@ -77,11 +49,11 @@ export default class Checkbox extends Component {
7749
'checkbox'
7850
);
7951

80-
const checkboxProps = _.clone(this.props);
81-
delete checkboxProps.className;
52+
const props = getUnhandledProps(this);
53+
8254
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} />
8557
<label>{this.props.label}</label>
8658
</div>
8759
);

test/specs/modules/Checkbox/Checkbox-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Checkbox', () => {
1010
it('should have a semantic ui plugin to handle the check action', () => {
1111
render(<Checkbox name='firstName' label='Include First' />)
1212
.first()
13-
.container.checkbox.called.should.equal(true);
13+
.element.checkbox.called.should.equal(true);
1414
});
1515
it('should have a fitted class if no label is given', () => {
1616
render(<Checkbox name='firstName' />).findClass('fitted');

0 commit comments

Comments
 (0)