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