import React, { useState } from "react"; import { Modal } from "./Modal"; import Button from "@mui/material/Button"; import Typography from "@mui/material/Typography"; import TextField from "@mui/material/TextField"; import IconButton from "@mui/material/IconButton"; import ReplyIcon from "@mui/icons-material/Reply"; import { Color, ColorPicker } from "material-ui-color"; import { ThemeEvents } from "./Theme"; import { Settings, defaultSettings } from "../../Settings/Settings"; interface IProps { open: boolean; onClose: () => void; } interface IColorEditorProps { name: string; color: string | undefined; onColorChange: (name: string, value: string) => void; defaultColor: string; } function ColorEditor({ name, onColorChange, color, defaultColor }: IColorEditorProps): React.ReactElement { if (color === undefined) { console.error(`color ${name} was undefined, reverting to default`); color = defaultColor; } return ( <> onColorChange(name, "#" + newColor.hex)} /> ), endAdornment: ( <> onColorChange(name, defaultColor)}> ), }} /> ); } export function ThemeEditorModal(props: IProps): React.ReactElement { const [customTheme, setCustomTheme] = useState<{ [key: string]: string | undefined }>({ ...Settings.theme, }); function onThemeChange(event: React.ChangeEvent): void { try { const importedTheme = JSON.parse(event.target.value); if (typeof importedTheme !== "object") return; setCustomTheme(importedTheme); for (const key of Object.keys(importedTheme)) { Settings.theme[key] = importedTheme[key]; } ThemeEvents.emit(); } catch (err) { // ignore } } function onColorChange(name: string, value: string): void { setCustomTheme((old: any) => { old[name] = value; return old; }); Settings.theme[name] = value; ThemeEvents.emit(); } return ( primary secondary warning info error








); }