import { MenuItem, Select, styled, Typography } from "@mui/material";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { PropsContentProps } from "./CustomPropsItem.tsx";
const NoLabelFilledSelect = styled(Select)(({ theme }) => ({
"& .MuiSelect-select": {
paddingTop: theme.spacing(1),
paddingBottom: theme.spacing(1),
fontSize: theme.typography.body2.fontSize,
"&.Mui-disabled": {
borderBottomStyle: "none",
"&::before": {
borderBottomStyle: "none !important",
},
},
},
"&.MuiInputBase-root.MuiFilledInput-root.MuiSelect-root": {
"&.Mui-disabled": {
borderBottomStyle: "none",
"&::before": {
borderBottomStyle: "none !important",
},
},
},
}));
const SelectPropsContent = ({ prop, onChange, loading, readOnly }: PropsContentProps) => {
const { t } = useTranslation();
const [value, setValue] = useState(prop.value || "");
useEffect(() => {
setValue(prop.value || "");
}, [prop.value]);
const handleChange = (selectedValue: string) => {
setValue(selectedValue);
if (selectedValue !== prop.value) {
onChange(selectedValue);
}
};
if (readOnly) {
return {value};
}
const options = prop.props.options || [];
return (
handleChange(e.target.value as string)}
onClick={(e) => e.stopPropagation()}
displayEmpty
renderValue={(selected) => {
if (!selected) {
return (
{t("application:fileManager.clickToEditSelect")}
);
}
return selected as string;
}}
>
{options.map((option) => (
))}
);
};
export default SelectPropsContent;