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