Last active
July 8, 2021 22:54
-
-
Save DZuz14/ef77baaee7b4e71191395339e21ca1fa to your computer and use it in GitHub Desktop.
Upload 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Upload = () => { | |
const [files, setFiles] = useState(null) | |
const inputRef = useRef() | |
const handleClick = () => { | |
inputRef.current.click() | |
} | |
const preventBubbling = (e) => { | |
e.stopPropagation() | |
e.preventDefault() | |
} | |
return ( | |
<div className="Upload" css={CSS}> | |
<div className="inner"> | |
<div className="list"> | |
<h5>Your Files:</h5> | |
<ul className="files">{/* file names here. */}</ul> | |
</div> | |
<div | |
className="form" | |
onDragEnter={preventBubbling} | |
onDragOver={preventBubbling} | |
onDrop={(e) => { | |
preventBubbling(e) | |
setFiles(e.dataTransfer.files) | |
}} | |
> | |
<i className="fa fa-cloud-upload fa-4x"></i> | |
<p>Drag and drop files or select files below.</p> | |
<input | |
ref={inputRef} | |
type="file" | |
multiple | |
style={{ display: 'none' }} | |
onChange={(e) => setFiles(e.target.files)} | |
/> | |
<button onClick={handleClick}>Choose Files</button> | |
</div> | |
</div> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment