diff --git a/packages/console/package.json b/packages/console/package.json index afdbe7b74..4d18ca4d9 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -18,6 +18,7 @@ "dependencies": { "@logto/phrases": "^0.1.0", "@logto/schemas": "^0.1.0", + "@monaco-editor/react": "^4.3.1", "@silverhand/essentials": "^1.1.6", "classnames": "^2.3.1", "csstype": "^3.0.11", @@ -25,6 +26,7 @@ "i18next-browser-languagedetector": "^6.1.3", "ky": "^0.30.0", "lodash.kebabcase": "^4.1.1", + "monaco-editor": "^0.32.1", "react": "^17.0.2", "react-dom": "^17.0.2", "react-hook-form": "^7.27.1", diff --git a/packages/console/src/components/CodeEditor/index.module.scss b/packages/console/src/components/CodeEditor/index.module.scss index f7a0e2ea0..66eadc20a 100644 --- a/packages/console/src/components/CodeEditor/index.module.scss +++ b/packages/console/src/components/CodeEditor/index.module.scss @@ -2,8 +2,4 @@ .editor { margin: _.unit(1) 0; - - textarea { - width: 100%; - } } diff --git a/packages/console/src/components/CodeEditor/index.tsx b/packages/console/src/components/CodeEditor/index.tsx index 865512a84..52dae4993 100644 --- a/packages/console/src/components/CodeEditor/index.tsx +++ b/packages/console/src/components/CodeEditor/index.tsx @@ -1,21 +1,51 @@ -import React, { ChangeEventHandler } from 'react'; +import MonacoEditor from '@monaco-editor/react'; +import * as monaco from 'monaco-editor'; +import React from 'react'; import * as styles from './index.module.scss'; -// Will be implemented in LOG-1708, defined 2 basic props for now. type Props = { + language: string; + isDarkMode?: boolean; + height?: string; + isReadonly?: boolean; value?: string; onChange?: (value: string) => void; }; -const CodeEditor = ({ value, onChange }: Props) => { - const handleChange: ChangeEventHandler = (event) => { - onChange?.(event.target.value); +const CodeEditor = ({ + value, + onChange, + language, + height = '300px', + isReadonly = false, + isDarkMode, +}: Props) => { + const handleChange = (changedValue = '') => { + onChange?.(changedValue); + }; + + // See https://microsoft.github.io/monaco-editor/api/enums/monaco.editor.EditorOption.html + const options: monaco.editor.IStandaloneEditorConstructionOptions = { + readOnly: isReadonly, + scrollBeyondLastLine: false, + codeLens: false, + minimap: { + enabled: false, + }, + folding: false, }; return (
-