mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-17 19:00:15 +08:00
5c99a5ee49
* type: fix .dumi typing error * type: fix React.Key type error * type: fix React.Key type error * type: fix React.Key type error * type: fix React.Key type error * Apply suggestions from code review Signed-off-by: afc163 <afc163@gmail.com> * fix: test case * fix: test case * chore: use @types/react latest version * Apply suggestions from code review Signed-off-by: afc163 <afc163@gmail.com> * chore: update form def * chore: more ts * chore: revert demo ts * chore: bump ver * chore: fix more * chore: fix demo * chore: back of ci * chore: fix ts * chore: fix ts * chore: part of it * chore: fix ts * chore: bump ver * chore: fix lint * chore: fix * test: update test --------- Signed-off-by: afc163 <afc163@gmail.com> Co-authored-by: 二货机器人 <smith3816@gmail.com>
59 lines
1.6 KiB
TypeScript
59 lines
1.6 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';
|
|
|
|
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;
|
|
}
|
|
|
|
const SiteThemeProvider: React.FC<ThemeProviderProps<any>> = ({ children, theme, ...rest }) => {
|
|
const { getPrefixCls, iconPrefixCls } = useContext(ConfigProvider.ConfigContext);
|
|
const rootPrefixCls = getPrefixCls();
|
|
const { token } = antdTheme.useToken();
|
|
|
|
React.useEffect(() => {
|
|
ConfigProvider.config({ theme: theme as ThemeConfig });
|
|
}, [theme]);
|
|
|
|
return (
|
|
<ThemeProvider<NewToken>
|
|
{...rest}
|
|
theme={theme}
|
|
customToken={{
|
|
headerHeight: 64,
|
|
bannerHeight: 38,
|
|
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,
|
|
}}
|
|
>
|
|
{children}
|
|
</ThemeProvider>
|
|
);
|
|
};
|
|
|
|
export default SiteThemeProvider;
|