0.0.4 • Published 12 months ago

@lyove/monaco-editor-react v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Monaco Code Editor for React, without need of configuration files or plugins

https://monaco-editor-react.netlify.app

💎 Using

📌 BaseEditor

import React from "react";
import MonacoEditor from "@lyove/monaco-editor-react";

const exampleCode = `console.log('Hello @lyove/monaco-editor-react');`

export default class CodeEditor extends React.PureComponent {
  render() {
    return (
      <MonacoEditor
        width={1000}
        height={400}
        language="javascript"
        value={exampleCode}
        theme="vs"
        supportFullScreen={true}
        options={{
          fontSize: 13,
          fontFamily: 'Menlo, Monaco, "Courier New", monospace',
          minimap: {
            enabled: true,
          },
          automaticLayout: true,
          formatOnPaste: true,
          scrollbar: {
            useShadows: false,
            verticalScrollbarSize: 10,
            horizontalScrollbarSize: 10,
          },
        }}
        monacoWillMount={(monaco) => {
          console.log("monaco:", monaco);
        }}
        editorDidMount={(editor, monaco) => {
          console.log("editor:", editor);
        }}
        onChange={(value: string | null) => {
          console.log("editor value:\n", value);
        }}
        // monacoPath="https://cdn.jsdelivr.net/npm/monaco-editor@0.38.0/min/vs"
      />
    );
  }
}

📌 DiffEditor

import React from "react";
import { DiffEditor } from "@lyove/monaco-editor-react";

const originalCode = `npm install monaco-editor`
const modifiedCode = `npm install @lyove/monaco-editor-react`

export default class CodeDiffEditor extends React.PureComponent {
  render() {
    return (
      <DiffEditor
        width={600}
        height={400}
        original={originalCode}
        modified={modifiedCode}
        language="markdown"
      />
    );
  }
}

🧩 Editor Props

NameTypeDefaultDescription
valuestringnulleditor value
widthnumbernulleditor width
heightnumbernulleditor height
languagestringnulleditor language
themestringvsvs, vs-dark, active4d, clouds, chrome, monokai, solarized-dark, solarized-light
optionsobjectnullIEditorOptions
borderedbooleantrueneed bordered ?
classNamestringnullwrapper class name
onChangefunc(value) => voidtriggered when the editor value changes
monacoWillMountfunc(monaco) => voidtriggered when the monaco will mounted
editorDidMountfunc(editor: MonacoEditor.editor, monaco: any) => voidtriggered when the editor did mounted
monacoPathstring"https://unpkg.com/monaco-editor@0.38.0/min/vs"custom cdn path, notice: monacoPath such as: "https://your-custom-cdn-path/monaco-editor@version/min/vs", the end of the path can only be "/monaco-editor@version/min/vs", no need for "/xxx.js"

🧩 DiffEditor Props

NameTypeDefaultDescription
originalstringnulldiff editor original value
modifiedstringnulldiff editor modified value
widthnumbernulldiff editor width
heightnumbernulldiff editor height
languagestringnulldiff editor language
originalLanguagestringnulldiff editor original language
modifiedLanguagestringnulldiff editor modified language
themestringvsvs, vs-dark, active4d, clouds, chrome, monokai, solarized-dark, solarized-light
optionsobjectnullIDiffEditorOptions
classNamestringnullwrapper class name
monacoWillMountfunc(monaco) => voidtriggered when the monaco will mounted
editorDidMountfunc(original: MonacoEditor.editor.ITextModel, modified: MonacoEditor.editor.ITextModel, editor: MonacoEditor.editor, monaco: any) => voidtriggered when the diff editor did mounted
onChange(value: string) => voidnullmodified model content change
monacoPathstring"https://unpkg.com/monaco-editor@0.38.0/min/vs"custom cdn path, notice: monacoPath such as: "https://your-custom-cdn-path/monaco-editor@version/min/vs", the end of the path can only be "/monaco-editor@version/min/vs", no need for "/xxx.js"

📋 License

Licensed under the MIT License.