From a26ac3e9f4d753d3eb7a0ac061b81f9db39dce4f Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 11 Aug 2022 14:24:39 +0800 Subject: [PATCH] feat: rating character add params --- components/rate/Star.tsx | 20 ++++++++++++++------ components/rate/index.tsx | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/components/rate/Star.tsx b/components/rate/Star.tsx index 76e0043b4..2112df096 100644 --- a/components/rate/Star.tsx +++ b/components/rate/Star.tsx @@ -1,6 +1,5 @@ import type { ExtractPropTypes } from 'vue'; import { defineComponent, computed } from 'vue'; -import { getPropsSlot } from '../_util/props-util'; import PropTypes from '../_util/vue-types'; export const starProps = { @@ -24,7 +23,7 @@ export default defineComponent({ inheritAttrs: false, props: starProps, emits: ['hover', 'click'], - setup(props, { slots, emit }) { + setup(props, { emit }) { const onHover = (e: MouseEvent) => { const { index } = props; emit('hover', e, index); @@ -61,8 +60,17 @@ export default defineComponent({ }); return () => { - const { disabled, prefixCls, characterRender, index, count, value } = props; - const character = getPropsSlot(slots, props, 'character'); + const { disabled, prefixCls, characterRender, character, index, count, value } = props; + const characterNode = + typeof character === 'function' + ? character({ + disabled, + prefixCls, + index, + count, + value, + }) + : character; let star = (
  • -
    {character}
    -
    {character}
    +
    {characterNode}
    +
    {characterNode}
  • ); diff --git a/components/rate/index.tsx b/components/rate/index.tsx index c9521db98..7ea0e1f34 100644 --- a/components/rate/index.tsx +++ b/components/rate/index.tsx @@ -1,6 +1,6 @@ import type { CSSProperties, ExtractPropTypes, PropType, VNode } from 'vue'; import { watch, defineComponent, ref, reactive, onMounted } from 'vue'; -import { initDefaultProps, getPropsSlot, findDOMNode } from '../_util/props-util'; +import { initDefaultProps, findDOMNode } from '../_util/props-util'; import { withInstall } from '../_util/type'; import { getOffsetLeft } from './util'; import classNames from '../_util/classNames'; @@ -196,13 +196,13 @@ const Rate = defineComponent({ if (!tooltips) return node; return {node}; }; - const character = getPropsSlot(slots, props, 'character') || ; return () => { const { count, allowHalf, disabled, tabindex, id = formItemContext.id.value } = props; const { class: className, style } = attrs; const stars = []; const disabledClass = disabled ? `${prefixCls.value}-disabled` : ''; + const character = props.character || slots.character || (() => ); for (let index = 0; index < count; index++) { stars.push(