2023-05-18 23:53:34 +08:00
|
|
|
import { ConfigProvider, theme as antdTheme } from 'antd';
|
2023-04-20 10:47:06 +08:00
|
|
|
import type { ThemeProviderProps } from 'antd-style';
|
2023-04-18 15:29:34 +08:00
|
|
|
import { ThemeProvider } from 'antd-style';
|
2023-05-18 23:53:34 +08:00
|
|
|
import type { FC } from 'react';
|
|
|
|
import React, { useContext } from 'react';
|
2023-04-18 15:29:34 +08:00
|
|
|
|
2023-05-18 23:53:34 +08:00
|
|
|
const SiteThemeProvider: FC<ThemeProviderProps> = ({ children, theme, ...rest }) => {
|
|
|
|
const { getPrefixCls, iconPrefixCls } = useContext(ConfigProvider.ConfigContext);
|
2023-04-18 15:29:34 +08:00
|
|
|
const rootPrefixCls = getPrefixCls();
|
2023-05-18 23:53:34 +08:00
|
|
|
const { token } = antdTheme.useToken();
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
ConfigProvider.config({
|
|
|
|
theme,
|
|
|
|
});
|
|
|
|
}, [theme]);
|
2023-04-18 15:29:34 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ThemeProvider
|
2023-04-20 10:47:06 +08:00
|
|
|
{...rest}
|
2023-05-18 23:53:34 +08:00
|
|
|
theme={theme}
|
2023-04-18 15:29:34 +08:00
|
|
|
customToken={{
|
|
|
|
headerHeight: 64,
|
|
|
|
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`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SiteThemeProvider;
|