2024-07-23 18:55:48 +08:00
|
|
|
import { useContext } from 'react';
|
|
|
|
import { genStyleUtils } from '@ant-design/cssinjs-utils';
|
2024-07-29 01:31:25 +08:00
|
|
|
import type { GetCompUnitless } from '@ant-design/cssinjs-utils/es/util/genStyleUtils';
|
2024-07-23 18:55:48 +08:00
|
|
|
|
|
|
|
import { ConfigContext } from '../../config-provider/context';
|
|
|
|
import { genCommonStyle, genLinkStyle } from '../../style';
|
2024-07-29 01:31:25 +08:00
|
|
|
import type { AliasToken, ComponentTokenMap, SeedToken } from '../interface';
|
|
|
|
import useLocalToken, { unitless } from '../useToken';
|
2024-07-23 18:55:48 +08:00
|
|
|
import useResetIconStyle from './useResetIconStyle';
|
|
|
|
|
2024-07-29 01:31:25 +08:00
|
|
|
export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = genStyleUtils<
|
2024-07-23 18:55:48 +08:00
|
|
|
ComponentTokenMap,
|
|
|
|
AliasToken,
|
|
|
|
SeedToken
|
|
|
|
>({
|
|
|
|
usePrefix: () => {
|
|
|
|
const { getPrefixCls, iconPrefixCls } = useContext(ConfigContext);
|
|
|
|
|
|
|
|
const rootPrefixCls = getPrefixCls();
|
|
|
|
|
|
|
|
return {
|
|
|
|
rootPrefixCls,
|
|
|
|
iconPrefixCls,
|
2024-07-29 01:31:25 +08:00
|
|
|
};
|
2024-07-23 18:55:48 +08:00
|
|
|
},
|
|
|
|
useToken: () => {
|
2024-07-29 01:31:25 +08:00
|
|
|
const [theme, realToken, hashId, token, cssVar] = useLocalToken();
|
|
|
|
return { theme, realToken, hashId, token, cssVar };
|
2024-07-23 18:55:48 +08:00
|
|
|
},
|
|
|
|
useCSP: () => {
|
|
|
|
const { csp, iconPrefixCls } = useContext(ConfigContext);
|
|
|
|
|
|
|
|
// Generate style for icons
|
|
|
|
useResetIconStyle(iconPrefixCls, csp);
|
|
|
|
|
|
|
|
return csp ?? {};
|
|
|
|
},
|
2024-07-29 01:31:25 +08:00
|
|
|
getResetStyles: (token) => [{ '&': genLinkStyle(token) }],
|
2024-07-23 19:27:06 +08:00
|
|
|
getCommonStyle: genCommonStyle,
|
2024-07-29 01:31:25 +08:00
|
|
|
getCompUnitless: (() => unitless) as GetCompUnitless<ComponentTokenMap, AliasToken>,
|
|
|
|
});
|