This commit is contained in:
2026-05-25 17:08:18 +08:00
parent df501f6151
commit f1259b71b5
9178 changed files with 1626125 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
import { useContext } from 'react';
import { genStyleUtils } from '@ant-design/cssinjs-utils';
import { ConfigContext, defaultIconPrefixCls } from '../../config-provider/context';
import { genCommonStyle, genIconStyle, genLinkStyle } from '../../style';
import useLocalToken, { unitless } from '../useToken';
export const {
genStyleHooks,
genComponentStyleHook,
genSubStyleComponent
} = genStyleUtils({
usePrefix: () => {
const {
getPrefixCls,
iconPrefixCls
} = useContext(ConfigContext);
const rootPrefixCls = getPrefixCls();
return {
rootPrefixCls,
iconPrefixCls
};
},
useToken: () => {
const [theme, realToken, hashId, token, cssVar, zeroRuntime] = useLocalToken();
return {
theme,
realToken,
hashId,
token,
cssVar,
zeroRuntime
};
},
useCSP: () => {
const {
csp
} = useContext(ConfigContext);
return csp ?? {};
},
getResetStyles: (token, config) => {
const linkStyle = genLinkStyle(token);
return [linkStyle, {
'&': linkStyle
}, genIconStyle(config?.prefix.iconPrefixCls ?? defaultIconPrefixCls)];
},
getCommonStyle: genCommonStyle,
getCompUnitless: () => unitless
});
export const genCssVar = (antCls, component) => {
const cssPrefix = `--${antCls.replace(/\./g, '')}-${component}-`;
const varName = name => {
return `${cssPrefix}${name}`;
};
const varRef = (name, fallback) => {
return fallback ? `var(${cssPrefix}${name}, ${fallback})` : `var(${cssPrefix}${name})`;
};
return [varName, varRef];
};