SQLEditor.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* eslint-disable react/jsx-props-no-spreading */
  2. import AceEditor, { IAceEditorProps } from 'react-ace';
  3. import 'ace-builds/src-noconflict/ace';
  4. import 'ace-builds/src-noconflict/mode-sql';
  5. import 'ace-builds/src-noconflict/theme-textmate';
  6. import 'ace-builds/src-noconflict/theme-dracula';
  7. import React, { useContext } from 'react';
  8. import { ThemeModeContext } from 'components/contexts/ThemeModeContext';
  9. interface SQLEditorProps extends IAceEditorProps {
  10. isFixedHeight?: boolean;
  11. }
  12. const SQLEditor = React.forwardRef<AceEditor | null, SQLEditorProps>(
  13. (props, ref) => {
  14. const { isFixedHeight, ...rest } = props;
  15. const { isDarkMode } = useContext(ThemeModeContext);
  16. return (
  17. <AceEditor
  18. ref={ref}
  19. mode="sql"
  20. theme={isDarkMode ? 'dracula' : 'textmate'}
  21. tabSize={2}
  22. width="100%"
  23. height={
  24. isFixedHeight
  25. ? `${(props.value?.split('\n').length || 32) * 16}px`
  26. : '372px'
  27. }
  28. wrapEnabled
  29. {...rest}
  30. />
  31. );
  32. }
  33. );
  34. SQLEditor.displayName = 'SQLEditor';
  35. export default SQLEditor;