Rev 2640 | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
/* eslint-disable react/prop-types */
import React, { useMemo } from "react";
import { useDropzone } from "react-dropzone";
const baseStyle = {
flex: 1,
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
width: "100%",
height: "100%",
borderWidth: 2,
borderRadius: 10,
borderColor: "#eeeeee",
borderStyle: "dashed",
color: "#bdbdbd",
outline: "none",
transition: "border .24s ease-in-out",
};
const activeStyle = {
borderColor: "#2196f3",
};
const acceptStyle = {
borderColor: "#00e676",
};
const rejectStyle = {
borderColor: "#ff1744",
};
function MyDropzone(props) {
const { onDrop, onDropRejected } = props;
const {
getRootProps,
getInputProps,
isDragActive,
isDragAccept,
isDragReject,
} = useDropzone({
multiple: false,
accept: "image/jpeg, image/png, image/jpg",
onDropAccepted: (acceptedFiles) => {
onDrop(acceptedFiles[0]);
},
onDropRejected: (acceptedFiles) => {
onDropRejected(acceptedFiles);
},
});
const style = useMemo(
() => ({
...baseStyle,
...(isDragActive ? activeStyle : {}),
...(isDragAccept ? acceptStyle : {}),
...(isDragReject ? rejectStyle : {}),
}),
[isDragActive, isDragReject, isDragAccept]
);
return (
<div {...getRootProps({ style })}>
<input {...getInputProps()} />
<p>Haz click o arrastra la imagen aqui</p>
Tamaño recomendado: 180x180
</div>
);
}
export default MyDropzone;