UI: Expose theme as css custom props (#2380)

This commit is contained in:
Shy
2025-11-04 01:58:09 +01:00
committed by GitHub
parent e599988af7
commit 9cd3ffd308
2 changed files with 19 additions and 0 deletions

View File

@@ -26,5 +26,12 @@ export default class FixJSDOMEnvironment extends JSDOMEnvironment {
this.global.TextDecoderStream = TextDecoderStream; this.global.TextDecoderStream = TextDecoderStream;
this.global.URL = URL; this.global.URL = URL;
this.global.Response = Response; this.global.Response = Response;
/**
* https://github.com/jsdom/jsdom/issues/3766
* https://github.com/jsdom/jsdom/issues/3444
*/
this.global.document.adoptedStyleSheets = [];
this.global.CSSStyleSheet.prototype.replaceSync = () => {};
} }
} }

View File

@@ -51,6 +51,7 @@ declare module "@mui/material/styles" {
} }
let theme: Theme; let theme: Theme;
const themeStyleSheet = new CSSStyleSheet();
export function refreshTheme(): void { export function refreshTheme(): void {
theme = createTheme({ theme = createTheme({
@@ -419,7 +420,18 @@ export function refreshTheme(): void {
}); });
document.body.style.backgroundColor = theme.colors.backgroundprimary?.toString() ?? "black"; document.body.style.backgroundColor = theme.colors.backgroundprimary?.toString() ?? "black";
const styleSheet =
":root {" +
Object.entries(Settings.theme)
.map(([k, v]) => `--bb-theme-${k}: ${v}`)
.join(";") +
"}";
themeStyleSheet.replaceSync(styleSheet);
} }
document.adoptedStyleSheets.push(themeStyleSheet);
refreshTheme(); refreshTheme();
interface IProps { interface IProps {