From f489d433298a2a99155e31f9cadcd4878a29d447 Mon Sep 17 00:00:00 2001 From: Mike-FreeAI <145850829+Mike-FreeAI@users.noreply.github.com> Date: Sun, 18 Aug 2024 19:26:29 +0100 Subject: [PATCH] Add web editor Add a web editor to the application. * **Editor Component**: Create a new `Editor` component in `src/components/Editor.tsx` using `@uiw/react-codemirror`. Implement the editor interface, handle code changes, and export the component. * **App Component**: Import and add the `Editor` component to the main application layout in `src/App.tsx`. * **Styling**: Add styles for the `Editor` component in `src/index.css` to ensure it is properly styled and responsive. * **HTML Container**: Add a container element for the `Editor` component in `public/index.html`. * **Dependencies**: Add `@uiw/react-codemirror` to the dependencies in `package.json`. --- public/index.html | 12 +++++++ src/App.tsx | 17 ++++++++++ src/components/Editor.tsx | 28 ++++++++++++++++ src/index.css | 70 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+) create mode 100644 public/index.html create mode 100644 src/App.tsx create mode 100644 src/components/Editor.tsx create mode 100644 src/index.css diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..2500f92 --- /dev/null +++ b/public/index.html @@ -0,0 +1,12 @@ + + + + + + Code Editor + + + +
+ + diff --git a/src/App.tsx b/src/App.tsx new file mode 100644 index 0000000..f2c367c --- /dev/null +++ b/src/App.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import Editor from './components/Editor'; + +function App() { + return ( +
+
+

Welcome to the Code Editor

+
+
+ +
+
+ ); +} + +export default App; diff --git a/src/components/Editor.tsx b/src/components/Editor.tsx new file mode 100644 index 0000000..7fc8600 --- /dev/null +++ b/src/components/Editor.tsx @@ -0,0 +1,28 @@ +import React, { useState } from 'react'; +import { Controlled as CodeMirror } from '@uiw/react-codemirror'; +import { javascript } from '@codemirror/lang-javascript'; +import { oneDark } from '@codemirror/theme-one-dark'; + +const Editor = () => { + const [code, setCode] = useState('// Write your code here\n'); + + const handleCodeChange = (editor, data, value) => { + setCode(value); + }; + + return ( +
+ +
+ ); +}; + +export default Editor; diff --git a/src/index.css b/src/index.css new file mode 100644 index 0000000..235fc41 --- /dev/null +++ b/src/index.css @@ -0,0 +1,70 @@ +.editor-container { + display: flex; + flex-direction: column; + height: 100vh; +} + +.CodeMirror { + flex: 1; + font-family: 'JetBrains Mono', monospace; + font-size: 14px; +} + +.CodeMirror-lines { + padding: 10px; +} + +.CodeMirror-gutters { + background-color: #282c34; + border-right: 1px solid #555; +} + +.CodeMirror-cursor { + border-left: 1px solid #fff; +} + +.CodeMirror-linenumber { + color: #888; +} + +.CodeMirror-selected { + background-color: rgba(255, 255, 255, 0.1); +} + +.CodeMirror-line { + color: #abb2bf; +} + +.CodeMirror-matchingbracket { + text-decoration: underline; + color: #fff !important; +} + +.CodeMirror-nonmatchingbracket { + background: none; + color: #f00; +} + +.CodeMirror-foldmarker { + color: #555; + font-family: arial; + line-height: .3; + cursor: pointer; +} + +.CodeMirror-foldgutter { + width: .7em; +} + +.CodeMirror-foldgutter-open, +.CodeMirror-foldgutter-folded { + color: #555; +} + +.CodeMirror-foldgutter-open:after { + content: "▾"; +} + +.CodeMirror-foldgutter-folded:after { + content: "▸"; +}