@jfvilas/react-file-manager 1.0.6 → 1.0.8

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
@@ -71,8 +71,35 @@ function App() {
71
71
  export default App;
72
72
  ```
73
73
 
74
- ## 📂 File Structure
74
+ ## Typescript Usage
75
+ 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
76
 
77
+ ```typescript
78
+ declare module '@jfvilas/react-file-manager' {
79
+ export interface IFileData {
80
+ name: string;
81
+ isDirectory: boolean;
82
+ path: string;
83
+ updatedAt?: string;
84
+ size?: number;
85
+ class?: string;
86
+ }
87
+
88
+ export interface IError {
89
+ type: string,
90
+ message: string,
91
+ response: {
92
+ status: number,
93
+ statusText: string,
94
+ data: any,
95
+ }
96
+ }
97
+ ...
98
+ ```
99
+
100
+ 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).
101
+
102
+ ## 📂 File Structure
76
103
  The `files` prop accepts an array of objects, where each object represents a file or folder. You can
77
104
  customize the structure to meet your application needs. Each file or folder object follows the
78
105
  structure detailed below:
@@ -89,37 +116,37 @@ type File = {
89
116
  ```
90
117
 
91
118
  ## 🎬 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.
119
+ 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
120
 
94
- - For example, you can have a top level category that consist of types of books: novel, essay, history...
121
+ - You can have a top level category that consist of types of books: novel, essay, history...
95
122
  - On a second level you can add the topic: science-fiction, love, thriller...
96
123
  - On a third level you can just store the book title.
97
124
 
98
- You can add specific icons for each object (category, topic, book))
125
+ You can also add specific icons for each object (category, topic, book).
99
126
 
100
- Moreover, you can add specific actions:
127
+ Moreover, you can add specific actions for each type of object:
101
128
 
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...
129
+ - For the top level, a sample action could be to show the list of books that belong to that category.
130
+ - For the third level, the book in itself, you could add some actions like: read, view details, share link...
104
131
 
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`.
132
+ 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`.
106
133
 
107
- The next step is to add the icons for these objects. You must create a Map like this:
134
+ The next step is to add the icons for these objects. You must create a Map like this one:
108
135
 
109
136
  ```javascript
110
137
  let icons = new Map();
111
- icons.set('category', { open: <JSX.Element />, closed: <JSX.Element /> })
112
- icons.set('topic', { open: <JSX.Element />, closed: <JSX.Element /> })
138
+ icons.set('category', { open: <JSX.Element />, closed: <JSX.Element />, list: <JSX.Element />, grid: <JSX.Element /> })
139
+ icons.set('topic', { default: <JSX.Element /> })
113
140
  icons.set('book', { open: <JSX.Element />, closed: <JSX.Element /> })
114
141
  ```
115
142
 
116
- This way, when rendering an object with the `class` `category`, react-file-manager will show the proper icon.
143
+ 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
144
 
118
145
  If you want to add specific actions for each `class`, you can, for example, create an `actions` map like this:
119
146
 
120
147
  ```javascript
121
148
  let actions = new Map();
122
- actions.set('namespace', [
149
+ actions.set('book', [
123
150
  {
124
151
  title: 'Read book',
125
152
  icon: <FaRead />,
@@ -139,15 +166,15 @@ If you want to add specific actions for each `class`, you can, for example, crea
139
166
 
140
167
  This previous piece of code adds two actions to objects of `class` `book`:
141
168
 
142
- - One for reading the book (the `onClick` method should open an ebook reader on screen)
169
+ - One for reading the book (the `onClick` method should open an ebook reader on screen).
143
170
  - Another one for viewing book details.
144
171
 
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).
172
+ A typical action contains these properties (review the `.d.td` file):
173
+ - `title`: the text to appear in context menus.
174
+ - `icon`: the icon to show next to the text.
175
+ - `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
176
 
150
- Once you have defined your `icons` and your `actions`, you just need to add tehm to your FileManager object like this:
177
+ Once you have defined your `icons` and your `actions`, you just need to add them to your FileManager object like this:
151
178
 
152
179
  ```xml
153
180
  <FileManager files={files} icons={icons} actions={actions} />
@@ -156,16 +183,16 @@ Once you have defined your `icons` and your `actions`, you just need to add tehm
156
183
  ...And you'll see the magic 🪄!!
157
184
 
158
185
  ## 🎨 UI Customization
159
- react-file-manager can be easily customized from your React application.
186
+ `react-file-manager` can be easily customized to mmet your React application UI srtyles.
160
187
 
161
- The simplest way for customizing is as follows:
188
+ The simplest way for customizing this component is as follows:
162
189
 
163
- 1. Create a css file in your project directory (`fm-custom.css`, for example).
190
+ 1. Create a `.css` file in your project directory (`custom-fm.css`, for example).
164
191
  2. Import it in the JSX or TSX file that contains your FileManager object:
165
192
  ```javascript
166
193
  import './custom-fm.css'
167
194
  ```
168
- 3. Customize your fileManager by adding classes to the `fm-custom.css` file. For example:
195
+ 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
196
  ```css
170
197
  .custom-fm .toolbar {
171
198
  background-color: #e0e0e0;
@@ -177,7 +204,7 @@ The simplest way for customizing is as follows:
177
204
  background-color: #f0f0f0;
178
205
  }
179
206
  ```
180
- 4. Add your class name to your `FileManager` object:
207
+ 4. Add your class name to your `FileManager` object this way:
181
208
  ```xml
182
209
  <FileManager ... className='custom-fm'>
183
210
  ```