1 | 'use strict';
|
2 |
|
3 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
4 |
|
5 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
6 |
|
7 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
8 |
|
9 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
10 |
|
11 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
12 |
|
13 | var React = require('react');
|
14 | var ReactTooltip = require('react-tooltip');
|
15 | var PropTypes = require('prop-types');
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | var FormInput = function (_React$PureComponent) {
|
22 | _inherits(FormInput, _React$PureComponent);
|
23 |
|
24 | function FormInput() {
|
25 | _classCallCheck(this, FormInput);
|
26 |
|
27 | return _possibleConstructorReturn(this, (FormInput.__proto__ || Object.getPrototypeOf(FormInput)).apply(this, arguments));
|
28 | }
|
29 |
|
30 | _createClass(FormInput, [{
|
31 | key: 'getClassName',
|
32 |
|
33 |
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | value: function getClassName() {
|
40 | var className = 'form-item';
|
41 | if (this.props.error) {
|
42 | return className + ' form-item-has-error';
|
43 | }
|
44 | return className;
|
45 | }
|
46 |
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | }, {
|
54 | key: 'getErrorId',
|
55 | value: function getErrorId() {
|
56 | return 'form-error-tooltip-' + this.props.name;
|
57 | }
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | }, {
|
66 | key: 'renderInfoSprinkle',
|
67 | value: function renderInfoSprinkle() {
|
68 | if (this.props.linkHandler) {
|
69 | return React.createElement('i', { className: 'help', onClick: this.props.linkHandler });
|
70 | }
|
71 | }
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | }, {
|
80 | key: 'renderError',
|
81 | value: function renderError() {
|
82 | if (this.props.error) {
|
83 | return React.createElement('i', { className: 'fa fa-exclamation-circle', 'aria-hidden': 'true' });
|
84 | }
|
85 | }
|
86 |
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | }, {
|
94 | key: 'renderErrorTooltip',
|
95 | value: function renderErrorTooltip() {
|
96 | if (this.props.error) {
|
97 | return React.createElement(ReactTooltip, { id: this.getErrorId() });
|
98 | }
|
99 | }
|
100 |
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | }, {
|
108 | key: 'render',
|
109 | value: function render() {
|
110 | var tooltipOptions = this.props.error ? {
|
111 | 'data-for': this.getErrorId(),
|
112 | 'data-effect': 'solid',
|
113 | 'data-place': 'bottom',
|
114 | 'data-offset': "{'bottom': -2}",
|
115 | 'data-tip': this.props.error,
|
116 | 'data-type': 'error'
|
117 | } : {};
|
118 | return React.createElement(
|
119 | 'div',
|
120 | { className: this.getClassName() },
|
121 | React.createElement(
|
122 | 'label',
|
123 | null,
|
124 | React.createElement(
|
125 | 'span',
|
126 | { className: 'form-item-label' },
|
127 | this.renderError(),
|
128 | this.props.label
|
129 | ),
|
130 | this.renderInfoSprinkle()
|
131 | ),
|
132 | React.createElement('input', _extends({
|
133 | name: this.props.name,
|
134 | placeholder: this.props.placeholder,
|
135 | onChange: this.props.changeHandler,
|
136 | onBlur: this.props.blurHandler,
|
137 | value: this.props.value,
|
138 | className: 'form-control',
|
139 | type: this.props.type || 'text'
|
140 | }, tooltipOptions)),
|
141 | this.renderErrorTooltip()
|
142 | );
|
143 | }
|
144 | }]);
|
145 |
|
146 | return FormInput;
|
147 | }(React.PureComponent);
|
148 |
|
149 | FormInput.propTypes = {
|
150 | label: PropTypes.string.isRequired,
|
151 | name: PropTypes.string.isRequired,
|
152 | changeHandler: PropTypes.func.isRequired,
|
153 | blurHandler: PropTypes.func,
|
154 | linkHandler: PropTypes.func,
|
155 | placeholder: PropTypes.string,
|
156 | value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
157 | type: PropTypes.string,
|
158 | error: PropTypes.string
|
159 | };
|
160 |
|
161 | FormInput.displayName = 'FormInput';
|
162 |
|
163 | module.exports = FormInput; |
\ | No newline at end of file |