diff --git a/.changeset/huge-doodles-bathe.md b/.changeset/huge-doodles-bathe.md new file mode 100644 index 0000000000..bf76e544cd --- /dev/null +++ b/.changeset/huge-doodles-bathe.md @@ -0,0 +1,5 @@ +--- +'@coveord/plasma-mantine': patch +--- + +Changed the layout of the label and actions of the codeeditor, minor color changes, test fixed diff --git a/packages/mantine/src/components/CodeEditor/CodeEditor.module.css b/packages/mantine/src/components/CodeEditor/CodeEditor.module.css index e0b052729c..a60085c117 100644 --- a/packages/mantine/src/components/CodeEditor/CodeEditor.module.css +++ b/packages/mantine/src/components/CodeEditor/CodeEditor.module.css @@ -1,15 +1,17 @@ .root { - --ce-bg: var(--mantine-color-gray-0); + --ce-bg: var(--mantine-color-white); --ce-border-color: var(--mantine-color-default-border); border: 1px solid var(--ce-border-color); border-radius: var(--mantine-radius-lg); z-index: 1; - height: 100%; background-color: var(--ce-bg); + display: flex; + flex-direction: column; + flex: 1; @mixin light { - --ce-bg: var(--mantine-color-gray-0); + --ce-bg: var(--mantine-color-white); } @mixin dark { @@ -17,6 +19,14 @@ } } +.actions { + border-bottom: 1px solid var(--ce-border-color); +} + +.editor { + flex: 1; +} + /* * The find widget's buttons (close, "Find in Selection", etc.) show a pointer-style hover tooltip. * A monaco bug (microsoft/monaco-editor#5208, #5139) makes that tooltip reposition on layout, which @@ -43,7 +53,7 @@ .disabled { @mixin light { --ce-bg: var(--mantine-color-gray-1); - --ce-border-color: var(--mantine-color-gray-1); + --ce-border-color: var(--mantine-color-default-border); :global { .monaco-editor { diff --git a/packages/mantine/src/components/CodeEditor/CodeEditor.tsx b/packages/mantine/src/components/CodeEditor/CodeEditor.tsx index 29e02c1d1d..5f7f8876a3 100644 --- a/packages/mantine/src/components/CodeEditor/CodeEditor.tsx +++ b/packages/mantine/src/components/CodeEditor/CodeEditor.tsx @@ -85,9 +85,9 @@ const defaultProps = { language: 'plaintext', monacoLoader: 'local', defaultValue: '', - minHeight: 300, + minHeight: 350, justify: 'flex-start', - gap: 'sm', + gap: 'xxs', } satisfies Partial; export const CodeEditor: FunctionComponent = (props) => { @@ -151,7 +151,7 @@ export const CodeEditor: FunctionComponent = (props) => { inherit: true, rules: [], colors: { - 'editor.background': theme.colors.gray[0], + 'editor.background': '#ffffff', // mantine color white is #fff and monaco only accepts 6 digits }, }); }; @@ -206,7 +206,7 @@ export const CodeEditor: FunctionComponent = (props) => { ) : null; const _buttons = ( - + onCopy?.()} /> @@ -218,8 +218,6 @@ export const CodeEditor: FunctionComponent = (props) => { const _editor = loaded ? ( = (props) => { )} data-testid="editor-wrapper" > - handleChange(nextValue ?? '')} - beforeMount={(monaco) => { - registerLanguages(monaco); - registerThemes(monaco); - }} - onMount={(editor) => { - editorRef.current = editor; - if (editorHandle) { - editorHandle.current = editor; - } - editor.onDidFocusEditorText(() => onFocus?.()); - editor.onDidDispose(() => { - // If the editor is disposed while the component is still mounted (e.g. React's - // `` tore down the effects to hide the panel), force a fresh instance so we - // never render against a disposed editor when the panel becomes visible again. - setEditorKey((key) => key + 1); - }); - editor.onDidBlurEditorText(async () => { - // monaco editor has a timeout of 500ms populating errors, we want to ensure that checking errors happen after that - setTimeout(async () => { - if (!hasMonacoErrorRef.current) { - await editor?.getAction('editor.action.formatDocument')?.run(); - } - }, 550); - }); - }} - /> + {_buttons} + + handleChange(nextValue ?? '')} + beforeMount={(monaco) => { + registerLanguages(monaco); + registerThemes(monaco); + }} + onMount={(editor) => { + editorRef.current = editor; + if (editorHandle) { + editorHandle.current = editor; + } + editor.onDidFocusEditorText(() => onFocus?.()); + editor.onDidDispose(() => { + // If the editor is disposed while the component is still mounted (e.g. React's + // `` tore down the effects to hide the panel), force a fresh instance so we + // never render against a disposed editor when the panel becomes visible again. + setEditorKey((key) => key + 1); + }); + editor.onDidBlurEditorText(async () => { + // monaco editor has a timeout of 500ms populating errors, we want to ensure that checking errors happen after that + setTimeout(async () => { + if (!hasMonacoErrorRef.current) { + await editor?.getAction('editor.action.formatDocument')?.run(); + } + }, 550); + }); + }} + /> + ) : (
@@ -278,12 +279,10 @@ export const CodeEditor: FunctionComponent = (props) => { ); const height = Math.max(Number.isNaN(parentHeight) ? 0 : parentHeight, minHeight); + return ( - - {_header} - {_buttons} - + {_header} {_editor} {_error} diff --git a/packages/mantine/src/components/CodeEditor/__tests__/CodeEditor.spec.tsx b/packages/mantine/src/components/CodeEditor/__tests__/CodeEditor.spec.tsx index 9a2bee5727..e93e42d765 100644 --- a/packages/mantine/src/components/CodeEditor/__tests__/CodeEditor.spec.tsx +++ b/packages/mantine/src/components/CodeEditor/__tests__/CodeEditor.spec.tsx @@ -83,6 +83,7 @@ describe('CodeEditor', () => { const user = userEvent.setup(); const onCopySpy = vi.fn(); render(); + await waitForElementToBeRemoved(screen.queryByRole('presentation')); await user.click(screen.getByRole('button', {name: /copy/i})); expect(onCopySpy).toHaveBeenCalledTimes(1);