added input text view + moved things
This commit is contained in:
1 parent
9694ffb238
commit
54c1edba0c
17 files changed
+166
-121
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import InputWrapper from "./InputWrapper";
|
||||
import * as yaml from "js-yaml";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
export interface Props<T> {
|
||||
label: string;
|
||||
value: T;
|
||||
onChange: (v: T) => void;
|
||||
}
|
||||
export default function InputYaml<T>({
|
||||
label,
|
||||
value={} as any,
|
||||
onChange,
|
||||
}: Props<T>) {
|
||||
const [text, setText] = useState("");
|
||||
useEffect(() => {
|
||||
setText(yaml.dump(value));
|
||||
}, [value]);
|
||||
const delayId = useRef<null | number>(null);
|
||||
const delayedUpdate = (update: string) => {
|
||||
if (delayId.current) {
|
||||
window.clearTimeout(delayId.current);
|
||||
delayId.current = null;
|
||||
}
|
||||
delayId.current = window.setTimeout(() => {
|
||||
onChange(yaml.load(update) as any)
|
||||
}, 1000);
|
||||
}
|
||||
return <InputWrapper label={label}>
|
||||
<textarea
|
||||
value={text}
|
||||
onChange={e => {
|
||||
e.preventDefault();
|
||||
setText(e.target.value);
|
||||
delayedUpdate(e.target.value);
|
||||
}}
|
||||
/>
|
||||
</InputWrapper>
|
||||
}
|
||||
Reference in new issue
Block a user