UNPKG

3.33 kBJavaScriptView Raw
1import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
3import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
4
5/* eslint-disable jsx-a11y/label-has-for */
6import classNames from 'classnames';
7import React from 'react';
8import PropTypes from 'prop-types';
9import warning from 'warning';
10import { bsClass, getClassSet, prefix, splitBsProps } from './utils/bootstrapUtils';
11var propTypes = {
12 inline: PropTypes.bool,
13 disabled: PropTypes.bool,
14 title: PropTypes.string,
15
16 /**
17 * Only valid if `inline` is not set.
18 */
19 validationState: PropTypes.oneOf(['success', 'warning', 'error', null]),
20
21 /**
22 * Attaches a ref to the `<input>` element. Only functions can be used here.
23 *
24 * ```js
25 * <Checkbox inputRef={ref => { this.input = ref; }} />
26 * ```
27 */
28 inputRef: PropTypes.func
29};
30var defaultProps = {
31 inline: false,
32 disabled: false,
33 title: ''
34};
35
36var Checkbox =
37/*#__PURE__*/
38function (_React$Component) {
39 _inheritsLoose(Checkbox, _React$Component);
40
41 function Checkbox() {
42 return _React$Component.apply(this, arguments) || this;
43 }
44
45 var _proto = Checkbox.prototype;
46
47 _proto.render = function render() {
48 var _this$props = this.props,
49 inline = _this$props.inline,
50 disabled = _this$props.disabled,
51 validationState = _this$props.validationState,
52 inputRef = _this$props.inputRef,
53 className = _this$props.className,
54 style = _this$props.style,
55 title = _this$props.title,
56 children = _this$props.children,
57 props = _objectWithoutPropertiesLoose(_this$props, ["inline", "disabled", "validationState", "inputRef", "className", "style", "title", "children"]);
58
59 var _splitBsProps = splitBsProps(props),
60 bsProps = _splitBsProps[0],
61 elementProps = _splitBsProps[1];
62
63 var input = React.createElement("input", _extends({}, elementProps, {
64 ref: inputRef,
65 type: "checkbox",
66 disabled: disabled
67 }));
68
69 if (inline) {
70 var _classes2;
71
72 var _classes = (_classes2 = {}, _classes2[prefix(bsProps, 'inline')] = true, _classes2.disabled = disabled, _classes2); // Use a warning here instead of in propTypes to get better-looking
73 // generated documentation.
74
75
76 process.env.NODE_ENV !== "production" ? 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.') : void 0;
77 return React.createElement("label", {
78 className: classNames(className, _classes),
79 style: style,
80 title: title
81 }, input, children);
82 }
83
84 var classes = _extends({}, getClassSet(bsProps), {
85 disabled: disabled
86 });
87
88 if (validationState) {
89 classes["has-" + validationState] = true;
90 }
91
92 return React.createElement("div", {
93 className: classNames(className, classes),
94 style: style
95 }, React.createElement("label", {
96 title: title
97 }, input, children));
98 };
99
100 return Checkbox;
101}(React.Component);
102
103Checkbox.propTypes = propTypes;
104Checkbox.defaultProps = defaultProps;
105export default bsClass('checkbox', Checkbox);
\No newline at end of file