|
1 | | -# react-file-upload |
| 1 | +# File Management with Preview - Fully Customized |
| 2 | + |
| 3 | +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. It allows customizing design by overriding the style classes. |
| 4 | + |
| 5 | +<img src="./gifs/full.gif"/> |
| 6 | + |
| 7 | +Checkout the live demo on, codesandbox <br /> |
| 8 | +[](https://codesandbox.io/p/sandbox/cranky-breeze-r4hht7?file=%2Fsrc%2Fmain.js) |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## Table of Contents |
| 13 | + |
| 14 | +- [Features](#features) |
| 15 | +- [Getting Started](#getting-started) |
| 16 | + - [Prerequisites](#prerequisites) |
| 17 | + - [Installation](#installation) |
| 18 | +- [Examples](#examples) |
| 19 | + - [Canvas View](#canvas-view) |
| 20 | + - [Square View](#square-view) |
| 21 | + - [Horizontal Long Square View](#horizontal-long-square-view) |
| 22 | + - [Circular View](#circular-view) |
| 23 | + - [Over-ride CSS](#over-ride-css) |
| 24 | +- [Properties and Events](#properties-and-events) |
| 25 | +- [Usage](#usage) |
| 26 | +- [Contributing](#contributing) |
| 27 | +- [License](#license) |
| 28 | +- [Contact Information](#contact-information) |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Features |
| 33 | + |
| 34 | +- **Single File Upload:** Users can upload or change a single file. |
| 35 | +- **Multiple File Management:** Easily manage multiple files. |
| 36 | +- **File Preview:** Provides a preview of uploaded files (e.g., images, videos, gifs). |
| 37 | +- **Responsive Design:** Ensures a seamless experience on various devices. |
| 38 | +- **Fully customized:** Customize file upload UI as per your requirements |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +## Getting Started |
| 43 | + |
| 44 | +Follow below instructions to configure this package into your project. |
| 45 | + |
| 46 | +### Prerequisites |
| 47 | + |
| 48 | +Before you begin, make sure you have the following software installed: |
| 49 | + |
| 50 | +- [Node.js](https://nodejs.org/) - v20.x |
| 51 | +- React with Next.js |
| 52 | +- sass |
| 53 | + |
| 54 | +### Installation |
| 55 | + |
| 56 | +Using npm: |
| 57 | + |
| 58 | +``` |
| 59 | +npm install @canopassoftware/vue-file-upload |
| 60 | +``` |
| 61 | + |
| 62 | +Using yarn: |
| 63 | + |
| 64 | +``` |
| 65 | +yarn add @canopassoftware/vue-file-upload |
| 66 | +``` |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Examples |
| 71 | + |
| 72 | +We are providing some examples with design. so, you can easily use it in your project. |
| 73 | + |
| 74 | +### Canvas View |
| 75 | + |
| 76 | +[view code](./examples/CanvasView.vue) |
| 77 | + |
| 78 | +<img src="./gifs/canvas-view.gif"/> |
| 79 | + |
| 80 | +### Square View |
| 81 | + |
| 82 | +[view code](./examples/SquareView.vue) |
| 83 | + |
| 84 | +<img src="./gifs/square-view.gif"/> |
| 85 | + |
| 86 | +### Horizontal Long Square View |
| 87 | + |
| 88 | +[view code](./examples/LongSquareView.vue) |
| 89 | + |
| 90 | +<img src="./gifs/long-square-view.gif"/> |
| 91 | + |
| 92 | +### Circular View |
| 93 | + |
| 94 | +[view code](./examples/RoundView.vue) |
| 95 | + |
| 96 | +<img src="./gifs/round-view.gif"/> |
| 97 | + |
| 98 | +### Over-ride CSS |
| 99 | + |
| 100 | +For over-riding the design of default buttons, you can over-ride it's CSS by class name. <br> |
| 101 | +For example., <br> |
| 102 | + |
| 103 | +- Over-ride CSS of remove file button you can add it like, |
| 104 | + |
| 105 | +```css |
| 106 | +.remove-btn { |
| 107 | + color: white; |
| 108 | + background-color: red; |
| 109 | + font-size: 25px; |
| 110 | + padding: 5px; |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +- Over-ride CSS of submit/upload file button you can add it like, |
| 115 | + |
| 116 | +```css |
| 117 | +.upload-btn { |
| 118 | + color: white; |
| 119 | + background-color: rgb(51, 65, 85); |
| 120 | + font-size: 25px; |
| 121 | + padding: 5px 10px; |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## Properties and Events |
| 128 | + |
| 129 | +### props |
| 130 | + |
| 131 | +- **callback="handleFileUploading"** |
| 132 | + |
| 133 | + - `required` |
| 134 | + - **Description:** Add your upload callback function while receive the selected file/files |
| 135 | + |
| 136 | +- **uploadedFile="setPreviewFileData"** - For single file component |
| 137 | + |
| 138 | + - `required` |
| 139 | + - Uploaded file object with below format, |
| 140 | + ``` |
| 141 | + { |
| 142 | + fileType: string, |
| 143 | + fileUrl: string, |
| 144 | + fileName: string |
| 145 | + } |
| 146 | + ``` |
| 147 | +
|
| 148 | +- **uploadedFiles="setPreviewFilesData"** - For multiple file component |
| 149 | +
|
| 150 | + - `required` |
| 151 | + - Uploaded files array with below format, |
| 152 | + ``` |
| 153 | + [ |
| 154 | + { |
| 155 | + fileType: string, |
| 156 | + fileUrl: string, |
| 157 | + fileName: string |
| 158 | + } |
| 159 | + ] |
| 160 | + ``` |
| 161 | +
|
| 162 | +- **uploadBtnText="'Upload'"** |
| 163 | +
|
| 164 | + - **default** : Upload |
| 165 | + - Text for save or upload file button |
| 166 | +
|
| 167 | +- **progressBtnText="'Uploading...'"** |
| 168 | +
|
| 169 | + - **default** : Uploading... |
| 170 | + - Text for the progress bar, showing file uploading under the process |
| 171 | +
|
| 172 | +- **removeBtnText="'Uploading...'"** |
| 173 | +
|
| 174 | + - **default** : x |
| 175 | + - Text for remove file button |
| 176 | +
|
| 177 | +- **accept="'image/jpg, image/jpeg, image/png, video/mp4, audio/mp3, application/zip'"** |
| 178 | +
|
| 179 | + - Validation for file type. By default it will select all the type of file. |
| 180 | +
|
| 181 | +- **(filetype)Preview="'(file location)'"** |
| 182 | + - **default** : Default file icons as per file types |
| 183 | + - Set path for your customized icon if needed |
| 184 | +
|
| 185 | +--- |
| 186 | +
|
| 187 | +## Usage |
| 188 | +
|
| 189 | +To manage and preview files with this library, follow these steps: |
| 190 | +
|
| 191 | +### Import the library into your file |
| 192 | +
|
| 193 | +```js |
| 194 | +// using CommonJS |
| 195 | +const { SingleFileUpload, MultipleFileUpload } = require("@canopassoftware/vue-file-upload"); |
| 196 | +
|
| 197 | +OR |
| 198 | +// using esModules |
| 199 | +import { SingleFileUpload, MultipleFileUpload } from "@canopassoftware/vue-file-upload"; |
| 200 | +``` |
| 201 | + |
| 202 | +### Creating custom UI with file preview |
| 203 | + |
| 204 | +- You can customize file uploading UI in inner part of component. |
| 205 | + |
| 206 | +### Single File Upload Management |
| 207 | + |
| 208 | +```js |
| 209 | +"use client"; |
| 210 | + |
| 211 | +import Image from "next/image"; |
| 212 | +import React, { useState } from "react"; |
| 213 | +import { SingleFileUpload } from '@canopassoftware/vue-file-upload'; |
| 214 | + |
| 215 | +export default function App() { |
| 216 | + const [previewFileData, setPreviewFileData] = useState( |
| 217 | + {} as { |
| 218 | + previewType: string; |
| 219 | + previewUrl: string | ArrayBuffer | null; |
| 220 | + previewName: string; |
| 221 | + isDragging: boolean; |
| 222 | + } |
| 223 | + ); |
| 224 | + |
| 225 | + const handleFileUploading = async (file: any) => { |
| 226 | + await new Promise((resolve) => setTimeout(resolve, 2000)); |
| 227 | + setPreviewFileData({ |
| 228 | + previewType: "image", |
| 229 | + previewUrl: "https://picsum.photos/300/224", |
| 230 | + previewName: file.name, |
| 231 | + isDragging: false, |
| 232 | + }); |
| 233 | + }; |
| 234 | +``` |
| 235 | +
|
| 236 | +```html |
| 237 | + return ( |
| 238 | + <main className="min-h-screen flex flex-col justify-between p-5"> |
| 239 | + <SingleFileUpload |
| 240 | + uploadedFile={setPreviewFileData} |
| 241 | + callback={handleFileUploading} |
| 242 | + uploadBtn={"Save"} |
| 243 | + progressBtn={"Saving..."} |
| 244 | + > |
| 245 | + </SingleFileUpload> |
| 246 | + </main> |
| 247 | + ); |
| 248 | +} |
| 249 | +``` |
| 250 | + |
| 251 | +## Contributing |
| 252 | + |
| 253 | +We welcome contributions from the community. To contribute to this project, please follow these guidelines: |
| 254 | + |
| 255 | +- Fork the repository. |
| 256 | +- Create a new branch for your feature or bug fix. |
| 257 | +- Make your changes and commit them. |
| 258 | +- Push your changes to your fork. |
| 259 | +- Submit a pull request with a clear description of your changes. |
| 260 | +- Please ensure your code follows the project's coding standards and includes appropriate documentation. |
| 261 | + |
| 262 | +## License |
| 263 | + |
| 264 | +This project is licensed under the [MIT](https://github.com/canopas/vue-file-upload/blob/main/LICENSE). |
| 265 | + |
| 266 | +## Contact Information |
| 267 | + |
| 268 | +Vue file upload is owned and maintained by the [Canopas team](https://canopas.com/). You can reach out them on Github at [canopas](https://github.com/canopas) for questions or need support. |
0 commit comments