diff --git a/packages/console/src/components/CodeEditor/index.module.scss b/packages/console/src/components/CodeEditor/index.module.scss index 66eadc20a..d3297f570 100644 --- a/packages/console/src/components/CodeEditor/index.module.scss +++ b/packages/console/src/components/CodeEditor/index.module.scss @@ -2,4 +2,20 @@ .editor { margin: _.unit(1) 0; + border-radius: _.unit(4); + padding: _.unit(4) 0; + // Use fixed color for both light and dark mode, the same as vs-dark. + background: #1e1e1e; + + .actions { + display: flex; + align-items: center; + justify-content: right; + padding: 0 _.unit(4); + + button:hover { + // Clear icons background style since the background color is fixed. + background: unset; + } + } } diff --git a/packages/console/src/components/CodeEditor/index.tsx b/packages/console/src/components/CodeEditor/index.tsx index 52dae4993..5a5abae24 100644 --- a/packages/console/src/components/CodeEditor/index.tsx +++ b/packages/console/src/components/CodeEditor/index.tsx @@ -2,29 +2,31 @@ import MonacoEditor from '@monaco-editor/react'; import * as monaco from 'monaco-editor'; import React from 'react'; +import Copy from '@/icons/Copy'; + +import IconButton from '../IconButton'; import * as styles from './index.module.scss'; type Props = { language: string; - isDarkMode?: boolean; height?: string; isReadonly?: boolean; value?: string; onChange?: (value: string) => void; }; -const CodeEditor = ({ - value, - onChange, - language, - height = '300px', - isReadonly = false, - isDarkMode, -}: Props) => { +const CodeEditor = ({ value, onChange, language, height = '300px', isReadonly = false }: Props) => { const handleChange = (changedValue = '') => { onChange?.(changedValue); }; + const handleCopy = async () => { + if (!value) { + return; + } + await navigator.clipboard.writeText(value); + }; + // See https://microsoft.github.io/monaco-editor/api/enums/monaco.editor.EditorOption.html const options: monaco.editor.IStandaloneEditorConstructionOptions = { readOnly: isReadonly, @@ -38,10 +40,15 @@ const CodeEditor = ({ return (
+
+ + + +
) => ( + + + +); + +export default Copy;