UNPKG

4.55 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4
5var _extends2 = require('babel-runtime/helpers/extends');
6
7var _extends3 = _interopRequireDefault(_extends2);
8
9var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
10
11var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
12
13var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
14
15var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
16
17var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
18
19var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
20
21var _inherits2 = require('babel-runtime/helpers/inherits');
22
23var _inherits3 = _interopRequireDefault(_inherits2);
24
25var _classnames = require('classnames');
26
27var _classnames2 = _interopRequireDefault(_classnames);
28
29var _react = require('react');
30
31var _react2 = _interopRequireDefault(_react);
32
33var _propTypes = require('prop-types');
34
35var _propTypes2 = _interopRequireDefault(_propTypes);
36
37var _warning = require('warning');
38
39var _warning2 = _interopRequireDefault(_warning);
40
41var _bootstrapUtils = require('./utils/bootstrapUtils');
42
43function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
44
45var propTypes = {
46 inline: _propTypes2.default.bool,
47 disabled: _propTypes2.default.bool,
48 title: _propTypes2.default.string,
49 /**
50 * Only valid if `inline` is not set.
51 */
52 validationState: _propTypes2.default.oneOf(['success', 'warning', 'error', null]),
53 /**
54 * Attaches a ref to the `<input>` element. Only functions can be used here.
55 *
56 * ```js
57 * <Checkbox inputRef={ref => { this.input = ref; }} />
58 * ```
59 */
60 inputRef: _propTypes2.default.func
61}; /* eslint-disable jsx-a11y/label-has-for */
62
63var defaultProps = {
64 inline: false,
65 disabled: false,
66 title: ''
67};
68
69var Checkbox = function (_React$Component) {
70 (0, _inherits3.default)(Checkbox, _React$Component);
71
72 function Checkbox() {
73 (0, _classCallCheck3.default)(this, Checkbox);
74 return (0, _possibleConstructorReturn3.default)(this, _React$Component.apply(this, arguments));
75 }
76
77 Checkbox.prototype.render = function render() {
78 var _props = this.props,
79 inline = _props.inline,
80 disabled = _props.disabled,
81 validationState = _props.validationState,
82 inputRef = _props.inputRef,
83 className = _props.className,
84 style = _props.style,
85 title = _props.title,
86 children = _props.children,
87 props = (0, _objectWithoutProperties3.default)(_props, ['inline', 'disabled', 'validationState', 'inputRef', 'className', 'style', 'title', 'children']);
88
89 var _splitBsProps = (0, _bootstrapUtils.splitBsProps)(props),
90 bsProps = _splitBsProps[0],
91 elementProps = _splitBsProps[1];
92
93 var input = _react2.default.createElement('input', (0, _extends3.default)({}, elementProps, {
94 ref: inputRef,
95 type: 'checkbox',
96 disabled: disabled
97 }));
98
99 if (inline) {
100 var _classes2;
101
102 var _classes = (_classes2 = {}, _classes2[(0, _bootstrapUtils.prefix)(bsProps, 'inline')] = true, _classes2.disabled = disabled, _classes2);
103
104 // Use a warning here instead of in propTypes to get better-looking
105 // generated documentation.
106 process.env.NODE_ENV !== 'production' ? (0, _warning2.default)(!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.') : void 0;
107
108 return _react2.default.createElement(
109 'label',
110 {
111 className: (0, _classnames2.default)(className, _classes),
112 style: style,
113 title: title
114 },
115 input,
116 children
117 );
118 }
119
120 var classes = (0, _extends3.default)({}, (0, _bootstrapUtils.getClassSet)(bsProps), {
121 disabled: disabled
122 });
123 if (validationState) {
124 classes['has-' + validationState] = true;
125 }
126
127 return _react2.default.createElement(
128 'div',
129 { className: (0, _classnames2.default)(className, classes), style: style },
130 _react2.default.createElement(
131 'label',
132 { title: title },
133 input,
134 children
135 )
136 );
137 };
138
139 return Checkbox;
140}(_react2.default.Component);
141
142Checkbox.propTypes = propTypes;
143Checkbox.defaultProps = defaultProps;
144
145exports.default = (0, _bootstrapUtils.bsClass)('checkbox', Checkbox);
146module.exports = exports['default'];
\No newline at end of file