UNPKG

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