2023-08-14 15:35:57 +00:00
|
|
|
|
import {
|
|
|
|
|
|
Typography,
|
|
|
|
|
|
Box,
|
|
|
|
|
|
useTheme,
|
|
|
|
|
|
ButtonBase,
|
|
|
|
|
|
Modal,
|
|
|
|
|
|
TextField,
|
|
|
|
|
|
InputAdornment,
|
|
|
|
|
|
} from "@mui/material";
|
2023-05-10 17:35:30 +00:00
|
|
|
|
import UploadBox from "@ui_kit/UploadBox";
|
2023-05-03 19:21:00 +00:00
|
|
|
|
import UploadIcon from "../../assets/icons/UploadIcon";
|
2023-08-14 15:35:57 +00:00
|
|
|
|
import SearchIcon from "../../assets/icons/SearchIcon";
|
2023-03-18 21:35:09 +00:00
|
|
|
|
import * as React from "react";
|
2023-03-15 22:56:53 +00:00
|
|
|
|
|
2023-08-14 15:35:57 +00:00
|
|
|
|
import UnsplashIcon from "../../assets/icons/Unsplash.svg";
|
|
|
|
|
|
|
2023-07-30 21:25:47 +00:00
|
|
|
|
interface ModalkaProps {
|
|
|
|
|
|
imgHC: (imgInp: HTMLInputElement) => void;
|
|
|
|
|
|
}
|
2023-03-22 23:46:06 +00:00
|
|
|
|
|
2023-07-30 21:25:47 +00:00
|
|
|
|
const Modalka: React.FC<ModalkaProps> = ({ imgHC }) => {
|
|
|
|
|
|
const theme = useTheme();
|
2023-03-24 23:43:15 +00:00
|
|
|
|
|
2023-07-30 21:25:47 +00:00
|
|
|
|
const dropZone = React.useRef<HTMLDivElement>(null);
|
|
|
|
|
|
const [ready, setReady] = React.useState(false);
|
2023-03-22 23:46:06 +00:00
|
|
|
|
|
2023-07-30 21:25:47 +00:00
|
|
|
|
const handleDragEnter = (event: React.DragEvent<HTMLDivElement>) => {
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
setReady(true);
|
|
|
|
|
|
};
|
2023-03-22 23:46:06 +00:00
|
|
|
|
|
2023-07-30 21:25:47 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
position: "absolute",
|
|
|
|
|
|
top: "50%",
|
|
|
|
|
|
left: "50%",
|
|
|
|
|
|
transform: "translate(-50%, -50%)",
|
|
|
|
|
|
maxWidth: "690px",
|
|
|
|
|
|
bgcolor: "background.paper",
|
|
|
|
|
|
borderRadius: "12px",
|
|
|
|
|
|
boxShadow: 24,
|
|
|
|
|
|
p: 0,
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
|
padding: "20px",
|
|
|
|
|
|
background: theme.palette.background.default,
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2023-08-14 15:35:57 +00:00
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{ marginBottom: "20px", fontWeight: "bold", color: "#4D4D4D" }}
|
|
|
|
|
|
>
|
|
|
|
|
|
Добавьте изображение
|
|
|
|
|
|
</Typography>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
<ButtonBase component="label" sx={{ justifyContent: "flex-start" }}>
|
2023-08-14 15:35:57 +00:00
|
|
|
|
<input
|
|
|
|
|
|
onChange={(event) => imgHC(event.target)}
|
|
|
|
|
|
hidden
|
|
|
|
|
|
accept="image/*"
|
|
|
|
|
|
multiple
|
|
|
|
|
|
type="file"
|
|
|
|
|
|
/>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
<Box
|
|
|
|
|
|
ref={dropZone}
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
width: "580px",
|
2023-08-14 15:35:57 +00:00
|
|
|
|
padding: "33px 10px 33px 55px",
|
2023-07-30 21:25:47 +00:00
|
|
|
|
display: "flex",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
backgroundColor: theme.palette.background.default,
|
|
|
|
|
|
border: `1px solid ${ready ? "red" : theme.palette.grey2.main}`,
|
|
|
|
|
|
borderRadius: "8px",
|
2023-08-14 15:35:57 +00:00
|
|
|
|
gap: "55px",
|
2023-07-30 21:25:47 +00:00
|
|
|
|
}}
|
|
|
|
|
|
onDragEnter={handleDragEnter} // Применяем обработчик onDragEnter напрямую
|
|
|
|
|
|
>
|
|
|
|
|
|
<UploadIcon />
|
|
|
|
|
|
<Box>
|
2023-08-14 15:35:57 +00:00
|
|
|
|
<Typography sx={{ color: "#9A9AAF", fontWeight: "bold" }}>
|
|
|
|
|
|
Загрузите или перетяните сюда файл
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
<Typography sx={{ color: "#9A9AAF", fontSize: "16px" }}>
|
|
|
|
|
|
Принимает JPG, PNG, и GIF формат — максимум 5mb
|
|
|
|
|
|
</Typography>
|
2023-03-22 23:46:06 +00:00
|
|
|
|
</Box>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
</Box>
|
|
|
|
|
|
</ButtonBase>
|
2023-08-14 15:35:57 +00:00
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
|
margin: "20px 0",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
fontWeight: "bold",
|
|
|
|
|
|
color: "#4D4D4D",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
Или выберите на фотостоке
|
|
|
|
|
|
</Typography>
|
|
|
|
|
|
<img src={UnsplashIcon} alt="" />
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
<TextField
|
|
|
|
|
|
id="search-in-unsplash"
|
|
|
|
|
|
placeholder="Ищите изображения на английском языка"
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
"& .MuiInputBase-input": {
|
|
|
|
|
|
height: "48px",
|
|
|
|
|
|
padding: "0 10px 0 0",
|
|
|
|
|
|
},
|
|
|
|
|
|
"& .MuiOutlinedInput-notchedOutline": {
|
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
|
},
|
|
|
|
|
|
"& .Mui-focused .MuiOutlinedInput-notchedOutline": {
|
|
|
|
|
|
border: "1px solid rgba(0, 0, 0, 0.23)",
|
|
|
|
|
|
},
|
|
|
|
|
|
"& .MuiInputBase-root.MuiOutlinedInput-root .MuiOutlinedInput-notchedOutline":
|
|
|
|
|
|
{
|
|
|
|
|
|
borderColor: "rgba(0, 0, 0, 0.23)",
|
|
|
|
|
|
},
|
|
|
|
|
|
}}
|
|
|
|
|
|
InputProps={{
|
|
|
|
|
|
startAdornment: (
|
|
|
|
|
|
<InputAdornment
|
|
|
|
|
|
position="start"
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
outline: "none",
|
|
|
|
|
|
"& svg > path": { stroke: "#9A9AAF" },
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<SearchIcon />
|
|
|
|
|
|
</InputAdornment>
|
|
|
|
|
|
),
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
</Box>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
2023-03-15 22:56:53 +00:00
|
|
|
|
|
2023-07-30 21:25:47 +00:00
|
|
|
|
export default function UploadImage() {
|
|
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
const [open, setOpen] = React.useState(false);
|
|
|
|
|
|
const handleOpen = () => setOpen(true);
|
|
|
|
|
|
const handleClose = () => setOpen(false);
|
|
|
|
|
|
const imgHC = (imgInp: HTMLInputElement) => {
|
|
|
|
|
|
if (imgInp.files) {
|
|
|
|
|
|
const fileArray = Array.from(imgInp.files);
|
|
|
|
|
|
const [file] = fileArray;
|
|
|
|
|
|
setImg(URL.createObjectURL(file));
|
|
|
|
|
|
handleClose();
|
2023-03-18 23:42:47 +00:00
|
|
|
|
}
|
2023-07-30 21:25:47 +00:00
|
|
|
|
};
|
|
|
|
|
|
const [img, setImg] = React.useState("");
|
2023-03-18 23:42:47 +00:00
|
|
|
|
|
2023-07-30 21:25:47 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<Box sx={{ padding: "20px" }}>
|
2023-08-14 15:35:57 +00:00
|
|
|
|
<Typography
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
fontWeight: 500,
|
|
|
|
|
|
color: theme.palette.grey3.main,
|
|
|
|
|
|
mt: "11px",
|
|
|
|
|
|
mb: "14px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
Загрузить изображение
|
|
|
|
|
|
</Typography>
|
2023-08-14 15:35:57 +00:00
|
|
|
|
<ButtonBase
|
|
|
|
|
|
onClick={handleOpen}
|
|
|
|
|
|
sx={{ width: "100%", maxWidth: "260px" }}
|
|
|
|
|
|
>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
{img ? (
|
|
|
|
|
|
<img width="400" src={img} />
|
|
|
|
|
|
) : (
|
2023-08-14 15:35:57 +00:00
|
|
|
|
<UploadBox
|
|
|
|
|
|
sx={{ maxWidth: "260px" }}
|
|
|
|
|
|
icon={<UploadIcon />}
|
|
|
|
|
|
text="5 MB максимум"
|
|
|
|
|
|
/>
|
2023-07-30 21:25:47 +00:00
|
|
|
|
)}
|
|
|
|
|
|
</ButtonBase>
|
|
|
|
|
|
<Modal
|
|
|
|
|
|
open={open}
|
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
|
aria-labelledby="modal-modal-title"
|
|
|
|
|
|
aria-describedby="modal-modal-description"
|
|
|
|
|
|
>
|
|
|
|
|
|
<Modalka imgHC={imgHC} />
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|