Skip to content

Commit

Permalink
[ES|QL] Use emotion instead of scss in the editor (elastic#208003)
Browse files Browse the repository at this point in the history
## Summary

Part of elastic/kibana-team#1417

Replaces scss with emotion in the ES|QL editor

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
stratoula and kibanamachine authored Jan 27, 2025
1 parent 91e8490 commit e426bf0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EuiPopover,
EuiDescriptionList,
EuiDescriptionListDescription,
euiTextBreakWord,
} from '@elastic/eui';
import { css } from '@emotion/react';
import { css as classNameCss } from '@emotion/css';
Expand Down Expand Up @@ -86,7 +87,7 @@ function ErrorsWarningsContent({
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false} className="ESQLEditor_errorMessage">
<EuiFlexItem grow={false} css={euiTextBreakWord()}>
{item.message}
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
useDebounceWithOptions,
onKeyDownResizeHandler,
onMouseDownResizeHandler,
getEditorOverwrites,
type MonacoMessage,
} from './helpers';
import { addQueriesToCache } from './history_local_storage';
Expand All @@ -56,8 +57,6 @@ import {
} from './esql_editor.styles';
import type { ESQLEditorProps, ESQLEditorDeps } from './types';

import './overwrite.scss';

// for editor width smaller than this value we want to start hiding some text
const BREAKPOINT_WIDTH = 540;

Expand Down Expand Up @@ -106,7 +105,7 @@ export const ESQLEditor = memo(function ESQLEditor({
}: ESQLEditorProps) {
const popoverRef = useRef<HTMLDivElement>(null);
const datePickerOpenStatusRef = useRef<boolean>(false);
const { euiTheme } = useEuiTheme();
const theme = useEuiTheme();
const kibana = useKibana<ESQLEditorDeps>();
const {
dataViews,
Expand Down Expand Up @@ -314,7 +313,7 @@ export const ESQLEditor = memo(function ESQLEditor({
});

const styles = esqlEditorStyles(
euiTheme,
theme.euiTheme,
editorHeight,
Boolean(editorMessages.errors.length),
Boolean(editorMessages.warnings.length),
Expand Down Expand Up @@ -686,7 +685,7 @@ export const ESQLEditor = memo(function ESQLEditor({
responsive={false}
justifyContent="flexEnd"
css={css`
padding: ${euiTheme.size.s};
padding: ${theme.euiTheme.size.s};
`}
>
<EuiFlexItem grow={false}>
Expand Down Expand Up @@ -730,6 +729,7 @@ export const ESQLEditor = memo(function ESQLEditor({
<div css={styles.editorContainer}>
<CodeEditor
languageId={ESQL_LANG_ID}
classNameCss={getEditorOverwrites(theme)}
value={code}
options={codeEditorOptions}
width="100%"
Expand Down Expand Up @@ -859,8 +859,8 @@ export const ESQLEditor = memo(function ESQLEditor({
tabIndex={0}
style={{
...popoverPosition,
backgroundColor: euiTheme.colors.emptyShade,
borderRadius: euiTheme.border.radius.small,
backgroundColor: theme.euiTheme.colors.emptyShade,
borderRadius: theme.euiTheme.border.radius.small,
position: 'absolute',
overflow: 'auto',
}}
Expand Down
33 changes: 33 additions & 0 deletions src/platform/packages/private/kbn-esql-editor/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import { useRef } from 'react';
import useDebounce from 'react-use/lib/useDebounce';
import { UseEuiTheme, euiShadow } from '@elastic/eui';
import { css } from '@emotion/react';
import { monaco } from '@kbn/monaco';
import type { CoreStart } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -310,3 +312,34 @@ export const onKeyDownResizeHandler = (
}
}
};

export const getEditorOverwrites = (theme: UseEuiTheme<{}>) => {
return css`
.monaco-hover {
display: block !important;
}
.margin-view-overlays .line-numbers {
color: ${theme.euiTheme.colors.textDisabled};
}
.current-line ~ .line-numbers {
color: ${theme.euiTheme.colors.textSubdued};
}
.suggest-widget,
.suggest-details-container {
border-radius: ${theme.euiTheme.border.radius.medium};
${euiShadow(theme, 'l')}
}
.suggest-details-container {
background-color: ${theme.euiTheme.colors.backgroundBasePlain};
line-height: 1.5rem;
}
.suggest-details {
padding-left: ${theme.euiTheme.size.s};
}
.monaco-list .monaco-scrollable-element .monaco-list-row.focused {
border-radius: ${theme.euiTheme.border.radius.medium};
}
`;
};
39 changes: 0 additions & 39 deletions src/platform/packages/private/kbn-esql-editor/src/overwrite.scss

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from '@kbn/monaco';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { css } from '@emotion/react';
import { css, Interpolation, Theme } from '@emotion/react';
import {
MonacoEditor as ReactMonacoEditor,
type MonacoEditorProps as ReactMonacoEditorProps,
Expand Down Expand Up @@ -157,6 +157,11 @@ export interface CodeEditorProps {
enableFindAction?: boolean;

dataTestSubj?: string;

/**
* Custom CSS class to apply to the container
*/
classNameCss?: Interpolation<Theme>;
}

export const CodeEditor: React.FC<CodeEditorProps> = ({
Expand Down Expand Up @@ -189,6 +194,7 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({
accessibilityOverlayEnabled = true,
enableFindAction,
dataTestSubj,
classNameCss,
}) => {
const { euiTheme } = useEuiTheme();

Expand Down Expand Up @@ -490,7 +496,7 @@ export const CodeEditor: React.FC<CodeEditorProps> = ({

return (
<div
css={styles.container}
css={[styles.container, classNameCss]}
onKeyDown={onKeyDown}
data-test-subj={dataTestSubj ?? 'kibanaCodeEditor'}
className="kibanaCodeEditor"
Expand Down

0 comments on commit e426bf0

Please sign in to comment.