diff --git a/components/_util/theme/interface.ts b/components/_util/theme/interface.ts index c91003d158..edf950b39e 100644 --- a/components/_util/theme/interface.ts +++ b/components/_util/theme/interface.ts @@ -55,6 +55,7 @@ export interface OverrideToken { Mentions?: MentionsComponentToken; Pagination?: {}; Popover?: {}; + Rate?: {}; Result?: {}; Select?: SelectComponentToken; Slider?: SliderComponentToken; diff --git a/components/rate/index.tsx b/components/rate/index.tsx index 9817e61c00..c9b3b71679 100644 --- a/components/rate/index.tsx +++ b/components/rate/index.tsx @@ -33,11 +33,11 @@ const Rate = React.forwardRef(({ prefixCls, tooltips, ...pro return {node}; }; - const { getPrefixCls, iconPrefixCls, direction } = React.useContext(ConfigContext); + const { getPrefixCls, direction } = React.useContext(ConfigContext); const ratePrefixCls = getPrefixCls('rate', prefixCls); // Style - const [wrapSSR, hashId] = useStyle(ratePrefixCls, iconPrefixCls); + const [wrapSSR, hashId] = useStyle(ratePrefixCls); return wrapSSR( { rateStarColor: string; rateStarSize: number; rateStarHoverScale: CSSObject['transform']; - rateCls: string; - iconPrefixCls: string; } const genRateStarStyle: GenerateStyle = token => { - const { rateCls } = token; + const { componentCls } = token; return { - [`${rateCls}-star`]: { + [`${componentCls}-star`]: { position: 'relative', display: 'inline-block', color: 'inherit', @@ -53,7 +44,7 @@ const genRateStarStyle: GenerateStyle = token => { transition: `all ${token.motionDurationSlow}`, userSelect: 'none', - [token.iconPrefixCls]: { + [token.iconCls]: { verticalAlign: 'middle', }, }, @@ -68,11 +59,11 @@ const genRateStarStyle: GenerateStyle = token => { opacity: 0, }, - [`&-half ${rateCls}-star-first, &-half ${rateCls}-star-second`]: { + [`&-half ${componentCls}-star-first, &-half ${componentCls}-star-second`]: { opacity: 1, }, - [`&-half ${rateCls}-star-first, &-full ${rateCls}-star-second`]: { + [`&-half ${componentCls}-star-first, &-full ${componentCls}-star-second`]: { color: 'inherit', }, }, @@ -80,16 +71,16 @@ const genRateStarStyle: GenerateStyle = token => { }; const genRateRtlStyle = (token: RateToken): CSSObject => ({ - [`&-rtl${token.rateCls}`]: { + [`&-rtl${token.componentCls}`]: { direction: 'rtl', }, }); const genRateStyle: GenerateStyle = token => { - const { rateCls } = token; + const { componentCls } = token; return { - [rateCls]: { + [componentCls]: { ...resetComponent(token), display: 'inline-block', @@ -102,7 +93,7 @@ const genRateStyle: GenerateStyle = token => { outline: 'none', // disable styles - [`&-disabled${rateCls} ${rateCls}-star`]: { + [`&-disabled${componentCls} ${componentCls}-star`]: { cursor: 'default', '&:hover': { @@ -114,7 +105,7 @@ const genRateStyle: GenerateStyle = token => { ...genRateStarStyle(token), // text styles - [`+ ${rateCls}-text`]: { + [`+ ${componentCls}-text`]: { display: 'inline-block', marginInlineStart: token.marginXS, fontSize: token.fontSize, @@ -127,24 +118,13 @@ const genRateStyle: GenerateStyle = token => { }; // ============================== Export ============================== -export default function useStyle( - prefixCls: string, - iconPrefixCls: string, -): UseComponentStyleResult { - const [theme, token, hashId] = useToken(); - +export default genComponentStyleHook('Rate', token => { const rateToken: RateToken = { ...token, // FIXME: missing token rateStarColor: '#fadb14', // @yellow-6 rateStarSize: 20, // fixed-value rateStarHoverScale: 'scale(1.1)', // fixed-value - rateCls: `.${prefixCls}`, - iconPrefixCls: `.${iconPrefixCls}`, }; - - return [ - useStyleRegister({ theme, token, hashId, path: [prefixCls] }, () => [genRateStyle(rateToken)]), - hashId, - ]; -} + return [genRateStyle(rateToken)]; +});