Skip to content

Commit

Permalink
Implement collapsible rows
Browse files Browse the repository at this point in the history
- Replaces code editor component with Monaco
- Monaco is what VSCode is built on, so it looks quite good.
- onChange passes the new text value within the editor, which is simple
  to deal with, especially in comparison to CodeMirror
  • Loading branch information
shapeseas committed Sep 20, 2024
1 parent 235de41 commit 6730ee8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@empirica/core": "^1.11.0",
"@hello-pangea/dnd": "^16.6.0",
"@hookform/resolvers": "^3.6.0",
"@monaco-editor/react": "^4.6.0",
"@uiw/react-textarea-code-editor": "^2.1.9",
"@watts-lab/surveys": "^1.13.4",
"next": "^13.5.6",
Expand Down
18 changes: 11 additions & 7 deletions src/app/editor/components/CodeEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import YamlEditor from '@uiw/react-textarea-code-editor'
import Editor from '@monaco-editor/react'
import { useState, useEffect, useMemo } from 'react'
import { parse } from 'yaml'
import { stringify } from 'yaml'
Expand Down Expand Up @@ -103,9 +103,9 @@ export default function CodeEditor() {
}
}, [defaultTreatment])

function handleChange(evn: any) {
let entry = evn.target.value
setCode(entry)
function handleChange(newValue: any) {
console.log('newValue from editor OnChange: ', newValue)
setCode(newValue)
}

function handleSave(e: any) {
Expand All @@ -125,14 +125,18 @@ export default function CodeEditor() {
<div
style={{ height: '95vh', overflow: 'auto', backgroundColor: '#F0F2F6' }}
>
<YamlEditor
<Editor
data-cy="code-editor"
value={code}
language="yaml"
placeholder={
options={{
wordWrap: 'on',
showFoldingControls: 'always',
}}
defaulValue={
'Please enter treatment configuration. Do not refresh the page before saving.'
}
onChange={(env) => handleChange(env)}
onChange={(newValue) => handleChange(newValue)}
padding={5}
style={{
fontSize: 12,
Expand Down

0 comments on commit 6730ee8

Please sign in to comment.