UNPKG

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