forked from yuristrelets/react-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckbox.js
More file actions
80 lines (71 loc) · 2.23 KB
/
Checkbox.js
File metadata and controls
80 lines (71 loc) · 2.23 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React, { Component, PropTypes } from 'react';
import classnames from 'classnames';
import { themr } from 'react-css-themr';
import { CHECKBOX } from '../identifiers.js';
import rippleFactory from '../ripple/Ripple.js';
import checkFactory from './Check.js';
const factory = (Check) => {
class Checkbox extends Component {
static propTypes = {
checked: PropTypes.bool,
className: PropTypes.string,
disabled: PropTypes.bool,
label: PropTypes.any,
onChange: PropTypes.func,
theme: PropTypes.shape({
disabled: PropTypes.string.isRequired,
field: PropTypes.string.isRequired,
input: PropTypes.string.isRequired,
ripple: PropTypes.string.isRequired
})
};
static defaultProps = {
checked: false,
className: '',
disabled: false
};
handleToggle = (event) => {
if (event.pageX !== 0 && event.pageY !== 0) this.blur();
if (!this.props.disabled && this.props.onChange) {
this.props.onChange(!this.props.checked, event);
}
};
blur () {
this.refs.input.blur();
}
focus () {
this.refs.input.focus();
}
render () {
const { onChange, theme, ...others } = this.props; //eslint-disable-line no-unused-vars
const className = classnames(theme.field, {
[theme.disabled]: this.props.disabled
}, this.props.className);
return (
<label data-react-toolbox='checkbox' className={className}>
<input
{...others}
className={theme.input}
onClick={this.handleToggle}
readOnly
ref='input'
type='checkbox'
/>
<Check
checked={this.props.checked}
disabled={this.props.disabled}
rippleClassName={theme.ripple}
theme={this.props.theme}
/>
{this.props.label ? <span data-react-toolbox='label' className={theme.text}>{this.props.label}</span> : null}
</label>
);
}
}
return Checkbox;
};
const Check = checkFactory(rippleFactory({ centered: true, spread: 2.6}));
const Checkbox = factory(Check);
export default themr(CHECKBOX)(Checkbox);
export { factory as checkboxFactory };
export { Checkbox };