|
@ -2,11 +2,11 @@ |
|
|
import type { CSSInterpolation } from '@ant-design/cssinjs'; |
|
|
import type { CSSInterpolation } from '@ant-design/cssinjs'; |
|
|
import { useStyleRegister } from '@ant-design/cssinjs'; |
|
|
import { useStyleRegister } from '@ant-design/cssinjs'; |
|
|
import { useContext } from 'react'; |
|
|
import { useContext } from 'react'; |
|
|
import { genCommonStyle, genLinkStyle } from '../../style'; |
|
|
|
|
|
import { ConfigContext } from '../../config-provider/context'; |
|
|
import { ConfigContext } from '../../config-provider/context'; |
|
|
|
|
|
import { genCommonStyle, genLinkStyle } from '../../style'; |
|
|
|
|
|
import type { ComponentTokenMap, GlobalToken } from '../interface'; |
|
|
import type { UseComponentStyleResult } from '../internal'; |
|
|
import type { UseComponentStyleResult } from '../internal'; |
|
|
import { mergeToken, statisticToken, useToken } from '../internal'; |
|
|
import { mergeToken, statisticToken, useToken } from '../internal'; |
|
|
import type { ComponentTokenMap, GlobalToken } from '../interface'; |
|
|
|
|
|
|
|
|
|
|
|
export type OverrideTokenWithoutDerivative = ComponentTokenMap; |
|
|
export type OverrideTokenWithoutDerivative = ComponentTokenMap; |
|
|
export type OverrideComponent = keyof OverrideTokenWithoutDerivative; |
|
|
export type OverrideComponent = keyof OverrideTokenWithoutDerivative; |
|
@ -44,11 +44,19 @@ export default function genComponentStyleHook<ComponentName extends OverrideComp |
|
|
) { |
|
|
) { |
|
|
return (prefixCls: string): UseComponentStyleResult => { |
|
|
return (prefixCls: string): UseComponentStyleResult => { |
|
|
const [theme, token, hashId] = useToken(); |
|
|
const [theme, token, hashId] = useToken(); |
|
|
const { getPrefixCls, iconPrefixCls } = useContext(ConfigContext); |
|
|
const { getPrefixCls, iconPrefixCls, csp } = useContext(ConfigContext); |
|
|
const rootPrefixCls = getPrefixCls(); |
|
|
const rootPrefixCls = getPrefixCls(); |
|
|
|
|
|
|
|
|
|
|
|
// Shared config
|
|
|
|
|
|
const sharedConfig: Omit<Parameters<typeof useStyleRegister>[0], 'path'> = { |
|
|
|
|
|
theme, |
|
|
|
|
|
token, |
|
|
|
|
|
hashId, |
|
|
|
|
|
nonce: () => csp?.nonce!, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
// Generate style for all a tags in antd component.
|
|
|
// Generate style for all a tags in antd component.
|
|
|
useStyleRegister({ theme, token, hashId, path: ['Shared', rootPrefixCls] }, () => [ |
|
|
useStyleRegister({ ...sharedConfig, path: ['Shared', rootPrefixCls] }, () => [ |
|
|
{ |
|
|
{ |
|
|
// Link
|
|
|
// Link
|
|
|
'&': genLinkStyle(token), |
|
|
'&': genLinkStyle(token), |
|
@ -56,40 +64,37 @@ export default function genComponentStyleHook<ComponentName extends OverrideComp |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
return [ |
|
|
return [ |
|
|
useStyleRegister( |
|
|
useStyleRegister({ ...sharedConfig, path: [component, prefixCls, iconPrefixCls] }, () => { |
|
|
{ theme, token, hashId, path: [component, prefixCls, iconPrefixCls] }, |
|
|
const { token: proxyToken, flush } = statisticToken(token); |
|
|
() => { |
|
|
|
|
|
const { token: proxyToken, flush } = statisticToken(token); |
|
|
|
|
|
|
|
|
|
|
|
const defaultComponentToken = |
|
|
const defaultComponentToken = |
|
|
typeof getDefaultToken === 'function' ? getDefaultToken(proxyToken) : getDefaultToken; |
|
|
typeof getDefaultToken === 'function' ? getDefaultToken(proxyToken) : getDefaultToken; |
|
|
const mergedComponentToken = { ...defaultComponentToken, ...token[component] }; |
|
|
const mergedComponentToken = { ...defaultComponentToken, ...token[component] }; |
|
|
|
|
|
|
|
|
const componentCls = `.${prefixCls}`; |
|
|
const componentCls = `.${prefixCls}`; |
|
|
const mergedToken = mergeToken< |
|
|
const mergedToken = mergeToken< |
|
|
TokenWithCommonCls<GlobalTokenWithComponent<OverrideComponent>> |
|
|
TokenWithCommonCls<GlobalTokenWithComponent<OverrideComponent>> |
|
|
>( |
|
|
>( |
|
|
proxyToken, |
|
|
proxyToken, |
|
|
{ |
|
|
{ |
|
|
componentCls, |
|
|
componentCls, |
|
|
prefixCls, |
|
|
|
|
|
iconCls: `.${iconPrefixCls}`, |
|
|
|
|
|
antCls: `.${rootPrefixCls}`, |
|
|
|
|
|
}, |
|
|
|
|
|
mergedComponentToken, |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const styleInterpolation = styleFn(mergedToken as unknown as FullToken<ComponentName>, { |
|
|
|
|
|
hashId, |
|
|
|
|
|
prefixCls, |
|
|
prefixCls, |
|
|
rootPrefixCls, |
|
|
iconCls: `.${iconPrefixCls}`, |
|
|
iconPrefixCls, |
|
|
antCls: `.${rootPrefixCls}`, |
|
|
overrideComponentToken: token[component], |
|
|
}, |
|
|
}); |
|
|
mergedComponentToken, |
|
|
flush(component, mergedComponentToken); |
|
|
); |
|
|
return [genCommonStyle(token, prefixCls), styleInterpolation]; |
|
|
|
|
|
}, |
|
|
const styleInterpolation = styleFn(mergedToken as unknown as FullToken<ComponentName>, { |
|
|
), |
|
|
hashId, |
|
|
|
|
|
prefixCls, |
|
|
|
|
|
rootPrefixCls, |
|
|
|
|
|
iconPrefixCls, |
|
|
|
|
|
overrideComponentToken: token[component], |
|
|
|
|
|
}); |
|
|
|
|
|
flush(component, mergedComponentToken); |
|
|
|
|
|
return [genCommonStyle(token, prefixCls), styleInterpolation]; |
|
|
|
|
|
}), |
|
|
hashId, |
|
|
hashId, |
|
|
]; |
|
|
]; |
|
|
}; |
|
|
}; |
|
|