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

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