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