mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-05 21:50:07 +08:00
4ab7a681a7
* fix: update alert code * chore: declare link type * chore: declare auto-complete type * chore: declare Badge type * chore: declare Breadcrumb type * chore: declare Calendar type * chore: declare Card type * chore: declare Checkbox type * chore: declare Descriptions type * chore: declare Dropdown * chore: declare Form type * chore: declare Mentions type * chore: declare Menu type * chore: declare popconfirm type * chore: update Radio typescript * chore: declare Rate type * chore: declare Transfer type * fix: update Transfer type * fix: update type * fix: update type
64 lines
1.8 KiB
Vue
64 lines
1.8 KiB
Vue
import { inject, defineComponent, VNode } from 'vue';
|
|
import omit from 'omit.js';
|
|
import PropTypes from '../_util/vue-types';
|
|
import { getOptionProps, getComponent } from '../_util/props-util';
|
|
import { defaultConfigProvider } from '../config-provider';
|
|
import VcRate from '../vc-rate';
|
|
import StarFilled from '@ant-design/icons-vue/StarFilled';
|
|
import Tooltip from '../tooltip';
|
|
import { withInstall } from '../_util/type';
|
|
|
|
export const RateProps = {
|
|
prefixCls: PropTypes.string,
|
|
count: PropTypes.number,
|
|
value: PropTypes.number,
|
|
defaultValue: PropTypes.number,
|
|
allowHalf: PropTypes.looseBool,
|
|
allowClear: PropTypes.looseBool,
|
|
tooltips: PropTypes.arrayOf(PropTypes.string),
|
|
disabled: PropTypes.looseBool,
|
|
character: PropTypes.any,
|
|
autofocus: PropTypes.looseBool,
|
|
};
|
|
|
|
const Rate = defineComponent({
|
|
name: 'ARate',
|
|
props: RateProps,
|
|
setup() {
|
|
return {
|
|
configProvider: inject('configProvider', defaultConfigProvider),
|
|
};
|
|
},
|
|
methods: {
|
|
characterRender(node: VNode, { index }) {
|
|
const { tooltips } = this.$props;
|
|
if (!tooltips) return node;
|
|
return <Tooltip title={tooltips[index]}>{node}</Tooltip>;
|
|
},
|
|
focus() {
|
|
(this.$refs.refRate as HTMLUListElement).focus();
|
|
},
|
|
blur() {
|
|
(this.$refs.refRate as HTMLUListElement).blur();
|
|
},
|
|
},
|
|
render() {
|
|
const { prefixCls: customizePrefixCls, ...restProps } = getOptionProps(this);
|
|
const { getPrefixCls } = this.configProvider;
|
|
const prefixCls = getPrefixCls('rate', customizePrefixCls);
|
|
|
|
const character = getComponent(this, 'character') || <StarFilled />;
|
|
const rateProps = {
|
|
character,
|
|
characterRender: this.characterRender,
|
|
prefixCls,
|
|
...omit(restProps, ['tooltips']),
|
|
...this.$attrs,
|
|
ref: 'refRate',
|
|
};
|
|
return <VcRate {...rateProps} />;
|
|
},
|
|
});
|
|
|
|
export default withInstall(Rate);
|