Skip to content

Commit

Permalink
feat(App): icon reset style feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Mar 13, 2023
1 parent f8092b7 commit be69055
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions components/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const App: React.FC<AppProps> & { useApp: typeof useApp } = (props) => {
notification,
style,
} = props;
const { getPrefixCls } = useContext<ConfigConsumerProps>(ConfigContext);
const { getPrefixCls, iconPrefixCls } = useContext<ConfigConsumerProps>(ConfigContext);
const prefixCls = getPrefixCls('app', customizePrefixCls);
const [wrapSSR, hashId] = useStyle(prefixCls);
const [wrapSSR, hashId] = useStyle(prefixCls, iconPrefixCls);
const customClassName = classNames(hashId, prefixCls, className, rootClassName);

const appConfig = useContext<AppConfig>(AppConfigContext);
Expand Down
12 changes: 11 additions & 1 deletion components/app/style/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { FullToken, GenerateStyle } from '../../theme/internal';
import { genComponentStyleHook } from '../../theme/internal';
import { useResetIconStyle } from '../../config-provider/style';

export type ComponentToken = {};

Expand All @@ -18,5 +19,14 @@ const genBaseStyle: GenerateStyle<AppToken> = (token) => {
};
};

const useStyle = (prefixCls: string, iconPrefixCls: string) => {
const [wrapSSR, ...rest] = genComponentStyleHook('App', genBaseStyle)(prefixCls);
const iconWrapSSR = useResetIconStyle(iconPrefixCls);

const finalWrapSSR = (node: React.ReactElement) => wrapSSR(iconWrapSSR(node));

return [finalWrapSSR, ...rest] as const;
};

// ============================== Export ==============================
export default genComponentStyleHook('App', (token) => [genBaseStyle(token)]);
export default useStyle;
4 changes: 2 additions & 2 deletions components/config-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -206,7 +206,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
const shouldWrapSSR = iconPrefixCls !== parentContext.iconPrefixCls;
const csp = customCsp || parentContext.csp;

const wrapSSR = useStyle(iconPrefixCls);
const wrapSSR = useResetIconStyle(iconPrefixCls);

const mergedTheme = useTheme(theme, parentContext.theme);

Expand Down
5 changes: 2 additions & 3 deletions components/config-provider/style/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable import/prefer-default-export */
import { useStyleRegister } from '@ant-design/cssinjs';
import { resetIcon } from '../../style';
import { useToken } from '../../theme/internal';

const useStyle = (iconPrefixCls: string) => {
export const useResetIconStyle = (iconPrefixCls: string) => {
const [theme, token] = useToken();
// Generate style for icons
return useStyleRegister(
Expand All @@ -19,5 +20,3 @@ const useStyle = (iconPrefixCls: string) => {
],
);
};

export default useStyle;

0 comments on commit be69055

Please sign in to comment.