added more state managers
This commit is contained in:
1 parent
08a50051d5
commit
f66895d0eb
14 files changed
+266
-14
No files matched your search
@@ -2,15 +2,18 @@ import { SelectHTMLAttributes } from "react";
|
||||
import InputWrapper from "./InputWrapper";
|
||||
|
||||
|
||||
export interface Props {
|
||||
current: string;
|
||||
options: readonly string[];
|
||||
export interface Props<T extends string> {
|
||||
current: T;
|
||||
options: readonly T[];
|
||||
onChange: (n: string) => void;
|
||||
id?: string;
|
||||
className?: string;
|
||||
label: string;
|
||||
}
|
||||
export default function InputList({current, options, onChange, label, ...selattr}: Props) {
|
||||
export default function InputList<T extends string>({
|
||||
current, options, onChange, label,
|
||||
...selattr
|
||||
}: Props<T>) {
|
||||
return <InputWrapper label={label}>
|
||||
<select {...selattr} value={current} onChange={e => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -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))
|
||||
}, 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