1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | var _excluded = ["as", "bsPrefix", "column", "srOnly", "className", "htmlFor"];
|
4 | import classNames from 'classnames';
|
5 | import React, { useContext } from 'react';
|
6 | import warning from 'warning';
|
7 | import Col from './Col';
|
8 | import FormContext from './FormContext';
|
9 | import { useBootstrapPrefix } from './ThemeProvider';
|
10 | var defaultProps = {
|
11 | column: false,
|
12 | srOnly: false
|
13 | };
|
14 | var FormLabel = React.forwardRef(function (_ref, ref) {
|
15 | var _ref$as = _ref.as,
|
16 | Component = _ref$as === void 0 ? 'label' : _ref$as,
|
17 | bsPrefix = _ref.bsPrefix,
|
18 | column = _ref.column,
|
19 | srOnly = _ref.srOnly,
|
20 | className = _ref.className,
|
21 | htmlFor = _ref.htmlFor,
|
22 | props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
23 |
|
24 | var _useContext = useContext(FormContext),
|
25 | controlId = _useContext.controlId;
|
26 |
|
27 | bsPrefix = useBootstrapPrefix(bsPrefix, 'form-label');
|
28 | var columnClass = 'col-form-label';
|
29 | if (typeof column === 'string') columnClass = columnClass + " " + columnClass + "-" + column;
|
30 | var classes = classNames(className, bsPrefix, srOnly && 'sr-only', column && columnClass);
|
31 | process.env.NODE_ENV !== "production" ? warning(controlId == null || !htmlFor, '`controlId` is ignored on `<FormLabel>` when `htmlFor` is specified.') : void 0;
|
32 | htmlFor = htmlFor || controlId;
|
33 | if (column) return React.createElement(Col, _extends({
|
34 | ref: ref,
|
35 | as: "label",
|
36 | className: classes,
|
37 | htmlFor: htmlFor
|
38 | }, props));
|
39 | return (
|
40 |
|
41 |
|
42 | React.createElement(Component, _extends({
|
43 | ref: ref,
|
44 | className: classes,
|
45 | htmlFor: htmlFor
|
46 | }, props))
|
47 | );
|
48 | });
|
49 | FormLabel.displayName = 'FormLabel';
|
50 | FormLabel.defaultProps = defaultProps;
|
51 | export default FormLabel; |
\ | No newline at end of file |