Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
import React, { useMemo } from "react";
2
import { useDropzone } from "react-dropzone";
3
 
4
const baseStyle = {
5
  flex: 1,
6
  display: "flex",
7
  flexDirection: "column",
8
  alignItems: "center",
9
  justifyContent: "center",
10
  width: "100%",
11
  height: "100%",
12
  borderWidth: 2,
2640 stevensc 13
  borderRadius: 10,
1 www 14
  borderColor: "#eeeeee",
15
  borderStyle: "dashed",
16
  backgroundColor: "#fafafa",
17
  color: "#bdbdbd",
18
  outline: "none",
19
  transition: "border .24s ease-in-out",
20
};
21
 
22
const activeStyle = {
23
  borderColor: "#2196f3",
24
};
25
 
26
const acceptStyle = {
27
  borderColor: "#00e676",
28
};
29
 
30
const rejectStyle = {
31
  borderColor: "#ff1744",
32
};
33
 
34
function MyDropzone(props) {
35
  const { onDrop, onDropRejected } = props;
36
 
37
  const {
38
    getRootProps,
39
    getInputProps,
40
    isDragActive,
41
    isDragAccept,
42
    isDragReject,
43
  } = useDropzone({
44
    multiple: false,
45
    accept: "image/jpeg, image/png, image/jpg",
46
    onDropAccepted: (acceptedFiles) => {
47
      onDrop(acceptedFiles[0]);
48
    },
49
    onDropRejected: (acceptedFiles) => {
50
      onDropRejected(acceptedFiles);
51
    },
52
  });
53
 
54
  const style = useMemo(
55
    () => ({
56
      ...baseStyle,
57
      ...(isDragActive ? activeStyle : {}),
58
      ...(isDragAccept ? acceptStyle : {}),
59
      ...(isDragReject ? rejectStyle : {}),
60
    }),
61
    [isDragActive, isDragReject, isDragAccept]
62
  );
63
 
64
  return (
65
    <div {...getRootProps({ style })}>
66
      <input {...getInputProps()} />
67
      <p>Haz click o arrastra la imagen aqui</p>
68
      Tamaño recomendado: 180x180
69
    </div>
70
  );
71
}
72
 
73
export default MyDropzone;