apply dark mode to material ui theme

This commit is contained in:
Moritz Hölting 2024-06-24 11:35:16 +02:00
parent 8fa9c6563f
commit 313fd3d152
7 changed files with 78 additions and 71 deletions

View File

@ -1,11 +1,6 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useMonaco, type Monaco } from "@monaco-editor/react"; import { useMonaco, type Monaco } from "@monaco-editor/react";
import { useImmer, type Updater } from "use-immer"; import { useImmer, type Updater } from "use-immer";
import "@styles/playground.scss";
import mainFileContent from "@assets/playground/main.shu?raw";
import packTomlContent from "@assets/playground/pack.toml?raw";
import FileView from "./playground/FileView"; import FileView from "./playground/FileView";
import Editor from "./playground/Editor"; import Editor from "./playground/Editor";
import Header from "./playground/Header"; import Header from "./playground/Header";
@ -15,6 +10,13 @@ import initWasm, {
compileZip, compileZip,
} from "@wasm/webcompiler/pkg/webcompiler"; } from "@wasm/webcompiler/pkg/webcompiler";
import type { Directory, File, PlaygroundLang } from "@utils/playground"; import type { Directory, File, PlaygroundLang } from "@utils/playground";
import { customTheme } from "@utils/material-ui-theme";
import "@styles/playground.scss";
import mainFileContent from "@assets/playground/main.shu?raw";
import packTomlContent from "@assets/playground/pack.toml?raw";
import ThemeProvider from "@mui/material/styles/ThemeProvider";
const FILE_STORAGE_KEY = "playground-files"; const FILE_STORAGE_KEY = "playground-files";
const DEFAULT_FILES = { const DEFAULT_FILES = {
@ -156,7 +158,7 @@ export default function Playground({ lang }: { lang: PlaygroundLang }) {
}); });
return ( return (
<> <ThemeProvider theme={customTheme(theme)}>
<main <main
className="playground not-content" className="playground not-content"
style={{ style={{
@ -222,7 +224,7 @@ export default function Playground({ lang }: { lang: PlaygroundLang }) {
theme={theme} theme={theme}
/> />
</main> </main>
</> </ThemeProvider>
); );
} }
@ -360,7 +362,7 @@ function getStorageOrDefault(key: string, def: any) {
} }
} }
function jsonReplacer(key: any, value: any): any { function jsonReplacer(_key: any, value: any): any {
if (value instanceof Map) { if (value instanceof Map) {
const res: { [key: string]: any } = {}; const res: { [key: string]: any } = {};
for (const [k, v] of value.entries()) { for (const [k, v] of value.entries()) {

View File

@ -8,9 +8,6 @@ import Paper from "@mui/material/Paper";
import Popper from "@mui/material/Popper"; import Popper from "@mui/material/Popper";
import MenuItem from "@mui/material/MenuItem"; import MenuItem from "@mui/material/MenuItem";
import MenuList from "@mui/material/MenuList"; import MenuList from "@mui/material/MenuList";
import { ThemeProvider } from "@mui/material";
import { customTheme } from "@utils/material-ui-theme";
export default function DropdownButton({ export default function DropdownButton({
options, options,
@ -48,7 +45,7 @@ export default function DropdownButton({
}; };
return ( return (
<ThemeProvider theme={customTheme}> <>
<ButtonGroup <ButtonGroup
variant="contained" variant="contained"
ref={anchorRef} ref={anchorRef}
@ -56,7 +53,11 @@ export default function DropdownButton({
style={style} style={style}
> >
{visible.map(([children, onClick], index) => { {visible.map(([children, onClick], index) => {
return <Button key={index} onClick={onClick}>{children}</Button>; return (
<Button key={index} onClick={onClick}>
{children}
</Button>
);
})} })}
<Button <Button
size="small" size="small"
@ -111,6 +112,6 @@ export default function DropdownButton({
</Grow> </Grow>
)} )}
</Popper> </Popper>
</ThemeProvider> </>
); );
} }

View File

@ -1,12 +1,10 @@
import { import Button from "@mui/material/Button";
Button, import Dialog from "@mui/material/Dialog";
Dialog, import DialogActions from "@mui/material/DialogActions";
DialogActions, import DialogContent from "@mui/material/DialogContent";
DialogContent, import DialogContentText from "@mui/material/DialogContentText";
DialogContentText, import DialogTitle from "@mui/material/DialogTitle";
DialogTitle, import TextField from "@mui/material/TextField";
TextField,
} from "@mui/material";
import type { PlaygroundExplorerLang } from "@utils/playground"; import type { PlaygroundExplorerLang } from "@utils/playground";
export default function AddFileDialog({ export default function AddFileDialog({

View File

@ -9,10 +9,8 @@ import {
GoChevronRight as ChevRight, GoChevronRight as ChevRight,
} from "react-icons/go"; } from "react-icons/go";
import FileElement from "./FileElement"; import FileElement from "./FileElement";
import { import Menu from "@mui/material/Menu";
Menu, import MenuItem from "@mui/material/MenuItem";
MenuItem,
} from "@mui/material";
import AddFileDialog from "./AddFileDialog"; import AddFileDialog from "./AddFileDialog";
export default function DirElement({ export default function DirElement({
@ -108,7 +106,13 @@ export default function DirElement({
{lang.menu.delete} {lang.menu.delete}
</MenuItem> </MenuItem>
</Menu> </Menu>
<AddFileDialog lang={lang} defaultPath={fullPath + "/"} open={addOpen} addFile={addFile} handleClose={handleAddClose} /> <AddFileDialog
lang={lang}
defaultPath={fullPath + "/"}
open={addOpen}
addFile={addFile}
handleClose={handleAddClose}
/>
<div style={{ marginLeft: "0.5cm" }} className="dirChildren"> <div style={{ marginLeft: "0.5cm" }} className="dirChildren">
{collapsed ? null : ( {collapsed ? null : (
<div> <div>

View File

@ -1,14 +1,12 @@
import { import Button from "@mui/material/Button";
Button, import Dialog from "@mui/material/Dialog";
Dialog, import DialogActions from "@mui/material/DialogActions";
DialogActions, import DialogContent from "@mui/material/DialogContent";
DialogContent, import DialogContentText from "@mui/material/DialogContentText";
DialogContentText, import DialogTitle from "@mui/material/DialogTitle";
DialogTitle, import Menu from "@mui/material/Menu";
Menu, import MenuItem from "@mui/material/MenuItem";
MenuItem, import TextField from "@mui/material/TextField";
TextField,
} from "@mui/material";
import type { PlaygroundExplorerLang } from "@utils/playground"; import type { PlaygroundExplorerLang } from "@utils/playground";
import React from "react"; import React from "react";
import { useState } from "react"; import { useState } from "react";

View File

@ -5,7 +5,8 @@ import type {
} from "@utils/playground"; } from "@utils/playground";
import DirElement from "./DirElement"; import DirElement from "./DirElement";
import FileElement from "./FileElement"; import FileElement from "./FileElement";
import { Menu, MenuItem } from "@mui/material"; import MenuItem from "@mui/material/MenuItem";
import Menu from "@mui/material/Menu";
import React, { useState } from "react"; import React, { useState } from "react";
import AddFileDialog from "./AddFileDialog"; import AddFileDialog from "./AddFileDialog";

View File

@ -1,31 +1,34 @@
import { createTheme } from '@mui/material/styles'; import { createTheme } from "@mui/material/styles";
export const customTheme = createTheme({ export function customTheme(mode: "light" | "dark") {
return createTheme({
palette: { palette: {
mode,
primary: { primary: {
light: '#a700c3', light: "#a700c3",
main: '#a400c0', main: "#a700c3",
dark: '#a400c0', dark: "#a700c3",
contrastText: '#fff', contrastText: "#fff",
}, },
secondary: { secondary: {
light: '#ff7961', light: "#ff7961",
main: '#f44336', main: "#f44336",
dark: '#ba000d', dark: "#ba000d",
contrastText: '#000', contrastText: "#000",
}, },
}, },
typography: { typography: {
fontFamily: [ fontFamily: [
'-apple-system', "-apple-system",
'BlinkMacSystemFont', "BlinkMacSystemFont",
'"Segoe UI"', '"Segoe UI"',
'"Helvetica Neue"', '"Helvetica Neue"',
'Arial', "Arial",
'sans-serif', "sans-serif",
'"Apple Color Emoji"', '"Apple Color Emoji"',
'"Segoe UI Emoji"', '"Segoe UI Emoji"',
'"Segoe UI Symbol"', '"Segoe UI Symbol"',
].join(','), ].join(","),
}, },
}); });
}