|
@@ -1,37 +1,40 @@
|
|
import React, { useState } from "react";
|
|
import React, { useState } from "react";
|
|
import "codemirror/lib/codemirror.css";
|
|
import "codemirror/lib/codemirror.css";
|
|
-import "codemirror/theme/material.css";
|
|
|
|
import "codemirror/mode/xml/xml";
|
|
import "codemirror/mode/xml/xml";
|
|
import "codemirror/mode/javascript/javascript";
|
|
import "codemirror/mode/javascript/javascript";
|
|
import "codemirror/mode/css/css";
|
|
import "codemirror/mode/css/css";
|
|
import { Controlled as ControlledEditor } from "react-codemirror2";
|
|
import { Controlled as ControlledEditor } from "react-codemirror2";
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
import { faCompressAlt, faExpandAlt } from "@fortawesome/free-solid-svg-icons";
|
|
import { faCompressAlt, faExpandAlt } from "@fortawesome/free-solid-svg-icons";
|
|
-import "./pen.css";
|
|
|
|
import { useDispatch } from "react-redux";
|
|
import { useDispatch } from "react-redux";
|
|
import style from "./Editor.module.scss";
|
|
import style from "./Editor.module.scss";
|
|
-
|
|
|
|
|
|
+import "./themes/twilight.css";
|
|
|
|
+import { ReactComponent as HtmlLogo } from "../../../assets/img/htmlLogo.svg";
|
|
|
|
+import { ReactComponent as CssLogo } from "../../../assets/img/cssLogo.svg";
|
|
|
|
+import { ReactComponent as JsLogo } from "../../../assets/img/jsLogo.svg";
|
|
export default function Editor(props) {
|
|
export default function Editor(props) {
|
|
const { language, displayName, value, onChange } = props;
|
|
const { language, displayName, value, onChange } = props;
|
|
- const [open, setOpen] = useState(true);
|
|
|
|
const dispatch = useDispatch();
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
+ const logos = {
|
|
|
|
+ xml: <HtmlLogo />,
|
|
|
|
+ css: <CssLogo />,
|
|
|
|
+ javascript: <JsLogo />,
|
|
|
|
+ };
|
|
|
|
+
|
|
function handleChange(editor, data, value) {
|
|
function handleChange(editor, data, value) {
|
|
dispatch(onChange(value));
|
|
dispatch(onChange(value));
|
|
}
|
|
}
|
|
|
|
|
|
return (
|
|
return (
|
|
- <div className={open ? style.editorOpen : style.collapsed}>
|
|
|
|
|
|
+ <div className={style.editor}>
|
|
<div className={style.header}>
|
|
<div className={style.header}>
|
|
- {displayName}
|
|
|
|
- <button
|
|
|
|
- type="button"
|
|
|
|
- className="expand-collapse-btn"
|
|
|
|
- onClick={() => setOpen((prevOpen) => !prevOpen)}
|
|
|
|
- >
|
|
|
|
- <FontAwesomeIcon icon={open ? faCompressAlt : faExpandAlt} />
|
|
|
|
- </button>
|
|
|
|
|
|
+ <h2>
|
|
|
|
+ {logos[language]}
|
|
|
|
+ {displayName}
|
|
|
|
+ </h2>
|
|
</div>
|
|
</div>
|
|
|
|
+
|
|
<ControlledEditor
|
|
<ControlledEditor
|
|
onBeforeChange={handleChange}
|
|
onBeforeChange={handleChange}
|
|
value={value}
|
|
value={value}
|
|
@@ -40,10 +43,9 @@ export default function Editor(props) {
|
|
lineWrapping: true,
|
|
lineWrapping: true,
|
|
lint: true,
|
|
lint: true,
|
|
mode: language,
|
|
mode: language,
|
|
- theme: "material",
|
|
|
|
|
|
+ theme: "twilight",
|
|
lineNumbers: true,
|
|
lineNumbers: true,
|
|
autoCorrect: true,
|
|
autoCorrect: true,
|
|
- autocapitalize: true,
|
|
|
|
}}
|
|
}}
|
|
/>
|
|
/>
|
|
</div>
|
|
</div>
|