@autobest-ui/components 2.9.2 → 2.10.0-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 +6 -3
- package/esm/index.js +4 -2
- package/esm/input/Input.d.ts +13 -1
- package/esm/input/Input.js +64 -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/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 +6 -3
- package/lib/index.js +40 -2
- package/lib/input/Input.d.ts +13 -1
- package/lib/input/Input.js +64 -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/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/index.js
CHANGED
|
@@ -26,7 +26,13 @@ Object.defineProperty(exports, "Carousel", {
|
|
|
26
26
|
Object.defineProperty(exports, "Checkbox", {
|
|
27
27
|
enumerable: true,
|
|
28
28
|
get: function get() {
|
|
29
|
-
return _checkbox.
|
|
29
|
+
return _checkbox.Checkbox;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "CheckboxGroup", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _checkbox.CheckboxGroup;
|
|
30
36
|
}
|
|
31
37
|
});
|
|
32
38
|
Object.defineProperty(exports, "Collapse", {
|
|
@@ -137,6 +143,18 @@ Object.defineProperty(exports, "Popover", {
|
|
|
137
143
|
return _popover.default;
|
|
138
144
|
}
|
|
139
145
|
});
|
|
146
|
+
Object.defineProperty(exports, "Radio", {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
get: function get() {
|
|
149
|
+
return _radio.Radio;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
Object.defineProperty(exports, "RadioGroup", {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
get: function get() {
|
|
155
|
+
return _radio.RadioGroup;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
140
158
|
Object.defineProperty(exports, "Script", {
|
|
141
159
|
enumerable: true,
|
|
142
160
|
get: function get() {
|
|
@@ -185,12 +203,30 @@ Object.defineProperty(exports, "Trigger", {
|
|
|
185
203
|
return _trigger.default;
|
|
186
204
|
}
|
|
187
205
|
});
|
|
206
|
+
Object.defineProperty(exports, "composeRef", {
|
|
207
|
+
enumerable: true,
|
|
208
|
+
get: function get() {
|
|
209
|
+
return _ref.composeRef;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
Object.defineProperty(exports, "fillRef", {
|
|
213
|
+
enumerable: true,
|
|
214
|
+
get: function get() {
|
|
215
|
+
return _ref.fillRef;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
188
218
|
Object.defineProperty(exports, "message", {
|
|
189
219
|
enumerable: true,
|
|
190
220
|
get: function get() {
|
|
191
221
|
return _message.default;
|
|
192
222
|
}
|
|
193
223
|
});
|
|
224
|
+
Object.defineProperty(exports, "supportRef", {
|
|
225
|
+
enumerable: true,
|
|
226
|
+
get: function get() {
|
|
227
|
+
return _ref.supportRef;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
194
230
|
var _accordion = _interopRequireDefault(require("./accordion"));
|
|
195
231
|
var _ellipsis = _interopRequireDefault(require("./ellipsis"));
|
|
196
232
|
var _affix = _interopRequireDefault(require("./affix"));
|
|
@@ -209,7 +245,7 @@ var _input = require("./input");
|
|
|
209
245
|
var _inputNumber = _interopRequireDefault(require("./input-number"));
|
|
210
246
|
var _lazyImage = _interopRequireDefault(require("./lazy-image"));
|
|
211
247
|
var _linkList = _interopRequireDefault(require("./link-list"));
|
|
212
|
-
var _checkbox =
|
|
248
|
+
var _checkbox = require("./checkbox");
|
|
213
249
|
var _script = _interopRequireDefault(require("./script"));
|
|
214
250
|
var _message = _interopRequireWildcard(require("./message"));
|
|
215
251
|
var _table = _interopRequireDefault(require("./table"));
|
|
@@ -220,5 +256,7 @@ var _loadingContainer = _interopRequireDefault(require("./loading-container"));
|
|
|
220
256
|
var _loadingBar = _interopRequireDefault(require("./loading-bar"));
|
|
221
257
|
var _loadingIcon = _interopRequireDefault(require("./loading-icon"));
|
|
222
258
|
var _trigger = _interopRequireDefault(require("./trigger"));
|
|
259
|
+
var _ref = require("./trigger/ref");
|
|
260
|
+
var _radio = require("./radio");
|
|
223
261
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
224
262
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
package/lib/input/Input.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { AdornProps } from './Adorn';
|
|
3
3
|
export declare type InputValue = string | File | undefined;
|
|
4
|
-
export interface InputProps<T = InputValue> extends Omit<AdornProps, 'prefixCls' | 'children' | 'onBlur' | 'onFocus'>, Pick<React.InputHTMLAttributes<any>, 'placeholder' | 'style' | 'maxLength' | 'type' | 'accept'> {
|
|
4
|
+
export interface InputProps<T = InputValue> extends Omit<AdornProps, 'prefixCls' | 'children' | 'onBlur' | 'onFocus'>, Pick<React.InputHTMLAttributes<any>, 'placeholder' | 'style' | 'maxLength' | 'type' | 'accept' | 'title' | 'aria-label' | 'onKeyUp'> {
|
|
5
5
|
/**
|
|
6
6
|
* 输入框默认值,用于非受控组件,配合ref使用
|
|
7
7
|
*/
|
|
@@ -34,6 +34,11 @@ export interface InputProps<T = InputValue> extends Omit<AdornProps, 'prefixCls'
|
|
|
34
34
|
* 用户触发keydown时的回调,主要用于键盘监听
|
|
35
35
|
*/
|
|
36
36
|
onKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>, name?: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* 在网络慢时,组件已经渲染js文件还未加载,用户此时修改input框会不触发onChange事件
|
|
39
|
+
* 需要在组件加载后检测输入框内容,触发一次onChange
|
|
40
|
+
*/
|
|
41
|
+
checkValueOnMounted?: boolean;
|
|
37
42
|
}
|
|
38
43
|
interface InputStates {
|
|
39
44
|
value: string | undefined;
|
|
@@ -50,12 +55,19 @@ export declare class InputNotRef extends React.Component<InputPropsWithRef, Inpu
|
|
|
50
55
|
static defaultProps: {
|
|
51
56
|
defaultValue: string;
|
|
52
57
|
type: string;
|
|
58
|
+
checkValueOnMounted: boolean;
|
|
53
59
|
};
|
|
54
60
|
constructor(props: InputPropsWithRef);
|
|
55
61
|
static getDerivedStateFromProps(nextProps: InputPropsWithRef, prevStates: InputStates): InputStates;
|
|
56
62
|
componentDidMount(): void;
|
|
57
63
|
isFileUpload: () => boolean;
|
|
58
64
|
getFileInfo: (element: HTMLInputElement) => File;
|
|
65
|
+
/**
|
|
66
|
+
* 在触发了onChange的前提下,如果当前为失焦状态,则触发一次onBlur
|
|
67
|
+
* @param value
|
|
68
|
+
*/
|
|
69
|
+
onBlurOnMounted: (value: any) => void;
|
|
70
|
+
checkCurrentValue: () => void;
|
|
59
71
|
/**
|
|
60
72
|
* 修改value值的回调
|
|
61
73
|
* @param ev
|
package/lib/input/Input.js
CHANGED
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.InputNotRef = void 0;
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _utils = require("@autobest-ui/utils");
|
|
10
|
+
var _components = require("@autobest-ui/components");
|
|
10
11
|
var _Adorn = _interopRequireDefault(require("./Adorn"));
|
|
11
12
|
var __extends = void 0 && (void 0).__extends || function () {
|
|
12
13
|
var _extendStatics = function extendStatics(d, b) {
|
|
@@ -54,6 +55,53 @@ var InputNotRef = /** @class */function (_super) {
|
|
|
54
55
|
_this.getFileInfo = function (element) {
|
|
55
56
|
return element && element.files && element.files.length ? element.files[0] : undefined;
|
|
56
57
|
};
|
|
58
|
+
/**
|
|
59
|
+
* 在触发了onChange的前提下,如果当前为失焦状态,则触发一次onBlur
|
|
60
|
+
* @param value
|
|
61
|
+
*/
|
|
62
|
+
_this.onBlurOnMounted = function (value) {
|
|
63
|
+
var _a = _this.props,
|
|
64
|
+
onBlur = _a.onBlur,
|
|
65
|
+
autoFocus = _a.autoFocus,
|
|
66
|
+
name = _a.name;
|
|
67
|
+
if (!onBlur || autoFocus || document.activeElement === _this.inputRef.current) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
onBlur(value, name);
|
|
71
|
+
};
|
|
72
|
+
_this.checkCurrentValue = function () {
|
|
73
|
+
if (!_this.inputRef.current) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (_this.isFileUpload()) {
|
|
77
|
+
var file = _this.getFileInfo(_this.inputRef.current);
|
|
78
|
+
if (file) {
|
|
79
|
+
var _a = _this.props,
|
|
80
|
+
name_1 = _a.name,
|
|
81
|
+
onChange = _a.onChange;
|
|
82
|
+
if (onChange) {
|
|
83
|
+
onChange(file, name_1);
|
|
84
|
+
}
|
|
85
|
+
_this.onBlurOnMounted(file);
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
var value = _this.inputRef.current.value;
|
|
90
|
+
if (!(0, _utils.isBlank)(value) && _this.state.value !== value) {
|
|
91
|
+
var _b = _this.props,
|
|
92
|
+
name_2 = _b.name,
|
|
93
|
+
onChange = _b.onChange;
|
|
94
|
+
if (onChange) {
|
|
95
|
+
onChange(value, name_2);
|
|
96
|
+
_this.onBlurOnMounted(value);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
_this.setState({
|
|
100
|
+
value: value
|
|
101
|
+
});
|
|
102
|
+
_this.onBlurOnMounted(value);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
57
105
|
/**
|
|
58
106
|
* 修改value值的回调
|
|
59
107
|
* @param ev
|
|
@@ -145,6 +193,10 @@ var InputNotRef = /** @class */function (_super) {
|
|
|
145
193
|
}
|
|
146
194
|
element.focus();
|
|
147
195
|
}
|
|
196
|
+
if (this.props.checkValueOnMounted) {
|
|
197
|
+
// ssr在网络慢时,用户在js文件加载完前修改input框的会导致不触发onChange
|
|
198
|
+
this.checkCurrentValue();
|
|
199
|
+
}
|
|
148
200
|
};
|
|
149
201
|
InputNotRef.prototype.render = function () {
|
|
150
202
|
var cls = this.prefixCls;
|
|
@@ -158,7 +210,10 @@ var InputNotRef = /** @class */function (_super) {
|
|
|
158
210
|
className = _a.className,
|
|
159
211
|
prefix = _a.prefix,
|
|
160
212
|
suffix = _a.suffix,
|
|
161
|
-
maxLength = _a.maxLength
|
|
213
|
+
maxLength = _a.maxLength,
|
|
214
|
+
title = _a.title,
|
|
215
|
+
onKeyUp = _a.onKeyUp,
|
|
216
|
+
name = _a.name;
|
|
162
217
|
var value = this.state.value;
|
|
163
218
|
var isFileUpload = this.isFileUpload();
|
|
164
219
|
return /*#__PURE__*/_react.default.createElement(_Adorn.default, {
|
|
@@ -171,21 +226,26 @@ var InputNotRef = /** @class */function (_super) {
|
|
|
171
226
|
suffix: suffix
|
|
172
227
|
}, /*#__PURE__*/_react.default.createElement("input", {
|
|
173
228
|
className: "".concat(cls, "-control"),
|
|
174
|
-
ref: (0,
|
|
229
|
+
ref: (0, _components.composeRef)(this.inputRef, upperRef),
|
|
175
230
|
type: type,
|
|
176
231
|
placeholder: placeholder,
|
|
177
232
|
disabled: disabled,
|
|
178
233
|
accept: accept,
|
|
179
234
|
maxLength: maxLength,
|
|
180
235
|
style: style,
|
|
236
|
+
name: name,
|
|
181
237
|
value: isFileUpload ? undefined : value || '',
|
|
182
238
|
onChange: this.onChange,
|
|
183
|
-
onKeyDown: this.onKeyDown
|
|
239
|
+
onKeyDown: this.onKeyDown,
|
|
240
|
+
title: title,
|
|
241
|
+
onKeyUp: onKeyUp,
|
|
242
|
+
"aria-label": this.props['aria-label']
|
|
184
243
|
}));
|
|
185
244
|
};
|
|
186
245
|
InputNotRef.defaultProps = {
|
|
187
246
|
defaultValue: '',
|
|
188
|
-
type: 'text'
|
|
247
|
+
type: 'text',
|
|
248
|
+
checkValueOnMounted: false
|
|
189
249
|
};
|
|
190
250
|
return InputNotRef;
|
|
191
251
|
}(_react.default.Component);
|
package/lib/input/TextArea.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ export interface TextAreaProps extends Omit<AdornProps, 'prefixCls' | 'children'
|
|
|
33
33
|
* 用户触发keydown时的回调,主要用于键盘监听
|
|
34
34
|
*/
|
|
35
35
|
onKeyDown?: (event: React.KeyboardEvent<HTMLTextAreaElement>, name?: string) => void;
|
|
36
|
+
/**
|
|
37
|
+
* 在网络慢时,组件已经渲染js文件还未加载,用户此时修改input框会不触发onChange事件
|
|
38
|
+
* 需要在组件加载后检测输入框内容,触发一次onChange
|
|
39
|
+
*/
|
|
40
|
+
checkValueOnMounted?: boolean;
|
|
36
41
|
}
|
|
37
42
|
interface TextareaStates {
|
|
38
43
|
value: string | undefined;
|
|
@@ -51,10 +56,13 @@ export declare class TextAreaNotRef extends React.Component<TextAreaPropsWithRef
|
|
|
51
56
|
defaultValue: string;
|
|
52
57
|
rows: number;
|
|
53
58
|
maxlength: number;
|
|
59
|
+
checkValueOnMounted: boolean;
|
|
54
60
|
};
|
|
55
61
|
constructor(props: TextAreaPropsWithRef);
|
|
56
62
|
static getDerivedStateFromProps(nextProps: TextAreaPropsWithRef, prevStates: TextareaStates): TextareaStates;
|
|
57
63
|
componentDidMount(): void;
|
|
64
|
+
changeValue: (value: any, onBlurAfterChange?: boolean) => void;
|
|
65
|
+
checkCurrentValue: () => void;
|
|
58
66
|
/**
|
|
59
67
|
* 修改value值的回调
|
|
60
68
|
* @param ev
|
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
|