-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Saifullah-dev/feature/upload-files
Feature/upload files
- Loading branch information
Showing
12 changed files
with
304 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { useState } from "react"; | ||
import Button from "../../components/Button/Button"; | ||
import { AiOutlineClose, AiOutlineCloudUpload } from "react-icons/ai"; | ||
import { getFileExtension } from "../../utils/getFileExtension"; | ||
import { useFileIcons } from "../../hooks/useFileIcons"; | ||
import { FaRegFile } from "react-icons/fa6"; | ||
import Progress from "../../components/Progress/Progress"; | ||
|
||
const UploadFileAction = ({ onFilesSelected }) => { | ||
const [files, setFiles] = useState([]); | ||
const [isDragging, setIsDragging] = useState(false); | ||
const fileIcons = useFileIcons(33); | ||
|
||
const handleDrop = (e) => { | ||
e.preventDefault(); | ||
setIsDragging(false); | ||
const droppedFiles = e.dataTransfer.files; | ||
if (droppedFiles.length > 0) { | ||
setFiles((prev) => [...prev, ...droppedFiles]); | ||
} | ||
}; | ||
|
||
const handleChooseFile = (e) => { | ||
const selectedFiles = e.target.files; | ||
if (selectedFiles.length > 0) { | ||
setFiles((prev) => [...prev, ...selectedFiles]); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className={`fm-upload-file ${files.length > 0 ? "file-selcted" : ""}`}> | ||
<div className="select-files"> | ||
<div | ||
className={`draggable-file-input ${isDragging ? "dragging" : ""}`} | ||
onDrop={handleDrop} | ||
onDragOver={(e) => e.preventDefault()} | ||
onDragEnter={() => setIsDragging(true)} | ||
onDragLeave={() => setIsDragging(false)} | ||
> | ||
<div className="input-text"> | ||
<AiOutlineCloudUpload size={30} /> | ||
<span>Drag files to upload</span> | ||
</div> | ||
</div> | ||
<div className="btn-choose-file"> | ||
<Button padding="0"> | ||
<label htmlFor="chooseFile">Choose File</label> | ||
<input | ||
type="file" | ||
id="chooseFile" | ||
className="choose-file-input" | ||
onChange={handleChooseFile} | ||
multiple | ||
/> | ||
</Button> | ||
</div> | ||
</div> | ||
{files.length > 0 && ( | ||
<div className="files-progress"> | ||
<h2>Uploading</h2> | ||
<ul> | ||
{files.map((file, index) => ( | ||
<li key={index}> | ||
<div className="file-icon"> | ||
{fileIcons[getFileExtension(file.name)] ?? <FaRegFile size={33} />} | ||
</div> | ||
<div className="file"> | ||
<div className="file-details"> | ||
<div className="file-info"> | ||
<span className="file-name text-truncate" title={file.name}> | ||
{file.name} | ||
</span> | ||
<span className="file-size"> {file.size / 1000} KB</span> | ||
</div> | ||
<div className="rm-file" title="remove"> | ||
<AiOutlineClose /> | ||
</div> | ||
</div> | ||
<Progress percent={20} /> | ||
</div> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default UploadFileAction; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
.fm-button { | ||
padding: 0.4rem 0.8rem; | ||
border-radius: 5px; | ||
font-weight: 600; | ||
border: none; | ||
|
This file contains 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
Oops, something went wrong.