1- import React from 'react' ;
1+ import type React from 'react' ;
22
33import type { CSSInterpolation , CSSObject , TokenType } from '@ant-design/cssinjs' ;
44
@@ -9,7 +9,6 @@ import type {
99 GlobalTokenWithComponent ,
1010 TokenMap ,
1111 TokenMapKey ,
12- UseComponentStyleResult ,
1312} from '../interface' ;
1413
1514import type AbstractCalculator from './calc/calculator' ;
@@ -197,10 +196,10 @@ function genStyleUtils<
197196 const useCSSVar = genCSSVarRegister ( componentName , getDefaultToken , mergedOptions ) ;
198197
199198 return ( prefixCls : string , rootCls : string = prefixCls ) => {
200- const [ , hashId ] = useStyle ( prefixCls , rootCls ) ;
201- const [ wrapCSSVar , cssVarCls ] = useCSSVar ( rootCls ) ;
199+ const hashId = useStyle ( prefixCls , rootCls ) ;
200+ const cssVarCls = useCSSVar ( rootCls ) ;
202201
203- return [ wrapCSSVar , hashId , cssVarCls ] as const ;
202+ return [ hashId , cssVarCls ] as const ;
204203 } ;
205204 }
206205
@@ -218,9 +217,11 @@ function genStyleUtils<
218217 prefixToken : ( key : string ) => string ;
219218 } ,
220219 ) {
221- const { unitless : compUnitless , injectStyle = true , prefixToken, ignore } = options ;
220+ const { unitless : compUnitless , prefixToken, ignore } = options ;
221+
222+ return ( rootCls : string ) => {
223+ const { cssVar } = useToken ( ) ;
222224
223- const CSSVarRegister : React . FC < Readonly < CSSVarRegisterProps > > = ( { rootCls, cssVar = { } } ) => {
224225 const { realToken } = useToken ( ) ;
225226 useCSSVarRegister (
226227 {
@@ -246,34 +247,18 @@ function genStyleUtils<
246247 deprecatedTokens : options ?. deprecatedTokens ,
247248 } ,
248249 ) ;
249- Object . keys ( defaultToken ) . forEach ( ( key ) => {
250- componentToken [ prefixToken ( key ) ] = componentToken [ key ] ;
251- delete componentToken [ key ] ;
252- } ) ;
250+ if ( defaultToken ) {
251+ Object . keys ( defaultToken ) . forEach ( ( key ) => {
252+ componentToken [ prefixToken ( key ) ] = componentToken [ key ] ;
253+ delete componentToken [ key ] ;
254+ } ) ;
255+ }
253256 return componentToken ;
254257 } ,
255258 ) ;
256- return null ;
257- } ;
258-
259- const useCSSVar = ( rootCls : string ) => {
260- const { cssVar } = useToken ( ) ;
261259
262- return [
263- ( node : React . ReactElement ) : React . ReactElement =>
264- injectStyle && cssVar ? (
265- < >
266- < CSSVarRegister rootCls = { rootCls } cssVar = { cssVar } component = { component } />
267- { node }
268- </ >
269- ) : (
270- node
271- ) ,
272- cssVar ?. key ,
273- ] as const ;
260+ return cssVar ?. key ;
274261 } ;
275-
276- return useCSSVar ;
277262 }
278263
279264 function genComponentStyleHook < C extends TokenMapKey < CompTokenMap > > (
@@ -312,25 +297,23 @@ function genStyleUtils<
312297 } ;
313298
314299 // Return new style hook
315- return ( prefixCls : string , rootCls : string = prefixCls ) : UseComponentStyleResult => {
300+ return ( prefixCls : string , rootCls : string = prefixCls ) : string => {
316301 const { theme, realToken, hashId, token, cssVar } = useToken ( ) ;
317302
318303 const { rootPrefixCls, iconPrefixCls } = usePrefix ( ) ;
319304 const csp = useCSP ( ) ;
320305
321- const type = cssVar ? 'css' : 'js ';
306+ const type = 'css' ;
322307
323308 // Use unique memo to share the result across all instances
324309 const calc = useUniqueMemo ( ( ) => {
325310 const unitlessCssVar = new Set < string > ( ) ;
326- if ( cssVar ) {
327- Object . keys ( options . unitless || { } ) . forEach ( ( key ) => {
328- // Some component proxy the AliasToken (e.g. Image) and some not (e.g. Modal)
329- // We should both pass in `unitlessCssVar` to make sure the CSSVar can be unitless.
330- unitlessCssVar . add ( token2CSSVar ( key , cssVar . prefix ) ) ;
331- unitlessCssVar . add ( token2CSSVar ( key , getCompVarPrefix ( component , cssVar . prefix ) ) ) ;
332- } ) ;
333- }
311+ Object . keys ( options . unitless || { } ) . forEach ( ( key ) => {
312+ // Some component proxy the AliasToken (e.g. Image) and some not (e.g. Modal)
313+ // We should both pass in `unitlessCssVar` to make sure the CSSVar can be unitless.
314+ unitlessCssVar . add ( token2CSSVar ( key , cssVar . prefix ) ) ;
315+ unitlessCssVar . add ( token2CSSVar ( key , getCompVarPrefix ( component , cssVar . prefix ) ) ) ;
316+ } ) ;
334317
335318 return genCalc ( type , unitlessCssVar ) ;
336319 } , [ type , component , cssVar ?. prefix ] ) ;
@@ -359,7 +342,7 @@ function genStyleUtils<
359342 ) ;
360343 }
361344
362- const wrapSSR = useStyleRegister (
345+ useStyleRegister (
363346 { ...sharedConfig , path : [ concatComponent , prefixCls , iconPrefixCls ] } ,
364347 ( ) => {
365348 if ( options . injectStyle === false ) {
@@ -382,7 +365,7 @@ function genStyleUtils<
382365 { deprecatedTokens : options . deprecatedTokens } ,
383366 ) ;
384367
385- if ( cssVar && defaultComponentToken && typeof defaultComponentToken === 'object' ) {
368+ if ( defaultComponentToken && typeof defaultComponentToken === 'object' ) {
386369 Object . keys ( defaultComponentToken ) . forEach ( ( key ) => {
387370 defaultComponentToken [ key ] = `var(${ token2CSSVar (
388371 key ,
@@ -398,12 +381,10 @@ function genStyleUtils<
398381 iconCls : `.${ iconPrefixCls } ` ,
399382 antCls : `.${ rootPrefixCls } ` ,
400383 calc,
401- // @ts -ignore
402384 max,
403- // @ts -ignore
404385 min,
405386 } ,
406- cssVar ? defaultComponentToken : componentToken ,
387+ defaultComponentToken ,
407388 ) ;
408389
409390 const styleInterpolation = styleFn ( mergedToken , {
@@ -421,7 +402,7 @@ function genStyleUtils<
421402 } ,
422403 ) ;
423404
424- return [ wrapSSR , hashId ] ;
405+ return hashId ;
425406 } ;
426407 }
427408
0 commit comments