-
Notifications
You must be signed in to change notification settings - Fork 280
/
Copy pathStringInput.tsx
51 lines (48 loc) · 1.1 KB
/
StringInput.tsx
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
import { Textarea } from "@/components/ui/textarea";
import { JsonSchemaType } from "./DynamicJsonForm";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "./ui/select";
interface Props {
id: string;
name: string;
property: JsonSchemaType;
value: string;
onChange: (value: string) => void;
}
export const StringInput = ({ id, name, property, value, onChange }: Props) => {
if (property.enum?.length) {
return (
<Select
value={value}
onValueChange={(value) => {
onChange(value);
}}
>
<SelectTrigger id={id} name={name}>
<SelectValue placeholder={property.description} />
</SelectTrigger>
<SelectContent>
{property.enum.map((item) => (
<SelectItem key={item} value={item}>
{item}
</SelectItem>
))}
</SelectContent>
</Select>
);
}
return (
<Textarea
id={id}
name={name}
placeholder={property.description}
value={value}
onChange={(e) => onChange(e.target.value)}
/>
);
};