nandi/oripublic Fork 0
b6cd929ab1425a4ef6073ea9c189917cca02cf3c
Commits
Clone
git clone https://git.rickub.com/nandi/ori.git
git clone ssh://git@rickub.com/nandi/ori.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

forked from bots-garden/ori

MonacoViewer.tsx · 51 lines · 1.2 KBTypeScript Blame HistoryRaw
 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
45
46
47
48
49
50
51
/**
 * MonacoViewer wraps the Monaco editor for both the read-only code preview
 * and the editable editor pane. It is the only module importing Monaco, and
 * is meant to be lazy-loaded (see CodeView / EditorPane).
 *
 * @example
 * <MonacoViewer content="package main" language="go" readOnly />
 */

import Editor, { type OnChange, type OnMount } from "@monaco-editor/react";
import "../monaco-setup";
import { useTheme } from "../theme";

interface MonacoViewerProps {
	content: string;
	language: string;
	readOnly?: boolean;
	/** Called with the new text on every edit (editable mode). */
	onChange?: OnChange;
	/** Gives access to the editor instance (key bindings, focus). */
	onMount?: OnMount;
}

export default function MonacoViewer({
	content,
	language,
	readOnly = false,
	onChange,
	onMount,
}: MonacoViewerProps) {
	// Monaco has its own palettes; pick the one matching the app theme.
	const theme =
		useTheme((state) => state.theme) === "dark" ? "vs-dark" : "light";
	return (
		<Editor
			height="100%"
			language={language}
			value={content}
			theme={theme}
			onChange={onChange}
			onMount={onMount}
			options={{
				readOnly,
				minimap: { enabled: false },
				scrollBeyondLastLine: false,
				fontSize: 13,
				automaticLayout: true,
			}}
		/>
	);
}