forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-editor.tsx
More file actions
44 lines (41 loc) · 1.14 KB
/
Copy pathcode-editor.tsx
File metadata and controls
44 lines (41 loc) · 1.14 KB
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
38
39
40
41
42
43
44
import React from "react";
import Editor from "@monaco-editor/react";
import { DemoFile } from "@/types/demo";
import { useTheme } from "next-themes";
interface CodeEditorProps {
file?: DemoFile;
onFileChange?: (fileName: string, content: string) => void;
}
export function CodeEditor({ file, onFileChange }: CodeEditorProps) {
const handleEditorChange = (value: string | undefined) => {
if (value && onFileChange) {
onFileChange(file!.name, value);
}
};
const theme = useTheme();
return file ? (
<div className="h-full flex flex-col">
<Editor
height="100%"
language={file.language}
value={file.content}
onChange={handleEditorChange}
options={{
minimap: { enabled: false },
fontSize: 16,
lineNumbers: "on",
readOnly: true,
wordWrap: "on",
stickyScroll: {
enabled: false,
},
}}
theme={theme.theme === "dark" ? "vs-dark" : "vs-light"}
/>
</div>
) : (
<div className="p-6 text-center text-muted-foreground">
Select a file from the file tree to view its code
</div>
);
}