Skip to content

Commit

Permalink
feat: add useResetStyle to generate style for all need reset tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
YumoImer committed Jul 11, 2024
1 parent 61890ac commit da1e61b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/hooks/useResetStyle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useStyleRegister } from '@ant-design/cssinjs';
import type { UsePrefix } from './usePrefix';

export type UseResetStyle = (
options: Omit<Parameters<typeof useStyleRegister>[0], 'path'>,
prefixs: ReturnType<UsePrefix>,
) => void;
19 changes: 6 additions & 13 deletions src/util/genStyleUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import useUniqueMemo from '../_util/hooks/useUniqueMemo';
import useDefaultCSP, { type UseCSP } from '../hooks/useCSP';
import { type UsePrefix } from '../hooks/usePrefix';
import { type UseToken } from '../hooks/useToken';
import { type UseResetStyle } from '../hooks/useResetStyle';

export interface StyleInfo {
hashId: string;
Expand Down Expand Up @@ -102,13 +103,15 @@ export default function genStyleUtils<
usePrefix: UsePrefix;
useToken: UseToken<CompTokenMap, DesignToken, AliasToken>;
useCSP?: UseCSP;
useResetStyle?: UseResetStyle;
}
) {
// Dependency inversion for preparing basic config.
const {
useCSP = useDefaultCSP,
useToken,
usePrefix,
useResetStyle = () => {},
} = config;

function genStyleHooks<C extends TokenMapKey<CompTokenMap>>(
Expand Down Expand Up @@ -304,7 +307,6 @@ export default function genStyleUtils<
unitless?: {
[key in ComponentTokenKey<CompTokenMap, C>]: boolean;
};
genLinkStyle?: (token: OverrideTokenMap<CompTokenMap>) => CSSObject;
genCommonStyle?: (
token: OverrideTokenMap<CompTokenMap>,
componentPrefixCls: string,
Expand Down Expand Up @@ -350,6 +352,7 @@ export default function genStyleUtils<

return genCalc(type, unitlessCssVar);
}, [type, component, cssVar?.prefix]);

const { max, min } = genMaxMin(type);

// Shared config
Expand All @@ -368,18 +371,8 @@ export default function genStyleUtils<
order: options.order || -999,
};

// Generate style for all a tags in antd component.
useStyleRegister(
{ ...sharedConfig, clientOnly: false, path: ['Shared', rootPrefixCls] },
() => [
{
// Link
'&': options?.genLinkStyle?.(token) ?? {},
},
],
);

// Generate style for icons
// Generate style for all need reset tags.
useResetStyle(sharedConfig, { rootPrefixCls, iconPrefixCls });

const wrapSSR = useStyleRegister(
{ ...sharedConfig, path: [concatComponent, prefixCls, iconPrefixCls] },
Expand Down

0 comments on commit da1e61b

Please sign in to comment.