2019-01-12 11:33:27 +08:00
|
|
|
import PropTypes from '../_util/vue-types';
|
|
|
|
import { initDefaultProps, getOptionProps } from '../_util/props-util';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import Icon from '../icon';
|
|
|
|
import VcInputNumber from '../vc-input-number/src';
|
2018-04-04 13:57:23 +08:00
|
|
|
|
|
|
|
export const InputNumberProps = {
|
|
|
|
prefixCls: PropTypes.string,
|
|
|
|
min: PropTypes.number,
|
|
|
|
max: PropTypes.number,
|
2019-01-12 11:33:27 +08:00
|
|
|
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
|
|
step: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
2018-04-04 13:57:23 +08:00
|
|
|
defaultValue: PropTypes.number,
|
|
|
|
tabIndex: PropTypes.number,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
size: PropTypes.oneOf(['large', 'small', 'default']),
|
|
|
|
formatter: PropTypes.func,
|
|
|
|
parser: PropTypes.func,
|
2018-12-09 11:49:18 +08:00
|
|
|
decimalSeparator: PropTypes.string,
|
2018-04-04 13:57:23 +08:00
|
|
|
placeholder: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
|
|
|
id: PropTypes.string,
|
|
|
|
precision: PropTypes.number,
|
2018-06-09 15:48:34 +08:00
|
|
|
autoFocus: PropTypes.bool,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-04-04 13:57:23 +08:00
|
|
|
|
2018-09-19 13:21:57 +08:00
|
|
|
const InputNumber = {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'AInputNumber',
|
2018-04-04 13:57:23 +08:00
|
|
|
model: {
|
|
|
|
prop: 'value',
|
|
|
|
event: 'change',
|
|
|
|
},
|
|
|
|
props: initDefaultProps(InputNumberProps, {
|
|
|
|
prefixCls: 'ant-input-number',
|
|
|
|
step: 1,
|
|
|
|
}),
|
|
|
|
methods: {
|
2019-01-12 11:33:27 +08:00
|
|
|
focus() {
|
|
|
|
this.$refs.inputNumberRef.focus();
|
2018-04-04 13:57:23 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
blur() {
|
|
|
|
this.$refs.inputNumberRef.blur();
|
2018-04-04 13:57:23 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
render() {
|
|
|
|
const { size, ...others } = getOptionProps(this);
|
2018-04-04 13:57:23 +08:00
|
|
|
const inputNumberClass = classNames({
|
|
|
|
[`${this.prefixCls}-lg`]: size === 'large',
|
|
|
|
[`${this.prefixCls}-sm`]: size === 'small',
|
2019-01-12 11:33:27 +08:00
|
|
|
});
|
|
|
|
const upIcon = <Icon type="up" class={`${this.prefixCls}-handler-up-inner`} />;
|
|
|
|
const downIcon = <Icon type="down" class={`${this.prefixCls}-handler-down-inner`} />;
|
2018-12-09 11:49:18 +08:00
|
|
|
|
2018-04-04 13:57:23 +08:00
|
|
|
const vcInputNumberprops = {
|
|
|
|
props: {
|
2018-12-09 11:49:18 +08:00
|
|
|
upHandler: upIcon,
|
|
|
|
downHandler: downIcon,
|
2018-04-04 13:57:23 +08:00
|
|
|
...others,
|
|
|
|
},
|
|
|
|
class: inputNumberClass,
|
|
|
|
ref: 'inputNumberRef',
|
|
|
|
on: this.$listeners,
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
|
|
|
return <VcInputNumber {...vcInputNumberprops} />;
|
2018-04-04 13:57:23 +08:00
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
|
|
|
/* istanbul ignore next */
|
2019-01-12 11:33:27 +08:00
|
|
|
InputNumber.install = function(Vue) {
|
|
|
|
Vue.component(InputNumber.name, InputNumber);
|
|
|
|
};
|
2018-09-19 13:21:57 +08:00
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
export default InputNumber;
|