import { Box, IconButton, Link, Typography } from "@mui/material"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { NoLabelFilledTextField } from "../../../Common/StyledComponents.tsx"; import Edit from "../../../Icons/Edit.tsx"; import { PropsContentProps } from "./CustomPropsItem.tsx"; const LinkPropsContent = ({ prop, onChange, loading, fullSize, readOnly }: PropsContentProps) => { const { t } = useTranslation(); const [value, setValue] = useState(prop.value); const [isEditing, setIsEditing] = useState(false); const [isHovered, setIsHovered] = useState(false); useEffect(() => { setValue(prop.value); }, [prop.value]); const handleEditClick = () => { setIsEditing(true); }; const handleBlur = () => { setIsEditing(false); if (value !== prop.value) { onChange(value); } }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter") { handleBlur(); } if (e.key === "Escape") { setValue(prop.value); setIsEditing(false); } }; if (readOnly) { if (!value) { return null; } return ( {value} ); } if (isEditing) { return ( e.stopPropagation()} onChange={(e) => setValue(e.target.value)} value={value ?? ""} onBlur={handleBlur} onKeyDown={handleKeyDown} /> ); } if (!value) { return ( {t("application:fileManager.clickToEdit")} ); } return ( setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} > {value} {isHovered && ( { e.stopPropagation(); handleEditClick(); }} > )} ); }; export default LinkPropsContent;