UNPKG

10.5 kBJavaScriptView Raw
1import "core-js/modules/es6.function.name";
2import _extends from "@babel/runtime/helpers/extends";
3import "core-js/modules/es6.object.assign";
4import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5import _createClass from "@babel/runtime/helpers/createClass";
6import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8import _inherits from "@babel/runtime/helpers/inherits";
9import React, { Component } from 'react';
10import omit from 'lodash/omit';
11import ToolTip from '@beisen-platform/tool-tip';
12import { decode } from '@beisen-platform/common-func';
13import CommonInput from '@beisen-platform/common-input';
14import CloseIcon from '@beisen-platform/react-icons/lib/icons/Close.js';
15import ArrowDownIcon from '@beisen-platform/react-icons/lib/icons/ArrowdownNomal.js';
16
17function empty() {}
18
19var Input =
20/*#__PURE__*/
21function (_Component) {
22 _inherits(Input, _Component);
23
24 function Input(props) {
25 var _this;
26
27 _classCallCheck(this, Input);
28
29 _this = _possibleConstructorReturn(this, _getPrototypeOf(Input).call(this, props));
30
31 _this.fixControlledValue = function (value, tempValue) {
32 if (!value) {
33 return tempValue ? " " : ""; //空值占位处理
34 } else {
35 return value;
36 }
37 };
38
39 _this.handlerKeyDown = function (event) {
40 if (_this.props.readOnly || !_this.props.isShowFindAll) return;
41
42 if (event.keyCode == 13) {
43 _this.props.onKeyDown(event);
44
45 _this.props.setComState('isShowDoropList', false);
46
47 if (Array.isArray(_this.props.listValue) && !_this.props.listValue.length) {
48 _this.refs.input.blur();
49
50 _this.setState({
51 isFocus: false
52 });
53
54 _this.props.handlerFindAll(event);
55 }
56 }
57 };
58
59 _this.handlerBlur = function (event) {
60 if (_this.props.readOnly) return;
61
62 if (_this.isActiveClear) {
63 _this.isActiveClear = false;
64
65 _this.refs.input.focus();
66
67 return;
68 }
69
70 _this.setState({
71 isFocus: false,
72 pointerEvent: 'auto'
73 });
74
75 _this.props.onBlur(event);
76 };
77
78 _this.handlerFocus = function (event) {
79 if (_this.props.readOnly) return;
80
81 if (_this.props.onlyShowAdvanced) {
82 _this.props.handlerFindAll();
83
84 _this.refs.input.blur();
85
86 return;
87 }
88
89 _this.refs.input.focus();
90
91 _this.setState({
92 isFocus: true
93 });
94
95 _this.props.setComState('isShowDoropList', true);
96
97 _this.props.onFocus(event);
98 };
99
100 _this.handlerChange = function (event) {
101 _this.props.onChange(event);
102 };
103
104 _this.handlerMouseOver = function (event) {
105 if (_this.props.readOnly || _this.props.disabled) return;
106
107 _this.setState({
108 isHover: true
109 });
110 };
111
112 _this.handlerMouseOut = function (event) {
113 if (_this.props.readOnly || _this.props.disabled) return;
114 var node = event.target;
115
116 if (node.nodeName.toLowerCase() == 'i') {
117 return;
118 } else {
119 _this.setState({
120 isHover: false
121 });
122 }
123 };
124
125 _this.clearValue = function (event) {
126 if (_this.state.isFocus) _this.isActiveClear = true;
127
128 _this.props.onChange('', true);
129 };
130
131 _this.clearMultiValue = function (event) {
132 if (_this.props.readOnly || _this.props.disabled) return;
133 var node = event.target;
134 var index;
135
136 if (node.nodeName.toLowerCase() == 'i') {
137 index = node.getAttribute('data-index');
138
139 _this.props.multipleClear(parseInt(index));
140 }
141 };
142
143 _this.tipsClick = function () {
144 _this.setState({
145 pointerEvent: "none"
146 });
147
148 _this.refs.input.focus();
149 };
150
151 _this.state = {
152 isFocus: false,
153 isHover: false,
154 defaultValue: '',
155 pointerEvent: "auto"
156 };
157
158 if (props.status == 'search') {
159 _this.state.isFocus = true;
160 }
161
162 _this.isShowClose = false;
163 return _this;
164 }
165
166 _createClass(Input, [{
167 key: "componentDidMount",
168 value: function componentDidMount() {
169 if (this.props.status == 'search') {
170 this.refs.input.focus();
171 }
172 }
173 }, {
174 key: "componentDidUpdate",
175 value: function componentDidUpdate(prevProps, prevState) {
176 if (this.props.status == 'edit' && !this.props.readOnly && !this.props.disabled) {
177 var wrapperDom = this.refs.wrapper;
178
179 var _expectHeight = this.props.promptMsg || this.props.errorMsg ? 46 : 26;
180
181 if (wrapperDom.offsetHeight > _expectHeight) {} else {
182 if (this.refs && this.refs.topIcon) this.refs.topIcon.style.display = 'block';
183 }
184 }
185 }
186 }, {
187 key: "render",
188 value: function render() {
189 var self = this;
190 var props = Object.assign({}, this.props);
191 var otherProps = omit(props, ['title', 'required', 'multiple']);
192
193 if ('value' in props) {
194 otherProps.value = decode(this.fixControlledValue(props.value, props.tempValue));
195 delete otherProps.defaultValue;
196 }
197
198 if (this.props.multiple && this.props.multiValue && this.props.multiValue.length > 0) {
199 otherProps.value = ' ';
200 }
201
202 var _className1 = this.state.isFocus ? " form-item__control_is-active " : "";
203
204 if (otherProps.value && otherProps.value.length && (this.state.isFocus || this.state.isHover)) {
205 this.isShowClose = true;
206 } else {
207 this.isShowClose = false;
208 }
209
210 var isHaveMsg;
211
212 if (props.promptMsg || props.errorMsg) {
213 isHaveMsg = true;
214 } else {
215 isHaveMsg = false;
216 }
217
218 var _className2 = props.readOnly ? " form-item__control_is-readonly " : "";
219
220 var _className3 = props.disabled ? " form-item__control_is-disabled " : "";
221
222 var _className4 = isHaveMsg ? props.promptMsg ? " form-item__control_has-info" : " form-item__control_is-active form-item__control_has-info form-item__control_has-error" : "";
223
224 var _className5 = props.multiple && props.multiValue && props.multiValue.length > 5 ? ' lookupv2__is-multiple ' : '';
225
226 var _iconCloseHeight = isHaveMsg ? 25 : 5;
227
228 if (props.readOnly) otherProps.placeholder = '';
229
230 if ((props.readOnly || props.disabled) && !props.multiple) {
231 return React.createElement(CommonInput, {
232 readonly: true,
233 errorStatus: isHaveMsg,
234 errorMsg: props.errorMsg,
235 defaultValue: decode(otherProps.value)
236 });
237 } else {
238 return React.createElement("div", {
239 className: "form-item__control" + _className1 + _className2 + _className3 + _className4 + _className5,
240 ref: "wrapper",
241 onMouseOut: this.handlerMouseOut,
242 onMouseOver: this.handlerMouseOver
243 }, React.createElement("ul", {
244 className: "list_horizontal list_wrap form-item__multi-list lookupv2__select-list",
245 onClick: this.clearMultiValue
246 }, props.multiple && props.multiValue.map(function (item, index) {
247 return React.createElement(MultiItem, _extends({
248 key: index
249 }, item, {
250 index: index,
251 readOnly: props.readOnly,
252 disabled: props.disabled
253 }));
254 }), !props.multiple ? React.createElement(ToolTip, {
255 title: decode(otherProps.value),
256 hidden: otherProps.value == ' ' ? true : false
257 }, React.createElement("div", {
258 className: "form-item_is-hidden-tips",
259 style: {
260 pointerEvents: this.state.pointerEvent
261 },
262 onClick: this.tipsClick
263 }, decode(otherProps.value))) : "", !props.multiple ? React.createElement("input", _extends({}, otherProps, {
264 defaultValue: decode(otherProps.value),
265 type: "text",
266 className: "u-input",
267 ref: "input",
268 onKeyDown: this.handlerKeyDown,
269 onFocus: this.handlerFocus,
270 onBlur: this.handlerBlur
271 })) : props.readOnly || props.disabled ? "" : React.createElement("input", _extends({}, otherProps, {
272 type: "text",
273 className: "u-input",
274 ref: "input",
275 onKeyDown: this.handlerKeyDown,
276 onFocus: this.handlerFocus,
277 onBlur: this.handlerBlur
278 }))), React.createElement("span", {
279 className: "form-item__right-icon"
280 }, props.multiple ? "" : React.createElement("i", {
281 className: "u-icon icon-close",
282 ref: "topIcon",
283 onMouseDown: this.clearValue,
284 style: this.isShowClose ? {
285 visibility: 'visible'
286 } : {
287 visibility: 'hidden'
288 }
289 }, React.createElement(CloseIcon, null)), props.status == 'edit' ? React.createElement("i", {
290 className: "u-icon icon-arrowdown",
291 onClick: this.handlerFocus,
292 onBlur: this.handlerBlur
293 }, React.createElement(ArrowDownIcon, {
294 width: 11,
295 height: 6
296 })) : null), isHaveMsg ? React.createElement("span", {
297 className: "form-item__explain"
298 }, props.promptMsg || props.errorMsg) : null);
299 }
300 }
301 }]);
302
303 return Input;
304}(Component);
305
306Input.defaultProps = {
307 value: '',
308 className: '',
309 placeholder: '',
310 promptMsg: '',
311 errorMsg: '',
312 multiple: false,
313 multiValue: [],
314 onKeyDown: empty,
315 readOnly: false,
316 disabled: false,
317 onBlur: empty,
318 onFocus: empty,
319 onChange: empty,
320 unmountBox: empty,
321 multipleClear: empty
322};
323export { Input as default };
324
325var MultiItem =
326/*#__PURE__*/
327function (_Component2) {
328 _inherits(MultiItem, _Component2);
329
330 function MultiItem() {
331 _classCallCheck(this, MultiItem);
332
333 return _possibleConstructorReturn(this, _getPrototypeOf(MultiItem).apply(this, arguments));
334 }
335
336 _createClass(MultiItem, [{
337 key: "render",
338 value: function render() {
339 var props = Object.assign({}, this.props);
340 return React.createElement("li", {
341 className: "form-item__multi-item"
342 }, React.createElement(ToolTip, _extends({}, props, {
343 title: decode(props.name)
344 }), React.createElement("span", {
345 className: "form-item__text"
346 }, decode(props.name))), !props.readOnly && !props.disabled ? React.createElement("i", {
347 className: "u-icon icon-close",
348 "data-index": props.index
349 }, React.createElement(CloseIcon, null)) : '');
350 }
351 }]);
352
353 return MultiItem;
354}(Component);
\No newline at end of file