import React, { useState } from "react"; import { Modal } from "../../ui/React/Modal"; import { defaultMonacoTheme } from "./themes"; import Typography from "@mui/material/Typography"; import Button from "@mui/material/Button"; import Box from "@mui/material/Box"; import Tooltip from "@mui/material/Tooltip"; import TextField from "@mui/material/TextField"; import IconButton from "@mui/material/IconButton"; import ReplyIcon from "@mui/icons-material/Reply"; import HistoryIcon from '@mui/icons-material/History'; import SaveIcon from '@mui/icons-material/Save'; import { Settings } from "../../Settings/Settings"; import { OptionSwitch } from "../../ui/React/OptionSwitch"; import _ from "lodash"; import { Color, ColorPicker } from "material-ui-color"; interface IProps { onClose: () => void; open: boolean; } interface IColorEditorProps { label: string; themePath: string; color: string | undefined; onColorChange: (name: string, value: string) => void; defaultColor: string; } // Slightly tweaked version of the same function found in game options function ColorEditor({ label, themePath, onColorChange, color, defaultColor }: IColorEditorProps): React.ReactElement { if (color === undefined) { console.error(`color ${themePath} was undefined, reverting to default`); color = defaultColor; } return ( <> onColorChange(themePath, newColor.hex)} disableAlpha /> ), endAdornment: ( <> onColorChange(themePath, defaultColor)}> ), }} /> ); } export function ThemeEditorModal(props: IProps): React.ReactElement { const setRerender = useState(false)[1]; function rerender(): void { setRerender((o) => !o); } // Need to deep copy the object since it has nested attributes const [themeCopy, setThemeCopy] = useState(JSON.parse(JSON.stringify(Settings.EditorTheme))); function onColorChange(name: string, value: string): void { setThemeCopy(_.set(themeCopy, name, value)); rerender(); } function onThemeChange(event: React.ChangeEvent): void { try { const importedTheme = JSON.parse(event.target.value); if (typeof importedTheme !== "object") return; setThemeCopy(importedTheme); } catch (err) { // ignore } } return ( Customize Editor theme Hover over input boxes for more information { setThemeCopy(_.set(themeCopy, "base", val ? "vs" : "vs-dark")); rerender(); }} text="Use light theme as base" tooltip={ <> If enabled, the vs light theme will be used as the theme base, otherwise, vs-dark will be used. } /> UI Syntax ) }