Can create VM from UI
This commit is contained in:
38
virtweb_frontend/src/widgets/forms/SelectInput.tsx
Normal file
38
virtweb_frontend/src/widgets/forms/SelectInput.tsx
Normal file
@ -0,0 +1,38 @@
|
||||
import { FormControl, InputLabel, MenuItem, Select } from "@mui/material";
|
||||
import { TextInput } from "./TextInput";
|
||||
|
||||
export interface SelectOption {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export function SelectInput(p: {
|
||||
value?: string;
|
||||
editing: boolean;
|
||||
label: string;
|
||||
options: SelectOption[];
|
||||
onValueChange: (o?: string) => void;
|
||||
}): React.ReactElement {
|
||||
if (!p.editing && !p.value) return <></>;
|
||||
|
||||
if (!p.editing) {
|
||||
const value = p.options.find((o) => o.value === p.value)?.label;
|
||||
return <TextInput label={p.label} editable={p.editing} value={value} />;
|
||||
}
|
||||
return (
|
||||
<FormControl fullWidth variant="standard" style={{ marginBottom: "15px" }}>
|
||||
<InputLabel>{p.label}</InputLabel>
|
||||
<Select
|
||||
value={p.value ?? ""}
|
||||
label={p.label}
|
||||
onChange={(e) => p.onValueChange(e.target.value)}
|
||||
>
|
||||
{p.options.map((e) => (
|
||||
<MenuItem key={e.value} value={e.value}>
|
||||
{e.label}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user