@cubone/react-file-manager 1.6.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,14 @@
1
- ![React File Manager](https://github.com/user-attachments/assets/53b09633-220e-460d-a5a5-48f553640dd0)
1
+ ![React File Manager](https://github.com/user-attachments/assets/cad4d71d-a2fd-4064-9fce-c0c3a7cb4613)
2
2
 
3
+ <div align="center">
4
+
5
+ ![NPM Downloads](https://img.shields.io/npm/d18m/%40cubone%2Freact-file-manager?style=for-the-badge) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/%40cubone%2Freact-file-manager?style=for-the-badge) ![NPM Version](https://img.shields.io/npm/v/%40cubone%2Freact-file-manager?style=for-the-badge&color=%23c87d32)
6
+
7
+ </div>
8
+
9
+ <p>
3
10
  An open-source React.js package for easy integration of a file manager into applications. It provides a user-friendly interface for managing files and folders, including viewing, uploading, and deleting, with full UI and backend integration.
11
+ </p>
4
12
 
5
13
  ## ✨ Features
6
14
 
@@ -21,7 +29,7 @@ npm i @cubone/react-file-manager
21
29
 
22
30
  Here’s a basic example of how to use the File Manager Component in your React application:
23
31
 
24
- ```javascript
32
+ ```jsx
25
33
  import { useState } from "react";
26
34
  import { FileManager } from "@cubone/react-file-manager";
27
35
  import "@cubone/react-file-manager/dist/style.css";
@@ -32,19 +40,19 @@ function App() {
32
40
  name: "Documents",
33
41
  isDirectory: true, // Folder
34
42
  path: "/Documents", // Located in Root directory
35
- updatedAt: "2024-09-09T10:30:00Z", // Last updated time (ISO 8601 format)
43
+ updatedAt: "2024-09-09T10:30:00Z", // Last updated time
36
44
  },
37
45
  {
38
46
  name: "Pictures",
39
- isDirectory: true, // Folder
40
- path: "/Pictures", // Located in Root directory
41
- updatedAt: "2024-09-09T11:00:00Z", // Last updated time (ISO 8601 format)
47
+ isDirectory: true,
48
+ path: "/Pictures", // Located in Root directory as well
49
+ updatedAt: "2024-09-09T11:00:00Z",
42
50
  },
43
51
  {
44
52
  name: "Pic.png",
45
53
  isDirectory: false, // File
46
54
  path: "/Pictures/Pic.png", // Located inside the "Pictures" folder
47
- updatedAt: "2024-09-08T16:45:00Z", // Last updated time (ISO 8601 format)
55
+ updatedAt: "2024-09-08T16:45:00Z",
48
56
  size: 2048, // File size in bytes (example: 2 KB)
49
57
  },
50
58
  ]);
@@ -55,6 +63,8 @@ function App() {
55
63
  </>
56
64
  );
57
65
  }
66
+
67
+ export default App;
58
68
  ```
59
69
 
60
70
  ## 📂 File Structure
@@ -63,30 +73,39 @@ The `files` prop accepts an array of objects, where each object represents a fil
63
73
 
64
74
  ```typescript
65
75
  type File = {
66
- name: string;
67
- isDirectory: boolean;
68
- path: string;
69
- updatedAt?: string;
70
- size?: number;
76
+ name: string; // The name of the file or folder
77
+ isDirectory: boolean; // `true` if it's a folder, `false` if it's a file
78
+ path: string; // Full path of the file or folder
79
+ updatedAt?: string; // Optional: Last update timestamp in ISO 8601 format
80
+ size?: number; // Optional: File size in bytes (only applicable for files)
71
81
  };
72
82
  ```
73
83
 
74
84
  ## ⚙️ Props
75
85
 
76
- | Name | Type | Description |
77
- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
78
- | `files` | Array<[File](#-file-structure)> | An array of file and folder objects representing the current directory structure. Each object includes `name`, `isDirectory`, and `path` properties. |
79
- | `isLoading` | boolean | A boolean state indicating whether the application is currently performing an operation, such as creating, renaming, or deleting a file/folder. Displays a loading state if set `true`. |
80
- | `fileUploadConfig` | { url: string; headers?: { [key: string]: string } } | Configuration object for file uploads. It includes the upload URL (`url`) and an optional `headers` object for setting custom HTTP headers in the upload request. The `headers` object can accept any standard or custom headers required by the server. Example: `{ url: "https://example.com/fileupload", headers: { Authorization: "Bearer" + TOKEN, "X-Custom-Header": "value" } }` |
81
- | `filePreviewPath` | String | The base URL for file previews e.g. `https://example.com`, file path will be appended automatically to it i.e. `https://example.com/yourFilePath`. |
82
- | `allowedFileExtensions` | String | A comma-separated list of allowed file extensions for uploading files. (e.g., `.txt, .png, .pdf`). |
83
- | `onCreateFolder` | (name: string, parentFolder: [File](#-file-structure)) => void | A callback function triggered when a new folder is created. Use this function to update the files state to include the new folder under the specified parent folder using create folder API call to your server. |
84
- | `onFileUploading` | (file: [File](#-file-structure), parentFolder: [File](#-file-structure)) => { [key: string]: any } | A callback function triggered during the file upload process. You can also return an object with key-value pairs that will be appended to the `FormData` along with the file being uploaded. The object can contain any number of valid properties. |
85
- | `onFileUploaded` | (response: { [key: string]: any }) => void | A callback function triggered after a file is successfully uploaded. Provides JSON `response` holding uploaded file details, use it to extract the uploaded file details and add it to the `files` state e.g. `setFiles((prev) => [...prev, JSON.parse(response)]);` |
86
- | `onRename` | (file: [File](#-file-structure), newName: string) => void | A callback function triggered when a file or folder is renamed. |
87
- | `onDelete` | (file: [File](#-file-structure)) => void | A callback function triggered when a file or folder is deleted. |
88
- | `onPaste` | (file: [File](#-file-structure), destinationFolder: [File](#-file-structure), operationType: "copy" \| "move") => void | A callback function triggered when a file or folder is pasted into a new location. Depending on `operationType`, use this to either copy or move the `sourceItem` to the `destinationFolder`, updating the files state accordingly. |
89
- | `onRefresh` | () => void | A callback function triggered when the file manager is refreshed. Use this to refresh the `files` state to reflect any changes or updates. |
86
+ | Name | Type | Description |
87
+ | ------------------- | ---------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
88
+ | `acceptedFileTypes` | string | A comma-separated list of allowed file extensions for uploading files. (e.g.,`.txt, .png, .pdf`). |
89
+ | `enableFilePreview` | boolean | A boolean flag indicating whether to use the default file previewer in the file manager. |
90
+ | `filePreviewPath` | string | The base URL for file previews e.g.`https://example.com`, file path will be appended automatically to it i.e. `https://example.com/yourFilePath`. |
91
+ | `fileUploadConfig` | { url: string; headers?: { [key: string]: string } } | Configuration object for file uploads. It includes the upload URL (`url`) and an optional `headers` object for setting custom HTTP headers in the upload request. The `headers` object can accept any standard or custom headers required by the server. Example: `{ url: "https://example.com/fileupload", headers: { Authorization: "Bearer" + TOKEN, "X-Custom-Header": "value" } }` |
92
+ | `files` | Array<[File](#-file-structure)> | An array of file and folder objects representing the current directory structure. Each object includes `name`, `isDirectory`, and `path` properties. |
93
+ | `height` | string \| number | The height of the component `default: 600px`. Can be a string (e.g., `'100%'`, `'10rem'`) or a number (in pixels). |
94
+ | `isLoading` | boolean | A boolean state indicating whether the application is currently performing an operation, such as creating, renaming, or deleting a file/folder. Displays a loading state if set `true`. |
95
+ | `layout` | "list" \| "grid" | Specifies the default layout style for the file manager. Can be either "list" or "grid". Default value is "grid". |
96
+ | `maxFileSize` | number | For limiting the maximum upload file size in bytes. |
97
+ | `onCreateFolder` | (name: string, parentFolder: [File](#-file-structure)) => void | A callback function triggered when a new folder is created. Use this function to update the files state to include the new folder under the specified parent folder using create folder API call to your server. |
98
+ | `onDelete` | (file: [File](#-file-structure)) => void | A callback function triggered when a file or folder is deleted. |
99
+ | `onDownload` | (file: [File](#-file-structure)) => void | A callback function triggered when a file is downloaded. |
100
+ | `onError` | (error: { type: string, message: string }, file: [File](#-file-structure)) => void | A callback function triggered whenever there is an error in the file manager. Where error is an object containing `type` ("upload", etc.) and a descriptive error `message`. |
101
+ | `onFileOpen` | (file: [File](#-file-structure)) => void | A callback function triggered when a file or folder is opened. |
102
+ | `onFileUploaded` | (response: { [key: string]: any }) => void | A callback function triggered after a file is successfully uploaded. Provides JSON `response` holding uploaded file details, use it to extract the uploaded file details and add it to the `files` state e.g. `setFiles((prev) => [...prev, JSON.parse(response)]);` |
103
+ | `onFileUploading` | (file: [File](#-file-structure), parentFolder: [File](#-file-structure)) => { [key: string]: any } | A callback function triggered during the file upload process. You can also return an object with key-value pairs that will be appended to the `FormData` along with the file being uploaded. The object can contain any number of valid properties. |
104
+ | `onLayoutChange` | (layout: "list" \| "grid") => void | A callback function triggered when the layout of the file manager is changed. |
105
+ | `onPaste` | (file: [File](#-file-structure), destinationFolder: [File](#-file-structure), operationType: "copy" \| "move") => void | A callback function triggered when a file or folder is pasted into a new location. Depending on `operationType`, use this to either copy or move the `sourceItem` to the `destinationFolder`, updating the files state accordingly. |
106
+ | `onRefresh` | () => void | A callback function triggered when the file manager is refreshed. Use this to refresh the `files` state to reflect any changes or updates. |
107
+ | `onRename` | (file: [File](#-file-structure), newName: string) => void | A callback function triggered when a file or folder is renamed. |
108
+ | `width` | string \| number | The width of the component `default: 100%`. Can be a string (e.g., `'100%'`, `'10rem'`) or a number (in pixels). |
90
109
 
91
110
  ## 🤝 Contributing
92
111