File size: 1,257 Bytes
1067b6f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import { Input } from "./ui/input";
import { Label } from "./ui/label";
import { Textarea } from "./ui/textarea";
export const TextInputWithLabel = ({
label,
id,
type,
inputType,
state,
setState,
...delegated
}: {
label: string;
id: string;
type: string;
inputType?: "input" | "textarea";
state: Record<string, unknown>;
setState: React.Dispatch<React.SetStateAction<any>>;
[x: string]: unknown;
}) => {
return (
<div className="flex flex-col gap-2">
<Label htmlFor={id}>{label}</Label>
{inputType === "textarea" ? (
<Textarea
name={id}
id={id}
value={state[id] ? String(state[id]) : ""}
onChange={(e) =>
setState((prev: Record<string, string>) => ({
...prev,
[id]: e.target.value,
}))
}
{...delegated}
/>
) : (
<Input
type={type}
name={id}
id={id}
value={state[id] ? String(state[id]) : ""}
onChange={(e) =>
setState((prev: Record<string, string>) => ({
...prev,
[id]: e.target.value,
}))
}
{...delegated}
/>
)}
</div>
);
};
|