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

84 lines
2.3 KiB
Vue
Raw Normal View History

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';
2019-04-10 08:51:42 +08:00
import { ConfigConsumerProps } from '../config-provider';
import Base from '../base';
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
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, {
step: 1,
}),
2019-04-10 08:51:42 +08:00
inject: {
2019-09-11 22:35:25 +08:00
configProvider: { default: () => ConfigConsumerProps },
2019-04-10 08:51:42 +08:00
},
2018-04-04 13:57:23 +08:00
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() {
2019-04-10 08:51:42 +08:00
const { prefixCls: customizePrefixCls, size, ...others } = getOptionProps(this);
2019-09-11 22:35:25 +08:00
const getPrefixCls = this.configProvider.getPrefixCls;
2019-04-10 09:08:29 +08:00
const prefixCls = getPrefixCls('input-number', customizePrefixCls);
2019-04-10 08:51:42 +08:00
2018-04-04 13:57:23 +08:00
const inputNumberClass = classNames({
2019-04-10 08:51:42 +08:00
[`${prefixCls}-lg`]: size === 'large',
[`${prefixCls}-sm`]: size === 'small',
2019-01-12 11:33:27 +08:00
});
2019-04-10 08:51:42 +08:00
const upIcon = <Icon type="up" class={`${prefixCls}-handler-up-inner`} />;
const downIcon = <Icon type="down" class={`${prefixCls}-handler-down-inner`} />;
2018-12-09 11:49:18 +08:00
2018-04-04 13:57:23 +08:00
const vcInputNumberprops = {
props: {
2019-04-10 08:51:42 +08:00
prefixCls,
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
};
/* istanbul ignore next */
2019-01-12 11:33:27 +08:00
InputNumber.install = function(Vue) {
Vue.use(Base);
2019-01-12 11:33:27 +08:00
Vue.component(InputNumber.name, InputNumber);
};
2019-01-12 11:33:27 +08:00
export default InputNumber;