Skip to content

Commit a26ac3e

Browse files
committed
feat: rating character add params
1 parent e7fdb12 commit a26ac3e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

components/rate/Star.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ExtractPropTypes } from 'vue';
22
import { defineComponent, computed } from 'vue';
3-
import { getPropsSlot } from '../_util/props-util';
43
import PropTypes from '../_util/vue-types';
54

65
export const starProps = {
@@ -24,7 +23,7 @@ export default defineComponent({
2423
inheritAttrs: false,
2524
props: starProps,
2625
emits: ['hover', 'click'],
27-
setup(props, { slots, emit }) {
26+
setup(props, { emit }) {
2827
const onHover = (e: MouseEvent) => {
2928
const { index } = props;
3029
emit('hover', e, index);
@@ -61,8 +60,17 @@ export default defineComponent({
6160
});
6261

6362
return () => {
64-
const { disabled, prefixCls, characterRender, index, count, value } = props;
65-
const character = getPropsSlot(slots, props, 'character');
63+
const { disabled, prefixCls, characterRender, character, index, count, value } = props;
64+
const characterNode =
65+
typeof character === 'function'
66+
? character({
67+
disabled,
68+
prefixCls,
69+
index,
70+
count,
71+
value,
72+
})
73+
: character;
6674
let star = (
6775
<li class={cls.value}>
6876
<div
@@ -75,8 +83,8 @@ export default defineComponent({
7583
aria-setsize={count}
7684
tabindex={disabled ? -1 : 0}
7785
>
78-
<div class={`${prefixCls}-first`}>{character}</div>
79-
<div class={`${prefixCls}-second`}>{character}</div>
86+
<div class={`${prefixCls}-first`}>{characterNode}</div>
87+
<div class={`${prefixCls}-second`}>{characterNode}</div>
8088
</div>
8189
</li>
8290
);

components/rate/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CSSProperties, ExtractPropTypes, PropType, VNode } from 'vue';
22
import { watch, defineComponent, ref, reactive, onMounted } from 'vue';
3-
import { initDefaultProps, getPropsSlot, findDOMNode } from '../_util/props-util';
3+
import { initDefaultProps, findDOMNode } from '../_util/props-util';
44
import { withInstall } from '../_util/type';
55
import { getOffsetLeft } from './util';
66
import classNames from '../_util/classNames';
@@ -196,13 +196,13 @@ const Rate = defineComponent({
196196
if (!tooltips) return node;
197197
return <Tooltip title={tooltips[index]}>{node}</Tooltip>;
198198
};
199-
const character = getPropsSlot(slots, props, 'character') || <StarFilled />;
200199

201200
return () => {
202201
const { count, allowHalf, disabled, tabindex, id = formItemContext.id.value } = props;
203202
const { class: className, style } = attrs;
204203
const stars = [];
205204
const disabledClass = disabled ? `${prefixCls.value}-disabled` : '';
205+
const character = props.character || slots.character || (() => <StarFilled />);
206206
for (let index = 0; index < count; index++) {
207207
stars.push(
208208
<Star

0 commit comments

Comments
 (0)