Skip to content

Commit 406297a

Browse files
committed
Add monaco editor
1 parent 485ffc2 commit 406297a

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

package-lock.json

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"@craco/craco": "^6.1.2",
77
"@headlessui/react": "^1.2.0",
88
"@heroicons/react": "^1.0.1",
9+
"@monaco-editor/react": "^4.1.3",
910
"@tailwindcss/forms": "^0.3.2",
1011
"@testing-library/jest-dom": "^5.11.4",
1112
"@testing-library/react": "^11.1.0",

src/components/Dashboard.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Disclosure, Menu, Transition } from '@headlessui/react';
22
import { BellIcon, MenuIcon, XIcon } from '@heroicons/react/outline';
3+
import Editor from '@monaco-editor/react';
34
import { Fragment } from 'react';
45

56
const navigation = ['Dashboard', 'Team', 'Projects', 'Calendar', 'Reports'];
@@ -10,6 +11,9 @@ function classNames(...classes: any[]) {
1011
}
1112

1213
export default function Example() {
14+
// function showValue() {
15+
// alert(editorRef.current.getValue());
16+
// }
1317
return (
1418
<div>
1519
<Disclosure as="nav" className="bg-gray-800">
@@ -194,7 +198,19 @@ export default function Example() {
194198
<div className="max-w-7xl mx-auto py-6 sm:px-6 lg:px-8">
195199
{/* Replace with your content */}
196200
<div className="px-4 py-6 sm:px-0">
197-
<div className="border-4 border-dashed border-gray-200 rounded-lg h-96" />
201+
<div className="border-4 border-dashed border-gray-200 rounded-lg h-96">
202+
{/* <button onClick={showValue}>Show value</button> */}
203+
<Editor
204+
height="90vh"
205+
defaultLanguage="python"
206+
defaultValue={`def _clip_grad(clr, grad, group_grad_clip):
207+
if group_grad_clip > 0:
208+
norm = grad.norm(2).item()
209+
if norm > group_grad_clip:
210+
clr *= group_grad_clip / (norm + 1e-10)
211+
return clr`}
212+
/>
213+
</div>
198214
</div>
199215
{/* /End replace */}
200216
</div>

0 commit comments

Comments
 (0)