UNPKG

2.81 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
24var propTypes = {
25 /**
26 * Uses `controlId` from `<FormGroup>` if not explicitly specified.
27 */
28 htmlFor: _propTypes.default.string,
29 srOnly: _propTypes.default.bool
30};
31var defaultProps = {
32 srOnly: false
33};
34var contextTypes = {
35 $bs_formGroup: _propTypes.default.object
36};
37
38var ControlLabel =
39/*#__PURE__*/
40function (_React$Component) {
41 (0, _inheritsLoose2.default)(ControlLabel, _React$Component);
42
43 function ControlLabel() {
44 return _React$Component.apply(this, arguments) || this;
45 }
46
47 var _proto = ControlLabel.prototype;
48
49 _proto.render = function render() {
50 var formGroup = this.context.$bs_formGroup;
51 var controlId = formGroup && formGroup.controlId;
52 var _this$props = this.props,
53 _this$props$htmlFor = _this$props.htmlFor,
54 htmlFor = _this$props$htmlFor === void 0 ? controlId : _this$props$htmlFor,
55 srOnly = _this$props.srOnly,
56 className = _this$props.className,
57 props = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["htmlFor", "srOnly", "className"]);
58
59 var _splitBsProps = (0, _bootstrapUtils.splitBsProps)(props),
60 bsProps = _splitBsProps[0],
61 elementProps = _splitBsProps[1];
62
63 process.env.NODE_ENV !== "production" ? (0, _warning.default)(controlId == null || htmlFor === controlId, '`controlId` is ignored on `<ControlLabel>` when `htmlFor` is specified.') : void 0;
64 var classes = (0, _extends2.default)({}, (0, _bootstrapUtils.getClassSet)(bsProps), {
65 'sr-only': srOnly
66 });
67 return _react.default.createElement("label", (0, _extends2.default)({}, elementProps, {
68 htmlFor: htmlFor,
69 className: (0, _classnames.default)(className, classes)
70 }));
71 };
72
73 return ControlLabel;
74}(_react.default.Component);
75
76ControlLabel.propTypes = propTypes;
77ControlLabel.defaultProps = defaultProps;
78ControlLabel.contextTypes = contextTypes;
79
80var _default = (0, _bootstrapUtils.bsClass)('control-label', ControlLabel);
81
82exports.default = _default;
83module.exports = exports["default"];
\No newline at end of file