@jfvilas/react-file-manager 1.0.2 → 1.0.4
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 +98 -21
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<div align="center">
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
</div>
|
|
10
|
-
|
|
1
|
+
# React File Manager
|
|
11
2
|
<p>
|
|
12
|
-
An open-source React
|
|
3
|
+
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
|
+
|
|
5
|
+
This project is forked from [this fantastic project](https://github.com/Saifullah-dev/react-file-manager).
|
|
13
6
|
</p>
|
|
14
7
|
|
|
15
8
|
## ✨ Features
|
|
@@ -28,8 +21,6 @@ An open-source React.js package for easy integration of a file manager into appl
|
|
|
28
21
|
- **Drag-and-Drop**: Move selected files and folders by dragging them to the desired directory,
|
|
29
22
|
making file organization effortless.
|
|
30
23
|
|
|
31
|
-

|
|
32
|
-
|
|
33
24
|
## 🚀 Installation
|
|
34
25
|
|
|
35
26
|
To install `React File Manager`, use the following command:
|
|
@@ -97,11 +88,101 @@ type File = {
|
|
|
97
88
|
};
|
|
98
89
|
```
|
|
99
90
|
|
|
100
|
-
## Icons & Actions
|
|
101
|
-
|
|
91
|
+
## 🎬 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.
|
|
93
|
+
|
|
94
|
+
- For example, you can have a top level category that consist of types of books: novel, essay, history...
|
|
95
|
+
- On a second level you can add the topic: science-fiction, love, thriller...
|
|
96
|
+
- On a third level you can just store the book title.
|
|
97
|
+
|
|
98
|
+
You can add specific icons for each object (category, topic, book))
|
|
99
|
+
|
|
100
|
+
Moreover, you can add specific actions:
|
|
101
|
+
|
|
102
|
+
- For the top level, a sample action could be to send the list of books that belong to that category.
|
|
103
|
+
- For the third level, the book in itself, you can have some actions like: read, view details, share link...
|
|
104
|
+
|
|
105
|
+
For achieving these purposes 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`.
|
|
106
|
+
|
|
107
|
+
The next step is to add the icons for these objects. You must create a Map like this:
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
let icons = new Map();
|
|
111
|
+
icons.set('category', { open: <JSX.Element />, closed: <JSX.Element /> })
|
|
112
|
+
icons.set('topic', { open: <JSX.Element />, closed: <JSX.Element /> })
|
|
113
|
+
icons.set('book', { open: <JSX.Element />, closed: <JSX.Element /> })
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
This way, when rendering an object with the `class` `category`, react-file-manager will show the proper icon.
|
|
102
117
|
|
|
103
|
-
|
|
104
|
-
|
|
118
|
+
If you want to add specific actions for each `class`, you can, for example, create an `actions` map like this:
|
|
119
|
+
|
|
120
|
+
```javascript
|
|
121
|
+
let actions = new Map();
|
|
122
|
+
actions.set('namespace', [
|
|
123
|
+
{
|
|
124
|
+
title: 'Read book',
|
|
125
|
+
icon: <FaRead />,
|
|
126
|
+
onClick: (files) => {
|
|
127
|
+
console.log('onclick view:', files)
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
title: 'Book details',
|
|
132
|
+
icon: <FaBook />,
|
|
133
|
+
onClick: (files) => {
|
|
134
|
+
console.log('onclick delete:', files)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
])
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
This previous piece of code adds two actions to objects of `class` `book`:
|
|
141
|
+
|
|
142
|
+
- One for reading the book (the `onClick` method should open an ebook reader on screen)
|
|
143
|
+
- Another one for viewing book details.
|
|
144
|
+
|
|
145
|
+
A typical action contains these properties:
|
|
146
|
+
- `title`: the text to appear in the context menu.
|
|
147
|
+
- `icon`: the icon to show next to the text
|
|
148
|
+
- `onClick`: a function to process the action (on only parameter will be send: an array contianing the files that which the action must be executed on).
|
|
149
|
+
|
|
150
|
+
Once you have defined your `icons` and your `actions`, you just need to add tehm to your FileManager object like this:
|
|
151
|
+
|
|
152
|
+
```xml
|
|
153
|
+
<FileManager files={files} icons={icons} actions={actions} />
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
...And you'll see the magic 🪄!!
|
|
157
|
+
|
|
158
|
+
## 🎨 UI Customization
|
|
159
|
+
react-file-manager can be easily customized from your React application.
|
|
160
|
+
|
|
161
|
+
The simplest way for customizing is as follows:
|
|
162
|
+
|
|
163
|
+
1. Create a css file in your project directory (`fm-custom.css`, for example).
|
|
164
|
+
2. Import it in the JSX or TSX file that contains your FileManager object:
|
|
165
|
+
```javascript
|
|
166
|
+
import './custom-fm.css'
|
|
167
|
+
```
|
|
168
|
+
3. Customize your fileManager by adding classes to the `fm-custom.css` file. For example:
|
|
169
|
+
```css
|
|
170
|
+
.custom-fm .toolbar {
|
|
171
|
+
background-color: #e0e0e0;
|
|
172
|
+
border-top-left-radius: 8px;
|
|
173
|
+
border-top-right-radius: 8px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.custom-fm .files-container {
|
|
177
|
+
background-color: #f0f0f0;
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
4. Add your class name to your `FileManager` object:
|
|
181
|
+
```xml
|
|
182
|
+
<FileManager ... className='custom-fm'>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Et voilà !
|
|
105
186
|
|
|
106
187
|
## ⚙️ Props
|
|
107
188
|
|
|
@@ -244,7 +325,3 @@ function App() {
|
|
|
244
325
|
- After that, folder changes are driven by `onFolderChange`.
|
|
245
326
|
- If you want to keep the path in sync with user navigation, use a controlled state (as shown
|
|
246
327
|
above).
|
|
247
|
-
|
|
248
|
-
## ©️ License
|
|
249
|
-
|
|
250
|
-
React File Manager is [MIT Licensed](LICENSE).
|