Merge pull request #1361 from MartinFournier/theme-color-picker

Add material-ui-color picker in theme editor
This commit is contained in:
hydroflame 2021-09-22 12:03:44 -04:00 committed by GitHub
commit d2008e86b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

@ -43,6 +43,7 @@
"jszip": "^3.7.0", "jszip": "^3.7.0",
"loader-runner": "^2.3.0", "loader-runner": "^2.3.0",
"loader-utils": "^1.1.0", "loader-utils": "^1.1.0",
"material-ui-color": "^1.2.0",
"mathjax-full": "^3.2.0", "mathjax-full": "^3.2.0",
"mathjax-react": "^1.0.6", "mathjax-react": "^1.0.6",
"memory-fs": "~0.4.1", "memory-fs": "~0.4.1",

@ -6,6 +6,7 @@ import TextField from "@mui/material/TextField";
import DoneIcon from "@mui/icons-material/Done"; import DoneIcon from "@mui/icons-material/Done";
import IconButton from "@mui/material/IconButton"; import IconButton from "@mui/material/IconButton";
import ReplyIcon from "@mui/icons-material/Reply"; import ReplyIcon from "@mui/icons-material/Reply";
import { Color, ColorPicker } from "material-ui-color";
import { ThemeEvents } from "./Theme"; import { ThemeEvents } from "./Theme";
import { Settings, defaultSettings } from "../../Settings/Settings"; import { Settings, defaultSettings } from "../../Settings/Settings";
@ -30,9 +31,15 @@ function ColorEditor({ name }: { name: string }): React.ReactElement {
setColor(defaultSettings.theme[name]); setColor(defaultSettings.theme[name]);
ThemeEvents.emit(); ThemeEvents.emit();
} }
function onChange(event: React.ChangeEvent<HTMLInputElement>): void { function onChange(event: React.ChangeEvent<HTMLInputElement>): void {
setColor(event.target.value); setColor(event.target.value);
} }
function onColorPickerChange(newValue: Color): void {
setColor("#" + newValue.hex.toLowerCase());
}
return ( return (
<> <>
<TextField <TextField
@ -42,6 +49,15 @@ function ColorEditor({ name }: { name: string }): React.ReactElement {
onChange={onChange} onChange={onChange}
variant="standard" variant="standard"
InputProps={{ InputProps={{
startAdornment: (
<>
<ColorPicker
hideTextfield
value={color}
onChange={onColorPickerChange}
/>
</>
),
endAdornment: ( endAdornment: (
<> <>
<IconButton onClick={set} disabled={!valid}> <IconButton onClick={set} disabled={!valid}>