mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 08:19:37 +08:00
f0c105d262
* feat: remove the hardcode of `use client` * chore: update `@ant-design/tools` * test: update * fix: incorrect dictionary * chore: update dep * ci: check use client * chore: update ci * fix: should be LIB_DIR * ci: should only run in dist * chore: update check tsx files
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import StarFilled from '@ant-design/icons/StarFilled';
|
|
import classNames from 'classnames';
|
|
import RcRate from 'rc-rate';
|
|
import type { RateRef, 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';
|
|
|
|
export interface RateProps extends RcRateProps {
|
|
rootClassName?: string;
|
|
tooltips?: Array<string>;
|
|
}
|
|
|
|
interface RateNodeProps {
|
|
index: number;
|
|
}
|
|
|
|
const Rate = React.forwardRef<RateRef, RateProps>((props, ref) => {
|
|
const {
|
|
prefixCls,
|
|
className,
|
|
rootClassName,
|
|
style,
|
|
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, rate } = React.useContext(ConfigContext);
|
|
const ratePrefixCls = getPrefixCls('rate', prefixCls);
|
|
|
|
// Style
|
|
const [wrapSSR, hashId] = useStyle(ratePrefixCls);
|
|
|
|
const mergedStyle: React.CSSProperties = { ...rate?.style, ...style };
|
|
|
|
return wrapSSR(
|
|
<RcRate
|
|
ref={ref}
|
|
character={character}
|
|
characterRender={characterRender}
|
|
{...rest}
|
|
className={classNames(className, rootClassName, hashId, rate?.className)}
|
|
style={mergedStyle}
|
|
prefixCls={ratePrefixCls}
|
|
direction={direction}
|
|
/>,
|
|
);
|
|
});
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
Rate.displayName = 'Rate';
|
|
}
|
|
|
|
export default Rate;
|