2023-03-18 21:35:09 +00:00
|
|
|
|
import {Typography, Box, useTheme, ButtonBase, Modal} from "@mui/material";
|
2023-03-30 18:39:59 +00:00
|
|
|
|
import UploadBox from "../../components/CreateQuiz/UploadBox";
|
|
|
|
|
|
import UploadIcon from "@icons/UploadIcon";
|
2023-03-18 21:35:09 +00:00
|
|
|
|
import * as React from "react";
|
2023-03-15 22:56:53 +00:00
|
|
|
|
|
2023-03-31 15:48:49 +00:00
|
|
|
|
const Modalka = ({imgHC}:any) => {
|
2023-03-22 23:46:06 +00:00
|
|
|
|
const theme = useTheme();
|
|
|
|
|
|
|
|
|
|
|
|
const dropZone = React.useRef<any>(null);
|
|
|
|
|
|
const [ready, setReady] = React.useState(false);
|
2023-03-24 23:43:15 +00:00
|
|
|
|
|
|
|
|
|
|
const dragenterHC = () => {
|
|
|
|
|
|
console.log("a")
|
|
|
|
|
|
setReady(true)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-22 23:46:06 +00:00
|
|
|
|
console.log(dropZone.current)
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
|
console.log(dropZone.current)
|
|
|
|
|
|
if (dropZone.current) {
|
2023-03-24 23:43:15 +00:00
|
|
|
|
dropZone.current.addEventListener("dragenter", dragenterHC)
|
2023-03-22 23:46:06 +00:00
|
|
|
|
}
|
2023-03-24 23:43:15 +00:00
|
|
|
|
return () => {dropZone.current.removeEventListener("dragenter", dragenterHC)}
|
|
|
|
|
|
},)
|
2023-03-22 23:46:06 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<Box
|
|
|
|
|
|
sx={{
|
|
|
|
|
|
position: 'absolute' as 'absolute',
|
|
|
|
|
|
top: '50%',
|
|
|
|
|
|
left: '50%',
|
|
|
|
|
|
transform: 'translate(-50%, -50%)',
|
|
|
|
|
|
maxWidth: '690px',
|
|
|
|
|
|
bgcolor: 'background.paper',
|
|
|
|
|
|
borderRadius: '12px',
|
|
|
|
|
|
|
|
|
|
|
|
boxShadow: 24,
|
|
|
|
|
|
p: 0,}}>
|
|
|
|
|
|
<Box
|
2023-03-24 23:43:15 +00:00
|
|
|
|
|
2023-03-22 23:46:06 +00:00
|
|
|
|
sx={{display: 'flex',
|
|
|
|
|
|
|
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
|
padding: '20px',
|
2023-03-24 23:43:15 +00:00
|
|
|
|
background: theme.palette.background.default,
|
2023-03-22 23:46:06 +00:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Typography>Добавьте изображение</Typography>
|
|
|
|
|
|
<ButtonBase component="label" sx={{justifyContent: 'flex-start'}} >
|
|
|
|
|
|
<input onChange={event => imgHC(event.target)} hidden accept="image/*" multiple type="file" />
|
|
|
|
|
|
<Box
|
2023-03-24 23:43:15 +00:00
|
|
|
|
ref={dropZone}
|
2023-03-22 23:46:06 +00:00
|
|
|
|
sx={{
|
|
|
|
|
|
width: '580px',
|
|
|
|
|
|
padding: '33px',
|
|
|
|
|
|
display: "flex",
|
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
backgroundColor: theme.palette.background.default,
|
2023-03-24 23:43:15 +00:00
|
|
|
|
border: `1px solid ${ready? "red" : theme.palette.grey2.main}`,
|
2023-03-22 23:46:06 +00:00
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
<UploadIcon />
|
|
|
|
|
|
<Box>
|
|
|
|
|
|
<Typography>Загрузите или перетяните сюда файл</Typography>
|
|
|
|
|
|
<Typography>Принимает JPG, PNG, и GIF формат — максимум 5mb</Typography>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
</ButtonBase>
|
|
|
|
|
|
<Typography>Или выберите на фотостоке</Typography>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
</Box>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2023-03-15 22:56:53 +00:00
|
|
|
|
|
|
|
|
|
|
export default function UploadImage () {
|
|
|
|
|
|
const theme = useTheme();
|
2023-03-18 21:35:09 +00:00
|
|
|
|
const [open, setOpen] = React.useState(false);
|
|
|
|
|
|
const handleOpen = () => setOpen(true);
|
|
|
|
|
|
const handleClose = () => setOpen(false);
|
2023-03-18 23:42:47 +00:00
|
|
|
|
const imgHC = (imgInp:any) => {
|
|
|
|
|
|
const [file] = imgInp.files
|
|
|
|
|
|
setImg(URL.createObjectURL(file))
|
|
|
|
|
|
handleClose()
|
|
|
|
|
|
}
|
|
|
|
|
|
const [img, setImg] = React.useState("");
|
|
|
|
|
|
|
2023-03-15 22:56:53 +00:00
|
|
|
|
return (
|
2023-03-18 21:35:09 +00:00
|
|
|
|
<Box sx={{padding: '20px'}}>
|
2023-03-15 22:56:53 +00:00
|
|
|
|
<Typography sx={{ fontWeight: 500, color: theme.palette.grey3.main, mt: "11px", mb: "14px" }}>Загрузить изображение</Typography>
|
2023-03-18 21:35:09 +00:00
|
|
|
|
<ButtonBase onClick={handleOpen} sx={{width: "100%", maxWidth: "260px"}}>
|
2023-03-18 23:42:47 +00:00
|
|
|
|
{img ?
|
|
|
|
|
|
<img width="400" src={img}/>
|
|
|
|
|
|
:
|
|
|
|
|
|
<UploadBox sx ={{maxWidth: "260px"}} icon={<UploadIcon />} text="5 MB максимум" />
|
|
|
|
|
|
}
|
2023-03-18 21:35:09 +00:00
|
|
|
|
</ButtonBase>
|
|
|
|
|
|
<Modal
|
|
|
|
|
|
open={open}
|
|
|
|
|
|
onClose={handleClose}
|
|
|
|
|
|
aria-labelledby="modal-modal-title"
|
|
|
|
|
|
aria-describedby="modal-modal-description"
|
|
|
|
|
|
>
|
2023-03-22 23:46:06 +00:00
|
|
|
|
<Modalka handleClose={handleClose} open={open} imgHC={imgHC}/>
|
2023-03-18 21:35:09 +00:00
|
|
|
|
</Modal>
|
2023-03-15 22:56:53 +00:00
|
|
|
|
</Box>
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|