-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeEditor.jsx
More file actions
37 lines (30 loc) · 963 Bytes
/
Copy pathCodeEditor.jsx
File metadata and controls
37 lines (30 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"use client";
import React, { useEffect, useRef } from 'react';
import { CodeJar } from 'codejar';
const CodeEditor = () => {
const editorRef = useRef(null);
useEffect(() => {
const node = editorRef.current;
if (!node) return;
const highlight = (editor) => {
const code = editor.textContent;
editor.innerHTML = code.replace(/(const|let|var|function)/g, '<span style="color:aqua">$1</span>');
};
const jar = CodeJar(node, highlight);
jar.updateCode(`function solve(input) {
// เขียนโค้ดของคุณที่นี่
}`);
return () => {
jar.destroy();
};
}, []);
return (
<div
ref={editorRef}
className="editor bg-slate-700 text-white p-4 rounded-lg"
style={{ minHeight: "1000px", fontSize: "16px", fontFamily: "monospace", overflowY:"auto", maxHeight:"1000px" }}
>
</div>
);
};
export default CodeEditor;