-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/#80 json view reader codemirror #243
Merged
brauliodiez
merged 8 commits into
Lemoncode:feature/develop
from
migalko94:feature/#80-json-view-reader-codemirror
Nov 9, 2023
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b6b95eb
first iteration
migalko94 c7e49e0
Merge remote-tracking branch 'upstream/feature/develop' into feature/…
migalko94 a5fba18
responsive upgrade
migalko94 5cc5a88
no gutter display
migalko94 fdde0d3
simplify structure codemirror
migalko94 6aa07d9
correction codemirror
migalko94 f13df75
style amendment
migalko94 1259327
correction theme
migalko94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
apps/react-app/src/common-app/components/codemirror/codemirror.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
|
||
import { EditorState } from '@codemirror/state'; | ||
import { json } from '@codemirror/lang-json'; | ||
import { basicSetup } from 'codemirror'; | ||
import { EditorView, ViewUpdate, placeholder } from '@codemirror/view'; | ||
|
||
import { codeMirrorTheme } from './codemirror.styles'; | ||
|
||
interface Props { | ||
value: string; | ||
onChange: (value: string) => void; | ||
className?: string; | ||
} | ||
|
||
export const CodeMirrorComponent: React.FC<Props> = props => { | ||
const { value, onChange, className } = props; | ||
const codeRef = React.useRef<HTMLDivElement>(null); | ||
const editorView = React.useRef<EditorView>(); | ||
React.useEffect(() => { | ||
if (codeRef.current) { | ||
editorView.current = new EditorView({ | ||
state: EditorState.create({ | ||
doc: value, | ||
extensions: [ | ||
basicSetup, | ||
json(), | ||
EditorView.lineWrapping, | ||
EditorView.updateListener.of((u: ViewUpdate) => onChange(u.state.doc.toString())), | ||
placeholder('Pega aquí tu JSON en formato MAC'), | ||
codeMirrorTheme, | ||
], | ||
}), | ||
parent: codeRef.current, | ||
}); | ||
} | ||
|
||
return () => editorView.current?.destroy(); | ||
}, []); | ||
|
||
return <div className={className} ref={codeRef} />; | ||
}; |
22 changes: 22 additions & 0 deletions
22
apps/react-app/src/common-app/components/codemirror/codemirror.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { EditorView } from 'codemirror'; | ||
|
||
export const codeMirrorTheme = EditorView.theme({ | ||
'&': { | ||
fontSize: '14px', | ||
flexDirection: 'column', | ||
display: 'flex', | ||
flexGrow: '1', | ||
maxHeight: '40vh', | ||
height: '100%', | ||
width: '100%', | ||
}, | ||
'.cm-scroller': { overflow: 'auto' }, | ||
'.cm-gutterElement': { display: 'none' }, | ||
'.cm content, .cm-gutters,': { | ||
minHeight: '100%', | ||
backgroundColor: '#152128', | ||
color: '#AAB0B1', | ||
textAlign: 'start', | ||
border: 'none', | ||
}, | ||
juanpms2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './codemirror.component'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use this theme color here, please
color: theme.palette.light[500]