Skip to content

Commit f5f5983

Browse files
committed
✨ feat: add antdPrefixCls
- Add antdPrefixCls to the return value of useStyles - Add antdPrefixCls to CreateStylesUtils
1 parent e8521e5 commit f5f5983

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

Diff for: src/core/createCSS.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { serializeStyles } from '@emotion/serialize';
77
const createClassNameGenerator =
88
(cache: EmotionCache, options: ClassNameGeneratorOption): ClassNameGenerator =>
99
(...args) => {
10-
const serialized = serializeStyles(args, cache.registered, undefined);
10+
// FIXME: fix type
11+
const serialized = serializeStyles(args as any, cache.registered, undefined);
1112

1213
insertStyles(cache, serialized, false, options);
1314

Diff for: src/core/createSerializeStyles.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export interface SerializeCSS {
1414
* 提供给 createStyles 方法,用于将用户写入的 css 字符串序列化成特定结构的样式对象
1515
* @param args
1616
*/
17-
export const serializeCSS: SerializeCSS = (...args) => serializeStyles(args);
17+
// FIXME: fix type
18+
export const serializeCSS: SerializeCSS = (...args) => serializeStyles(args as any);

Diff for: src/factories/createStyles/index.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ export const createStylesFactory =
5757

5858
// 函数场景
5959
if (styleOrGetStyle instanceof Function) {
60-
const { stylish, appearance, isDarkMode, prefixCls, iconPrefixCls, ...token } = theme;
60+
const {
61+
stylish,
62+
appearance,
63+
isDarkMode,
64+
prefixCls,
65+
iconPrefixCls,
66+
antdPrefixCls,
67+
...token
68+
} = theme;
6169

6270
// 创建响应式断点选择器的工具函数
6371
// @ts-ignore
@@ -74,6 +82,7 @@ export const createStylesFactory =
7482
isDarkMode,
7583
prefixCls,
7684
iconPrefixCls,
85+
antdPrefixCls,
7786
// 工具函数们
7887
cx,
7988
css: serializeCSS,
@@ -122,8 +131,8 @@ export const createStylesFactory =
122131
}, [props, theme]);
123132

124133
return useMemo(() => {
125-
const { prefixCls, iconPrefixCls, ...res } = theme;
126-
return { styles, cx, theme: res, prefixCls, iconPrefixCls };
134+
const { prefixCls, iconPrefixCls, antdPrefixCls, ...res } = theme;
135+
return { styles, cx, theme: res, prefixCls, iconPrefixCls, antdPrefixCls };
127136
}, [styles, theme]);
128137
};
129138
};

Diff for: src/factories/createStyles/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ export interface CreateStylesUtils extends CommonStyleUtils {
3232
*/
3333
prefixCls: string;
3434
iconPrefixCls: string;
35+
antdPrefixCls: string;
3536
}
3637

3738
/**
3839
* 最终返回 styles 对象的类型定义
3940
*/
4041
export interface ReturnStyles<T extends BaseReturnType> extends Pick<CommonStyleUtils, 'cx'> {
4142
styles: ReturnStyleToUse<T>;
42-
theme: Omit<Theme, 'prefixCls'>;
43+
theme: Omit<Theme, 'prefixCls' | 'antdPrefixCls'>;
4344
iconPrefixCls: string;
45+
antdPrefixCls: string;
4446
prefixCls: string;
4547
}
4648

Diff for: src/factories/createUseTheme.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const createUseTheme = (options: CreateUseThemeOptions) => (): Theme => {
2727
const { iconPrefixCls, getPrefixCls } = useContext(ConfigProvider.ConfigContext);
2828

2929
const antdPrefixCls = getPrefixCls();
30-
// 只有当用户在 createInstance 中传入与 ant 不一样的 prefixCls 时,才会使用用户的 prefixCls
30+
// 只有当用户在 createInstance 中传入与字符串 'ant' 不一样的 prefixCls 时,才会使用用户的 prefixCls
3131
// 否则其他情况下都优先使用 antd 的 prefixCls
3232
const prefixCls = outPrefixCls && outPrefixCls !== 'ant' ? outPrefixCls : antdPrefixCls;
3333

@@ -38,14 +38,15 @@ export const createUseTheme = (options: CreateUseThemeOptions) => (): Theme => {
3838
...defaultCustomTheme,
3939
prefixCls,
4040
iconPrefixCls,
41+
antdPrefixCls,
4142
}),
42-
[antdTheme, themeState, defaultCustomTheme, prefixCls, iconPrefixCls],
43+
[antdTheme, themeState, defaultCustomTheme, prefixCls, iconPrefixCls, antdPrefixCls],
4344
);
4445

4546
// 如果是个空值,说明没有套 Provider,返回 antdTheme 的默认值
4647
if (!styledTheme || Object.keys(styledTheme).length === 0) {
4748
return initTheme;
4849
}
4950

50-
return { ...styledTheme, prefixCls, iconPrefixCls } as Theme;
51+
return { ...styledTheme, prefixCls, iconPrefixCls, antdPrefixCls } as Theme;
5152
};

Diff for: src/types/theme.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ export interface FullToken extends AntdToken, CustomToken {}
7373
export interface Theme extends FullToken, ThemeContextState {
7474
stylish: FullStylish;
7575
/**
76-
* antd 组件的 prefixCls
76+
* 只有当用户在 createInstance 中传入与字符串 'ant' 不一样的 prefixCls 时,才会返回用户的 prefixCls
77+
* 否则返回 antd 的 prefixCls
7778
*/
7879
prefixCls: string;
7980
iconPrefixCls: string;
81+
/**
82+
* antd 组件的 prefixCls
83+
*/
84+
antdPrefixCls: string;
8085
}

0 commit comments

Comments
 (0)