forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckbox.js
More file actions
99 lines (86 loc) · 2.15 KB
/
Checkbox.js
File metadata and controls
99 lines (86 loc) · 2.15 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import classNames from 'classnames';
import React from 'react';
import warning from 'warning';
import { bsClass, getClassSet, prefix, splitBsProps }
from './utils/bootstrapUtils';
const propTypes = {
inline: React.PropTypes.bool,
disabled: React.PropTypes.bool,
/**
* Only valid if `inline` is not set.
*/
validationState: React.PropTypes.oneOf(['success', 'warning', 'error']),
/**
* Attaches a ref to the `<input>` element. Only functions can be used here.
*
* ```js
* <Checkbox inputRef={ref => { this.input = ref; }} />
* ```
*/
inputRef: React.PropTypes.func,
};
const defaultProps = {
inline: false,
disabled: false,
};
class Checkbox extends React.Component {
render() {
const {
inline,
disabled,
validationState,
inputRef,
className,
style,
children,
...props
} = this.props;
const [bsProps, elementProps] = splitBsProps(props);
const input = (
<input
{...elementProps}
ref={inputRef}
type="checkbox"
disabled={disabled}
/>
);
if (inline) {
const classes = {
[prefix(bsProps, 'inline')]: true,
disabled,
};
// Use a warning here instead of in propTypes to get better-looking
// generated documentation.
warning(
!validationState,
'`validationState` is ignored on `<Checkbox inline>`. To display ' +
'validation state on an inline checkbox, set `validationState` on a ' +
'parent `<FormGroup>` or other element instead.'
);
return (
<label className={classNames(className, classes)} style={style}>
{input}
{children}
</label>
);
}
const classes = {
...getClassSet(bsProps),
disabled,
};
if (validationState) {
classes[`has-${validationState}`] = true;
}
return (
<div className={classNames(className, classes)} style={style}>
<label>
{input}
{children}
</label>
</div>
);
}
}
Checkbox.propTypes = propTypes;
Checkbox.defaultProps = defaultProps;
export default bsClass('checkbox', Checkbox);