ant-design-vue/components/rate/index.jsx

77 lines
1.9 KiB
Vue
Raw Normal View History

2019-03-18 12:00:00 +00:00
import omit from 'omit.js';
2019-01-12 03:33:27 +00:00
import PropTypes from '../_util/vue-types';
2019-03-18 12:00:00 +00:00
import { getOptionProps, getComponentFromProp } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
2019-01-12 03:33:27 +00:00
import VcRate from '../vc-rate';
import Icon from '../icon';
2019-03-18 12:00:00 +00:00
import Tooltip from '../tooltip';
2018-03-21 07:45:01 +00:00
export const RateProps = {
prefixCls: PropTypes.string,
count: PropTypes.number,
value: PropTypes.value,
defaultValue: PropTypes.value,
allowHalf: PropTypes.bool,
allowClear: PropTypes.bool,
2019-03-18 12:00:00 +00:00
tooltips: PropTypes.arrayOf(PropTypes.string),
2018-03-21 07:45:01 +00:00
disabled: PropTypes.bool,
character: PropTypes.any,
autoFocus: PropTypes.bool,
2019-01-12 03:33:27 +00:00
};
2018-03-21 07:45:01 +00:00
const Rate = {
2018-04-08 13:17:20 +00:00
name: 'ARate',
2018-03-21 07:45:01 +00:00
model: {
prop: 'value',
event: 'change',
},
2019-03-18 12:00:00 +00:00
props: RateProps,
inject: {
configProvider: { default: () => ({}) },
},
2018-03-21 07:45:01 +00:00
methods: {
2019-01-12 03:33:27 +00:00
focus() {
this.$refs.refRate.focus();
2018-03-21 07:45:01 +00:00
},
2019-01-12 03:33:27 +00:00
blur() {
this.$refs.refRate.blur();
2018-03-21 07:45:01 +00:00
},
2019-03-18 12:00:00 +00:00
characterRender(node, { index }) {
const { tooltips } = this.$props;
if (!tooltips) return node;
const tooltipsProps = {
props: {
title: tooltips[index],
},
};
return <Tooltip {...tooltipsProps}>{node}</Tooltip>;
},
2018-03-21 07:45:01 +00:00
},
2019-01-12 03:33:27 +00:00
render() {
2019-03-18 12:00:00 +00:00
const { prefixCls: customizePrefixCls, ...restProps } = getOptionProps(this);
const getPrefixCls = this.configProvider.getPrefixCls || ConfigConsumerProps.getPrefixCls;
const prefixCls = getPrefixCls('rate', customizePrefixCls);
2019-01-12 03:33:27 +00:00
const character = getComponentFromProp(this, 'character') || (
<Icon type="star" theme="filled" />
);
2018-03-21 07:45:01 +00:00
const rateProps = {
props: {
character,
2019-03-18 12:00:00 +00:00
characterRender: this.characterRender,
prefixCls,
...omit(restProps, ['tooltips']),
2018-03-21 07:45:01 +00:00
},
on: this.$listeners,
ref: 'refRate',
2019-01-12 03:33:27 +00:00
};
return <VcRate {...rateProps} />;
2018-03-21 07:45:01 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-03-21 07:45:01 +00:00
/* istanbul ignore next */
2019-01-12 03:33:27 +00:00
Rate.install = function(Vue) {
Vue.component(Rate.name, Rate);
};
export default Rate;