UNPKG

2.22 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";
4import classNames from 'classnames';
5import React from 'react';
6import PropTypes from 'prop-types';
7import warning from 'warning';
8import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
9var propTypes = {
10 /**
11 * Uses `controlId` from `<FormGroup>` if not explicitly specified.
12 */
13 htmlFor: PropTypes.string,
14 srOnly: PropTypes.bool
15};
16var defaultProps = {
17 srOnly: false
18};
19var contextTypes = {
20 $bs_formGroup: PropTypes.object
21};
22
23var ControlLabel =
24/*#__PURE__*/
25function (_React$Component) {
26 _inheritsLoose(ControlLabel, _React$Component);
27
28 function ControlLabel() {
29 return _React$Component.apply(this, arguments) || this;
30 }
31
32 var _proto = ControlLabel.prototype;
33
34 _proto.render = function render() {
35 var formGroup = this.context.$bs_formGroup;
36 var controlId = formGroup && formGroup.controlId;
37
38 var _this$props = this.props,
39 _this$props$htmlFor = _this$props.htmlFor,
40 htmlFor = _this$props$htmlFor === void 0 ? controlId : _this$props$htmlFor,
41 srOnly = _this$props.srOnly,
42 className = _this$props.className,
43 props = _objectWithoutPropertiesLoose(_this$props, ["htmlFor", "srOnly", "className"]);
44
45 var _splitBsProps = splitBsProps(props),
46 bsProps = _splitBsProps[0],
47 elementProps = _splitBsProps[1];
48
49 process.env.NODE_ENV !== "production" ? warning(controlId == null || htmlFor === controlId, '`controlId` is ignored on `<ControlLabel>` when `htmlFor` is specified.') : void 0;
50
51 var classes = _extends({}, getClassSet(bsProps), {
52 'sr-only': srOnly
53 });
54
55 return React.createElement("label", _extends({}, elementProps, {
56 htmlFor: htmlFor,
57 className: classNames(className, classes)
58 }));
59 };
60
61 return ControlLabel;
62}(React.Component);
63
64ControlLabel.propTypes = propTypes;
65ControlLabel.defaultProps = defaultProps;
66ControlLabel.contextTypes = contextTypes;
67export default bsClass('control-label', ControlLabel);
\No newline at end of file