@jfvilas/react-file-manager 1.0.7 → 1.0.9
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 +60 -26
- package/dist/react-file-manager.es.js +3186 -3175
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# React File Manager
|
|
2
|
-
<p>
|
|
3
2
|
An open-source React 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.
|
|
4
3
|
|
|
5
4
|
This project is forked from [this fantastic project](https://github.com/Saifullah-dev/react-file-manager).
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
And our source code project is [here](https://github.com/jfvilas/react-file-manager).
|
|
7
7
|
|
|
8
8
|
## ✨ Features
|
|
9
9
|
|
|
@@ -20,6 +20,7 @@ This project is forked from [this fantastic project](https://github.com/Saifulla
|
|
|
20
20
|
intuitive keyboard shortcuts.
|
|
21
21
|
- **Drag-and-Drop**: Move selected files and folders by dragging them to the desired directory,
|
|
22
22
|
making file organization effortless.
|
|
23
|
+
- **Context cutomization**: Add your specifcia use-case icons and actions for your unique object types.
|
|
23
24
|
|
|
24
25
|
## 🚀 Installation
|
|
25
26
|
|
|
@@ -71,8 +72,35 @@ function App() {
|
|
|
71
72
|
export default App;
|
|
72
73
|
```
|
|
73
74
|
|
|
74
|
-
##
|
|
75
|
+
## Typescript Usage
|
|
76
|
+
If you plan to user react-file-manager in a Typescript project, you can add type management by adding a `.d.ts` file. What follows is a sample file, but you can donwload a full module declaaration file **[here](https://raw.githubusercontent.com/jfvilas/react-file-manager/refs/heads/main/frontend/public/jfvilas-react-file-manager.d.ts)**. Inside that file you will find a module declaration and a bunch of type and interface declarations. What follows is just a excerpt.
|
|
75
77
|
|
|
78
|
+
```typescript
|
|
79
|
+
declare module '@jfvilas/react-file-manager' {
|
|
80
|
+
export interface IFileData {
|
|
81
|
+
name: string;
|
|
82
|
+
isDirectory: boolean;
|
|
83
|
+
path: string;
|
|
84
|
+
updatedAt?: string;
|
|
85
|
+
size?: number;
|
|
86
|
+
class?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface IError {
|
|
90
|
+
type: string,
|
|
91
|
+
message: string,
|
|
92
|
+
response: {
|
|
93
|
+
status: number,
|
|
94
|
+
statusText: string,
|
|
95
|
+
data: any,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
...
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
In order to use this 'types' declaration file, just donwload and add it to your project inside your source folder (or any other folder and change your `package.json` accordingly).
|
|
102
|
+
|
|
103
|
+
## 📂 File Structure
|
|
76
104
|
The `files` prop accepts an array of objects, where each object represents a file or folder. You can
|
|
77
105
|
customize the structure to meet your application needs. Each file or folder object follows the
|
|
78
106
|
structure detailed below:
|
|
@@ -89,37 +117,39 @@ type File = {
|
|
|
89
117
|
```
|
|
90
118
|
|
|
91
119
|
## 🎬 Icons & Actions
|
|
92
|
-
By adding your own icons and specific actions for your items, you can think of react-file-manager as just a hierarchical object manager, that is, this package is no longer just a file manager, you can, for example, create a hierarchy of books and implement particular actions.
|
|
120
|
+
By adding your own icons and specific actions for your items, you can think of react-file-manager as just a hierarchical object manager, that is, this package is no longer just a file manager, you can, for example, create a hierarchy of books and implement particular actions. For example...:
|
|
93
121
|
|
|
94
|
-
-
|
|
122
|
+
- You can have a top level category that consist of types of books: novel, essay, history...
|
|
95
123
|
- On a second level you can add the topic: science-fiction, love, thriller...
|
|
96
124
|
- On a third level you can just store the book title.
|
|
97
125
|
|
|
98
|
-
You can add specific icons for each object (category, topic, book)
|
|
126
|
+
You can also add specific icons for each object (category, topic, book).
|
|
99
127
|
|
|
100
|
-
Moreover, you can add specific actions:
|
|
128
|
+
Moreover, you can add specific actions for each type of object:
|
|
101
129
|
|
|
102
|
-
- For the top level, a sample action could be to
|
|
103
|
-
- For the third level, the book in itself, you
|
|
130
|
+
- For the top level, a sample action could be to show the list of books that belong to that category.
|
|
131
|
+
- For the third level, the book in itself, you could add some actions like: read, view details, share link...
|
|
104
132
|
|
|
105
|
-
|
|
133
|
+
You can build interfaces like this: ![https://raw.githubusercontent.com/jfvilas/react-file-manager/refs/heads/main/frontend/public/fileman.png]
|
|
106
134
|
|
|
107
|
-
|
|
135
|
+
For achieving these objectives you need to add to each entry in the `files` object an **optional** property called `class`. So, for the top level, the class property could be `category`. For the second level, the value of `class` could be something like `topic`, and for the third level it could be something like `book`.
|
|
136
|
+
|
|
137
|
+
The next step is to add the icons for these objects. You must create a Map like this one:
|
|
108
138
|
|
|
109
139
|
```javascript
|
|
110
140
|
let icons = new Map();
|
|
111
|
-
icons.set('category', { open: <JSX.Element />, closed: <JSX.Element /> })
|
|
112
|
-
icons.set('topic', {
|
|
141
|
+
icons.set('category', { open: <JSX.Element />, closed: <JSX.Element />, list: <JSX.Element />, grid: <JSX.Element /> })
|
|
142
|
+
icons.set('topic', { default: <JSX.Element /> })
|
|
113
143
|
icons.set('book', { open: <JSX.Element />, closed: <JSX.Element /> })
|
|
114
144
|
```
|
|
115
145
|
|
|
116
|
-
This way, when rendering an object with the `class` `category`, react-file-manager will show the proper icon.
|
|
146
|
+
This way, when rendering an object with the `class` `category`, react-file-manager will show the proper icon, in the folder tree and also in the file list, wherever it be a grid or a list.
|
|
117
147
|
|
|
118
148
|
If you want to add specific actions for each `class`, you can, for example, create an `actions` map like this:
|
|
119
149
|
|
|
120
150
|
```javascript
|
|
121
151
|
let actions = new Map();
|
|
122
|
-
actions.set('
|
|
152
|
+
actions.set('book', [
|
|
123
153
|
{
|
|
124
154
|
title: 'Read book',
|
|
125
155
|
icon: <FaRead />,
|
|
@@ -139,15 +169,15 @@ If you want to add specific actions for each `class`, you can, for example, crea
|
|
|
139
169
|
|
|
140
170
|
This previous piece of code adds two actions to objects of `class` `book`:
|
|
141
171
|
|
|
142
|
-
- One for reading the book (the `onClick` method should open an ebook reader on screen)
|
|
172
|
+
- One for reading the book (the `onClick` method should open an ebook reader on screen).
|
|
143
173
|
- Another one for viewing book details.
|
|
144
174
|
|
|
145
|
-
A typical action contains these properties:
|
|
146
|
-
- `title`: the text to appear in
|
|
147
|
-
- `icon`: the icon to show next to the text
|
|
148
|
-
- `onClick`: a function to process the action (
|
|
175
|
+
A typical action contains these properties (review the `.d.td` file):
|
|
176
|
+
- `title`: the text to appear in context menus.
|
|
177
|
+
- `icon`: the icon to show next to the text.
|
|
178
|
+
- `onClick`: a function to process the action (one only parameter will be send: an array contianing the files which the action must be executed on).
|
|
149
179
|
|
|
150
|
-
Once you have defined your `icons` and your `actions`, you just need to add
|
|
180
|
+
Once you have defined your `icons` and your `actions`, you just need to add them to your FileManager object like this:
|
|
151
181
|
|
|
152
182
|
```xml
|
|
153
183
|
<FileManager files={files} icons={icons} actions={actions} />
|
|
@@ -155,17 +185,21 @@ Once you have defined your `icons` and your `actions`, you just need to add tehm
|
|
|
155
185
|
|
|
156
186
|
...And you'll see the magic 🪄!!
|
|
157
187
|
|
|
188
|
+
What follows is an example with Kubernetes objects, icons and actions that we have implemented in (Kwirth)[https://www.github.com/jfvilas/kwirth] project.
|
|
189
|
+
|
|
190
|
+
![https://raw.githubusercontent.com/jfvilas/react-file-manager/refs/heads/main/frontend/public/fileman-2.png]
|
|
191
|
+
|
|
158
192
|
## 🎨 UI Customization
|
|
159
|
-
react-file-manager can be easily customized
|
|
193
|
+
`react-file-manager` can be easily customized to mmet your React application UI srtyles.
|
|
160
194
|
|
|
161
|
-
The simplest way for customizing is as follows:
|
|
195
|
+
The simplest way for customizing this component is as follows:
|
|
162
196
|
|
|
163
|
-
1. Create a css file in your project directory (`fm
|
|
197
|
+
1. Create a `.css` file in your project directory (`custom-fm.css`, for example).
|
|
164
198
|
2. Import it in the JSX or TSX file that contains your FileManager object:
|
|
165
199
|
```javascript
|
|
166
200
|
import './custom-fm.css'
|
|
167
201
|
```
|
|
168
|
-
3. Customize your
|
|
202
|
+
3. Customize your FileManager by adding classes to the `custom-fm.css` file. For example (please note we add our class name `custom-fm` on each style):
|
|
169
203
|
```css
|
|
170
204
|
.custom-fm .toolbar {
|
|
171
205
|
background-color: #e0e0e0;
|
|
@@ -177,7 +211,7 @@ The simplest way for customizing is as follows:
|
|
|
177
211
|
background-color: #f0f0f0;
|
|
178
212
|
}
|
|
179
213
|
```
|
|
180
|
-
4. Add your class name to your `FileManager` object:
|
|
214
|
+
4. Add your class name to your `FileManager` object this way:
|
|
181
215
|
```xml
|
|
182
216
|
<FileManager ... className='custom-fm'>
|
|
183
217
|
```
|