mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-13 15:49:10 +08:00
43d7b9ca92
* chore: static config of theme * chore: static all method * test: add test case * docs: comment * docs: more info * test: update snapshot * test: fix test logic
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { ConfigProvider, theme as antdTheme } from 'antd';
|
|
import type { ThemeProviderProps } from 'antd-style';
|
|
import { ThemeProvider } from 'antd-style';
|
|
import type { FC } from 'react';
|
|
import React, { useContext } from 'react';
|
|
|
|
const SiteThemeProvider: FC<ThemeProviderProps> = ({ children, theme, ...rest }) => {
|
|
const { getPrefixCls, iconPrefixCls } = useContext(ConfigProvider.ConfigContext);
|
|
const rootPrefixCls = getPrefixCls();
|
|
const { token } = antdTheme.useToken();
|
|
|
|
React.useEffect(() => {
|
|
ConfigProvider.config({
|
|
theme,
|
|
});
|
|
}, [theme]);
|
|
|
|
return (
|
|
<ThemeProvider
|
|
{...rest}
|
|
theme={theme}
|
|
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;
|