ant-design/components/theme/util/genStyleUtils.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

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';
import { ConfigContext } from '../../config-provider/context';
2024-12-06 14:13:34 +08:00
import { genCommonStyle, genLinkStyle, genIconStyle } from '../../style';
2024-07-29 01:31:25 +08:00
import type { AliasToken, ComponentTokenMap, SeedToken } from '../interface';
import useLocalToken, { unitless } from '../useToken';
2024-07-29 01:31:25 +08:00
export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = genStyleUtils<
ComponentTokenMap,
AliasToken,
SeedToken
>({
usePrefix: () => {
const { getPrefixCls, iconPrefixCls } = useContext(ConfigContext);
const rootPrefixCls = getPrefixCls();
return {
rootPrefixCls,
iconPrefixCls,
2024-07-29 01:31:25 +08:00
};
},
useToken: () => {
2024-07-29 01:31:25 +08:00
const [theme, realToken, hashId, token, cssVar] = useLocalToken();
return { theme, realToken, hashId, token, cssVar };
},
useCSP: () => {
const { csp } = useContext(ConfigContext);
return csp ?? {};
},
getResetStyles: (token) => [{ '&': genLinkStyle(token) }, genIconStyle()],
getCommonStyle: genCommonStyle,
2024-07-29 01:31:25 +08:00
getCompUnitless: (() => unitless) as GetCompUnitless<ComponentTokenMap, AliasToken>,
});