mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 12:09:14 +08:00
8950642664
* feat: config support container * feat: add test * feat: reset demo * feat: test * feat: test * feat: test * feat: test * feat: md * feat: limit * fix: prefix * feat: limit * feat: message support app config * feat: notification support app config * feat: add maxCount test * feat: icons * feat: 增加 2 个 todo * feat: holderRender * feat: md * feat: message 兼容旧逻辑 * feat: notification 兼容完成 * feat: modal 兼容完成 * feat: 优化 modal * feat: 优化代码 * feat: 优化代码 * feat: 给 CP 添加 demo * feat: 优先级完成/demo迁移完成 * feat: review * feat: review * feat: 优化 modal 代码 * feat: 支持 rtl * feat: 修改注释 * feat: 优化单测 * feat: 优先级注释 * feat: remove getPrefixCls * feat: demo * feat: demo * feat: demo --------- Co-authored-by: MadCcc <madccc@foxmail.com>
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import React, { useContext } from 'react';
|
|
import { theme as antdTheme, ConfigProvider } from 'antd';
|
|
import type { ThemeConfig } from 'antd';
|
|
import type { ThemeProviderProps } from 'antd-style';
|
|
import { ThemeProvider } from 'antd-style';
|
|
|
|
import SiteContext from './slots/SiteContext';
|
|
|
|
interface NewToken {
|
|
bannerHeight: number;
|
|
headerHeight: number;
|
|
menuItemBorder: number;
|
|
mobileMaxWidth: number;
|
|
siteMarkdownCodeBg: string;
|
|
antCls: string;
|
|
iconCls: string;
|
|
marginFarXS: number;
|
|
marginFarSM: number;
|
|
marginFar: number;
|
|
codeFamily: string;
|
|
contentMarginTop: number;
|
|
anchorTop: number;
|
|
}
|
|
|
|
// 通过给 antd-style 扩展 CustomToken 对象类型定义,可以为 useTheme 中增加相应的 token 对象
|
|
declare module 'antd-style' {
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
export interface CustomToken extends NewToken {}
|
|
}
|
|
|
|
const headerHeight = 64;
|
|
const bannerHeight = 38;
|
|
|
|
const SiteThemeProvider: React.FC<ThemeProviderProps<any>> = ({ children, theme, ...rest }) => {
|
|
const { getPrefixCls, iconPrefixCls } = useContext(ConfigProvider.ConfigContext);
|
|
const rootPrefixCls = getPrefixCls();
|
|
const { token } = antdTheme.useToken();
|
|
const { bannerVisible } = useContext(SiteContext);
|
|
React.useEffect(() => {
|
|
// 需要注意与 components/config-provider/demo/holderRender.tsx 配置冲突
|
|
ConfigProvider.config({ theme: theme as ThemeConfig });
|
|
}, [theme]);
|
|
|
|
return (
|
|
<ThemeProvider<NewToken>
|
|
{...rest}
|
|
theme={theme}
|
|
customToken={{
|
|
headerHeight,
|
|
bannerHeight,
|
|
menuItemBorder: 2,
|
|
mobileMaxWidth: 767.99,
|
|
siteMarkdownCodeBg: token.colorFillTertiary,
|
|
antCls: `.${rootPrefixCls}`,
|
|
iconCls: `.${iconPrefixCls}`,
|
|
/** 56 */
|
|
marginFarXS: (token.marginXXL / 6) * 7,
|
|
/** 80 */
|
|
marginFarSM: (token.marginXXL / 3) * 5,
|
|
/** 96 */
|
|
marginFar: token.marginXXL * 2,
|
|
codeFamily: `'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace`,
|
|
contentMarginTop: 40,
|
|
anchorTop: headerHeight + token.margin + (bannerVisible ? bannerHeight : 0),
|
|
}}
|
|
>
|
|
{children}
|
|
</ThemeProvider>
|
|
);
|
|
};
|
|
|
|
export default SiteThemeProvider;
|