react monacoeditor
v3.6.0
Komponen Editor Monako untuk Bereaksi. demo @uiwjs.github.io/react-monacoeditor/
npm install @uiw/react-monacoeditor --save import React from 'react' ;
import MonacoEditor from '@uiw/react-monacoeditor' ;
export default function Demo ( ) {
return (
< MonacoEditor
language = "html"
value = "<h1>I ♥ react-monacoeditor</h1>"
height = "300px"
options = { {
theme : 'vs-dark' ,
} }
/>
) ;
} import React from 'react' ;
import { render } from 'react-dom' ;
import MonacoEditor from '@uiw/react-monacoeditor' ;
const code = `import React, { PureComponent } from 'react';
import MonacoEditor from '@uiw/react-monacoeditor';
export default class App extends PureComponent {
render() {
return (
<MonacoEditor
language="html"
value="<h1>I ♥ react-codemirror2</h1>"
options={{
selectOnLineNumbers: true,
roundedSelection: false,
cursorStyle: 'line',
automaticLayout: false,
theme: 'vs-dark',
}}
/>
);
}
}
` ;
class App extends React . Component {
constructor ( props ) {
super ( props ) ;
this . state = {
code : '// type your code...' ,
}
}
editorDidMount ( editor , monaco ) {
console . log ( 'editorDidMount' , editor , monaco ) ;
editor . focus ( ) ;
}
onChange ( newValue , e ) {
console . log ( 'onChange' , newValue , e ) ;
}
render ( ) {
const options = {
selectOnLineNumbers : true ,
roundedSelection : false ,
readOnly : false ,
cursorStyle : 'line' ,
automaticLayout : false ,
theme : 'vs-dark' ,
scrollbar : {
// Subtle shadows to the left & top. Defaults to true.
useShadows : false ,
// Render vertical arrows. Defaults to false.
verticalHasArrows : true ,
// Render horizontal arrows. Defaults to false.
horizontalHasArrows : true ,
// Render vertical scrollbar.
// Accepted values: 'auto', 'visible', 'hidden'.
// Defaults to 'auto'
vertical : 'visible' ,
// Render horizontal scrollbar.
// Accepted values: 'auto', 'visible', 'hidden'.
// Defaults to 'auto'
horizontal : 'visible' ,
verticalScrollbarSize : 17 ,
horizontalScrollbarSize : 17 ,
arrowSize : 30 ,
} ,
} ;
return (
< MonacoEditor
height = "500px"
language = "javascript"
editorDidMount = { this . editorDidMount . bind ( this ) }
onChange = { this . onChange . bind ( this ) }
value = { code }
options = { options }
/>
) ;
}
}
render (
< App /> ,
document . getElementById ( 'root' )
) ; Tambahkan monaco editor Webpack Loader Plugin monaco-editor-webpack-plugin ke webpack.config.js Anda:
const MonacoWebpackPlugin = require ( 'monaco-editor-webpack-plugin' ) ;
module . exports = {
plugins : [
new MonacoWebpackPlugin ( )
]
} ; Jika Anda menentukan value properti, komponen berperilaku dalam mode terkontrol. Kalau tidak, ia berperilaku dalam mode yang tidak terkendali.
width editor. Default hingga 100% .height . Default hingga 100% .value nilai model yang dibuat otomatis di editor.defaultValue Nilai awal model yang dibuat otomatis di editor.language Bahasa awal model yang dibuat otomatis di editor.theme Tema Editor vs , vs-dark , hc-blackoptions mengacu pada monaco interface iEditorConstructionOptions.editorDidMount(editor, monaco) Suatu peristiwa yang dipancarkan ketika editor telah dipasang (mirip dengan componentDidMount of React).onChange(newValue, event) Suatu peristiwa yang dipancarkan ketika konten model saat ini telah berubah.autoComplete?: (model: monaco.editor.ITextModel, position: monaco.Position) => languages.CompletionItem[]; Pengguna yang disediakan penyedia fungsi ekstensi untuk lengkap secara otomatis. #47 Lihat IEDITOR MONACO INTERFACE.
Seperti biasa, terima kasih kepada kontributor kami yang luar biasa!
Dibuat dengan GitHub-action-contributors.
Berlisensi di bawah lisensi MIT.