import { Typography, Box, useTheme, ButtonBase, Modal, TextField, InputAdornment } from "@mui/material"; import UploadIcon from "../../../assets/icons/UploadIcon"; import SearchIcon from "../../../assets/icons/SearchIcon"; import UnsplashIcon from "../../../assets/icons/Unsplash.svg"; import { useRef, useState, type DragEvent } from "react"; type ImageFormat = "jpg" | "jpeg" | "png" | "gif"; interface ModalkaProps { isOpen: boolean; onClose: () => void; handleImageChange: (file: File) => void; description?: string; accept?: ImageFormat[]; } export const UploadImageModal: React.FC = ({ handleImageChange, isOpen, onClose, accept, description, }) => { const theme = useTheme(); const dropZone = useRef(null); const [ready, setReady] = useState(false); const handleDragEnter = (event: DragEvent) => { event.preventDefault(); setReady(true); }; const handleDrop = (event: DragEvent) => { event.preventDefault(); event.stopPropagation(); const file = event.dataTransfer.files[0]; if (!file) return; handleImageChange(file); }; const acceptedFormats = accept ? accept.map((format) => "." + format).join(", ") : ""; return ( Добавьте изображение event.target.files?.[0] && handleImageChange(event.target.files[0])} hidden accept={acceptedFormats || ".jpg, .jpeg, .png , .gif"} multiple type="file" data-cy="upload-image-input" /> ) => event.preventDefault()} onDrop={handleDrop} ref={dropZone} sx={{ width: "580px", padding: "33px 10px 33px 55px", display: "flex", alignItems: "center", backgroundColor: theme.palette.background.default, border: `1px solid ${ready ? "red" : theme.palette.grey2.main}`, borderRadius: "8px", gap: "55px", }} onDragEnter={handleDragEnter} // Применяем обработчик onDragEnter напрямую > Загрузите или перетяните сюда файл {description || "Принимает JPG, PNG, и GIF формат — максимум 5mb"} {/* */} {/* */} {/* Или выберите на фотостоке*/} {/* */} {/* */} {/* */} {/* path": { stroke: "#9A9AAF" },*/} {/* }}*/} {/* >*/} {/* */} {/* */} {/* ),*/} {/* }}*/} {/* />*/} ); };