├── .github
└── workflows
│ ├── lint.yml
│ └── publish.yml
├── LICENSE.md
├── README.md
├── assets
└── images
│ ├── apk-icon.png
│ ├── banner.png
│ ├── canvas.svg
│ ├── cta.png
│ ├── example-img.jpg
│ ├── file-icon.png
│ ├── loader.png
│ ├── music-icon.png
│ ├── pdf-icon.png
│ ├── placeholder.png
│ ├── sql-icon.png
│ ├── text-icon.png
│ └── zip-icon.png
├── gifs
├── canvas-view.gif
├── full.gif
├── long-square-view.gif
├── multiple-file-uploading.gif
├── round-view.gif
├── single-file-uploading.gif
└── square-view.gif
├── react
├── .eslintrc.json
├── .gitignore
├── .npmignore
├── README.md
├── examples
│ ├── CanvasView.tsx
│ ├── LongSquareView.tsx
│ ├── RoundView.tsx
│ ├── SquareView.tsx
│ └── demo
│ │ ├── .eslintrc.json
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── next.config.js
│ │ ├── package.json
│ │ ├── postcss.config.js
│ │ ├── public
│ │ ├── next.svg
│ │ └── vercel.svg
│ │ ├── src
│ │ ├── app
│ │ │ ├── favicon.ico
│ │ │ ├── globals.css
│ │ │ ├── layout.tsx
│ │ │ └── page.tsx
│ │ └── assets
│ │ │ └── images
│ │ │ ├── example-img.jpg
│ │ │ ├── loader.png
│ │ │ └── placeholder.png
│ │ ├── tailwind.config.ts
│ │ └── tsconfig.json
├── next.config.js
├── package-lock.json
├── package.json
├── postcss.config.js
├── public
│ ├── next.svg
│ └── vercel.svg
├── src
│ └── app
│ │ ├── components
│ │ ├── multipleFileUpload.tsx
│ │ └── singleFileUpload.tsx
│ │ ├── favicon.ico
│ │ ├── globals.css
│ │ ├── index.ts
│ │ ├── layout.tsx
│ │ ├── page.tsx
│ │ └── style.scss
├── tailwind.config.ts
├── tsconfig.json
└── vite.config.js
└── vue
├── .babelrc
├── .eslintrc.cjs
├── .gitignore
├── .npmignore
├── .prettierrc.json
├── README.md
├── env.d.ts
├── examples
├── CanvasView.vue
├── LongSquareView.vue
├── RoundView.vue
├── SquareView.vue
└── demo
│ ├── README.md
│ ├── env.d.ts
│ ├── index.html
│ ├── package.json
│ ├── public
│ └── favicon.ico
│ ├── src
│ ├── App.vue
│ ├── assets
│ │ ├── logo.svg
│ │ └── main.css
│ ├── main.ts
│ ├── router
│ │ └── index.ts
│ └── views
│ │ └── IndexView.vue
│ ├── tsconfig.app.json
│ ├── tsconfig.json
│ ├── tsconfig.node.json
│ └── vite.config.ts
├── index.html
├── package-lock.json
├── package.json
├── public
└── favicon.ico
├── src
├── App.vue
├── assets
│ └── logo.svg
├── components
│ ├── MultipleFile.vue
│ └── SingleFile.vue
├── index.ts
├── input.css
├── router
│ └── index.ts
├── style.scss
└── views
│ └── IndexView.vue
├── tailwind.config.ts
├── tsconfig.app.json
├── tsconfig.json
├── tsconfig.node.json
└── vite.config.ts
/.github/workflows/lint.yml:
--------------------------------------------------------------------------------
1 | name: Run lint in vue and react
2 |
3 | on:
4 | push:
5 |
6 | jobs:
7 | vue-lint:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v4
11 | - uses: actions/setup-node@v3
12 | with:
13 | node-version: "20.x"
14 | - run: |
15 | cd vue
16 | npm ci
17 | npm run lint
18 |
19 | react-lint:
20 | runs-on: ubuntu-latest
21 | steps:
22 | - uses: actions/checkout@v4
23 | - uses: actions/setup-node@v3
24 | with:
25 | node-version: "20.x"
26 | - run: |
27 | cd react
28 | npm ci
29 | npm run lint
30 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish Package to npmjs
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 |
8 | jobs:
9 | vue-publish:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v4
13 | - uses: actions/setup-node@v3
14 | with:
15 | node-version: "20.x"
16 | registry-url: "https://registry.npmjs.org"
17 | - run: |
18 | cd vue
19 | npm ci
20 | npm run build
21 |
22 | # Check if the vue-file-upload version already exists on npm
23 | - name: Check Version Existence
24 | id: check_vue_version
25 | run: |
26 | if npm show @canopassoftware/vue-file-upload@1.0.8; then
27 | echo "Version already published. Skipping npm publish."
28 | echo "::set-output name=skip_vue_publish::true"
29 | else
30 | echo "::set-output name=skip_vue_publish::false"
31 | fi
32 |
33 | # Publish only if the vue-file-upload version check passed
34 | - name: Publish to npm
35 | if: steps.check_vue_version.outputs.skip_vue_publish != 'true'
36 | run: |
37 | cd vue
38 | npm publish --access public
39 | env:
40 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
41 |
42 | react-publish:
43 | runs-on: ubuntu-latest
44 | steps:
45 | - uses: actions/checkout@v4
46 | - uses: actions/setup-node@v3
47 | with:
48 | node-version: "20.x"
49 | registry-url: "https://registry.npmjs.org"
50 | - run: |
51 | cd react
52 | npm ci
53 | npm run build
54 |
55 | # Check if the react-file-upload version already exists on npm
56 | - name: Check Version Existence
57 | id: check_react_version
58 | run: |
59 | if npm show @canopassoftware/react-file-upload@1.2.0; then
60 | echo "Version already published. Skipping npm publish."
61 | echo "::set-output name=skip_react_publish::true"
62 | else
63 | echo "::set-output name=skip_react_publish::false"
64 | fi
65 |
66 | # Publish only if the react-file-upload version check passed
67 | - name: Publish to npm
68 | if: steps.check_react_version.outputs.skip_react_publish != 'true'
69 | run: |
70 | cd react
71 | npm publish --access public
72 | env:
73 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
74 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Canopas
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Web File Management with Preview - Fully Customized
4 |
5 | A versatile and user-friendly file management system built for Vue and React that allows single and multiple file uploading with a preview feature, returning an array of selected files. It supports custom designs by overriding the style classes.
6 |
7 |
8 |
9 | ---
10 |
11 | ### The library provides support for Vue and React. Each has its own set of features and information. Explore the individual folders for more details.
12 |
13 | ## Vue File Upload
14 |
15 | This folder includes files and resources related to the Vue file upload library. and also, it has [demo](./vue/examples/demo/) project. so, it's easy to understand and you can use it directly.
16 |
17 | Checkout the live demo on, codesandbox
18 | [](https://codesandbox.io/p/sandbox/cranky-breeze-r4hht7?file=%2Fsrc%2Fmain.js)
19 |
20 | For more details, check out the [Vue README](./vue/README.md).
21 |
22 | ## React File Upload
23 |
24 | This folder includes files and resources related to the React file upload library. and also, it has [demo](./react/examples/demo/) project. so, it's easy to understand and you can use it directly.
25 |
26 | Checkout the live demo on, codesandbox
27 | [](https://codesandbox.io/p/devbox/eager-mountain-n4zgs6?file=%2Fsrc%2FApp.tsx)
28 |
29 | For more details, check out the [React README](./react/README.md).
30 |
31 | Feel free to explore each folder for specific information about Vue and React!
32 |
33 | ---
34 |
35 | ## Table of Contents
36 |
37 | - [Features](#features)
38 | - [Installation](#installation)
39 | - [Vue](#vue)
40 | - [React](#react)
41 | - [Examples](#examples)
42 | - [Canvas View](#canvas-view)
43 | - [Square View](#square-view)
44 | - [Horizontal Long Square View](#horizontal-long-square-view)
45 | - [Circular View](#circular-view)
46 | - [Over-ride CSS](#over-ride-css)
47 | - [Contributing](#contributing)
48 | - [Credits](#credits)
49 | - [License](#license)
50 |
51 | ---
52 |
53 | ## Features
54 |
55 | - **Single File Upload:** Users can upload or change a single file.
56 | - **Multiple File Management:** Easily manage multiple files.
57 | - **File Preview:** Provides a preview of uploaded files (e.g., images, videos, gifs).
58 | - **Responsive Design:** Ensures a seamless experience on various devices.
59 | - **Fully customized:** Customize file upload UI as per your requirements
60 |
61 | ---
62 |
63 | ## Installation
64 |
65 | ### Vue
66 |
67 | Using npm:
68 |
69 | ```
70 | npm install @canopassoftware/vue-file-upload
71 | ```
72 |
73 | Using yarn:
74 |
75 | ```
76 | yarn add @canopassoftware/vue-file-upload
77 | ```
78 |
79 | ---
80 |
81 | ### React
82 |
83 | Using npm:
84 |
85 | ```
86 | npm install @canopassoftware/react-file-upload
87 | ```
88 |
89 | Using yarn:
90 |
91 | ```
92 | yarn add @canopassoftware/react-file-upload
93 | ```
94 |
95 | ---
96 |
97 | ## Examples
98 |
99 | We are providing some examples with design. so, you can easily take it and use into your project.
100 |
101 | ### Canvas View
102 |
103 | vue - [view code](./vue/examples/CanvasView.vue)
104 | react - [view code](./react/examples/CanvasView.tsx)
105 |
106 |
107 |
108 | ### Square View
109 |
110 | vue- [view code](./vue/examples/SquareView.vue)
111 | react - [view code](./react/examples/SquareView.tsx)
112 |
113 |
114 |
115 | ### Horizontal Long Square View
116 |
117 | vue - [view code](./vue/examples/LongSquareView.vue)
118 | react - [view code](./react/examples/LongSquareView.tsx)
119 |
120 |
121 |
122 | ### Circular View
123 |
124 | vue - [view code](./vue/examples/RoundView.vue)
125 | react - [view code](./react/examples/RoundView.tsx)
126 |
127 |
128 |
129 | ### Over-ride CSS
130 |
131 | For over-riding the design of default buttons, you can over-ride it's CSS by class name.
132 | For example.,
133 |
134 | - Over-ride CSS of remove file button you can add it like,
135 |
136 | ```css
137 | .remove-btn {
138 | color: white;
139 | background-color: red;
140 | font-size: 25px;
141 | padding: 5px;
142 | }
143 | ```
144 |
145 | - Over-ride CSS of submit/upload file button you can add it like,
146 |
147 | ```css
148 | .upload-btn {
149 | color: white;
150 | background-color: rgb(51, 65, 85);
151 | font-size: 25px;
152 | padding: 5px 10px;
153 | }
154 | ```
155 |
156 | ---
157 |
158 | ## Contributing
159 |
160 | We welcome contributions from the community. To contribute to this project, please follow these guidelines:
161 |
162 | - Fork the repository.
163 | - Create a new branch for your feature or bug fix.
164 | - Make your changes and commit them.
165 | - Push your changes to your fork.
166 | - Submit a pull request with a clear description of your changes.
167 | - Please ensure your code follows the project's coding standards and includes appropriate documentation.
168 |
169 | ---
170 |
171 | ## Credits
172 |
173 | This repository is owned and maintained by the [Canopas team](https://canopas.com/). If you are interested in building web apps or designing products, please let us know. We'd love to hear from you!
174 |
175 |
176 |
177 | ---
178 |
179 | ## License
180 |
181 | This project is licensed under the [MIT](https://github.com/canopas/web-file-upload/blob/main/LICENSE).
182 |
--------------------------------------------------------------------------------
/assets/images/apk-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/apk-icon.png
--------------------------------------------------------------------------------
/assets/images/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/banner.png
--------------------------------------------------------------------------------
/assets/images/canvas.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/assets/images/cta.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/cta.png
--------------------------------------------------------------------------------
/assets/images/example-img.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/example-img.jpg
--------------------------------------------------------------------------------
/assets/images/file-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/file-icon.png
--------------------------------------------------------------------------------
/assets/images/loader.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/loader.png
--------------------------------------------------------------------------------
/assets/images/music-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/music-icon.png
--------------------------------------------------------------------------------
/assets/images/pdf-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/pdf-icon.png
--------------------------------------------------------------------------------
/assets/images/placeholder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/placeholder.png
--------------------------------------------------------------------------------
/assets/images/sql-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/sql-icon.png
--------------------------------------------------------------------------------
/assets/images/text-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/text-icon.png
--------------------------------------------------------------------------------
/assets/images/zip-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/assets/images/zip-icon.png
--------------------------------------------------------------------------------
/gifs/canvas-view.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/gifs/canvas-view.gif
--------------------------------------------------------------------------------
/gifs/full.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/gifs/full.gif
--------------------------------------------------------------------------------
/gifs/long-square-view.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/gifs/long-square-view.gif
--------------------------------------------------------------------------------
/gifs/multiple-file-uploading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/gifs/multiple-file-uploading.gif
--------------------------------------------------------------------------------
/gifs/round-view.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/gifs/round-view.gif
--------------------------------------------------------------------------------
/gifs/single-file-uploading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/gifs/single-file-uploading.gif
--------------------------------------------------------------------------------
/gifs/square-view.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/canopas/web-file-upload/ebdf242a69b84ba03d6778db87e3b2e064d3c933/gifs/square-view.gif
--------------------------------------------------------------------------------
/react/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "next/core-web-vitals"
3 | }
4 |
--------------------------------------------------------------------------------
/react/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 | .yarn/install-state.gz
8 |
9 | # testing
10 | /coverage
11 |
12 | # next.js
13 | /.next/
14 | /out/
15 | /dist
16 |
17 | # production
18 | /build
19 |
20 | # misc
21 | .DS_Store
22 | *.pem
23 |
24 | # debug
25 | npm-debug.log*
26 | yarn-debug.log*
27 | yarn-error.log*
28 |
29 | # local env files
30 | .env*.local
31 |
32 | .vscode/*
33 |
34 | # vercel
35 | .vercel
36 |
37 | # typescript
38 | *.tsbuildinfo
39 | next-env.d.ts
40 |
41 | # src/app/style.scss
42 |
43 | index.mjs
44 | index.umd.js
45 | next.svg
46 | vercel.svg
47 | style.css
--------------------------------------------------------------------------------
/react/.npmignore:
--------------------------------------------------------------------------------
1 | /*
--------------------------------------------------------------------------------
/react/README.md:
--------------------------------------------------------------------------------
1 | # React File Management with Preview - Fully Customized
2 |
3 | React 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 | ---
6 |
7 | ## Table of Contents
8 |
9 | - [Getting Started](#getting-started)
10 | - [Prerequisites](#prerequisites)
11 | - [Installation](#installation)
12 | - [Properties and Events](#properties-and-events)
13 | - [Usage](#usage)
14 |
15 | ---
16 |
17 | ## Getting Started
18 |
19 | Follow below instructions to configure this package into your project.
20 |
21 | ### Prerequisites
22 |
23 | Before you begin, make sure you have the following software installed:
24 |
25 | - [Node.js](https://nodejs.org/) - v20.x
26 | - React
27 |
28 | ### Installation
29 |
30 | Using npm:
31 |
32 | ```
33 | npm install @canopassoftware/react-file-upload
34 | ```
35 |
36 | Using yarn:
37 |
38 | ```
39 | yarn add @canopassoftware/react-file-upload
40 | ```
41 |
42 | Note: we have already configure this in demo project. so, refer it for more information.
43 |
44 | ---
45 |
46 | ## Properties and Events
47 |
48 | ### props
49 |
50 | - **callback="handleFileUploading"**
51 |
52 | - `required`
53 | - **Description:** Add your upload callback function while receive the selected file/files
54 |
55 | - **uploadedFile="setPreviewFileData"** - For single file component
56 |
57 | - `required`
58 | - Uploaded file object with below format,
59 | ```
60 | {
61 | fileType: string,
62 | fileUrl: string,
63 | fileName: string
64 | }
65 | ```
66 |
67 | - **uploadedFiles="setPreviewFilesData"** - For multiple file component
68 |
69 | - `required`
70 | - Uploaded files array with below format,
71 | ```
72 | [
73 | {
74 | fileType: string,
75 | fileUrl: string,
76 | fileName: string
77 | }
78 | ]
79 | ```
80 |
81 | - **uploadBtnText="'Upload'"**
82 |
83 | - **default** : Upload
84 | - Text for save or upload file button
85 |
86 | - **progressBtnText="'Uploading...'"**
87 |
88 | - **default** : Uploading...
89 | - Text for the progress bar, showing file uploading under the process
90 |
91 | - **removeBtnText="'Uploading...'"**
92 |
93 | - **default** : x
94 | - Text for remove file button
95 |
96 | - **accept="'image/jpg, image/jpeg, image/png, video/mp4, audio/mp3, application/zip'"**
97 |
98 | - Validation for file type. By default it will select all the type of file.
99 |
100 | - **(filetype)Preview="'(file location)'"**
101 | - **default** : Default file icons as per file types
102 | - Set path for your customized icon if needed
103 |
104 | ---
105 |
106 | ## Usage
107 |
108 | To manage and preview files with this library, follow these steps:
109 |
110 | ### Import the library into your file
111 |
112 | ```js
113 | // using CommonJS
114 | const {
115 | SingleFileUpload,
116 | MultipleFileUpload,
117 | } = require("@canopassoftware/react-file-upload");
118 |
119 | OR;
120 |
121 | // using esModules
122 | import {
123 | SingleFileUpload,
124 | MultipleFileUpload,
125 | } from "@canopassoftware/react-file-upload";
126 | ```
127 |
128 | ### Use default CSS
129 |
130 | - Use `style.css` for UI by importing like,
131 |
132 | ```js
133 | import "@canopassoftware/react-file-upload/style.css";
134 | ```
135 |
136 | ### Creating custom UI with file preview
137 |
138 | - You can customize file uploading UI in inner part of component.
139 | - The `file` containing `file` object with following keys, we will use this object to show preview.
140 |
141 | ```js
142 | file = file: {
143 | previewType: 'video', // type of the preview. like, file is image or video
144 | previewUrl: 'data:image/jpeg;base64,/9j/D1AAAACRsdW1pAAAD...', // URL of the file preview
145 | previewName: 'a152148640581.62d918f12a0b4.mp4', // preview file name
146 | isDragging: false // you will get it `true` when you dragging the file on design
147 | }
148 | ```
149 |
150 | ### Single File Upload Management
151 |
152 | ```js
153 | "use client";
154 |
155 | import Image from "next/image";
156 | import React, { useState } from "react";
157 | import { SingleFileUpload } from '@canopassoftware/react-file-upload';
158 |
159 | export default function App() {
160 | const [previewFileData, setPreviewFileData] = useState(
161 | {} as {
162 | previewType: string;
163 | previewUrl: string | ArrayBuffer | null;
164 | previewName: string;
165 | isDragging: boolean;
166 | }
167 | );
168 |
169 | // callback function
170 | const handleFileUploading = async (file: any) => {
171 | await new Promise((resolve) => setTimeout(resolve, 2000));
172 | setPreviewFileData({
173 | previewType: "image",
174 | previewUrl: "https://picsum.photos/300/224",
175 | previewName: file.name,
176 | isDragging: false,
177 | });
178 | };
179 | ```
180 |
181 | ```html
182 | return (
183 |
184 |
190 |
191 |
192 |
193 | );
194 | }
195 | ```
196 |
197 | ### Multiple File Upload Management
198 |
199 | ```js
200 | "use client";
201 |
202 | import Image, { StaticImageData } from "next/image";
203 | import React from "react";
204 | import MultipleFileUpload from "@canopassoftware/react-file-upload";
205 |
206 | export default function App() {
207 | const uploadedFiles = [] as Array<{
208 | fileType: string;
209 | fileUrl: string | StaticImageData;
210 | fileName: string;
211 | }>;
212 |
213 | // callback function
214 | const handleFilesUploading = async (files: any) => {
215 | const uploadedFiles = [];
216 |
217 | for (var i = 0; i < files.length; i++) {
218 | uploadedFiles.push({
219 | fileType: "image",
220 | fileUrl: images[i],
221 | fileName: files[i].name,
222 | });
223 | }
224 |
225 | await new Promise((resolve) => setTimeout(resolve, 5000));
226 | return uploadedFiles;
227 | };
228 | ```
229 |
230 | ```html
231 | return (
232 |
233 |
241 | {(file: any) => (
242 |
243 | )}
244 |
245 |
246 | );
247 | }
248 | ```
249 |
--------------------------------------------------------------------------------
/react/examples/CanvasView.tsx:
--------------------------------------------------------------------------------
1 | "use client";
2 |
3 | import Image, { StaticImageData } from "next/image";
4 | import React, { useState } from "react";
5 | import "@canopassoftware/react-file-upload/style.css";
6 | import {
7 | SingleFileUpload,
8 | MultipleFileUpload,
9 | } from "@canopassoftware/react-file-upload";
10 |
11 | export default function App() {
12 | // for single file upload component
13 | const [previewFileData, setPreviewFileData] = useState(
14 | {} as {
15 | previewType: string;
16 | previewUrl: string | StaticImageData | ArrayBuffer | null;
17 | previewName: string;
18 | isDragging: boolean;
19 | }
20 | );
21 |
22 | const handleFileUploading = async (file: any) => {
23 | await new Promise((resolve) => setTimeout(resolve, 2000));
24 | setPreviewFileData({
25 | previewType: "image",
26 | previewUrl: "https://picsum.photos/300/224",
27 | previewName: file.name,
28 | isDragging: false,
29 | });
30 | };
31 |
32 | // for multiple file upload component
33 | const uploadedFiles = [] as Array<{
34 | fileType: string;
35 | fileUrl: string | StaticImageData;
36 | fileName: string;
37 | }>;
38 |
39 | const handleFilesUploading = async (files: any) => {
40 | const uploadedFiles = [];
41 |
42 | for (var i = 0; i < files.length; i++) {
43 | uploadedFiles.push({
44 | fileType: "image",
45 | fileUrl: "https://picsum.photos/300/224",
46 | fileName: files[i].name,
47 | });
48 | }
49 |
50 | await new Promise((resolve) => setTimeout(resolve, 5000));
51 | return uploadedFiles;
52 | };
53 |
54 | return (
55 |
56 |