ant-design/components/rate/index.tsx
lijianan ddaead6777
fix: delete defaultprops (#37822)
* fix: delete defaultprops

* fix: delete defaultprops
2022-09-30 17:44:24 +08:00

45 lines
1.1 KiB
TypeScript

import StarFilled from '@ant-design/icons/StarFilled';
import RcRate from 'rc-rate';
import type { RateProps as RcRateProps } from 'rc-rate/lib/Rate';
import * as React from 'react';
import { ConfigContext } from '../config-provider';
import Tooltip from '../tooltip';
export interface RateProps extends RcRateProps {
tooltips?: Array<string>;
}
interface RateNodeProps {
index: number;
}
const Rate = React.forwardRef<unknown, RateProps>((props, ref) => {
const { prefixCls, tooltips, character = <StarFilled />, ...rest } = props;
const characterRender = (node: React.ReactElement, { index }: RateNodeProps) => {
if (!tooltips) {
return node;
}
return <Tooltip title={tooltips[index]}>{node}</Tooltip>;
};
const { getPrefixCls, direction } = React.useContext(ConfigContext);
const ratePrefixCls = getPrefixCls('rate', prefixCls);
return (
<RcRate
ref={ref}
character={character}
characterRender={characterRender}
{...rest}
prefixCls={ratePrefixCls}
direction={direction}
/>
);
});
if (process.env.NODE_ENV !== 'production') {
Rate.displayName = 'Rate';
}
export default Rate;