Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit 29a8b79

Browse files
committed
Add drag and drop feature
1 parent 4d2ac57 commit 29a8b79

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,13 @@
22

33
A versatile and user-friendly file management system built with React, Next.js and TypeScript that allows for single and multiple file uploading with a preview feature. It allows you to select files and preview them, returning an array of selected files. You can provide custom design and override classes for your file component.
44

5-
Checkout the live demo on, <br />
6-
[![codesandbox.io](https://codesandbox.io/favicon.ico)](https://codesandbox.io/p/sandbox/cranky-breeze-r4hht7?file=%2Fsrc%2Fmain.js)
7-
85
## Table of Contents
96

107
- [Features](#features)
118
- [Getting Started](#getting-started)
129
- [Prerequisites](#prerequisites)
1310
- [Installation](#installation)
1411
- [Usage](#usage)
15-
- [Examples](#examples)
16-
- [Square View](#square-view)
17-
- [Horizontal Long Square View](#horizontal-long-square-view)
18-
- [Circular View](#circular-view)
19-
- [Over-ride CSS](#over-ride-css)
2012
- [Contributing](#contributing)
2113
- [License](#license)
2214
- [Contact Information](#contact-information)
@@ -211,10 +203,6 @@ return (
211203

212204
- Also, you can over-ride all the classes for changing the UI as per your requirement.
213205

214-
## Examples
215-
216-
We are providing some examples with design. so, you can easily take it and use it in your project.
217-
218206
### Over-ride CSS
219207

220208
For over-riding the design of default buttons, you can over-ride it's CSS by class name. <br>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
10-
"build-css": "tailwindcss -i ./src/app/globals.css -o ./dist/css/output.css --minify && cp -i ./src/app/style.scss -o ./dist/css/style.scss --minify"
10+
"build-css": "tailwindcss -i ./src/app/globals.css -o ./dist/css/output.css --minify && cp ./src/app/style.scss ./dist/css/style.scss"
1111
},
1212
"dependencies": {
1313
"next": "14.0.0",

src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import Image from "next/image";
44
import React, { useState } from "react";
5-
import SingleFileUpload from "./singleFile";
5+
import SingleFileUpload from "../components/singleFile";
66

77
export default function App() {
88
const [fileData, setPreviewFileData] = useState(

src/app/singleFile.tsx renamed to src/components/singleFile.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export default function SingleFileUpload({
3939
};
4040

4141
const selectFile = () => {
42+
if (uploadingStatus) {
43+
return;
44+
}
4245
if (inputRef.current) {
4346
(inputRef.current as HTMLInputElement).click();
4447
}
@@ -100,9 +103,41 @@ export default function SingleFileUpload({
100103
}
101104
}
102105

106+
const handleDragOver = (event: any) => {
107+
if (uploadingStatus) {
108+
return;
109+
}
110+
event.preventDefault();
111+
fileData.isDragging = true;
112+
};
113+
114+
const handleDragLeave = (event: any) => {
115+
event.preventDefault();
116+
fileData.isDragging = false;
117+
};
118+
119+
const handleDrop = (event: any) => {
120+
if (uploadingStatus) {
121+
return;
122+
}
123+
event.preventDefault();
124+
fileData.isDragging = false;
125+
126+
const file = event.dataTransfer.files[0];
127+
if (file) {
128+
previewFile(file);
129+
}
130+
};
131+
103132
return (
104133
<div className="flex">
105-
<div className="cursor-pointer" onClick={selectFile}>
134+
<div
135+
className="cursor-pointer"
136+
onClick={selectFile}
137+
onDragOver={handleDragOver}
138+
onDragLeave={handleDragLeave}
139+
onDrop={handleDrop}
140+
>
106141
{children}
107142
<input
108143
type="file"

0 commit comments

Comments
 (0)