@autobest-ui/components 2.9.2 → 2.10.1-alpha.0
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/affix/index.d.ts +3 -3
- package/esm/affix/index.js +2 -2
- package/esm/carousel/index.d.ts +2 -2
- package/esm/carousel/index.js +1 -1
- package/esm/checkbox/Checkbox.d.ts +60 -0
- package/esm/checkbox/Checkbox.js +120 -0
- package/esm/checkbox/CheckboxGroup.d.ts +16 -0
- package/esm/checkbox/CheckboxGroup.js +57 -0
- package/esm/checkbox/index.d.ts +4 -52
- package/esm/checkbox/index.js +2 -114
- package/esm/checkbox/style/index.css +1 -1
- package/esm/ellipsis/index.d.ts +1 -8
- package/esm/ellipsis/index.js +9 -9
- package/esm/ellipsis/style/index.css +1 -1
- package/esm/index.d.ts +8 -3
- package/esm/index.js +5 -2
- package/esm/input/Input.d.ts +13 -1
- package/esm/input/Input.js +66 -4
- package/esm/input/TextArea.d.ts +8 -0
- package/esm/input/TextArea.js +43 -12
- package/esm/input-number/getParserOriginalValue.d.ts +26 -0
- package/esm/input-number/getParserOriginalValue.js +73 -0
- package/esm/input-number/index.d.ts +20 -7
- package/esm/input-number/index.js +60 -48
- package/esm/input-phone/format.d.ts +23 -0
- package/esm/input-phone/format.js +81 -0
- package/esm/input-phone/index.d.ts +65 -0
- package/esm/input-phone/index.js +190 -0
- package/esm/input-phone/style/index.css +1 -0
- package/esm/modal/index.d.ts +3 -3
- package/esm/modal/index.js +2 -2
- package/esm/move/index.d.ts +6 -6
- package/esm/move/index.js +5 -5
- package/esm/popover/index.d.ts +1 -1
- package/esm/popover/index.js +7 -2
- package/esm/radio/Radio.d.ts +4 -0
- package/esm/radio/Radio.js +80 -0
- package/esm/radio/RadioGroup.d.ts +16 -0
- package/esm/radio/RadioGroup.js +106 -0
- package/esm/radio/context.d.ts +5 -0
- package/esm/radio/context.js +4 -0
- package/esm/radio/index.d.ts +3 -0
- package/esm/radio/index.js +2 -0
- package/esm/radio/interface.d.ts +17 -0
- package/esm/radio/interface.js +1 -0
- package/esm/radio/style/index.css +1 -0
- package/esm/select/index.d.ts +2 -2
- package/esm/select/index.js +1 -1
- package/esm/style.css +1 -1
- package/esm/table/body/CheckIcon.js +1 -1
- package/esm/table/header/CheckIcon.js +1 -1
- package/esm/table/index.d.ts +2 -2
- package/esm/table/index.js +2 -1
- package/esm/table/style/index.css +1 -1
- package/esm/tabs/index.d.ts +2 -2
- package/esm/tabs/index.js +1 -1
- package/esm/trigger/index.d.ts +5 -5
- package/esm/trigger/index.js +5 -5
- package/lib/affix/index.d.ts +3 -3
- package/lib/affix/index.js +2 -2
- package/lib/carousel/index.d.ts +2 -2
- package/lib/carousel/index.js +1 -1
- package/lib/checkbox/Checkbox.d.ts +60 -0
- package/lib/checkbox/Checkbox.js +128 -0
- package/lib/checkbox/CheckboxGroup.d.ts +16 -0
- package/lib/checkbox/CheckboxGroup.js +65 -0
- package/lib/checkbox/index.d.ts +4 -52
- package/lib/checkbox/index.js +13 -115
- package/lib/checkbox/style/index.css +1 -1
- package/lib/ellipsis/index.d.ts +1 -8
- package/lib/ellipsis/index.js +9 -9
- package/lib/ellipsis/style/index.css +1 -1
- package/lib/index.d.ts +8 -3
- package/lib/index.js +47 -2
- package/lib/input/Input.d.ts +13 -1
- package/lib/input/Input.js +66 -4
- package/lib/input/TextArea.d.ts +8 -0
- package/lib/input/TextArea.js +43 -12
- package/lib/input-number/getParserOriginalValue.d.ts +26 -0
- package/lib/input-number/getParserOriginalValue.js +79 -0
- package/lib/input-number/index.d.ts +20 -7
- package/lib/input-number/index.js +59 -47
- package/lib/input-phone/format.d.ts +23 -0
- package/lib/input-phone/format.js +90 -0
- package/lib/input-phone/index.d.ts +65 -0
- package/lib/input-phone/index.js +198 -0
- package/lib/input-phone/style/index.css +1 -0
- package/lib/modal/index.d.ts +3 -3
- package/lib/modal/index.js +2 -2
- package/lib/move/index.d.ts +6 -6
- package/lib/move/index.js +5 -5
- package/lib/popover/index.d.ts +1 -1
- package/lib/popover/index.js +7 -2
- package/lib/radio/Radio.d.ts +4 -0
- package/lib/radio/Radio.js +91 -0
- package/lib/radio/RadioGroup.d.ts +16 -0
- package/lib/radio/RadioGroup.js +117 -0
- package/lib/radio/context.d.ts +5 -0
- package/lib/radio/context.js +15 -0
- package/lib/radio/index.d.ts +3 -0
- package/lib/radio/index.js +20 -0
- package/lib/radio/interface.d.ts +17 -0
- package/lib/radio/interface.js +5 -0
- package/lib/radio/style/index.css +1 -0
- package/lib/select/index.d.ts +2 -2
- package/lib/select/index.js +1 -1
- package/lib/style.css +1 -1
- package/lib/table/body/CheckIcon.js +2 -2
- package/lib/table/header/CheckIcon.js +2 -2
- package/lib/table/index.d.ts +2 -2
- package/lib/table/index.js +2 -1
- package/lib/table/style/index.css +1 -1
- package/lib/tabs/index.d.ts +2 -2
- package/lib/tabs/index.js +1 -1
- package/lib/trigger/index.d.ts +5 -5
- package/lib/trigger/index.js +5 -5
- package/package.json +5 -4
package/lib/input/TextArea.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = exports.TextAreaNotRef = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _components = require("@autobest-ui/components");
|
|
9
10
|
var _utils = require("@autobest-ui/utils");
|
|
10
11
|
var _Adorn = _interopRequireDefault(require("./Adorn"));
|
|
11
12
|
var __extends = void 0 && (void 0).__extends || function () {
|
|
@@ -51,15 +52,10 @@ var TextAreaNotRef = /** @class */function (_super) {
|
|
|
51
52
|
var _this = _super.call(this, props) || this;
|
|
52
53
|
_this.prefixCls = 'ab-textarea';
|
|
53
54
|
_this.textareaRef = /*#__PURE__*/_react.default.createRef();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*/
|
|
58
|
-
_this.onChange = function (ev) {
|
|
59
|
-
if (_this.props.disabled) {
|
|
60
|
-
return;
|
|
55
|
+
_this.changeValue = function (value, onBlurAfterChange) {
|
|
56
|
+
if (onBlurAfterChange === void 0) {
|
|
57
|
+
onBlurAfterChange = false;
|
|
61
58
|
}
|
|
62
|
-
var value = ev.target.value;
|
|
63
59
|
if (_this.props.maxLength > 0) {
|
|
64
60
|
var currentLength = getValueLength(value);
|
|
65
61
|
if (_this.props.maxLength && currentLength > _this.props.maxLength) {
|
|
@@ -71,14 +67,43 @@ var TextAreaNotRef = /** @class */function (_super) {
|
|
|
71
67
|
}
|
|
72
68
|
var _a = _this.props,
|
|
73
69
|
onChange = _a.onChange,
|
|
74
|
-
name = _a.name
|
|
70
|
+
name = _a.name,
|
|
71
|
+
onBlur = _a.onBlur;
|
|
75
72
|
if (onChange) {
|
|
76
73
|
onChange(value, name);
|
|
74
|
+
if (onBlurAfterChange && onBlur) {
|
|
75
|
+
onBlur(value, name);
|
|
76
|
+
}
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
_this.setState({
|
|
80
80
|
value: value
|
|
81
81
|
});
|
|
82
|
+
if (onBlurAfterChange && onBlur) {
|
|
83
|
+
onBlur(value, name);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
_this.checkCurrentValue = function () {
|
|
87
|
+
if (!_this.textareaRef.current) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
var value = _this.textareaRef.current.value;
|
|
91
|
+
if (!(0, _utils.isBlank)(value) && _this.state.value !== value) {
|
|
92
|
+
var autoFocus = _this.props.autoFocus;
|
|
93
|
+
// 在值改变了的前提下,如果当前为失焦状态,则触发一次onBlur
|
|
94
|
+
_this.changeValue(value, !autoFocus && document.activeElement !== _this.textareaRef.current);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* 修改value值的回调
|
|
99
|
+
* @param ev
|
|
100
|
+
*/
|
|
101
|
+
_this.onChange = function (ev) {
|
|
102
|
+
if (_this.props.disabled) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
var value = ev.target.value;
|
|
106
|
+
_this.changeValue(value);
|
|
82
107
|
};
|
|
83
108
|
_this.onFocus = function (ev) {
|
|
84
109
|
var _a = _this.props,
|
|
@@ -136,6 +161,9 @@ var TextAreaNotRef = /** @class */function (_super) {
|
|
|
136
161
|
}
|
|
137
162
|
element.focus();
|
|
138
163
|
}
|
|
164
|
+
if (this.props.checkValueOnMounted) {
|
|
165
|
+
this.checkCurrentValue();
|
|
166
|
+
}
|
|
139
167
|
};
|
|
140
168
|
TextAreaNotRef.prototype.renderSuffix = function () {
|
|
141
169
|
var maxLength = this.props.maxLength;
|
|
@@ -154,7 +182,8 @@ var TextAreaNotRef = /** @class */function (_super) {
|
|
|
154
182
|
className = _a.className,
|
|
155
183
|
prefix = _a.prefix,
|
|
156
184
|
rows = _a.rows,
|
|
157
|
-
maxLength = _a.maxLength
|
|
185
|
+
maxLength = _a.maxLength,
|
|
186
|
+
name = _a.name;
|
|
158
187
|
var value = this.state.value;
|
|
159
188
|
return /*#__PURE__*/_react.default.createElement(_Adorn.default, {
|
|
160
189
|
prefixCls: cls,
|
|
@@ -166,11 +195,12 @@ var TextAreaNotRef = /** @class */function (_super) {
|
|
|
166
195
|
suffix: this.renderSuffix()
|
|
167
196
|
}, /*#__PURE__*/_react.default.createElement("textarea", {
|
|
168
197
|
className: "".concat(cls, "-control"),
|
|
169
|
-
ref: (0,
|
|
198
|
+
ref: (0, _components.composeRef)(this.textareaRef, upperRef),
|
|
170
199
|
placeholder: placeholder,
|
|
171
200
|
rows: rows,
|
|
172
201
|
disabled: disabled,
|
|
173
202
|
maxLength: maxLength,
|
|
203
|
+
name: name,
|
|
174
204
|
style: style,
|
|
175
205
|
value: value || '',
|
|
176
206
|
onChange: this.onChange,
|
|
@@ -180,7 +210,8 @@ var TextAreaNotRef = /** @class */function (_super) {
|
|
|
180
210
|
TextAreaNotRef.defaultProps = {
|
|
181
211
|
defaultValue: '',
|
|
182
212
|
rows: 5,
|
|
183
|
-
maxlength: 0
|
|
213
|
+
maxlength: 0,
|
|
214
|
+
checkValueOnMounted: false
|
|
184
215
|
};
|
|
185
216
|
return TextAreaNotRef;
|
|
186
217
|
}(_react.default.Component);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
interface GetParserOriginalValueParams {
|
|
2
|
+
originalValue: string | number;
|
|
3
|
+
prevParserValue: string | number;
|
|
4
|
+
trimStartZero?: boolean;
|
|
5
|
+
precision?: number;
|
|
6
|
+
isRounding?: boolean;
|
|
7
|
+
min?: number;
|
|
8
|
+
max?: number;
|
|
9
|
+
skipError?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param originalValueParam
|
|
14
|
+
* @param trimStartZero
|
|
15
|
+
* @param prevParserValue
|
|
16
|
+
* @param precision
|
|
17
|
+
* @param isRounding
|
|
18
|
+
* @param min
|
|
19
|
+
* @param max
|
|
20
|
+
* @param skipError 遇到首位0、小于最小值、大于最大值问题,不对value进行处理,输出控制台警告
|
|
21
|
+
*/
|
|
22
|
+
export default function ({ originalValue: originalValueParam, trimStartZero, prevParserValue, precision, isRounding, min, max, skipError }: GetParserOriginalValueParams): {
|
|
23
|
+
parserValueStr: string | undefined;
|
|
24
|
+
parserValue: string | number | undefined;
|
|
25
|
+
};
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
var _utils = require("@autobest-ui/utils");
|
|
8
|
+
var _constants = require("./constants");
|
|
9
|
+
function consoleError(msg) {
|
|
10
|
+
if (process.env.NODE_ENV === 'development') {
|
|
11
|
+
// eslint-disable-next-line no-console
|
|
12
|
+
console.error(msg);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function getValueBetweenMinAndMax(value, min, max, skipError) {
|
|
16
|
+
var currentValue = parseFloat(value);
|
|
17
|
+
if (!(0, _utils.isBlank)(min) && currentValue < min) {
|
|
18
|
+
if (!skipError) {
|
|
19
|
+
return min;
|
|
20
|
+
}
|
|
21
|
+
consoleError('Value is smaller than min');
|
|
22
|
+
}
|
|
23
|
+
if (!(0, _utils.isBlank)(max) && currentValue > max) {
|
|
24
|
+
if (!skipError) {
|
|
25
|
+
return max;
|
|
26
|
+
}
|
|
27
|
+
consoleError('Value is greater than max');
|
|
28
|
+
}
|
|
29
|
+
return currentValue;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param originalValueParam
|
|
34
|
+
* @param trimStartZero
|
|
35
|
+
* @param prevParserValue
|
|
36
|
+
* @param precision
|
|
37
|
+
* @param isRounding
|
|
38
|
+
* @param min
|
|
39
|
+
* @param max
|
|
40
|
+
* @param skipError 遇到首位0、小于最小值、大于最大值问题,不对value进行处理,输出控制台警告
|
|
41
|
+
*/
|
|
42
|
+
function _default(_a) {
|
|
43
|
+
var originalValueParam = _a.originalValue,
|
|
44
|
+
trimStartZero = _a.trimStartZero,
|
|
45
|
+
prevParserValue = _a.prevParserValue,
|
|
46
|
+
precision = _a.precision,
|
|
47
|
+
isRounding = _a.isRounding,
|
|
48
|
+
min = _a.min,
|
|
49
|
+
max = _a.max,
|
|
50
|
+
skipError = _a.skipError;
|
|
51
|
+
// 输入为空
|
|
52
|
+
if ((0, _utils.isBlank)(originalValueParam)) {
|
|
53
|
+
return {
|
|
54
|
+
parserValueStr: undefined,
|
|
55
|
+
parserValue: undefined
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
var originalValue = typeof originalValueParam === 'number' ? originalValueParam.toString() : originalValueParam;
|
|
59
|
+
var hasFirstZero = _constants.FirstZeroReg.test(originalValue);
|
|
60
|
+
if (!_constants.NumberReg.test(originalValue) || trimStartZero && hasFirstZero) {
|
|
61
|
+
if (!skipError) {
|
|
62
|
+
return {
|
|
63
|
+
parserValueStr: (0, _utils.isBlank)(prevParserValue) ? undefined : prevParserValue.toString(),
|
|
64
|
+
parserValue: prevParserValue
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
consoleError('Value has first 0');
|
|
68
|
+
}
|
|
69
|
+
var currentValue = getValueBetweenMinAndMax(originalValue, min, max, skipError);
|
|
70
|
+
var parserString = (0, _utils.toFixed)(currentValue, precision, isRounding);
|
|
71
|
+
if (hasFirstZero) {
|
|
72
|
+
// 补齐首位0
|
|
73
|
+
parserString = parserString.padStart(originalValue.split('.')[0].length, '0');
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
parserValueStr: parserString,
|
|
77
|
+
parserValue: hasFirstZero ? parserString : (0, _utils.getNumberFromString)(parserString)
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { AddListenerEventRemoveHandler } from '@autobest-ui/utils';
|
|
3
3
|
import { InputProps, InputValue } from '../input/Input';
|
|
4
|
-
export interface InputNumberProps extends Omit<InputProps<number>, 'value' | 'defaultValue' | 'suffix' | 'onKeyDown'> {
|
|
4
|
+
export interface InputNumberProps extends Omit<InputProps<number | string>, 'value' | 'defaultValue' | 'suffix' | 'onKeyDown'> {
|
|
5
5
|
/**
|
|
6
6
|
* 输入框默认值,用于非受控组件,配合ref使用
|
|
7
7
|
*/
|
|
@@ -42,15 +42,23 @@ export interface InputNumberProps extends Omit<InputProps<number>, 'value' | 'de
|
|
|
42
42
|
* 值发生改变将会触发,onChange是不合法将不在触发,只在最后onBlur时再触发一次
|
|
43
43
|
* 该方法主要用在用户输入内容判断上,不要在此方法中执行修改value的操作
|
|
44
44
|
*/
|
|
45
|
-
onContinualChange?: (originalValue: string | number | undefined, parserValue: number | undefined, name?: string) => void;
|
|
45
|
+
onContinualChange?: (originalValue: string | number | undefined, parserValue: string | number | undefined, name?: string) => void;
|
|
46
46
|
/**
|
|
47
47
|
* 用户触发keydown时的回调,主要用于键盘监听
|
|
48
48
|
*/
|
|
49
|
-
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>, parserValue: number | undefined, name?: string) => void;
|
|
49
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>, parserValue: string | number | undefined, name?: string) => void;
|
|
50
|
+
/**
|
|
51
|
+
* 是否过滤开头的0,默认true过滤
|
|
52
|
+
*/
|
|
53
|
+
trimStartZero?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* 处理用户输入值时是否要四舍五入,默认true
|
|
56
|
+
*/
|
|
57
|
+
isRounding?: boolean;
|
|
50
58
|
}
|
|
51
59
|
interface InputNumberStates {
|
|
52
60
|
originalValueStr: string | undefined;
|
|
53
|
-
parserValue: number | undefined;
|
|
61
|
+
parserValue: string | number | undefined;
|
|
54
62
|
}
|
|
55
63
|
interface InputNumberPropsWithRef extends InputNumberProps {
|
|
56
64
|
/**
|
|
@@ -61,12 +69,14 @@ interface InputNumberPropsWithRef extends InputNumberProps {
|
|
|
61
69
|
export declare class InputNumberNotRef extends React.Component<InputNumberPropsWithRef, InputNumberStates> {
|
|
62
70
|
prefixCls: string;
|
|
63
71
|
inputRef: React.RefObject<HTMLInputElement>;
|
|
64
|
-
keyboardHandler:
|
|
72
|
+
keyboardHandler: AddListenerEventRemoveHandler;
|
|
65
73
|
static defaultProps: {
|
|
66
74
|
defaultValue: string;
|
|
67
75
|
controls: boolean;
|
|
68
76
|
step: number;
|
|
69
77
|
keyboard: boolean;
|
|
78
|
+
trimStartZero: boolean;
|
|
79
|
+
isRounding: boolean;
|
|
70
80
|
};
|
|
71
81
|
constructor(props: InputNumberPropsWithRef);
|
|
72
82
|
static getDerivedStateFromProps(nextProps: InputNumberPropsWithRef, prevStates: InputNumberStates): InputNumberStates;
|
|
@@ -75,7 +85,10 @@ export declare class InputNumberNotRef extends React.Component<InputNumberPropsW
|
|
|
75
85
|
* 解析用户输入的内容,并返回解析后的结果
|
|
76
86
|
* @param originalValue
|
|
77
87
|
*/
|
|
78
|
-
getParserOriginalValue: (originalValue: string) =>
|
|
88
|
+
getParserOriginalValue: (originalValue: string) => {
|
|
89
|
+
parserValueStr: string;
|
|
90
|
+
parserValue: string | number;
|
|
91
|
+
};
|
|
79
92
|
/**
|
|
80
93
|
* 键盘和点击上下按钮更新value值
|
|
81
94
|
* @param isUp
|
|
@@ -7,10 +7,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.InputNumberNotRef = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var _components = require("@autobest-ui/components");
|
|
10
11
|
var _utils = require("@autobest-ui/utils");
|
|
11
12
|
var _Input = _interopRequireDefault(require("../input/Input"));
|
|
12
13
|
var _constants = require("./constants");
|
|
13
14
|
var _ControlArrow = _interopRequireDefault(require("./ControlArrow"));
|
|
15
|
+
var _getParserOriginalValue = _interopRequireDefault(require("./getParserOriginalValue"));
|
|
14
16
|
var __extends = void 0 && (void 0).__extends || function () {
|
|
15
17
|
var _extendStatics = function extendStatics(d, b) {
|
|
16
18
|
_extendStatics = Object.setPrototypeOf || {
|
|
@@ -56,25 +58,10 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
56
58
|
* @param originalValue
|
|
57
59
|
*/
|
|
58
60
|
_this.getParserOriginalValue = function (originalValue) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
if (!_constants.NumberReg.test(originalValue) || _constants.FirstZeroReg.test(originalValue)) {
|
|
64
|
-
return (0, _utils.isBlank)(_this.state.parserValue) ? undefined : _this.state.parserValue.toString();
|
|
65
|
-
}
|
|
66
|
-
var _a = _this.props,
|
|
67
|
-
min = _a.min,
|
|
68
|
-
max = _a.max,
|
|
69
|
-
precision = _a.precision;
|
|
70
|
-
var currentValue = parseFloat(originalValue);
|
|
71
|
-
if (!(0, _utils.isBlank)(min) && currentValue < min) {
|
|
72
|
-
currentValue = min;
|
|
73
|
-
}
|
|
74
|
-
if (!(0, _utils.isBlank)(max) && currentValue > max) {
|
|
75
|
-
currentValue = max;
|
|
76
|
-
}
|
|
77
|
-
return (0, _utils.toFixed)(currentValue, precision);
|
|
61
|
+
return (0, _getParserOriginalValue.default)(__assign(__assign({}, _this.props), {
|
|
62
|
+
originalValue: originalValue,
|
|
63
|
+
prevParserValue: _this.state.parserValue
|
|
64
|
+
}));
|
|
78
65
|
};
|
|
79
66
|
/**
|
|
80
67
|
* 键盘和点击上下按钮更新value值
|
|
@@ -82,14 +69,20 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
82
69
|
*/
|
|
83
70
|
_this.changeValueWithStep = function (isUp) {
|
|
84
71
|
var step = _this.props.step;
|
|
85
|
-
var
|
|
72
|
+
var prevParserValue = _this.state.parserValue;
|
|
73
|
+
var prevValue = prevParserValue ? typeof prevParserValue === 'number' ? prevParserValue : parseFloat(prevParserValue) : 0;
|
|
86
74
|
var keyboardValue = isUp ? prevValue + step : prevValue - step;
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
var keyboardValueStr = keyboardValue.toString();
|
|
76
|
+
if (typeof prevParserValue === 'string' && _constants.FirstZeroReg.test(prevParserValue)) {
|
|
77
|
+
keyboardValueStr = keyboardValueStr.padStart(prevParserValue.length, '0');
|
|
78
|
+
}
|
|
79
|
+
var _a = _this.getParserOriginalValue(keyboardValueStr),
|
|
80
|
+
parserValueStr = _a.parserValueStr,
|
|
81
|
+
parserValue = _a.parserValue;
|
|
82
|
+
var _b = _this.props,
|
|
83
|
+
name = _b.name,
|
|
84
|
+
onChange = _b.onChange,
|
|
85
|
+
onContinualChange = _b.onContinualChange;
|
|
93
86
|
if (prevValue !== parserValue) {
|
|
94
87
|
if (onContinualChange) {
|
|
95
88
|
onContinualChange(parserValueStr, parserValue, name);
|
|
@@ -130,14 +123,13 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
130
123
|
}
|
|
131
124
|
var onFocus = _this.props.onFocus;
|
|
132
125
|
if (onFocus) {
|
|
133
|
-
var
|
|
134
|
-
var parserValue = (0, _utils.getNumberFromString)(parserValueStr);
|
|
126
|
+
var parserValue = _this.getParserOriginalValue(originalValueStr).parserValue;
|
|
135
127
|
onFocus(parserValue, name);
|
|
136
128
|
}
|
|
137
129
|
};
|
|
138
130
|
_this.onBlur = function (originalValueStr, name) {
|
|
139
131
|
if (_this.keyboardHandler) {
|
|
140
|
-
_this.keyboardHandler
|
|
132
|
+
_this.keyboardHandler();
|
|
141
133
|
_this.keyboardHandler = null;
|
|
142
134
|
}
|
|
143
135
|
if (_this.props.disabled) {
|
|
@@ -147,8 +139,9 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
147
139
|
onBlur = _a.onBlur,
|
|
148
140
|
onChange = _a.onChange,
|
|
149
141
|
onContinualChange = _a.onContinualChange;
|
|
150
|
-
var
|
|
151
|
-
|
|
142
|
+
var _b = _this.getParserOriginalValue(originalValueStr),
|
|
143
|
+
parserValueStr = _b.parserValueStr,
|
|
144
|
+
parserValue = _b.parserValue;
|
|
152
145
|
_this.setState({
|
|
153
146
|
originalValueStr: parserValueStr
|
|
154
147
|
});
|
|
@@ -178,11 +171,12 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
178
171
|
if (_this.props.disabled) {
|
|
179
172
|
return;
|
|
180
173
|
}
|
|
181
|
-
var
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
174
|
+
var _a = _this.getParserOriginalValue(originalValueStr),
|
|
175
|
+
parserValueStr = _a.parserValueStr,
|
|
176
|
+
parserValue = _a.parserValue;
|
|
177
|
+
var _b = _this.props,
|
|
178
|
+
onChange = _b.onChange,
|
|
179
|
+
onContinualChange = _b.onContinualChange;
|
|
186
180
|
if (onContinualChange) {
|
|
187
181
|
onContinualChange(originalValueStr, parserValue, name);
|
|
188
182
|
}
|
|
@@ -226,10 +220,16 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
226
220
|
onKeyDown(ev, _this.state.parserValue, name);
|
|
227
221
|
}
|
|
228
222
|
};
|
|
229
|
-
var
|
|
223
|
+
var _a = (0, _getParserOriginalValue.default)(__assign(__assign({}, props), {
|
|
224
|
+
originalValue: props.defaultValue,
|
|
225
|
+
prevParserValue: undefined,
|
|
226
|
+
skipError: true
|
|
227
|
+
})),
|
|
228
|
+
parserValueStr = _a.parserValueStr,
|
|
229
|
+
parserValue = _a.parserValue;
|
|
230
230
|
_this.state = {
|
|
231
|
-
originalValueStr:
|
|
232
|
-
parserValue:
|
|
231
|
+
originalValueStr: parserValueStr,
|
|
232
|
+
parserValue: parserValue
|
|
233
233
|
};
|
|
234
234
|
return _this;
|
|
235
235
|
}
|
|
@@ -240,9 +240,15 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
240
240
|
if (nextProps.value !== prevStates.parserValue && (
|
|
241
241
|
// 兼容外部传入空string/null的情况, 只有当一个值非空时,才会重新重置State信息
|
|
242
242
|
!(0, _utils.isBlank)(nextProps.value) || !(0, _utils.isBlank)(prevStates.parserValue))) {
|
|
243
|
-
var
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
var _a = (0, _getParserOriginalValue.default)(__assign(__assign({}, nextProps), {
|
|
244
|
+
originalValue: nextProps.value,
|
|
245
|
+
prevParserValue: prevStates.parserValue,
|
|
246
|
+
skipError: true
|
|
247
|
+
})),
|
|
248
|
+
parserValueStr = _a.parserValueStr,
|
|
249
|
+
parserValue = _a.parserValue;
|
|
250
|
+
nextState.parserValue = parserValue;
|
|
251
|
+
nextState.originalValueStr = parserValueStr;
|
|
246
252
|
}
|
|
247
253
|
}
|
|
248
254
|
if ((0, _utils.isEmptyObject)(nextState)) {
|
|
@@ -252,7 +258,7 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
252
258
|
};
|
|
253
259
|
InputNumberNotRef.prototype.componentWillUnmount = function () {
|
|
254
260
|
if (this.keyboardHandler) {
|
|
255
|
-
this.keyboardHandler
|
|
261
|
+
this.keyboardHandler();
|
|
256
262
|
this.keyboardHandler = null;
|
|
257
263
|
}
|
|
258
264
|
};
|
|
@@ -267,10 +273,12 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
267
273
|
disabled = _b.disabled,
|
|
268
274
|
style = _b.style,
|
|
269
275
|
prefix = _b.prefix,
|
|
270
|
-
controls = _b.controls
|
|
276
|
+
controls = _b.controls,
|
|
277
|
+
checkValueOnMounted = _b.checkValueOnMounted,
|
|
278
|
+
maxLength = _b.maxLength;
|
|
271
279
|
var originalValueStr = this.state.originalValueStr;
|
|
272
280
|
return /*#__PURE__*/_react.default.createElement(_Input.default, {
|
|
273
|
-
ref: (0,
|
|
281
|
+
ref: (0, _components.composeRef)(this.inputRef, upperRef),
|
|
274
282
|
className: (0, _classnames.default)(cls, className, (_a = {}, _a["".concat(cls, "-has-controls")] = controls, _a)),
|
|
275
283
|
placeholder: placeholder,
|
|
276
284
|
disabled: disabled,
|
|
@@ -286,14 +294,18 @@ var InputNumberNotRef = /** @class */function (_super) {
|
|
|
286
294
|
cls: cls,
|
|
287
295
|
onUp: this.onUp,
|
|
288
296
|
onDown: this.onDown
|
|
289
|
-
}) : null
|
|
297
|
+
}) : null,
|
|
298
|
+
checkValueOnMounted: checkValueOnMounted,
|
|
299
|
+
maxLength: maxLength
|
|
290
300
|
});
|
|
291
301
|
};
|
|
292
302
|
InputNumberNotRef.defaultProps = {
|
|
293
303
|
defaultValue: '',
|
|
294
304
|
controls: true,
|
|
295
305
|
step: 1,
|
|
296
|
-
keyboard: true
|
|
306
|
+
keyboard: true,
|
|
307
|
+
trimStartZero: true,
|
|
308
|
+
isRounding: true
|
|
297
309
|
};
|
|
298
310
|
return InputNumberNotRef;
|
|
299
311
|
}(_react.default.Component);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 按照给定的模板(111-222-333)格式化数字形式电话号码(111222333)
|
|
3
|
+
* @param value
|
|
4
|
+
* @param format
|
|
5
|
+
* @param placeholder
|
|
6
|
+
*/
|
|
7
|
+
export declare function getPhoneFormat(value: any, format: any, placeholder: any): any;
|
|
8
|
+
/**
|
|
9
|
+
* 删除字符串中非数字内容
|
|
10
|
+
* @param value
|
|
11
|
+
*/
|
|
12
|
+
export declare function getNumberValue(value: any): any;
|
|
13
|
+
export declare function getFirstCursorPosition(value: any, format: string, placeholder: any): any;
|
|
14
|
+
export declare function getUpdatedValue({ value, prevValue, format, selectionEnd, placeholder }: {
|
|
15
|
+
value: any;
|
|
16
|
+
prevValue: any;
|
|
17
|
+
format: any;
|
|
18
|
+
selectionEnd: any;
|
|
19
|
+
placeholder: any;
|
|
20
|
+
}): {
|
|
21
|
+
value: any;
|
|
22
|
+
cursorPosition: any;
|
|
23
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFirstCursorPosition = getFirstCursorPosition;
|
|
7
|
+
exports.getNumberValue = getNumberValue;
|
|
8
|
+
exports.getPhoneFormat = getPhoneFormat;
|
|
9
|
+
exports.getUpdatedValue = getUpdatedValue;
|
|
10
|
+
var _utils = require("@autobest-ui/utils");
|
|
11
|
+
/**
|
|
12
|
+
* 按照给定的模板(111-222-333)格式化数字形式电话号码(111222333)
|
|
13
|
+
* @param value
|
|
14
|
+
* @param format
|
|
15
|
+
* @param placeholder
|
|
16
|
+
*/
|
|
17
|
+
function getPhoneFormat(value, format, placeholder) {
|
|
18
|
+
var defaultValueArr = getNumberValue(value).split('');
|
|
19
|
+
return format.replace(/\d/g, function () {
|
|
20
|
+
return defaultValueArr.shift() || placeholder;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 删除字符串中非数字内容
|
|
25
|
+
* @param value
|
|
26
|
+
*/
|
|
27
|
+
function getNumberValue(value) {
|
|
28
|
+
if ((0, _utils.isBlank)(value)) {
|
|
29
|
+
return '';
|
|
30
|
+
}
|
|
31
|
+
return value.replace(/[^\d]/g, '');
|
|
32
|
+
}
|
|
33
|
+
function getFirstCursorPosition(value, format, placeholder) {
|
|
34
|
+
if ((0, _utils.isBlank)(value)) {
|
|
35
|
+
return format.search(/\d/);
|
|
36
|
+
}
|
|
37
|
+
var match;
|
|
38
|
+
while ((match = new RegExp(placeholder, 'g').exec(value)) !== null) {
|
|
39
|
+
if (match[0] !== format[match.index]) {
|
|
40
|
+
return match.index;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return value.length;
|
|
44
|
+
}
|
|
45
|
+
function getDifferIndex(value, prevValue) {
|
|
46
|
+
for (var i = 0, l = Math.max(value.length, prevValue.length); i < l; i++) {
|
|
47
|
+
if (value[i] !== prevValue[i]) {
|
|
48
|
+
return i;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return prevValue.length;
|
|
52
|
+
}
|
|
53
|
+
function getSlice(str, start, end) {
|
|
54
|
+
if (!end) {
|
|
55
|
+
return str.slice(start);
|
|
56
|
+
}
|
|
57
|
+
return str.slice(start, end);
|
|
58
|
+
}
|
|
59
|
+
function getUpdatedValue(_a) {
|
|
60
|
+
var value = _a.value,
|
|
61
|
+
prevValue = _a.prevValue,
|
|
62
|
+
format = _a.format,
|
|
63
|
+
selectionEnd = _a.selectionEnd,
|
|
64
|
+
placeholder = _a.placeholder;
|
|
65
|
+
if ((0, _utils.isBlank)(value)) {
|
|
66
|
+
return {
|
|
67
|
+
value: getPhoneFormat('', format, placeholder),
|
|
68
|
+
cursorPosition: getFirstCursorPosition('', format, placeholder)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
var lastCursorIndex = (value.length - selectionEnd) * -1;
|
|
72
|
+
var differIndex = getDifferIndex(getSlice(value, 0, lastCursorIndex), getSlice(prevValue, 0, lastCursorIndex));
|
|
73
|
+
var differNumberArr = getNumberValue(getSlice(value, differIndex, lastCursorIndex)).split('');
|
|
74
|
+
var cursorPosition = differIndex;
|
|
75
|
+
var endIndex = format.length + lastCursorIndex;
|
|
76
|
+
var formatValue = format.replace(/\d/g, function (_match, index) {
|
|
77
|
+
if (index < differIndex) {
|
|
78
|
+
return prevValue[index];
|
|
79
|
+
}
|
|
80
|
+
if (!differNumberArr.length) {
|
|
81
|
+
return index >= endIndex ? prevValue[index] : placeholder;
|
|
82
|
+
}
|
|
83
|
+
cursorPosition = index + 1;
|
|
84
|
+
return differNumberArr.shift();
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
value: formatValue,
|
|
88
|
+
cursorPosition: cursorPosition
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { InputProps } from '../input/Input';
|
|
3
|
+
export interface InputPhoneProps extends Omit<InputProps<string>, 'onFocus' | 'onBlur' | 'onChange'> {
|
|
4
|
+
/**
|
|
5
|
+
* 输入框是否可以操作
|
|
6
|
+
*/
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* 号码显示格式,以任意数字代替需要填入的数字位置
|
|
10
|
+
* 默认为(111)111-1111,表示会显示(xxx)xxx-xxxx格式的号码
|
|
11
|
+
*/
|
|
12
|
+
format?: string;
|
|
13
|
+
/**
|
|
14
|
+
* 数字未填时的留空字符,默认为_
|
|
15
|
+
*/
|
|
16
|
+
placeholderChar?: string;
|
|
17
|
+
/**
|
|
18
|
+
* 获得焦点的回调函数
|
|
19
|
+
* formatValue: 显示在输入框中的格式化后的电话号码
|
|
20
|
+
* phoneValue: 纯数字电话号码
|
|
21
|
+
*/
|
|
22
|
+
onFocus?: (formatValue: string, phoneValue: string, name?: string) => void;
|
|
23
|
+
/**
|
|
24
|
+
* 失去焦点的回调函数
|
|
25
|
+
* formatValue: 显示在输入框中的格式化后的电话号码
|
|
26
|
+
* phoneValue: 纯数字电话号码
|
|
27
|
+
*/
|
|
28
|
+
onBlur?: (formatValue: string, phoneValue: string, name?: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* 值修改后的回调函数,用于修改value属性
|
|
31
|
+
* formatValue: 显示在输入框中的格式化后的电话号码
|
|
32
|
+
* phoneValue: 纯数字电话号码
|
|
33
|
+
*/
|
|
34
|
+
onChange?: (formatValue: string, phoneValue: string, name?: string) => void;
|
|
35
|
+
}
|
|
36
|
+
interface InputPhoneState {
|
|
37
|
+
formatValue: string;
|
|
38
|
+
}
|
|
39
|
+
interface InputPhonePropsWithRef extends InputPhoneProps {
|
|
40
|
+
/**
|
|
41
|
+
* 此属性可以忽略, storybook问题
|
|
42
|
+
*/
|
|
43
|
+
upperRef: React.Ref<HTMLInputElement>;
|
|
44
|
+
}
|
|
45
|
+
export declare class InputPhoneNotRef extends React.Component<InputPhonePropsWithRef, InputPhoneState> {
|
|
46
|
+
prefixCls: string;
|
|
47
|
+
inputRef: React.RefObject<HTMLInputElement>;
|
|
48
|
+
prevFormatValue: string;
|
|
49
|
+
static defaultProps: {
|
|
50
|
+
defaultValue: string;
|
|
51
|
+
format: string;
|
|
52
|
+
placeholderChar: string;
|
|
53
|
+
};
|
|
54
|
+
constructor(props: InputPhonePropsWithRef);
|
|
55
|
+
static getDerivedStateFromProps(nextProps: InputPhoneProps, prevState: InputPhoneState): {
|
|
56
|
+
formatValue: any;
|
|
57
|
+
};
|
|
58
|
+
setInputCursor: (cursorPosition: any, timeout?: number) => void;
|
|
59
|
+
onFocus: (inputValue: string, name?: string) => void;
|
|
60
|
+
onBlur: (inputValue: string, name?: string) => void;
|
|
61
|
+
onChange: (inputValue: string, name?: string) => void;
|
|
62
|
+
render(): JSX.Element;
|
|
63
|
+
}
|
|
64
|
+
declare const InputPhone: React.ForwardRefExoticComponent<InputPhoneProps & React.RefAttributes<HTMLInputElement>>;
|
|
65
|
+
export default InputPhone;
|