1 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
2 | import _extends from 'babel-runtime/helpers/extends';
|
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 Glyphicon from './Glyphicon';
|
11 | import { bsClass, getClassSet, splitBsProps } from './utils/bootstrapUtils';
|
12 |
|
13 | var defaultProps = {
|
14 | bsRole: 'feedback'
|
15 | };
|
16 |
|
17 | var contextTypes = {
|
18 | $bs_formGroup: PropTypes.object
|
19 | };
|
20 |
|
21 | var FormControlFeedback = function (_React$Component) {
|
22 | _inherits(FormControlFeedback, _React$Component);
|
23 |
|
24 | function FormControlFeedback() {
|
25 | _classCallCheck(this, FormControlFeedback);
|
26 |
|
27 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
28 | }
|
29 |
|
30 | FormControlFeedback.prototype.getGlyph = function getGlyph(validationState) {
|
31 | switch (validationState) {
|
32 | case 'success':
|
33 | return 'ok';
|
34 | case 'warning':
|
35 | return 'warning-sign';
|
36 | case 'error':
|
37 | return 'remove';
|
38 | default:
|
39 | return null;
|
40 | }
|
41 | };
|
42 |
|
43 | FormControlFeedback.prototype.renderDefaultFeedback = function renderDefaultFeedback(formGroup, className, classes, elementProps) {
|
44 | var glyph = this.getGlyph(formGroup && formGroup.validationState);
|
45 | if (!glyph) {
|
46 | return null;
|
47 | }
|
48 |
|
49 | return React.createElement(Glyphicon, _extends({}, elementProps, {
|
50 | glyph: glyph,
|
51 | className: classNames(className, classes)
|
52 | }));
|
53 | };
|
54 |
|
55 | FormControlFeedback.prototype.render = function render() {
|
56 | var _props = this.props,
|
57 | className = _props.className,
|
58 | children = _props.children,
|
59 | props = _objectWithoutProperties(_props, ['className', 'children']);
|
60 |
|
61 | var _splitBsProps = splitBsProps(props),
|
62 | bsProps = _splitBsProps[0],
|
63 | elementProps = _splitBsProps[1];
|
64 |
|
65 | var classes = getClassSet(bsProps);
|
66 |
|
67 | if (!children) {
|
68 | return this.renderDefaultFeedback(this.context.$bs_formGroup, className, classes, elementProps);
|
69 | }
|
70 |
|
71 | var child = React.Children.only(children);
|
72 | return React.cloneElement(child, _extends({}, elementProps, {
|
73 | className: classNames(child.props.className, className, classes)
|
74 | }));
|
75 | };
|
76 |
|
77 | return FormControlFeedback;
|
78 | }(React.Component);
|
79 |
|
80 | FormControlFeedback.defaultProps = defaultProps;
|
81 | FormControlFeedback.contextTypes = contextTypes;
|
82 |
|
83 | export default bsClass('form-control-feedback', FormControlFeedback); |
\ | No newline at end of file |