mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-10-12 15:31:32 +08:00

* chore: added jsx-runtime plugin in eslint tsconfig Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * chore: updated react imports Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * chore: renamed redux dispatch Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> * fix: build is fixed --------- Signed-off-by: GermaVinsmoke <vaibhav1180@gmail.com> Co-authored-by: Palash Gupta <palashgdev@gmail.com>
57 lines
1.1 KiB
TypeScript
57 lines
1.1 KiB
TypeScript
import MEditor, { EditorProps } from '@monaco-editor/react';
|
|
import { useIsDarkMode } from 'hooks/useDarkMode';
|
|
import { useMemo } from 'react';
|
|
|
|
function Editor({
|
|
value,
|
|
language,
|
|
onChange,
|
|
readOnly,
|
|
height,
|
|
options,
|
|
}: MEditorProps): JSX.Element {
|
|
const isDarkMode = useIsDarkMode();
|
|
|
|
const onChangeHandler = (newValue?: string): void => {
|
|
if (readOnly) return;
|
|
|
|
if (typeof newValue === 'string' && onChange) onChange(newValue);
|
|
};
|
|
|
|
const editorOptions = useMemo(
|
|
() => ({ fontSize: 16, automaticLayout: true, readOnly, ...options }),
|
|
[options, readOnly],
|
|
);
|
|
|
|
return (
|
|
<MEditor
|
|
theme={isDarkMode ? 'vs-dark' : 'vs-light'}
|
|
language={language}
|
|
value={value}
|
|
options={editorOptions}
|
|
height={height}
|
|
onChange={onChangeHandler}
|
|
data-testid="monaco-editor"
|
|
/>
|
|
);
|
|
}
|
|
|
|
interface MEditorProps {
|
|
value: string;
|
|
language?: string;
|
|
onChange?: (value: string) => void;
|
|
readOnly?: boolean;
|
|
height?: string;
|
|
options?: EditorProps['options'];
|
|
}
|
|
|
|
Editor.defaultProps = {
|
|
language: 'yaml',
|
|
readOnly: false,
|
|
height: '40vh',
|
|
options: {},
|
|
onChange: (): void => {},
|
|
};
|
|
|
|
export default Editor;
|