ant-design-vue/components/input-number/index.jsx

75 lines
2.0 KiB
Vue
Raw Normal View History

2019-01-12 03:33:27 +00: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 05:57:23 +00:00
export const InputNumberProps = {
prefixCls: PropTypes.string,
min: PropTypes.number,
max: PropTypes.number,
2019-01-12 03:33:27 +00:00
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
step: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
2018-04-04 05:57:23 +00: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 03:49:18 +00:00
decimalSeparator: PropTypes.string,
2018-04-04 05:57:23 +00:00
placeholder: PropTypes.string,
name: PropTypes.string,
id: PropTypes.string,
precision: PropTypes.number,
2018-06-09 07:48:34 +00:00
autoFocus: PropTypes.bool,
2019-01-12 03:33:27 +00:00
};
2018-04-04 05:57:23 +00:00
const InputNumber = {
2018-04-08 13:17:20 +00:00
name: 'AInputNumber',
2018-04-04 05:57:23 +00:00
model: {
prop: 'value',
event: 'change',
},
props: initDefaultProps(InputNumberProps, {
prefixCls: 'ant-input-number',
step: 1,
}),
methods: {
2019-01-12 03:33:27 +00:00
focus() {
this.$refs.inputNumberRef.focus();
2018-04-04 05:57:23 +00:00
},
2019-01-12 03:33:27 +00:00
blur() {
this.$refs.inputNumberRef.blur();
2018-04-04 05:57:23 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
const { size, ...others } = getOptionProps(this);
2018-04-04 05:57:23 +00:00
const inputNumberClass = classNames({
[`${this.prefixCls}-lg`]: size === 'large',
[`${this.prefixCls}-sm`]: size === 'small',
2019-01-12 03:33:27 +00: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 03:49:18 +00:00
2018-04-04 05:57:23 +00:00
const vcInputNumberprops = {
props: {
2018-12-09 03:49:18 +00:00
upHandler: upIcon,
downHandler: downIcon,
2018-04-04 05:57:23 +00:00
...others,
},
class: inputNumberClass,
ref: 'inputNumberRef',
on: this.$listeners,
2019-01-12 03:33:27 +00:00
};
return <VcInputNumber {...vcInputNumberprops} />;
2018-04-04 05:57:23 +00:00
},
2019-01-12 03:33:27 +00:00
};
/* istanbul ignore next */
2019-01-12 03:33:27 +00:00
InputNumber.install = function(Vue) {
Vue.component(InputNumber.name, InputNumber);
};
2019-01-12 03:33:27 +00:00
export default InputNumber;