nicer yaml editor
This commit is contained in:
1 parent
25770e1c1d
commit
952dcba3ac
3 files changed
+153
-9
No files matched your search
@@ -1,8 +1,11 @@
|
||||
import * as yaml from "js-yaml";
|
||||
import { useState } from "react";
|
||||
import InputTextArea from "./InputTextArea";
|
||||
import { useDelayEffect } from 'utils/useDelay';
|
||||
|
||||
import CodeMirror from '@uiw/react-codemirror';
|
||||
import InputWrapper from "./InputWrapper";
|
||||
|
||||
|
||||
export interface Props<T extends {}> {
|
||||
label: string;
|
||||
value: T;
|
||||
@@ -24,6 +27,7 @@ export default function InputYaml<T>({
|
||||
});
|
||||
const setText = (t: string) => {
|
||||
try {
|
||||
yaml.load(t)
|
||||
setState({ text: t, error: undefined })
|
||||
} catch (_) {
|
||||
setState({ text: t, error: "! Invalid Yaml !" })
|
||||
@@ -40,11 +44,12 @@ export default function InputYaml<T>({
|
||||
}
|
||||
}
|
||||
}, [text], 1000)
|
||||
return <InputTextArea
|
||||
error={error}
|
||||
label={label}
|
||||
value={text}
|
||||
onChange={setText}
|
||||
resizable={resizable}
|
||||
/>
|
||||
return <InputWrapper label={label} error={error}>
|
||||
<CodeMirror
|
||||
theme={"dark"}
|
||||
value={text}
|
||||
lang="yaml"
|
||||
onChange={setText}
|
||||
/>
|
||||
</InputWrapper>
|
||||
}
|
||||
Reference in new issue
Block a user