mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-19 20:08:43 +08:00
refactor: fixed the issue of icon styles being duplicated.
This commit is contained in:
parent
2ba2801d10
commit
8a82e55197
@ -6,6 +6,7 @@ import { ConfigContext } from '../../config-provider/context';
|
||||
import { genCommonStyle, genLinkStyle } from '../../style';
|
||||
import type { AliasToken, ComponentTokenMap, SeedToken } from '../interface';
|
||||
import useLocalToken, { unitless } from '../useToken';
|
||||
import { genIconStyle } from './useResetIconStyle';
|
||||
|
||||
export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = genStyleUtils<
|
||||
ComponentTokenMap,
|
||||
@ -30,7 +31,7 @@ export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = ge
|
||||
const { csp } = useContext(ConfigContext);
|
||||
return csp ?? {};
|
||||
},
|
||||
getResetStyles: (token) => [{ '&': genLinkStyle(token) }],
|
||||
getResetStyles: (token) => [{ '&': genLinkStyle(token) }, genIconStyle()],
|
||||
getCommonStyle: genCommonStyle,
|
||||
getCompUnitless: (() => unitless) as GetCompUnitless<ComponentTokenMap, AliasToken>,
|
||||
});
|
||||
|
@ -1,34 +1,35 @@
|
||||
import { useStyleRegister } from '@ant-design/cssinjs';
|
||||
import type { CSSObject } from '@ant-design/cssinjs';
|
||||
|
||||
import type { CSPConfig } from '../../config-provider';
|
||||
import { resetIcon } from '../../style';
|
||||
import useToken from '../useToken';
|
||||
|
||||
export const genIconStyle = (iconPrefixCls = 'anticon'): CSSObject => ({
|
||||
[`.${iconPrefixCls}`]: {
|
||||
...resetIcon(),
|
||||
[`.${iconPrefixCls} .${iconPrefixCls}-icon`]: {
|
||||
display: 'block',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const useResetIconStyle = (iconPrefixCls: string, csp?: CSPConfig) => {
|
||||
const [theme, token] = useToken();
|
||||
const [theme, token, hashId] = useToken();
|
||||
|
||||
// Generate style for icons
|
||||
return useStyleRegister(
|
||||
{
|
||||
theme,
|
||||
token,
|
||||
hashId: '',
|
||||
hashId,
|
||||
path: ['ant-design-icons', iconPrefixCls],
|
||||
nonce: () => csp?.nonce!,
|
||||
layer: {
|
||||
name: 'antd',
|
||||
},
|
||||
},
|
||||
() => [
|
||||
{
|
||||
[`.${iconPrefixCls}`]: {
|
||||
...resetIcon(),
|
||||
[`.${iconPrefixCls} .${iconPrefixCls}-icon`]: {
|
||||
display: 'block',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
() => [genIconStyle(iconPrefixCls)],
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -107,7 +107,7 @@
|
||||
"dependencies": {
|
||||
"@ant-design/colors": "^7.1.0",
|
||||
"@ant-design/cssinjs": "^1.21.1",
|
||||
"@ant-design/cssinjs-utils": "^1.1.1",
|
||||
"@ant-design/cssinjs-utils": "^1.1.3",
|
||||
"@ant-design/icons": "^5.5.2",
|
||||
"@ant-design/react-slick": "~1.1.2",
|
||||
"@babel/runtime": "^7.25.7",
|
||||
|
Loading…
Reference in New Issue
Block a user