ant-design-vue/components/rate/index.jsx
tangjinzhou da0f17d1b6 Merge remote-tracking branch 'origin/master' into feat-1.4.0
# Conflicts:
#	components/affix/index.jsx
#	components/alert/index.jsx
#	components/back-top/index.jsx
#	components/carousel/index.jsx
#	components/cascader/index.jsx
#	components/comment/index.jsx
#	components/config-provider/index.jsx
#	components/divider/index.jsx
#	components/drawer/index.jsx
#	components/form/Form.jsx
#	components/input-number/index.jsx
#	components/menu/index.jsx
#	components/modal/confirm.js
#	components/modal/index.js
#	components/popconfirm/index.jsx
#	components/popover/index.jsx
#	components/rate/index.jsx
#	components/steps/index.jsx
#	components/switch/index.jsx
#	components/time-picker/index.jsx
#	components/tree-select/index.jsx
#	site/components.js
2019-08-28 22:36:44 +08:00

79 lines
2.0 KiB
Vue

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