2021-01-05 05:25:58 +00:00
|
|
|
import { close } from 'inspector';
|
2021-01-05 02:30:43 +00:00
|
|
|
import React from 'react';
|
|
|
|
import Dropzone from 'react-dropzone';
|
|
|
|
import styled from 'styled-components';
|
2021-01-05 05:25:58 +00:00
|
|
|
import CollectionSelector from './CollectionSelector';
|
2021-01-05 02:30:43 +00:00
|
|
|
|
|
|
|
const getColor = (props) => {
|
|
|
|
if (props.isDragAccept) {
|
|
|
|
return '#00e676';
|
|
|
|
}
|
|
|
|
if (props.isDragReject) {
|
|
|
|
return '#ff1744';
|
|
|
|
}
|
|
|
|
if (props.isDragActive) {
|
|
|
|
return '#2196f3';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const enableBorder = (props) => (props.isDragActive ? 'dashed' : 'none');
|
|
|
|
|
|
|
|
const DropDiv = styled.div`
|
|
|
|
flex: 1;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
align-items: center;
|
|
|
|
border-width: 2px;
|
|
|
|
border-radius: 2px;
|
|
|
|
border-color: ${(props) => getColor(props)};
|
|
|
|
border-style: ${(props) => enableBorder(props)};
|
|
|
|
outline: none;
|
|
|
|
transition: border 0.24s ease-in-out;
|
|
|
|
`;
|
|
|
|
|
2021-01-05 05:25:58 +00:00
|
|
|
const FileUpload = ({
|
|
|
|
children,
|
|
|
|
noClick,
|
|
|
|
modalView,
|
|
|
|
closeModal,
|
|
|
|
showModal,
|
|
|
|
}) => {
|
2021-01-05 02:30:43 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Dropzone
|
|
|
|
onDrop={(acceptedFiles) => {
|
|
|
|
console.log(acceptedFiles);
|
|
|
|
}}
|
2021-01-05 02:43:38 +00:00
|
|
|
noClick={noClick}
|
2021-01-05 05:25:58 +00:00
|
|
|
onDragOver={showModal}
|
|
|
|
onDragLeave={closeModal}
|
2021-01-05 02:30:43 +00:00
|
|
|
>
|
|
|
|
{({
|
|
|
|
getRootProps,
|
|
|
|
getInputProps,
|
|
|
|
isDragActive,
|
|
|
|
isDragAccept,
|
|
|
|
isDragReject,
|
|
|
|
}) => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DropDiv
|
|
|
|
{...getRootProps({
|
|
|
|
isDragActive,
|
|
|
|
isDragAccept,
|
|
|
|
isDragReject,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<input {...getInputProps()} />
|
|
|
|
{children}
|
2021-01-05 05:25:58 +00:00
|
|
|
<CollectionSelector
|
|
|
|
modalView={modalView}
|
|
|
|
closeModal={closeModal}
|
|
|
|
showModal={showModal}
|
|
|
|
/>
|
2021-01-05 02:30:43 +00:00
|
|
|
</DropDiv>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Dropzone>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FileUpload;
|