Compare commits

...

2 Commits

Author SHA1 Message Date
wuxh 3146cb49a3
chore: update 2 years ago
wuxh 1060bcdc00
feat: default add resetIcon Style 2 years ago
  1. 27
      components/app/__tests__/index.test.tsx
  2. 4
      components/config-provider/index.tsx
  3. 5
      components/config-provider/style/index.ts
  4. 4
      components/theme/util/genComponentStyleHook.ts

27
components/app/__tests__/index.test.tsx

@ -1,3 +1,4 @@
import { SmileOutlined } from '@ant-design/icons';
import React, { useEffect } from 'react';
import App from '..';
import mountTest from '../../../tests/shared/mountTest';
@ -140,4 +141,30 @@ describe('App', () => {
);
expect(container.querySelector<HTMLDivElement>('.ant-app')).toHaveStyle('color: blue;');
});
// https://github.com/ant-design/ant-design/issues/41197#issuecomment-1465803061
describe('restIcon style', () => {
beforeEach(() => {
Array.from(document.querySelectorAll('style')).forEach((style) => {
style.parentNode?.removeChild(style);
});
});
it('should work by default', () => {
const { container } = render(
<App>
<SmileOutlined />
</App>,
);
expect(container.querySelector('.anticon')).toBeTruthy();
const dynamicStyles = Array.from(document.querySelectorAll('style[data-css-hash]'));
expect(
dynamicStyles.some((style) => {
const { innerHTML } = style;
return innerHTML.startsWith('.anticon');
}),
).toBeTruthy();
});
});
});

4
components/config-provider/index.tsx

@ -25,7 +25,7 @@ import useConfig from './hooks/useConfig';
import useTheme from './hooks/useTheme';
import type { SizeType } from './SizeContext';
import SizeContext, { SizeContextProvider } from './SizeContext';
import useStyle from './style';
import { useResetIconStyle } from './style';
/**
* Since too many feedback using static method like `Modal.confirm` not getting theme,
@ -206,7 +206,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
const shouldWrapSSR = iconPrefixCls !== parentContext.iconPrefixCls;
const csp = customCsp || parentContext.csp;
const wrapSSR = useStyle(iconPrefixCls, csp);
const wrapSSR = useResetIconStyle(iconPrefixCls, csp);
const mergedTheme = useTheme(theme, parentContext.theme);

5
components/config-provider/style/index.ts

@ -1,9 +1,10 @@
/* eslint-disable import/prefer-default-export */
import { useStyleRegister } from '@ant-design/cssinjs';
import type { CSPConfig } from '..';
import { resetIcon } from '../../style';
import { useToken } from '../../theme/internal';
const useStyle = (iconPrefixCls: string, csp?: CSPConfig) => {
export const useResetIconStyle = (iconPrefixCls: string, csp?: CSPConfig) => {
const [theme, token] = useToken();
// Generate style for icons
@ -27,5 +28,3 @@ const useStyle = (iconPrefixCls: string, csp?: CSPConfig) => {
],
);
};
export default useStyle;

4
components/theme/util/genComponentStyleHook.ts

@ -4,6 +4,7 @@ import { useStyleRegister } from '@ant-design/cssinjs';
import { useContext } from 'react';
import { ConfigContext } from '../../config-provider/context';
import { genCommonStyle, genLinkStyle } from '../../style';
import { useResetIconStyle } from '../../config-provider/style';
import type { ComponentTokenMap, GlobalToken } from '../interface';
import type { UseComponentStyleResult } from '../internal';
import { mergeToken, statisticToken, useToken } from '../internal';
@ -66,6 +67,9 @@ export default function genComponentStyleHook<ComponentName extends OverrideComp
},
]);
// Generate style for icons
useResetIconStyle(iconPrefixCls);
return [
useStyleRegister({ ...sharedConfig, path: [component, prefixCls, iconPrefixCls] }, () => {
const { token: proxyToken, flush } = statisticToken(token);

Loading…
Cancel
Save