passing mui colors to css
This commit is contained in:
1 parent
81f22ccd2a
commit
d50674c8fe
1 file changed
+34
-23
@@ -1,11 +1,18 @@
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { createRef, FC, ReactNode, useEffect, useRef } from "react";
|
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 { VersionBox } from "components/VersionBox";
|
||||||
import { SnackbarKey, SnackbarProvider, useSnackbar } from "notistack";
|
import { SnackbarKey, SnackbarProvider, useSnackbar } from "notistack";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import { useHAConnection } from "haService/connection";
|
import { useHAConnection } from "haService/connection";
|
||||||
import { ConfirmProvider } from "material-ui-confirm";
|
import { ConfirmProvider } from "material-ui-confirm";
|
||||||
|
import { Color } from "@mui/material";
|
||||||
|
|
||||||
const theme = createTheme({
|
const theme = createTheme({
|
||||||
palette: {
|
palette: {
|
||||||
@@ -66,30 +73,11 @@ export const InternalPage: FC<{
|
|||||||
background: theme.palette.background.default,
|
background: theme.palette.background.default,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* <style>
|
<style>
|
||||||
{`:root {
|
{`:root {
|
||||||
--primary: ${theme.palette.primary.main};
|
${convertPaletteToCss(theme.palette)}
|
||||||
--secondary: ${theme.palette.secondary.main};
|
|
||||||
--secondary: ${theme.palette..main};
|
|
||||||
--primary-accent: #bbb;
|
|
||||||
--primary-accent-light: #eee;
|
|
||||||
--secondary-accent: #929191;
|
|
||||||
--green: #1f1;
|
|
||||||
--green-opaque: #1f15;
|
|
||||||
--green-light: #6f5;
|
|
||||||
--error: #c55;
|
|
||||||
--error-light: #f77;
|
|
||||||
--error-dark: #5c2323;
|
|
||||||
--error-opaque: #c555;
|
|
||||||
--error-accent: #9f3a3a;
|
|
||||||
--change: #0f9;
|
|
||||||
--condition-primary: #447;
|
|
||||||
--condition-accent: #8af;
|
|
||||||
--condition-primary-opaque: #4476;
|
|
||||||
touch-action: pan-x pan-y;
|
|
||||||
height: 100%;
|
|
||||||
}`}
|
}`}
|
||||||
</style> */}
|
</style>
|
||||||
<VersionBox />
|
<VersionBox />
|
||||||
{children}
|
{children}
|
||||||
</main>
|
</main>
|
||||||
@@ -124,3 +112,26 @@ export const Page: FC<{
|
|||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
Reference in new issue
Block a user