2022-06-24 15:00:21 +05:30
|
|
|
import MEditor, { EditorProps } from '@monaco-editor/react';
|
2022-03-16 23:24:27 +05:30
|
|
|
import React from 'react';
|
2022-06-24 15:00:21 +05:30
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
|
import { AppState } from 'store/reducers';
|
|
|
|
|
import AppReducer from 'types/reducer/app';
|
2021-11-22 11:49:09 +05:30
|
|
|
|
2022-04-25 22:41:46 +05:30
|
|
|
function Editor({
|
|
|
|
|
value,
|
2022-06-24 15:00:21 +05:30
|
|
|
language,
|
2022-04-25 22:41:46 +05:30
|
|
|
onChange,
|
2022-06-24 15:00:21 +05:30
|
|
|
readOnly,
|
|
|
|
|
height,
|
|
|
|
|
options,
|
|
|
|
|
}: MEditorProps): JSX.Element {
|
|
|
|
|
const { isDarkMode } = useSelector<AppState, AppReducer>((state) => state.app);
|
2022-03-16 23:24:27 +05:30
|
|
|
return (
|
|
|
|
|
<MEditor
|
2022-06-24 15:00:21 +05:30
|
|
|
theme={isDarkMode ? 'vs-dark' : 'vs-light'}
|
2022-04-25 22:41:46 +05:30
|
|
|
language={language}
|
|
|
|
|
value={value}
|
2022-06-24 15:00:21 +05:30
|
|
|
options={{ fontSize: 16, automaticLayout: true, readOnly, ...options }}
|
|
|
|
|
height={height}
|
2022-03-23 19:03:05 +05:30
|
|
|
onChange={(newValue): void => {
|
2022-06-24 15:00:21 +05:30
|
|
|
if (typeof newValue === 'string') onChange(newValue);
|
2022-03-23 19:03:05 +05:30
|
|
|
}}
|
2022-03-16 23:24:27 +05:30
|
|
|
/>
|
|
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-11-22 11:49:09 +05:30
|
|
|
|
2022-06-24 15:00:21 +05:30
|
|
|
interface MEditorProps {
|
2022-04-25 22:41:46 +05:30
|
|
|
value: string;
|
|
|
|
|
language?: string;
|
|
|
|
|
onChange: (value: string) => void;
|
2022-04-27 22:21:57 +05:30
|
|
|
readOnly?: boolean;
|
2022-06-24 15:00:21 +05:30
|
|
|
height?: string;
|
|
|
|
|
options?: EditorProps['options'];
|
2021-11-22 11:49:09 +05:30
|
|
|
}
|
|
|
|
|
|
2022-04-22 20:03:08 +05:30
|
|
|
Editor.defaultProps = {
|
2022-06-24 15:00:21 +05:30
|
|
|
language: 'yaml',
|
2022-04-27 22:21:57 +05:30
|
|
|
readOnly: false,
|
2022-06-24 15:00:21 +05:30
|
|
|
height: '40vh',
|
|
|
|
|
options: {},
|
2022-04-22 20:03:08 +05:30
|
|
|
};
|
|
|
|
|
|
2021-11-22 11:49:09 +05:30
|
|
|
export default Editor;
|