2016-09-21 11:54:53 +08:00
|
|
|
import React from 'react';
|
2015-11-25 15:46:44 +08:00
|
|
|
import classNames from 'classnames';
|
2016-03-21 09:22:14 +08:00
|
|
|
import RcInputNumber from 'rc-input-number';
|
2015-07-01 14:48:47 +08:00
|
|
|
|
2016-08-19 17:11:06 +08:00
|
|
|
export interface InputNumberProps {
|
|
|
|
prefixCls?: string;
|
|
|
|
min?: number;
|
|
|
|
max?: number;
|
|
|
|
value?: number;
|
|
|
|
step?: number | string;
|
|
|
|
defaultValue?: number;
|
2017-02-07 17:27:28 +08:00
|
|
|
onChange?: (value: number | string | undefined) => void;
|
2016-08-19 17:11:06 +08:00
|
|
|
disabled?: boolean;
|
|
|
|
size?: 'large' | 'small' | 'default';
|
2017-03-10 18:20:28 +08:00
|
|
|
formatter?: (value: number | string | undefined) => string;
|
2017-04-11 21:16:02 +08:00
|
|
|
parser?: (displayValue: string | undefined) => number;
|
2016-09-19 10:17:07 +08:00
|
|
|
placeholder?: string;
|
2016-10-10 22:38:47 +08:00
|
|
|
style?: React.CSSProperties;
|
|
|
|
className?: string;
|
2017-05-27 09:31:06 +08:00
|
|
|
name?: string;
|
2017-08-18 18:17:06 +08:00
|
|
|
id?: string;
|
2017-07-04 14:02:56 +08:00
|
|
|
precision?: number;
|
2016-08-19 17:11:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default class InputNumber extends React.Component<InputNumberProps, any> {
|
2016-03-29 14:01:10 +08:00
|
|
|
static defaultProps = {
|
|
|
|
prefixCls: 'ant-input-number',
|
|
|
|
step: 1,
|
2016-07-13 11:14:24 +08:00
|
|
|
};
|
2016-03-29 14:01:10 +08:00
|
|
|
|
2017-09-15 15:47:06 +08:00
|
|
|
private inputNumberRef: any;
|
|
|
|
|
2015-07-01 14:48:47 +08:00
|
|
|
render() {
|
2016-12-19 15:19:15 +08:00
|
|
|
const { className, size, ...others } = this.props;
|
2015-11-25 15:46:44 +08:00
|
|
|
const inputNumberClass = classNames({
|
2016-03-30 10:58:37 +08:00
|
|
|
[`${this.props.prefixCls}-lg`]: size === 'large',
|
|
|
|
[`${this.props.prefixCls}-sm`]: size === 'small',
|
2016-11-30 10:20:23 +08:00
|
|
|
}, className);
|
2015-11-25 15:46:44 +08:00
|
|
|
|
2017-09-15 15:47:06 +08:00
|
|
|
return <RcInputNumber ref={c => this.inputNumberRef = c} className={inputNumberClass} {...others} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
focus() {
|
|
|
|
this.inputNumberRef.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
blur() {
|
|
|
|
this.inputNumberRef.blur();
|
2015-07-01 14:48:47 +08:00
|
|
|
}
|
2016-03-21 09:22:14 +08:00
|
|
|
}
|