From d50674c8fe62d58e89fd8023e23e6393b3f681e8 Mon Sep 17 00:00:00 2001 From: Ari Date: Mon, 4 Jul 2022 22:24:48 -0400 Subject: [PATCH] passing mui colors to css --- webapp/src/components/Page/index.tsx | 57 +++++++++++++++++----------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/webapp/src/components/Page/index.tsx b/webapp/src/components/Page/index.tsx index ab2b3ec..b4f1928 100644 --- a/webapp/src/components/Page/index.tsx +++ b/webapp/src/components/Page/index.tsx @@ -1,11 +1,18 @@ import "./index.css"; import { createRef, FC, ReactNode, useEffect, useRef } from "react"; -import { createTheme, ThemeProvider, useTheme } from "@mui/material/styles"; +import { + createTheme, + Palette, + PaletteColor, + ThemeProvider, + useTheme, +} from "@mui/material/styles"; import { VersionBox } from "components/VersionBox"; import { SnackbarKey, SnackbarProvider, useSnackbar } from "notistack"; import Button from "@mui/material/Button"; import { useHAConnection } from "haService/connection"; import { ConfirmProvider } from "material-ui-confirm"; +import { Color } from "@mui/material"; const theme = createTheme({ palette: { @@ -66,30 +73,11 @@ export const InternalPage: FC<{ background: theme.palette.background.default, }} > - {/* */} + {children} @@ -124,3 +112,26 @@ export const Page: FC<{ ); }; + +export const convertPaletteToCss = (p: Palette): string => { + let out = ``; + for (const k of [ + "primary", + "secondary", + "error", + "warning", + "info", + "success", + "grey", + "text", + "action", + "background", + "common", + ]) { + const pc = p[k as keyof Palette] as PaletteColor | Color; + Object.entries(pc).forEach(([n, v]) => { + out += `\n --mui-${k}-${n}: ${v};`; + }); + } + return out; +};