@talend/react-bootstrap
Version:
Bootstrap 3 components built with React
47 lines • 1.42 kB
JavaScript
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import warning from 'warning';
import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
import { jsx as _jsx } from "react/jsx-runtime";
const propTypes = {
/**
* Uses `controlId` from `<FormGroup>` if not explicitly specified.
*/
htmlFor: PropTypes.string,
srOnly: PropTypes.bool
};
const defaultProps = {
srOnly: false
};
const contextTypes = {
$bs_formGroup: PropTypes.object
};
class ControlLabel extends React.Component {
render() {
const formGroup = this.context.$bs_formGroup;
const controlId = formGroup && formGroup.controlId;
const {
htmlFor = controlId,
srOnly,
className,
...props
} = this.props;
const [bsProps, elementProps] = splitBsProps(props);
warning(controlId == null || htmlFor === controlId, '`controlId` is ignored on `<ControlLabel>` when `htmlFor` is specified.');
const classes = {
...getClassSet(bsProps),
'sr-only': srOnly
};
return /*#__PURE__*/_jsx("label", {
...elementProps,
htmlFor: htmlFor,
className: classNames(className, classes)
});
}
}
ControlLabel.propTypes = propTypes;
ControlLabel.defaultProps = defaultProps;
ControlLabel.contextTypes = contextTypes;
export default bsClass('control-label', ControlLabel);
//# sourceMappingURL=ControlLabel.js.map