2023-08-11 09:09:40 +00:00
|
|
|
import { FormControl, InputLabel, MenuItem, Select } from "@mui/material";
|
|
|
|
import { PropEdit } from "./PropEdit";
|
|
|
|
|
|
|
|
export interface SelectOption {
|
|
|
|
value: string;
|
|
|
|
label: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function PropSelect(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 <PropEdit label={p.label} editable={p.editing} value={value} />;
|
|
|
|
}
|
|
|
|
return (
|
2023-08-11 09:31:33 +00:00
|
|
|
<FormControl fullWidth variant="filled" style={{ marginBottom: "15px" }}>
|
2023-08-11 09:09:40 +00:00
|
|
|
<InputLabel>{p.label}</InputLabel>
|
|
|
|
<Select
|
2023-08-17 10:50:16 +00:00
|
|
|
value={p.value ?? ""}
|
2023-08-11 09:09:40 +00:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|