mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 20:29:04 +08:00
feat: editor is updated (#2464)
This commit is contained in:
parent
65c2a0bf6a
commit
91c3abae37
@ -1,6 +1,6 @@
|
|||||||
import MEditor, { EditorProps } from '@monaco-editor/react';
|
import MEditor, { EditorProps } from '@monaco-editor/react';
|
||||||
import { useIsDarkMode } from 'hooks/useDarkMode';
|
import { useIsDarkMode } from 'hooks/useDarkMode';
|
||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
|
||||||
function Editor({
|
function Editor({
|
||||||
value,
|
value,
|
||||||
@ -11,16 +11,24 @@ function Editor({
|
|||||||
options,
|
options,
|
||||||
}: MEditorProps): JSX.Element {
|
}: MEditorProps): JSX.Element {
|
||||||
const isDarkMode = useIsDarkMode();
|
const isDarkMode = useIsDarkMode();
|
||||||
|
|
||||||
|
const onChangeHandler = (newValue?: string): void => {
|
||||||
|
if (typeof newValue === 'string' && onChange) onChange(newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
const editorOptions = useMemo(
|
||||||
|
() => ({ fontSize: 16, automaticLayout: true, readOnly, ...options }),
|
||||||
|
[options, readOnly],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MEditor
|
<MEditor
|
||||||
theme={isDarkMode ? 'vs-dark' : 'vs-light'}
|
theme={isDarkMode ? 'vs-dark' : 'vs-light'}
|
||||||
language={language}
|
language={language}
|
||||||
value={value}
|
value={value}
|
||||||
options={{ fontSize: 16, automaticLayout: true, readOnly, ...options }}
|
options={editorOptions}
|
||||||
height={height}
|
height={height}
|
||||||
onChange={(newValue): void => {
|
onChange={onChangeHandler}
|
||||||
if (typeof newValue === 'string') onChange(newValue);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -28,7 +36,7 @@ function Editor({
|
|||||||
interface MEditorProps {
|
interface MEditorProps {
|
||||||
value: string;
|
value: string;
|
||||||
language?: string;
|
language?: string;
|
||||||
onChange: (value: string) => void;
|
onChange?: (value: string) => void;
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
height?: string;
|
height?: string;
|
||||||
options?: EditorProps['options'];
|
options?: EditorProps['options'];
|
||||||
@ -39,6 +47,7 @@ Editor.defaultProps = {
|
|||||||
readOnly: false,
|
readOnly: false,
|
||||||
height: '40vh',
|
height: '40vh',
|
||||||
options: {},
|
options: {},
|
||||||
|
onChange: (): void => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Editor;
|
export default Editor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user