Skip to content

Commit

Permalink
perf(MonacoEditor): use antd-sytle to get theme mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Carrotzpc committed Feb 1, 2024
1 parent 79f0182 commit 18d8d6a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/MonacoEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import type {
IGeneralManacoEditorProps,
ISingleMonacoEditorProps,
} from '@alilc/lowcode-plugin-base-monaco-editor/lib/helper';
import { theme as antdTheme } from 'antd';
import { useThemeMode } from 'antd-style';
import type { editor as IEditor } from 'monaco-editor';
import React, { useMemo, useState } from 'react';

import { useCdnFn } from '..';

const { useToken } = antdTheme;

export {
type EditorMeta,
Controller as MonacoController,
Expand Down Expand Up @@ -57,13 +55,13 @@ export const BaseMonacoEditor: React.FC<
...otherProps
} = props;

const token = useToken();
const { isDarkMode } = useThemeMode();
const theme = useMemo(() => {
if (themeFromProps) {
return themeFromProps;
}
return token.theme.id === 2 ? 'vs-dark' : 'vs';
}, [token.theme.id, themeFromProps]);
return isDarkMode ? 'vs-dark' : 'vs';
}, [isDarkMode, themeFromProps]);

const [editorInstance, setEditorInstance] = useState<IEditorInstance>();
const handleEditorDidMount: BaseMonacoEditorProps['editorDidMount'] = (monaco, editor) => {
Expand Down

0 comments on commit 18d8d6a

Please sign in to comment.