@jfvilas/react-file-manager 1.0.2 → 1.0.3
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 +94 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,11 +97,101 @@ type File = {
|
|
|
97
97
|
};
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
## Icons & Actions
|
|
101
|
-
|
|
100
|
+
## 🎬 Icons & Actions
|
|
101
|
+
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.
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
|
|
103
|
+
- For example, you can have a top level category that consist of types of books: novel, essay, history...
|
|
104
|
+
- On a second level you can add the topic: science-fiction, love, thriller...
|
|
105
|
+
- On a third level you can just store the book title.
|
|
106
|
+
|
|
107
|
+
You can add specific icons for each object (category, topic, book))
|
|
108
|
+
|
|
109
|
+
Moreover, you can add specific actions:
|
|
110
|
+
|
|
111
|
+
- For the top level, a sample action could be to send the list of books that belong to that category.
|
|
112
|
+
- For the third level, the book in itself, you can have some actions like: read, view details, share link...
|
|
113
|
+
|
|
114
|
+
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`.
|
|
115
|
+
|
|
116
|
+
The next step is to add the icons for these objects. You must create a Map like this:
|
|
117
|
+
|
|
118
|
+
```javascript
|
|
119
|
+
let icons = new Map();
|
|
120
|
+
icons.set('category', { open: <JSX.Element />, closed: <JSX.Element /> })
|
|
121
|
+
icons.set('topic', { open: <JSX.Element />, closed: <JSX.Element /> })
|
|
122
|
+
icons.set('book', { open: <JSX.Element />, closed: <JSX.Element /> })
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
This way, when rendering an object with the `class` `category`, react-file-manager will show the proper icon.
|
|
126
|
+
|
|
127
|
+
If you want to add specific actions for each `class`, you can, for example, create an `actions` map like this:
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
let actions = new Map();
|
|
131
|
+
actions.set('namespace', [
|
|
132
|
+
{
|
|
133
|
+
title: 'Read book',
|
|
134
|
+
icon: <FaRead />,
|
|
135
|
+
onClick: (files) => {
|
|
136
|
+
console.log('onclick view:', files)
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
title: 'Book details',
|
|
141
|
+
icon: <FaBook />,
|
|
142
|
+
onClick: (files) => {
|
|
143
|
+
console.log('onclick delete:', files)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
])
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This previous piece of code adds two actions to objects of `class` `book`:
|
|
150
|
+
|
|
151
|
+
- One for reading the book (the `onClick` method should open an ebook reader on screen)
|
|
152
|
+
- Another one for viewing book details.
|
|
153
|
+
|
|
154
|
+
A typical action contains these properties:
|
|
155
|
+
- `title`: the text to appear in the context menu.
|
|
156
|
+
- `icon`: the icon to show next to the text
|
|
157
|
+
- `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).
|
|
158
|
+
|
|
159
|
+
Once you have defined your `icons` and your `actions`, you just need to add tehm to your FileManager object like this:
|
|
160
|
+
|
|
161
|
+
```xml
|
|
162
|
+
<FileManager files={files} icons={icons} actions={actions} />
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
...And you'll see the magic 🪄!!
|
|
166
|
+
|
|
167
|
+
## 🎨 UI Customization
|
|
168
|
+
react-file-manager can be easily customized from your React application.
|
|
169
|
+
|
|
170
|
+
The simplest way for customizing is as follows:
|
|
171
|
+
|
|
172
|
+
1. Create a css file in your project directory (`fm-custom.css`, for example).
|
|
173
|
+
2. Import it in the JSX or TSX file that contains your FileManager object:
|
|
174
|
+
```javascript
|
|
175
|
+
import './custom-fm.css'
|
|
176
|
+
```
|
|
177
|
+
3. Customize your fileManager by adding classes to the `fm-custom.css` file. For example:
|
|
178
|
+
```css
|
|
179
|
+
.custom-fm .toolbar {
|
|
180
|
+
background-color: #e0e0e0;
|
|
181
|
+
border-top-left-radius: 8px;
|
|
182
|
+
border-top-right-radius: 8px;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.custom-fm .files-container {
|
|
186
|
+
background-color: #f0f0f0;
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
4. Add your class name to your `FileManager` object:
|
|
190
|
+
```xml
|
|
191
|
+
<FileManager ... className='custom-fm'>
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Et voilà !
|
|
105
195
|
|
|
106
196
|
## ⚙️ Props
|
|
107
197
|
|