@autobest-ui/components 2.1.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = void 0;
8
+ exports.default = exports.InputNumberNotRef = void 0;
9
9
 
10
10
  var _react = _interopRequireDefault(require("react"));
11
11
 
@@ -13,6 +13,10 @@ var _classnames = _interopRequireDefault(require("classnames"));
13
13
 
14
14
  var _utils = require("@autobest-ui/utils");
15
15
 
16
+ var _constants = require("./constants");
17
+
18
+ var _ControlArrow = _interopRequireDefault(require("./ControlArrow"));
19
+
16
20
  var __extends = void 0 && (void 0).__extends || function () {
17
21
  var _extendStatics = function extendStatics(d, b) {
18
22
  _extendStatics = Object.setPrototypeOf || {
@@ -57,588 +61,351 @@ var __assign = void 0 && (void 0).__assign || function () {
57
61
  return __assign.apply(this, arguments);
58
62
  };
59
63
 
60
- var cls = 'ab-input-number'; // TODO: 重构组件
61
-
62
- var InputNumber =
64
+ var InputNumberNotRef =
63
65
  /** @class */
64
66
  function (_super) {
65
- __extends(InputNumber, _super);
67
+ __extends(InputNumberNotRef, _super);
66
68
 
67
- function InputNumber(props) {
69
+ function InputNumberNotRef(props) {
68
70
  var _this = _super.call(this, props) || this;
69
71
 
70
- _this.currentRef = /*#__PURE__*/_react.default.createRef();
72
+ _this.prefixCls = 'ab-input-number';
73
+ _this.inputRef = /*#__PURE__*/_react.default.createRef();
74
+ /**
75
+ * 解析用户输入的内容,并返回解析后的结果
76
+ * @param originalValue
77
+ */
71
78
 
72
- _this.onFocus = function (e) {
73
- var _a = _this.props,
74
- visibleButton = _a.visibleButton,
75
- onFocus = _a.onFocus;
76
-
77
- if (onFocus) {
78
- onFocus(e);
79
+ _this.getParserOriginalValue = function (originalValue) {
80
+ // 输入为空
81
+ if ((0, _utils.isBlank)(originalValue)) {
82
+ return undefined;
79
83
  }
80
84
 
81
- if (!visibleButton) {
82
- return;
85
+ if (!_constants.NumberReg.test(originalValue) || _constants.FirstZeroReg.test(originalValue)) {
86
+ return (0, _utils.isBlank)(_this.state.parserValue) ? undefined : _this.state.parserValue.toString();
83
87
  }
84
88
 
85
- _this.setState({
86
- focus: true
87
- });
88
- };
89
-
90
- _this.onBlur = function (e) {
91
89
  var _a = _this.props,
92
- visibleButton = _a.visibleButton,
93
- onBlur = _a.onBlur;
90
+ min = _a.min,
91
+ max = _a.max,
92
+ precision = _a.precision;
93
+ var currentValue = parseFloat(originalValue);
94
94
 
95
- if (onBlur) {
96
- onBlur(e);
95
+ if (!(0, _utils.isBlank)(min) && currentValue < min) {
96
+ currentValue = min;
97
97
  }
98
98
 
99
- if (!visibleButton) {
100
- return;
99
+ if (!(0, _utils.isBlank)(max) && currentValue > max) {
100
+ currentValue = max;
101
101
  }
102
102
 
103
- _this.setState({
104
- focus: false
105
- });
103
+ return (0, _utils.toFixed)(currentValue, precision);
106
104
  };
105
+ /**
106
+ * 键盘和点击上下按钮更新value值
107
+ * @param isUp
108
+ */
107
109
 
108
- _this.onMouseEnter = function () {
109
- if (!_this.props.visibleButton) {
110
- return;
111
- }
112
-
113
- _this.setState({
114
- enter: true
115
- }, function () {
116
- _this.getLocationInfo();
117
- });
118
- };
119
110
 
120
- _this.onMouseLeave = function () {
121
- if (!_this.props.visibleButton) {
122
- return;
123
- }
111
+ _this.changeValueWithStep = function (isUp) {
112
+ var step = _this.props.step;
113
+ var prevValue = _this.state.parserValue ? _this.state.parserValue : 0;
114
+ var keyboardValue = isUp ? prevValue + step : prevValue - step;
124
115
 
125
- _this.setState({
126
- enter: false
127
- });
128
- };
116
+ var parserValueStr = _this.getParserOriginalValue(keyboardValue.toString());
129
117
 
130
- _this.onMouseMove = function (ev) {
131
- if (!_this.props.visibleButton) {
132
- return;
133
- }
118
+ var parserValue = (0, _utils.getNumberFromString)(parserValueStr);
119
+ var _a = _this.props,
120
+ name = _a.name,
121
+ onChange = _a.onChange;
134
122
 
135
- var _a = _this.getElement(),
136
- inputEl = _a.inputEl,
137
- addBtnEl = _a.addBtnEl,
138
- subBtnEl = _a.subBtnEl;
123
+ if (prevValue !== parserValue) {
124
+ if (onChange) {
125
+ onChange(parserValue, name);
126
+ return;
127
+ }
139
128
 
140
- if (!inputEl || !addBtnEl || !subBtnEl) {
141
- return;
129
+ _this.setState({
130
+ parserValue: parserValue,
131
+ originalValueStr: parserValueStr
132
+ });
142
133
  }
134
+ };
135
+ /**
136
+ * 设置input焦点
137
+ */
143
138
 
144
- var _b = _this.getMouseElement(ev),
145
- isAdd = _b.isAdd,
146
- isSub = _b.isSub;
147
139
 
148
- if (isAdd) {
149
- inputEl.style.cursor = 'default';
150
- addBtnEl.setAttribute('class', "".concat(cls, "-button ").concat(cls, "-hover"));
151
- return;
152
- }
140
+ _this.setInputFocus = function () {
141
+ var element = _this.inputRef.current;
153
142
 
154
- if (isSub) {
155
- inputEl.style.cursor = 'default';
156
- subBtnEl.setAttribute('class', "".concat(cls, "-button ").concat(cls, "-hover"));
143
+ if (!element) {
157
144
  return;
158
145
  }
159
146
 
160
- inputEl.style.cursor = 'text';
161
- addBtnEl.setAttribute('class', "".concat(cls, "-button"));
162
- subBtnEl.setAttribute('class', "".concat(cls, "-button"));
147
+ element.focus();
163
148
  };
164
149
 
165
- _this.onMouseDown = function (ev) {
166
- if (!_this.props.visibleButton) {
150
+ _this.onKeyboard = function (ev) {
151
+ if (_this.props.disabled) {
167
152
  return;
168
153
  }
169
154
 
170
- var _a = _this.getElement(),
171
- addBtnEl = _a.addBtnEl,
172
- subBtnEl = _a.subBtnEl;
173
-
174
- if (!addBtnEl || !subBtnEl) {
175
- return;
176
- } // 按下时清除move事件
177
-
178
-
179
- if (_this.mouseMoveHandler) {
180
- _this.mouseMoveHandler.remove();
181
-
182
- _this.mouseMoveHandler = null;
183
- }
184
-
185
- var _b = _this.getMouseElement(ev),
186
- isAdd = _b.isAdd,
187
- isSub = _b.isSub;
188
-
189
- if (isAdd) {
190
- addBtnEl.setAttribute('class', "".concat(cls, "-button ").concat(cls, "-active"));
191
-
192
- _this.onAdd();
193
- }
194
-
195
- if (isSub) {
196
- subBtnEl.setAttribute('class', "".concat(cls, "-button ").concat(cls, "-active"));
197
-
198
- _this.onSub();
199
- }
200
-
201
- _this.addMouseUpListener();
202
- };
203
-
204
- _this.onMouseUp = function () {
205
- if (_this.mouseUpHandler) {
206
- _this.mouseUpHandler.remove();
155
+ if (ev.code === 'ArrowUp' || ev.code === 'ArrowDown') {
156
+ ev.preventDefault();
207
157
 
208
- _this.mouseUpHandler = null;
158
+ _this.changeValueWithStep(ev.code === 'ArrowUp');
209
159
  }
210
-
211
- var _a = _this.getElement(),
212
- addBtnEl = _a.addBtnEl,
213
- subBtnEl = _a.subBtnEl;
214
-
215
- if (addBtnEl && subBtnEl) {
216
- addBtnEl.setAttribute('class', "".concat(cls, "-button"));
217
- subBtnEl.setAttribute('class', "".concat(cls, "-button"));
218
- } // 重新添加move事件
219
-
220
-
221
- _this.addMouseMoveListener();
222
160
  };
223
161
 
224
- _this.addMouseMoveListener = function () {
225
- var inputEl = _this.getElement().inputEl;
226
-
227
- if (!inputEl) {
162
+ _this.onFocus = function (ev) {
163
+ if (_this.props.disabled) {
228
164
  return;
229
165
  }
230
166
 
231
- _this.mouseMoveHandler = (0, _utils.addEventListener)(inputEl, 'mousemove', _this.onMouseMove);
232
- };
233
-
234
- _this.addMouseUpListener = function () {
235
- _this.mouseUpHandler = (0, _utils.addEventListener)(window.document, 'mouseup', _this.onMouseUp);
236
- };
237
-
238
- _this.getElement = function () {
239
- var element = _this.currentRef.current;
240
- var inputEl;
241
- var buttonEl;
242
- var addBtnEl;
243
- var subBtnEl;
244
-
245
- if (element && element.childNodes.length) {
246
- inputEl = element.childNodes[0];
247
- }
248
-
249
- if (element && element.childNodes.length > 1) {
250
- buttonEl = element.childNodes[1];
251
- addBtnEl = buttonEl.children[0];
252
- subBtnEl = buttonEl.children[1];
167
+ if (!_this.state.isFocusInput) {
168
+ _this.setState({
169
+ isFocusInput: true
170
+ });
253
171
  }
254
172
 
255
- return {
256
- inputEl: inputEl,
257
- addBtnEl: addBtnEl,
258
- subBtnEl: subBtnEl
259
- };
260
- }; // 判断鼠标是否在按钮位置,在哪个按钮
261
-
262
-
263
- _this.getMouseElement = function (ev) {
264
- var isAdd = _this.isInside(ev, _this.addLocationInfo);
265
-
266
- var isSub = _this.isInside(ev, _this.subLocationInfo);
267
-
268
- return {
269
- isAdd: isAdd,
270
- isSub: isSub
271
- };
272
- };
273
-
274
- _this.isInside = function (ev, locationInfo) {
275
- if (!locationInfo) {
276
- return false;
173
+ if (_this.props.keyboard && !_this.keyboardHandler) {
174
+ _this.keyboardHandler = (0, _utils.addEventListener)(ev.target, 'keydown', _this.onKeyboard);
277
175
  }
278
-
279
- var pageX = ev.pageX,
280
- pageY = ev.pageY;
281
- var left = locationInfo.left,
282
- top = locationInfo.top,
283
- width = locationInfo.width,
284
- height = locationInfo.height;
285
- return pageX > left && pageX < left + width && pageY > top && pageY < top + height;
286
176
  };
287
177
 
288
- _this.getLocationInfo = function () {
289
- var _a = _this.getElement(),
290
- addBtnEl = _a.addBtnEl,
291
- subBtnEl = _a.subBtnEl;
178
+ _this.onBlur = function (ev) {
179
+ if (_this.keyboardHandler) {
180
+ _this.keyboardHandler.remove();
292
181
 
293
- if (!addBtnEl || !subBtnEl) {
294
- return;
182
+ _this.keyboardHandler = null;
295
183
  }
296
184
 
297
- _this.addLocationInfo = (0, _utils.getOffsetAndSize)(addBtnEl);
298
- _this.subLocationInfo = (0, _utils.getOffsetAndSize)(subBtnEl);
299
- }; // 不需要根据props的value更新
300
-
301
-
302
- _this.getCurrentValue = function (value) {
303
- var _a = _this.props,
304
- min = _a.min,
305
- max = _a.max;
306
- var valueNumber = parseFloat(value);
307
- var packMultiple = _this.props.packMultiple || 1; // 取大于等于值且是打包个数倍数的值
308
-
309
- var ceilNumber = Math.ceil(valueNumber / packMultiple) * packMultiple; // 当值在临界点和临界点之外时
310
-
311
- if (ceilNumber <= min) {
312
- return Math.ceil(min / packMultiple) * packMultiple;
185
+ if (_this.state.isFocusInput) {
186
+ _this.setState({
187
+ isFocusInput: false
188
+ });
313
189
  }
314
190
 
315
- if (ceilNumber >= max) {
316
- return Math.floor(max / packMultiple) * packMultiple;
191
+ if (_this.props.disabled) {
192
+ return;
317
193
  }
318
194
 
319
- return ceilNumber;
320
- };
321
-
322
- _this.getPadDigitalValue = function (value) {
195
+ var originalValueStr = ev.target.value;
323
196
  var _a = _this.props,
324
- digital = _a.digital,
325
- padDigital = _a.padDigital;
197
+ name = _a.name,
198
+ onBlur = _a.onBlur,
199
+ onChange = _a.onChange,
200
+ onContinualChange = _a.onContinualChange;
326
201
 
327
- if (!padDigital || (0, _utils.isBlank)(value) || !digital) {
328
- return value;
329
- }
202
+ var parserValueStr = _this.getParserOriginalValue(originalValueStr);
330
203
 
331
- var resultArr = value.split('.');
332
- return "".concat(resultArr[0], ".").concat((resultArr[1] || '').padEnd(digital, '0'));
333
- };
204
+ var parserValue = (0, _utils.getNumberFromString)(parserValueStr);
334
205
 
335
- _this.onChangePackMultipleValue = function (value) {
336
- var currentValue = _this.getCurrentValue(value).toString();
206
+ _this.setState({
207
+ originalValueStr: parserValueStr
208
+ });
337
209
 
338
- var _a = _this.props,
339
- onChange = _a.onChange,
340
- onChangePackMultipleAfter = _a.onChangePackMultipleAfter,
341
- name = _a.name;
342
- onChange(currentValue, name);
210
+ if ('value' in _this.props && parserValue !== _this.props.value || parserValue !== _this.state.parserValue) {
211
+ // 触发onChange, 因为在onChange阶段,不合法将不会触发,当用户结束输入后触发最后一次合法的onChange
212
+ if (onContinualChange) {
213
+ onContinualChange(parserValueStr, parserValue, name);
214
+ }
343
215
 
344
- if (onChangePackMultipleAfter) {
345
- onChangePackMultipleAfter(currentValue, name);
216
+ if (onChange) {
217
+ onChange(parserValue, name);
218
+ } else {
219
+ _this.setState({
220
+ parserValue: parserValue
221
+ });
222
+ }
346
223
  }
347
- };
348
-
349
- _this.onPadDigital = function (value) {
350
- var currentValue = _this.getPadDigitalValue(value);
351
-
352
- var _a = _this.props,
353
- onChange = _a.onChange,
354
- name = _a.name;
355
224
 
356
- if (value !== currentValue) {
357
- onChange(currentValue, name);
225
+ if (onBlur) {
226
+ onBlur(parserValue, name);
358
227
  }
359
228
  };
229
+ /**
230
+ * 修改value值的回调
231
+ * 注:value值当不在合法时,将不再触发onChange
232
+ * 在输入结束后(onBlur时),触发最后一次
233
+ * @param ev
234
+ */
360
235
 
361
- _this.getPadDigitalDebounce = function () {
362
- if (_this.padDigitalDebounce) {
363
- return _this.padDigitalDebounce;
364
- }
365
-
366
- _this.padDigitalDebounce = (0, _utils.debounce)(_this.onPadDigital, _this.props.delay);
367
- return _this.padDigitalDebounce;
368
- };
369
236
 
370
- _this.getChangePackMultipleValueDebounce = function () {
371
- if (_this.changePackMultipleValueDebounce) {
372
- return _this.changePackMultipleValueDebounce;
237
+ _this.onChangeValue = function (ev) {
238
+ if (_this.props.disabled) {
239
+ return;
373
240
  }
374
241
 
375
- _this.changePackMultipleValueDebounce = (0, _utils.debounce)(_this.onChangePackMultipleValue, _this.props.delay);
376
- return _this.changePackMultipleValueDebounce;
377
- };
242
+ var originalValueStr = ev.target.value;
243
+
244
+ var parserValueStr = _this.getParserOriginalValue(originalValueStr);
378
245
 
379
- _this.callback = function (value, ignoreDelay) {
246
+ var parserValue = (0, _utils.getNumberFromString)(parserValueStr);
380
247
  var _a = _this.props,
381
248
  name = _a.name,
382
249
  onChange = _a.onChange,
383
- onChangePackMultipleBefore = _a.onChangePackMultipleBefore,
384
- packMultiple = _a.packMultiple,
385
- padDigital = _a.padDigital;
250
+ onContinualChange = _a.onContinualChange;
386
251
 
387
- if (onChange && value !== _this.props.value) {
388
- onChange(value, name);
252
+ if (onContinualChange) {
253
+ onContinualChange(originalValueStr, parserValue, name);
389
254
  }
390
255
 
391
- if (packMultiple && !(0, _utils.isBlank)(value) && parseFloat(value) % packMultiple !== 0) {
392
- if (onChangePackMultipleBefore) {
393
- onChangePackMultipleBefore(value, name);
394
- }
256
+ _this.setState({
257
+ originalValueStr: originalValueStr
258
+ }); // 若输入的内容不合法,将不再触发onChange/setStates
259
+ // 在输入结束后(onBlur时),触发一次
395
260
 
396
- if (ignoreDelay) {
397
- _this.onChangePackMultipleValue(value);
398
- } else {
399
- _this.getChangePackMultipleValueDebounce()(value);
400
- }
401
261
 
262
+ if (parserValueStr !== originalValueStr) {
402
263
  return;
403
264
  }
404
265
 
405
- if (padDigital) {
406
- if (ignoreDelay) {
407
- _this.onPadDigital(value);
408
-
409
- return;
410
- }
411
-
412
- _this.getPadDigitalDebounce()(value);
413
- }
414
- };
415
-
416
- _this.onValueChange = function (ev, ignoreDelay) {
417
- if (_this.changePackMultipleValueDebounce) {
418
- _this.changePackMultipleValueDebounce.cancel();
419
- }
420
-
421
- var _a = _this.props,
422
- min = _a.min,
423
- max = _a.max,
424
- digital = _a.digital,
425
- value = _a.value;
426
- var currentValue = ev.target.value.toString(); // 输入为空
427
-
428
- if ((0, _utils.isBlank)(currentValue)) {
429
- _this.callback('', ignoreDelay);
430
-
266
+ if (onChange) {
267
+ onChange(parserValue, name);
431
268
  return;
432
269
  }
433
270
 
434
- var preValue = value.toString(); // 输入的不是数字格式
435
-
436
- var reg = /^-$|(^(-?\d+)(\.\d*)?)$/;
437
-
438
- if (!reg.test(currentValue)) {
439
- _this.callback(preValue, ignoreDelay);
440
-
441
- return;
442
- } // 0开头后面直接是数字,没有点如:011, 这是不合法的
443
-
444
-
445
- var zeroReg = /^0\d+$/;
271
+ _this.setState({
272
+ parserValue: parserValue
273
+ });
274
+ };
446
275
 
447
- if (zeroReg.test(currentValue)) {
448
- _this.callback(preValue, ignoreDelay);
276
+ _this.onKeyup = function (ev) {
277
+ ev.preventDefault();
449
278
 
279
+ if (!_this.props.controls || _this.props.disabled) {
450
280
  return;
451
- } // 小数位数限制
452
-
453
-
454
- if (digital) {
455
- currentValue = new RegExp("[^.]+([.](\\d{0,".concat(digital, "}))?")).exec(currentValue)[0].toString();
456
281
  }
457
282
 
458
- var valueNumber = parseFloat(currentValue);
459
-
460
- if (!(0, _utils.isBlank)(min)) {
461
- if (min > valueNumber) {
462
- _this.callback(preValue, ignoreDelay);
283
+ _this.setInputFocus();
463
284
 
464
- return;
465
- } // 如果min>= 0, 将阻止输入-
466
-
467
-
468
- if (min >= 0 && currentValue.indexOf('-') > -1) {
469
- _this.callback('', ignoreDelay);
470
-
471
- return;
472
- }
473
- }
285
+ _this.changeValueWithStep(true);
286
+ };
474
287
 
475
- if (!(0, _utils.isBlank)(max) && max < valueNumber) {
476
- _this.callback(preValue, ignoreDelay);
288
+ _this.onKeydown = function (ev) {
289
+ ev.preventDefault();
477
290
 
291
+ if (!_this.props.controls || _this.props.disabled) {
478
292
  return;
479
293
  }
480
294
 
481
- if (!digital && currentValue.indexOf('.') > -1) {
482
- _this.callback(preValue, ignoreDelay);
483
-
484
- return;
485
- }
295
+ _this.setInputFocus();
486
296
 
487
- _this.callback(currentValue, ignoreDelay);
297
+ _this.changeValueWithStep(false);
488
298
  };
489
299
 
490
- _this.getValueCalculate = function (value, offset) {
491
- var valueStr = value.toString();
492
- var offsetStr = offset.toString();
493
-
494
- if (valueStr.indexOf('.') < 0 && offsetStr.indexOf('.') < 0) {
495
- return value + offset;
300
+ _this.onMouseEnter = function () {
301
+ if (!_this.props.controls || _this.state.isEnterInput || _this.props.disabled) {
302
+ return;
496
303
  }
497
304
 
498
- var digital = _this.props.digital;
499
- var powValue = Math.pow(10, digital);
500
- return Math.round((value + offset) * powValue) / powValue;
305
+ _this.setState({
306
+ isEnterInput: true
307
+ });
501
308
  };
502
309
 
503
- _this.onAdd = function () {
504
- var _a = _this.props,
505
- packMultiple = _a.packMultiple,
506
- value = _a.value;
507
- var step = packMultiple || 1; // valueNumber 可能为NaN
508
-
509
- var ev = {
510
- target: {
511
- value: _this.getPadDigitalValue(_this.getValueCalculate(Number(value), step).toString())
512
- }
513
- };
514
-
515
- _this.onValueChange(ev);
516
- };
310
+ _this.onMouseLeave = function () {
311
+ if (!_this.props.controls || !_this.state.isEnterInput || _this.props.disabled) {
312
+ return;
313
+ }
517
314
 
518
- _this.onSub = function () {
519
- var _a = _this.props,
520
- packMultiple = _a.packMultiple,
521
- value = _a.value;
522
- var step = packMultiple || 1;
523
- var ev = {
524
- target: {
525
- value: _this.getPadDigitalValue(_this.getValueCalculate(Number(value), step * -1).toString())
526
- }
527
- };
528
-
529
- _this.onValueChange(ev);
530
- }; // 渲染加减按钮
531
-
532
-
533
- _this.renderButton = function () {
534
- return /*#__PURE__*/_react.default.createElement("div", {
535
- className: "".concat(cls, "-button-wrap")
536
- }, /*#__PURE__*/_react.default.createElement("div", {
537
- className: "".concat(cls, "-button"),
538
- onClick: _this.onAdd
539
- }, /*#__PURE__*/_react.default.createElement("div", {
540
- className: "".concat(cls, "-add")
541
- })), /*#__PURE__*/_react.default.createElement("div", {
542
- className: "".concat(cls, "-button"),
543
- onClick: _this.onSub
544
- }, /*#__PURE__*/_react.default.createElement("div", {
545
- className: "".concat(cls, "-sub")
546
- })));
315
+ _this.setState({
316
+ isEnterInput: false
317
+ });
547
318
  };
548
319
 
320
+ var defaultValueStr = (0, _utils.toFixed)(props.defaultValue, props.precision);
549
321
  _this.state = {
550
- enter: false,
551
- focus: false
322
+ originalValueStr: defaultValueStr,
323
+ parserValue: (0, _utils.getNumberFromString)(defaultValueStr),
324
+ isEnterInput: false,
325
+ isFocusInput: false
552
326
  };
553
327
  return _this;
554
328
  }
555
329
 
556
- InputNumber.prototype.componentDidMount = function () {
557
- this.addMouseMoveListener();
558
- this.onValueChange({
559
- target: {
560
- value: this.props.value
561
- }
562
- }, true);
563
- };
330
+ InputNumberNotRef.getDerivedStateFromProps = function (nextProps, prevStates) {
331
+ var nextState = {}; // 判断是否为受控方式
564
332
 
565
- InputNumber.prototype.componentWillUnmount = function () {
566
- if (this.mouseUpHandler) {
567
- this.mouseUpHandler.remove();
568
- this.mouseUpHandler = null;
569
- }
333
+ if ('value' in nextProps) {
334
+ var fixedValueStr = (0, _utils.toFixed)(nextProps.value, nextProps.precision);
570
335
 
571
- if (this.mouseMoveHandler) {
572
- this.mouseMoveHandler.remove();
573
- this.mouseMoveHandler = null;
336
+ if (nextProps.value !== prevStates.parserValue) {
337
+ nextState.parserValue = (0, _utils.getNumberFromString)(fixedValueStr);
338
+ nextState.originalValueStr = fixedValueStr;
339
+ }
574
340
  }
575
341
 
576
- if (this.padDigitalDebounce) {
577
- this.padDigitalDebounce.cancel();
578
- this.padDigitalDebounce = null;
342
+ if ((0, _utils.isEmptyObject)(nextState)) {
343
+ return null;
579
344
  }
580
345
 
581
- if (this.changePackMultipleValueDebounce) {
582
- this.changePackMultipleValueDebounce.cancel();
583
- this.changePackMultipleValueDebounce = null;
584
- }
346
+ return nextState;
585
347
  };
586
348
 
587
- InputNumber.prototype.render = function () {
588
- var copyProps = __assign({}, this.props);
589
-
590
- delete copyProps.onChangePackMultipleBefore;
591
- delete copyProps.onChangePackMultipleAfter;
592
- delete copyProps.digital;
593
- delete copyProps.padDigital;
594
- delete copyProps.packMultiple;
595
- delete copyProps.visibleButton;
596
- delete copyProps.onChange;
597
- delete copyProps.min;
598
- delete copyProps.max;
599
- delete copyProps.delay;
600
-
601
- if ((0, _utils.isBlank)(copyProps.name)) {
602
- delete copyProps.name;
349
+ InputNumberNotRef.prototype.componentWillUnmount = function () {
350
+ if (this.keyboardHandler) {
351
+ this.keyboardHandler.remove();
352
+ this.keyboardHandler = null;
603
353
  }
354
+ };
604
355
 
605
- var _a = this.props,
606
- className = _a.className,
607
- visibleButton = _a.visibleButton;
608
- var _b = this.state,
609
- enter = _b.enter,
610
- focus = _b.focus;
611
- var inputStyle = visibleButton ? {
612
- paddingRight: '.2rem'
613
- } : {};
614
- return /*#__PURE__*/_react.default.createElement("label", {
615
- className: "".concat(cls, "-wrap"),
616
- ref: this.currentRef
617
- }, /*#__PURE__*/_react.default.createElement("input", __assign({}, copyProps, {
618
- className: (0, _classnames.default)(cls, className),
356
+ InputNumberNotRef.prototype.render = function () {
357
+ var _a, _b, _c;
358
+
359
+ var cls = this.prefixCls;
360
+ var _d = this.props,
361
+ upperRef = _d.upperRef,
362
+ className = _d.className,
363
+ placeholder = _d.placeholder,
364
+ disabled = _d.disabled,
365
+ style = _d.style,
366
+ controls = _d.controls;
367
+ var _e = this.state,
368
+ isEnterInput = _e.isEnterInput,
369
+ isFocusInput = _e.isFocusInput,
370
+ originalValueStr = _e.originalValueStr;
371
+ return /*#__PURE__*/_react.default.createElement("div", {
372
+ className: (0, _classnames.default)(cls, className, (_a = {}, _a["".concat(cls, "-enter")] = isEnterInput || isFocusInput, _a), (_b = {}, _b["".concat(cls, "-focus")] = isFocusInput, _b), (_c = {}, _c["".concat(cls, "-disabled")] = disabled, _c)),
373
+ onMouseEnter: this.onMouseEnter,
374
+ onMouseLeave: this.onMouseLeave
375
+ }, /*#__PURE__*/_react.default.createElement("input", {
376
+ className: "".concat(cls, "-control"),
377
+ ref: (0, _utils.composeRef)(this.inputRef, upperRef),
619
378
  type: "text",
620
- onChange: this.onValueChange,
621
- onMouseDown: this.onMouseDown,
379
+ placeholder: placeholder,
380
+ disabled: disabled,
381
+ style: style,
382
+ value: originalValueStr || '',
383
+ onChange: this.onChangeValue,
622
384
  onFocus: this.onFocus,
623
- onBlur: this.onBlur,
624
- onMouseEnter: this.onMouseEnter,
625
- onMouseLeave: this.onMouseLeave,
626
- style: inputStyle
627
- })), visibleButton && (enter || focus) ? this.renderButton() : null);
385
+ onBlur: this.onBlur
386
+ }), controls ? /*#__PURE__*/_react.default.createElement(_ControlArrow.default, {
387
+ cls: this.prefixCls,
388
+ onKeyup: this.onKeyup,
389
+ onKeydown: this.onKeydown
390
+ }) : null);
628
391
  };
629
392
 
630
- InputNumber.defaultProps = {
631
- value: '',
632
- name: '',
633
- size: 3,
634
- disabled: false,
635
- digital: 0,
636
- padDigital: false,
637
- delay: 1000,
638
- visibleButton: false
393
+ InputNumberNotRef.defaultProps = {
394
+ defaultValue: '',
395
+ controls: true,
396
+ step: 1,
397
+ keyboard: true
639
398
  };
640
- return InputNumber;
399
+ return InputNumberNotRef;
641
400
  }(_react.default.Component);
642
401
 
402
+ exports.InputNumberNotRef = InputNumberNotRef;
403
+
404
+ var InputNumber = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
405
+ return /*#__PURE__*/_react.default.createElement(InputNumberNotRef, __assign({}, props, {
406
+ upperRef: ref
407
+ }));
408
+ });
409
+
643
410
  var _default = InputNumber;
644
411
  exports.default = _default;