|
@@ -10,13 +10,13 @@ import Input, { InputProps } from '../input';
|
|
|
import { forwardStatics } from '@douyinfe/semi-foundation/utils/object';
|
|
import { forwardStatics } from '@douyinfe/semi-foundation/utils/object';
|
|
|
import isNullOrUndefined from '@douyinfe/semi-foundation/utils/isNullOrUndefined';
|
|
import isNullOrUndefined from '@douyinfe/semi-foundation/utils/isNullOrUndefined';
|
|
|
import isBothNaN from '@douyinfe/semi-foundation/utils/isBothNaN';
|
|
import isBothNaN from '@douyinfe/semi-foundation/utils/isBothNaN';
|
|
|
-import InputNumberFoundation, { InputNumberAdapter } from '@douyinfe/semi-foundation/inputNumber/foundation';
|
|
|
|
|
|
|
+import InputNumberFoundation, { BaseInputNumberState, InputNumberAdapter } from '@douyinfe/semi-foundation/inputNumber/foundation';
|
|
|
import BaseComponent from '../_base/baseComponent';
|
|
import BaseComponent from '../_base/baseComponent';
|
|
|
import { cssClasses, numbers, strings } from '@douyinfe/semi-foundation/inputNumber/constants';
|
|
import { cssClasses, numbers, strings } from '@douyinfe/semi-foundation/inputNumber/constants';
|
|
|
import { IconChevronUp, IconChevronDown } from '@douyinfe/semi-icons';
|
|
import { IconChevronUp, IconChevronDown } from '@douyinfe/semi-icons';
|
|
|
|
|
|
|
|
import '@douyinfe/semi-foundation/inputNumber/inputNumber.scss';
|
|
import '@douyinfe/semi-foundation/inputNumber/inputNumber.scss';
|
|
|
-import { isNaN, noop } from 'lodash';
|
|
|
|
|
|
|
+import { isNaN, isString, noop } from 'lodash';
|
|
|
import { ArrayElement } from '../_base/base';
|
|
import { ArrayElement } from '../_base/base';
|
|
|
|
|
|
|
|
export interface InputNumberProps extends InputProps {
|
|
export interface InputNumberProps extends InputProps {
|
|
@@ -54,12 +54,7 @@ export interface InputNumberProps extends InputProps {
|
|
|
onUpClick?: (value: string, e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
onUpClick?: (value: string, e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export interface InputNumberState {
|
|
|
|
|
- value?: number | string;
|
|
|
|
|
- number?: number | null; // Current parsed numbers
|
|
|
|
|
- focusing?: boolean;
|
|
|
|
|
- hovering?: boolean;
|
|
|
|
|
-}
|
|
|
|
|
|
|
+export interface InputNumberState extends BaseInputNumberState {}
|
|
|
|
|
|
|
|
class InputNumber extends BaseComponent<InputNumberProps, InputNumberState> {
|
|
class InputNumber extends BaseComponent<InputNumberProps, InputNumberState> {
|
|
|
static propTypes = {
|
|
static propTypes = {
|
|
@@ -222,6 +217,9 @@ class InputNumber extends BaseComponent<InputNumberProps, InputNumberState> {
|
|
|
},
|
|
},
|
|
|
setClickUpOrDown: value => {
|
|
setClickUpOrDown: value => {
|
|
|
this.clickUpOrDown = value;
|
|
this.clickUpOrDown = value;
|
|
|
|
|
+ },
|
|
|
|
|
+ updateStates: (states, callback) => {
|
|
|
|
|
+ this.setState(states, callback);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
@@ -250,13 +248,15 @@ class InputNumber extends BaseComponent<InputNumberProps, InputNumberState> {
|
|
|
componentDidUpdate(prevProps: InputNumberProps) {
|
|
componentDidUpdate(prevProps: InputNumberProps) {
|
|
|
const { value } = this.props;
|
|
const { value } = this.props;
|
|
|
const { focusing } = this.state;
|
|
const { focusing } = this.state;
|
|
|
|
|
+ let newValue;
|
|
|
/**
|
|
/**
|
|
|
* To determine whether the front and back are equal
|
|
* To determine whether the front and back are equal
|
|
|
* NaN need to check whether both are NaN
|
|
* NaN need to check whether both are NaN
|
|
|
*/
|
|
*/
|
|
|
if (value !== prevProps.value && !isBothNaN(value, prevProps.value)) {
|
|
if (value !== prevProps.value && !isBothNaN(value, prevProps.value)) {
|
|
|
if (isNullOrUndefined(value) || value === '') {
|
|
if (isNullOrUndefined(value) || value === '') {
|
|
|
- this.setState({ value: '', number: null });
|
|
|
|
|
|
|
+ newValue = '';
|
|
|
|
|
+ this.foundation.updateStates({ value: newValue, number: null });
|
|
|
} else {
|
|
} else {
|
|
|
let valueStr = value;
|
|
let valueStr = value;
|
|
|
if (typeof value === 'number') {
|
|
if (typeof value === 'number') {
|
|
@@ -306,22 +306,30 @@ class InputNumber extends BaseComponent<InputNumberProps, InputNumberState> {
|
|
|
*/
|
|
*/
|
|
|
if (this.clickUpOrDown) {
|
|
if (this.clickUpOrDown) {
|
|
|
obj.value = this.foundation.doFormat(valueStr, true);
|
|
obj.value = this.foundation.doFormat(valueStr, true);
|
|
|
|
|
+ newValue = obj.value;
|
|
|
}
|
|
}
|
|
|
- this.setState(obj, () => this.adapter.restoreCursor());
|
|
|
|
|
|
|
+ this.foundation.updateStates(obj, () => this.adapter.restoreCursor());
|
|
|
} else if (!isNaN(toNum)) {
|
|
} else if (!isNaN(toNum)) {
|
|
|
// Update input content when controlled input is illegal and not NaN
|
|
// Update input content when controlled input is illegal and not NaN
|
|
|
- this.setState({ value: this.foundation.doFormat(toNum, false) });
|
|
|
|
|
|
|
+ newValue = this.foundation.doFormat(toNum, false);
|
|
|
|
|
+ this.foundation.updateStates({ value: newValue });
|
|
|
} else {
|
|
} else {
|
|
|
// Update input content when controlled input NaN
|
|
// Update input content when controlled input NaN
|
|
|
- this.setState({ value: this.foundation.doFormat(valueStr, false) });
|
|
|
|
|
|
|
+ newValue = this.foundation.doFormat(valueStr, false);
|
|
|
|
|
+ this.foundation.updateStates({ value: newValue });
|
|
|
}
|
|
}
|
|
|
} else if (this.foundation.isValidNumber(parsedNum)) {
|
|
} else if (this.foundation.isValidNumber(parsedNum)) {
|
|
|
- this.setState({ number: parsedNum, value: this.foundation.doFormat(parsedNum) });
|
|
|
|
|
|
|
+ newValue = this.foundation.doFormat(parsedNum);
|
|
|
|
|
+ this.foundation.updateStates({ number: parsedNum, value: newValue });
|
|
|
} else {
|
|
} else {
|
|
|
// Invalid digital analog blurring effect instead of controlled failure
|
|
// Invalid digital analog blurring effect instead of controlled failure
|
|
|
- this.setState({ number: null, value: '' });
|
|
|
|
|
|
|
+ newValue = '';
|
|
|
|
|
+ this.foundation.updateStates({ number: null, value: newValue });
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (isString(newValue) && newValue !== String(this.props.value)) {
|
|
|
|
|
+ this.foundation.notifyChange(newValue, null);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!this.clickUpOrDown) {
|
|
if (!this.clickUpOrDown) {
|