mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 01:19:45 +08:00
63 lines
1.3 KiB
TypeScript
63 lines
1.3 KiB
TypeScript
|
import { useContext } from 'react';
|
||
|
import { genStyleUtils } from '@ant-design/cssinjs-utils';
|
||
|
|
||
|
import { ConfigContext } from '../../config-provider/context';
|
||
|
import { genCommonStyle, genLinkStyle } from '../../style';
|
||
|
import type {
|
||
|
AliasToken,
|
||
|
ComponentTokenMap,
|
||
|
SeedToken,
|
||
|
} from '../interface';
|
||
|
|
||
|
import localUseToken from '../useToken';
|
||
|
import useResetIconStyle from './useResetIconStyle';
|
||
|
|
||
|
export const {
|
||
|
genStyleHooks,
|
||
|
genComponentStyleHook,
|
||
|
genSubStyleComponent,
|
||
|
} = genStyleUtils<
|
||
|
ComponentTokenMap,
|
||
|
AliasToken,
|
||
|
SeedToken
|
||
|
>({
|
||
|
usePrefix: () => {
|
||
|
const { getPrefixCls, iconPrefixCls } = useContext(ConfigContext);
|
||
|
|
||
|
const rootPrefixCls = getPrefixCls();
|
||
|
|
||
|
return {
|
||
|
rootPrefixCls,
|
||
|
iconPrefixCls,
|
||
|
}
|
||
|
},
|
||
|
useToken: () => {
|
||
|
const [theme, realToken, hashId, token, cssVar] = localUseToken();
|
||
|
|
||
|
return {
|
||
|
theme,
|
||
|
realToken,
|
||
|
hashId,
|
||
|
token,
|
||
|
cssVar,
|
||
|
};
|
||
|
},
|
||
|
useCSP: () => {
|
||
|
const { csp, iconPrefixCls } = useContext(ConfigContext);
|
||
|
|
||
|
// Generate style for icons
|
||
|
useResetIconStyle(iconPrefixCls, csp);
|
||
|
|
||
|
return csp ?? {};
|
||
|
},
|
||
|
getResetStyles: (token) =>
|
||
|
[
|
||
|
{
|
||
|
// Link
|
||
|
'&': genLinkStyle(token as any),
|
||
|
},
|
||
|
]
|
||
|
,
|
||
|
getCommonStyle: genCommonStyle as any,
|
||
|
})
|