mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 11:10:01 +08:00
refactor(rate): improve code (#24524)
This commit is contained in:
parent
afe7172974
commit
81bde547cd
@ -1,6 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import RcRate from 'rc-rate';
|
||||
import omit from 'omit.js';
|
||||
import StarFilled from '@ant-design/icons/StarFilled';
|
||||
|
||||
import Tooltip from '../tooltip';
|
||||
@ -26,23 +25,20 @@ interface RateNodeProps {
|
||||
index: number;
|
||||
}
|
||||
|
||||
const Rate = React.forwardRef<unknown, RateProps>((props, ref) => {
|
||||
const Rate = React.forwardRef<unknown, RateProps>(({ prefixCls, tooltips, ...props }, ref) => {
|
||||
const characterRender = (node: React.ReactElement, { index }: RateNodeProps) => {
|
||||
const { tooltips } = props;
|
||||
if (!tooltips) return node;
|
||||
return <Tooltip title={tooltips[index]}>{node}</Tooltip>;
|
||||
};
|
||||
|
||||
const { getPrefixCls, direction } = React.useContext(ConfigContext);
|
||||
const { prefixCls, ...restProps } = props;
|
||||
const rateProps = omit(restProps, ['tooltips']);
|
||||
const ratePrefixCls = getPrefixCls('rate', prefixCls);
|
||||
|
||||
return (
|
||||
<RcRate
|
||||
ref={ref}
|
||||
characterRender={characterRender}
|
||||
{...rateProps}
|
||||
{...props}
|
||||
prefixCls={ratePrefixCls}
|
||||
direction={direction}
|
||||
/>
|
||||
|
Loading…
Reference in New Issue
Block a user