aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/editor/EditorArea.tsx
blob: cfb988b2422d330d0414cd30735e01bc0c7a9f4e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Box from '@mui/material/Box';
import { useTheme } from '@mui/material/styles';
import { observer } from 'mobx-react-lite';
import { useCallback, useEffect } from 'react';

import type EditorStore from './EditorStore';
import EditorTheme from './EditorTheme';

export default observer(function EditorArea({
  editorStore,
}: {
  editorStore: EditorStore;
}): JSX.Element {
  const {
    palette: { mode: paletteMode },
  } = useTheme();

  useEffect(
    () => editorStore.setDarkMode(paletteMode === 'dark'),
    [editorStore, paletteMode],
  );

  const editorParentRef = useCallback(
    (editorParent: HTMLDivElement | null) => {
      editorStore.setEditorParent(editorParent ?? undefined);
    },
    [editorStore],
  );

  return (
    <Box flexGrow={1} flexShrink={1} overflow="auto">
      <EditorTheme
        showLineNumbers={editorStore.showLineNumbers}
        showActiveLine={!editorStore.hasSelection}
        ref={editorParentRef}
      />
    </Box>
  );
});