moved back the components

This commit is contained in:
ari committed 2021-12-01 16:38:30 -05:00
1 parent 24afb602cb
commit 0764feb432
18 files changed
+786

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";
import InputTextArea from "./InputTextArea";
export interface Props<T extends {}> {
label: string;
value: T;
onChange: (v: T) => void;
resizable?: boolean;
}
export default function InputYaml<T>({
label,
value={} as any,
onChange,
resizable,
}: Props<T>) {
const [text, setText] = useState("");
useEffect(() => {
setText(yaml.dump(value));
}, [value]);
const delayId = useRef<null | number>(null);
const delayedUpdate = (update: string) => {
setText(update)
if (delayId.current) {
window.clearTimeout(delayId.current);
delayId.current = null;
}
delayId.current = window.setTimeout(() => {
onChange(yaml.load(update) as any)
}, 1000);
}
return <InputTextArea
label={label}
value={text}
onChange={delayedUpdate}
resizable={resizable}
/>
}