UNPKG

2.7 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 { bsClass, bsSizes, getClassSet, splitBsPropsAndOmit } from './utils/bootstrapUtils';
8import { Size } from './utils/StyleConfig';
9import ValidComponentChildren from './utils/ValidComponentChildren';
10var propTypes = {
11 /**
12 * Sets `id` on `<FormControl>` and `htmlFor` on `<FormGroup.Label>`.
13 */
14 controlId: PropTypes.string,
15 validationState: PropTypes.oneOf(['success', 'warning', 'error', null])
16};
17var childContextTypes = {
18 $bs_formGroup: PropTypes.object.isRequired
19};
20
21var FormGroup =
22/*#__PURE__*/
23function (_React$Component) {
24 _inheritsLoose(FormGroup, _React$Component);
25
26 function FormGroup() {
27 return _React$Component.apply(this, arguments) || this;
28 }
29
30 var _proto = FormGroup.prototype;
31
32 _proto.getChildContext = function getChildContext() {
33 var _this$props = this.props,
34 controlId = _this$props.controlId,
35 validationState = _this$props.validationState;
36 return {
37 $bs_formGroup: {
38 controlId: controlId,
39 validationState: validationState
40 }
41 };
42 };
43
44 _proto.hasFeedback = function hasFeedback(children) {
45 var _this = this;
46
47 return ValidComponentChildren.some(children, function (child) {
48 return child.props.bsRole === 'feedback' || child.props.children && _this.hasFeedback(child.props.children);
49 });
50 };
51
52 _proto.render = function render() {
53 var _this$props2 = this.props,
54 validationState = _this$props2.validationState,
55 className = _this$props2.className,
56 children = _this$props2.children,
57 props = _objectWithoutPropertiesLoose(_this$props2, ["validationState", "className", "children"]);
58
59 var _splitBsPropsAndOmit = splitBsPropsAndOmit(props, ['controlId']),
60 bsProps = _splitBsPropsAndOmit[0],
61 elementProps = _splitBsPropsAndOmit[1];
62
63 var classes = _extends({}, getClassSet(bsProps), {
64 'has-feedback': this.hasFeedback(children)
65 });
66
67 if (validationState) {
68 classes["has-" + validationState] = true;
69 }
70
71 return React.createElement("div", _extends({}, elementProps, {
72 className: classNames(className, classes)
73 }), children);
74 };
75
76 return FormGroup;
77}(React.Component);
78
79FormGroup.propTypes = propTypes;
80FormGroup.childContextTypes = childContextTypes;
81export default bsClass('form-group', bsSizes([Size.LARGE, Size.SMALL], FormGroup));
\No newline at end of file