You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

import StarFilled from '@ant-design/icons/StarFilled';
import classNames from 'classnames';
9 years ago
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';
import useStyle from './style';
9 years ago
export interface RateProps extends RcRateProps {
tooltips?: Array<string>;
}
interface RateNodeProps {
index: number;
}
const Rate = React.forwardRef<unknown, RateProps>(({ prefixCls, tooltips, ...props }, ref) => {
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);
// Style
const [wrapSSR, hashId] = useStyle(ratePrefixCls);
return wrapSSR(
<RcRate
ref={ref}
characterRender={characterRender}
{...props}
className={classNames(props.className, hashId)}
prefixCls={ratePrefixCls}
direction={direction}
/>,
);
});
Rate.displayName = 'Rate';
Rate.defaultProps = {
character: <StarFilled />,
};
export default Rate;