fix html fontsize

This commit is contained in:
Gabe Yuan
2023-11-22 10:23:14 +08:00
parent 013a05201b
commit f8bfcba317
7 changed files with 33 additions and 12 deletions

View File

@@ -12,10 +12,24 @@ import { THEME_DARK, THEME_LIGHT } from "../config";
export default function Theme({ children, options }) {
const { darkMode } = useDarkMode();
const theme = useMemo(() => {
let htmlFontSize = 16;
try {
const s = window.getComputedStyle(document.body.parentNode).fontSize;
const fontSize = parseInt(s.replace("px", ""));
if (fontSize > 0 && fontSize < 1000) {
htmlFontSize = fontSize;
}
} catch (err) {
//
}
return createTheme({
palette: {
mode: darkMode ? THEME_DARK : THEME_LIGHT,
},
typography: {
htmlFontSize,
},
...options,
});
}, [darkMode, options]);