1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 | import classNames from 'classnames';
|
7 | import React from 'react';
|
8 | import PropTypes from 'prop-types';
|
9 |
|
10 | import { bsClass, bsSizes, getClassSet, splitBsPropsAndOmit } from './utils/bootstrapUtils';
|
11 | import { Size } from './utils/StyleConfig';
|
12 | import ValidComponentChildren from './utils/ValidComponentChildren';
|
13 |
|
14 | var propTypes = {
|
15 | |
16 |
|
17 |
|
18 | controlId: PropTypes.string,
|
19 | validationState: PropTypes.oneOf(['success', 'warning', 'error', null])
|
20 | };
|
21 |
|
22 | var childContextTypes = {
|
23 | $bs_formGroup: PropTypes.object.isRequired
|
24 | };
|
25 |
|
26 | var FormGroup = function (_React$Component) {
|
27 | _inherits(FormGroup, _React$Component);
|
28 |
|
29 | function FormGroup() {
|
30 | _classCallCheck(this, FormGroup);
|
31 |
|
32 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
33 | }
|
34 |
|
35 | FormGroup.prototype.getChildContext = function getChildContext() {
|
36 | var _props = this.props,
|
37 | controlId = _props.controlId,
|
38 | validationState = _props.validationState;
|
39 |
|
40 |
|
41 | return {
|
42 | $bs_formGroup: {
|
43 | controlId: controlId,
|
44 | validationState: validationState
|
45 | }
|
46 | };
|
47 | };
|
48 |
|
49 | FormGroup.prototype.hasFeedback = function hasFeedback(children) {
|
50 | var _this2 = this;
|
51 |
|
52 | return ValidComponentChildren.some(children, function (child) {
|
53 | return child.props.bsRole === 'feedback' || child.props.children && _this2.hasFeedback(child.props.children);
|
54 | });
|
55 | };
|
56 |
|
57 | FormGroup.prototype.render = function render() {
|
58 | var _props2 = this.props,
|
59 | validationState = _props2.validationState,
|
60 | className = _props2.className,
|
61 | children = _props2.children,
|
62 | props = _objectWithoutProperties(_props2, ['validationState', 'className', 'children']);
|
63 |
|
64 | var _splitBsPropsAndOmit = splitBsPropsAndOmit(props, ['controlId']),
|
65 | bsProps = _splitBsPropsAndOmit[0],
|
66 | elementProps = _splitBsPropsAndOmit[1];
|
67 |
|
68 | var classes = _extends({}, getClassSet(bsProps), {
|
69 | 'has-feedback': this.hasFeedback(children)
|
70 | });
|
71 | if (validationState) {
|
72 | classes['has-' + validationState] = true;
|
73 | }
|
74 |
|
75 | return React.createElement(
|
76 | 'div',
|
77 | _extends({}, elementProps, { className: classNames(className, classes) }),
|
78 | children
|
79 | );
|
80 | };
|
81 |
|
82 | return FormGroup;
|
83 | }(React.Component);
|
84 |
|
85 | FormGroup.propTypes = propTypes;
|
86 | FormGroup.childContextTypes = childContextTypes;
|
87 |
|
88 | export default bsClass('form-group', bsSizes([Size.LARGE, Size.SMALL], FormGroup)); |
\ | No newline at end of file |