update App.js, src/components/Modal/index.js, src/components/ReactMonacoEditor/index.js and src/components/Tabbar/index.js
parent
b564c6e6d3
commit
fe04b3e2d9
4 changed files with 101 additions and 89 deletions
@ -1,97 +1,105 @@ |
||||
import React from "react"; |
||||
import { render } from "react-dom"; |
||||
import MonacoEditor, { MonacoDiffEditor } from "react-monaco-editor"; |
||||
// import React from "react";
|
||||
// import { render } from "react-dom";
|
||||
// import MonacoEditor, { MonacoDiffEditor } from "react-monaco-editor";
|
||||
|
||||
class CodeEditor extends React.Component { |
||||
constructor() { |
||||
super(); |
||||
this.state = { |
||||
code: "// type your code... \n", |
||||
theme: "vs-light", |
||||
}; |
||||
} |
||||
// class CodeEditor extends React.Component {
|
||||
// constructor() {
|
||||
// super();
|
||||
// this.state = {
|
||||
// code: "// type your code... \n",
|
||||
// theme: "vs-light",
|
||||
// };
|
||||
// }
|
||||
|
||||
onChange = (newValue) => { |
||||
console.log("onChange", newValue); // eslint-disable-line no-console
|
||||
}; |
||||
// onChange = (newValue) => {
|
||||
// console.log("onChange", newValue); // eslint-disable-line no-console
|
||||
// };
|
||||
|
||||
editorDidMount = (editor) => { |
||||
// eslint-disable-next-line no-console
|
||||
console.log("editorDidMount", editor, editor.getValue(), editor.getModel()); |
||||
this.editor = editor; |
||||
}; |
||||
// editorDidMount = (editor) => {
|
||||
// // eslint-disable-next-line no-console
|
||||
// console.log("editorDidMount", editor, editor.getValue(), editor.getModel());
|
||||
// this.editor = editor;
|
||||
// };
|
||||
|
||||
changeEditorValue = () => { |
||||
if (this.editor) { |
||||
this.editor.setValue("// code changed! \n"); |
||||
} |
||||
}; |
||||
// changeEditorValue = () => {
|
||||
// if (this.editor) {
|
||||
// this.editor.setValue("// code changed! \n");
|
||||
// }
|
||||
// };
|
||||
|
||||
changeBySetState = () => { |
||||
this.setState({ code: "// code changed by setState! \n" }); |
||||
}; |
||||
// changeBySetState = () => {
|
||||
// this.setState({ code: "// code changed by setState! \n" });
|
||||
// };
|
||||
|
||||
setDarkTheme = () => { |
||||
this.setState({ theme: "vs-dark" }); |
||||
}; |
||||
// setDarkTheme = () => {
|
||||
// this.setState({ theme: "vs-dark" });
|
||||
// };
|
||||
|
||||
setLightTheme = () => { |
||||
this.setState({ theme: "vs-light" }); |
||||
}; |
||||
// setLightTheme = () => {
|
||||
// this.setState({ theme: "vs-light" });
|
||||
// };
|
||||
|
||||
render() { |
||||
const { code, theme } = this.state; |
||||
const options = { |
||||
selectOnLineNumbers: true, |
||||
roundedSelection: false, |
||||
readOnly: false, |
||||
cursorStyle: "line", |
||||
automaticLayout: false, |
||||
}; |
||||
return ( |
||||
<div> |
||||
<div> |
||||
<button onClick={this.changeEditorValue} type="button"> |
||||
Change value |
||||
</button> |
||||
<button onClick={this.changeBySetState} type="button"> |
||||
Change by setState |
||||
</button> |
||||
<button onClick={this.setDarkTheme} type="button"> |
||||
Set dark theme |
||||
</button> |
||||
<button onClick={this.setLightTheme} type="button"> |
||||
Set light theme |
||||
</button> |
||||
</div> |
||||
<hr /> |
||||
<MonacoEditor |
||||
height="400" |
||||
language="javascript" |
||||
value={code} |
||||
options={options} |
||||
onChange={this.onChange} |
||||
editorDidMount={this.editorDidMount} |
||||
theme={theme} |
||||
/> |
||||
</div> |
||||
); |
||||
} |
||||
} |
||||
// render() {
|
||||
// const { code, theme } = this.state;
|
||||
// const options = {
|
||||
// selectOnLineNumbers: true,
|
||||
// roundedSelection: false,
|
||||
// readOnly: false,
|
||||
// cursorStyle: "line",
|
||||
// automaticLayout: false,
|
||||
// };
|
||||
// return (
|
||||
// <div>
|
||||
// <div>
|
||||
// <button onClick={this.changeEditorValue} type="button">
|
||||
// Change value
|
||||
// </button>
|
||||
// <button onClick={this.changeBySetState} type="button">
|
||||
// Change by setState
|
||||
// </button>
|
||||
// <button onClick={this.setDarkTheme} type="button">
|
||||
// Set dark theme
|
||||
// </button>
|
||||
// <button onClick={this.setLightTheme} type="button">
|
||||
// Set light theme
|
||||
// </button>
|
||||
// </div>
|
||||
// <hr />
|
||||
// <MonacoEditor
|
||||
// height="400"
|
||||
// language="javascript"
|
||||
// value={code}
|
||||
// options={options}
|
||||
// onChange={this.onChange}
|
||||
// editorDidMount={this.editorDidMount}
|
||||
// theme={theme}
|
||||
// />
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
// const ReactMonacoEditor = () => {
|
||||
// return (
|
||||
// <div>
|
||||
// <h2>Monaco Editor Sample (controlled mode)</h2>
|
||||
// <CodeEditor />
|
||||
// <hr />
|
||||
// <h2>Another editor (uncontrolled mode)</h2>
|
||||
// {/* <AnotherEditor /> */}
|
||||
// <hr />
|
||||
// <h2>Another editor (showing a diff)</h2>
|
||||
// {/* <DiffEditor /> */}
|
||||
// </div>
|
||||
// );
|
||||
// };
|
||||
|
||||
// export default ReactMonacoEditor;
|
||||
|
||||
import React from "react"; |
||||
|
||||
const ReactMonacoEditor = () => { |
||||
return ( |
||||
<div> |
||||
<h2>Monaco Editor Sample (controlled mode)</h2> |
||||
<CodeEditor /> |
||||
<hr /> |
||||
<h2>Another editor (uncontrolled mode)</h2> |
||||
{/* <AnotherEditor /> */} |
||||
<hr /> |
||||
<h2>Another editor (showing a diff)</h2> |
||||
{/* <DiffEditor /> */} |
||||
</div> |
||||
); |
||||
return <div>ReactMonacoEditor</div>; |
||||
}; |
||||
|
||||
export default ReactMonacoEditor; |
||||
|
Loading…
Reference in new issue