mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
refactor(ui/editor): migrate code-editor to react [EE-4848] (#8257)
This commit is contained in:
parent
273a3f9a10
commit
5507b1e8c9
18 changed files with 259 additions and 130 deletions
41
app/react/components/CodeEditor.tsx
Normal file
41
app/react/components/CodeEditor.tsx
Normal file
|
@ -0,0 +1,41 @@
|
|||
import CodeMirror from '@uiw/react-codemirror';
|
||||
import { StreamLanguage } from '@codemirror/language';
|
||||
import { yaml } from '@codemirror/legacy-modes/mode/yaml';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
interface Props {
|
||||
id: string;
|
||||
placeholder?: string;
|
||||
yaml?: boolean;
|
||||
readonly?: boolean;
|
||||
onChange: (value: string) => void;
|
||||
value: string;
|
||||
height?: string;
|
||||
}
|
||||
|
||||
export function CodeEditor({
|
||||
id,
|
||||
onChange,
|
||||
placeholder,
|
||||
readonly,
|
||||
value,
|
||||
height = '500px',
|
||||
yaml: isYaml,
|
||||
}: Props) {
|
||||
const extensions = useMemo(
|
||||
() => (isYaml ? [StreamLanguage.define(yaml)] : []),
|
||||
[isYaml]
|
||||
);
|
||||
|
||||
return (
|
||||
<CodeMirror
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
readOnly={readonly}
|
||||
placeholder={placeholder}
|
||||
id={id}
|
||||
extensions={extensions}
|
||||
height={height}
|
||||
/>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue