ui-admin-lib 1.0.0 → 1.1.0
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 +473 -477
- package/package.json +64 -64
package/README.md
CHANGED
|
@@ -1,477 +1,473 @@
|
|
|
1
|
-
# UI Admin Library
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install ui-admin-lib
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
##
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```tsx
|
|
16
|
-
import { AdminPanel, CrudService } from 'ui-admin-lib'
|
|
17
|
-
import 'ui-admin-lib/styles'
|
|
18
|
-
|
|
19
|
-
// 1.
|
|
20
|
-
const userService = new CrudService({
|
|
21
|
-
baseUrl: 'https://api.example.com/users',
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
{
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{ name: '
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
- `
|
|
228
|
-
- `
|
|
229
|
-
- `
|
|
230
|
-
- `
|
|
231
|
-
- `
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
{
|
|
274
|
-
],
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
-
|
|
307
|
-
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
###
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
- `
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
- `
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
- `
|
|
325
|
-
- `
|
|
326
|
-
- `
|
|
327
|
-
- `
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
- `
|
|
331
|
-
|
|
332
|
-
###
|
|
333
|
-
- `
|
|
334
|
-
|
|
335
|
-
###
|
|
336
|
-
- `
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
- `
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
- `
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
- `
|
|
405
|
-
- `
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
#
|
|
445
|
-
npm
|
|
446
|
-
|
|
447
|
-
#
|
|
448
|
-
npm run
|
|
449
|
-
|
|
450
|
-
#
|
|
451
|
-
npm run
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
#
|
|
465
|
-
npm
|
|
466
|
-
|
|
467
|
-
#
|
|
468
|
-
npm
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
## Лицензия
|
|
475
|
-
|
|
476
|
-
MIT
|
|
477
|
-
|
|
1
|
+
# UI Admin Library
|
|
2
|
+
|
|
3
|
+
Library for quickly creating admin panels in React with full CRUD functionality. Create a complete admin panel in just a few lines of code!
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install ui-admin-lib
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Create an admin panel in a few lines:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { AdminPanel, CrudService } from 'ui-admin-lib'
|
|
17
|
+
import 'ui-admin-lib/styles'
|
|
18
|
+
|
|
19
|
+
// 1. Create a service for working with API
|
|
20
|
+
const userService = new CrudService({
|
|
21
|
+
baseUrl: 'https://api.example.com/users',
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// 2. Define a model
|
|
25
|
+
const userModel = {
|
|
26
|
+
name: 'users',
|
|
27
|
+
label: 'Users',
|
|
28
|
+
service: userService,
|
|
29
|
+
columns: [
|
|
30
|
+
{ key: 'id', title: 'ID', dataIndex: 'id' },
|
|
31
|
+
{ key: 'name', title: 'Name', dataIndex: 'name' },
|
|
32
|
+
{ key: 'email', title: 'Email', dataIndex: 'email' },
|
|
33
|
+
],
|
|
34
|
+
fields: [
|
|
35
|
+
{ name: 'name', label: 'Name', type: 'text', required: true },
|
|
36
|
+
{ name: 'email', label: 'Email', type: 'email', required: true },
|
|
37
|
+
],
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 3. Use AdminPanel
|
|
41
|
+
function App() {
|
|
42
|
+
return (
|
|
43
|
+
<AdminPanel
|
|
44
|
+
title="My Admin"
|
|
45
|
+
models={[userModel]}
|
|
46
|
+
login={{
|
|
47
|
+
onSubmit: async (username, password) => {
|
|
48
|
+
// Your authorization logic
|
|
49
|
+
},
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
That's it! AdminPanel will automatically create:
|
|
57
|
+
- Login page
|
|
58
|
+
- Sidebar navigation
|
|
59
|
+
- Data tables
|
|
60
|
+
- Create/edit forms
|
|
61
|
+
- Full CRUD functionality
|
|
62
|
+
|
|
63
|
+
## Full Configuration Example
|
|
64
|
+
|
|
65
|
+
Here's a complete example with multiple models and all features:
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import { AdminPanel, CrudService, AdminModel } from 'ui-admin-lib'
|
|
69
|
+
import type { Column, FormField } from 'ui-admin-lib'
|
|
70
|
+
import 'ui-admin-lib/styles'
|
|
71
|
+
|
|
72
|
+
// Data types
|
|
73
|
+
interface User {
|
|
74
|
+
id: number
|
|
75
|
+
name: string
|
|
76
|
+
email: string
|
|
77
|
+
role: string
|
|
78
|
+
active: boolean
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface Product {
|
|
82
|
+
id: number
|
|
83
|
+
title: string
|
|
84
|
+
price: number
|
|
85
|
+
category: string
|
|
86
|
+
inStock: boolean
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Create services for working with API
|
|
90
|
+
const userService = new CrudService<User>({
|
|
91
|
+
baseUrl: 'https://api.example.com/users',
|
|
92
|
+
headers: {
|
|
93
|
+
'Authorization': 'Bearer YOUR_TOKEN',
|
|
94
|
+
'Content-Type': 'application/json'
|
|
95
|
+
},
|
|
96
|
+
// Optional: custom URLs for operations
|
|
97
|
+
getListUrl: () => 'https://api.example.com/users',
|
|
98
|
+
getDetailUrl: (id) => `https://api.example.com/users/${id}`,
|
|
99
|
+
getCreateUrl: () => 'https://api.example.com/users',
|
|
100
|
+
getUpdateUrl: (id) => `https://api.example.com/users/${id}`,
|
|
101
|
+
getDeleteUrl: (id) => `https://api.example.com/users/${id}`,
|
|
102
|
+
// Optional: data transformation
|
|
103
|
+
transformRequest: (data) => data, // Transform before sending
|
|
104
|
+
transformResponse: (data) => data, // Transform after receiving
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const productService = new CrudService<Product>({
|
|
108
|
+
baseUrl: 'https://api.example.com/products',
|
|
109
|
+
headers: {
|
|
110
|
+
'Authorization': 'Bearer YOUR_TOKEN'
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
// User model configuration
|
|
115
|
+
const userModel: AdminModel<User> = {
|
|
116
|
+
name: 'users',
|
|
117
|
+
label: 'Users',
|
|
118
|
+
service: userService,
|
|
119
|
+
columns: [
|
|
120
|
+
{ key: 'id', title: 'ID', dataIndex: 'id' },
|
|
121
|
+
{ key: 'name', title: 'Name', dataIndex: 'name' },
|
|
122
|
+
{ key: 'email', title: 'Email', dataIndex: 'email' },
|
|
123
|
+
{
|
|
124
|
+
key: 'role',
|
|
125
|
+
title: 'Role',
|
|
126
|
+
dataIndex: 'role',
|
|
127
|
+
render: (value) => value.charAt(0).toUpperCase() + value.slice(1),
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
key: 'active',
|
|
131
|
+
title: 'Active',
|
|
132
|
+
dataIndex: 'active',
|
|
133
|
+
render: (value) => (value ? 'Yes' : 'No'),
|
|
134
|
+
},
|
|
135
|
+
] as Column<User>[],
|
|
136
|
+
fields: [
|
|
137
|
+
{ name: 'name', label: 'Name', type: 'text', required: true, placeholder: 'Enter name' },
|
|
138
|
+
{ name: 'email', label: 'Email', type: 'email', required: true, placeholder: 'Enter email' },
|
|
139
|
+
{
|
|
140
|
+
name: 'role',
|
|
141
|
+
label: 'Role',
|
|
142
|
+
type: 'select',
|
|
143
|
+
required: true,
|
|
144
|
+
options: [
|
|
145
|
+
{ value: 'admin', label: 'Administrator' },
|
|
146
|
+
{ value: 'user', label: 'User' },
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
{ name: 'active', label: 'Active', type: 'checkbox' },
|
|
150
|
+
] as FormField[],
|
|
151
|
+
// Optional: custom ID getter function
|
|
152
|
+
getItemId: (item) => item.id,
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Product model configuration
|
|
156
|
+
const productModel: AdminModel<Product> = {
|
|
157
|
+
name: 'products',
|
|
158
|
+
label: 'Products',
|
|
159
|
+
service: productService,
|
|
160
|
+
columns: [
|
|
161
|
+
{ key: 'id', title: 'ID', dataIndex: 'id' },
|
|
162
|
+
{ key: 'title', title: 'Title', dataIndex: 'title' },
|
|
163
|
+
{
|
|
164
|
+
key: 'price',
|
|
165
|
+
title: 'Price',
|
|
166
|
+
dataIndex: 'price',
|
|
167
|
+
render: (value) => `$${value.toLocaleString('en-US')}`,
|
|
168
|
+
},
|
|
169
|
+
{ key: 'category', title: 'Category', dataIndex: 'category' },
|
|
170
|
+
{
|
|
171
|
+
key: 'inStock',
|
|
172
|
+
title: 'In Stock',
|
|
173
|
+
dataIndex: 'inStock',
|
|
174
|
+
render: (value) => (value ? 'Yes' : 'No'),
|
|
175
|
+
},
|
|
176
|
+
] as Column<Product>[],
|
|
177
|
+
fields: [
|
|
178
|
+
{ name: 'title', label: 'Title', type: 'text', required: true },
|
|
179
|
+
{ name: 'price', label: 'Price', type: 'number', required: true },
|
|
180
|
+
{ name: 'category', label: 'Category', type: 'text', required: true },
|
|
181
|
+
{ name: 'inStock', label: 'In Stock', type: 'checkbox' },
|
|
182
|
+
] as FormField[],
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Usage
|
|
186
|
+
function App() {
|
|
187
|
+
return (
|
|
188
|
+
<AdminPanel
|
|
189
|
+
title="Admin Panel"
|
|
190
|
+
logo={<span>My Logo</span>} // Optional: custom logo
|
|
191
|
+
models={[userModel, productModel]}
|
|
192
|
+
login={{
|
|
193
|
+
onSubmit: async (username, password) => {
|
|
194
|
+
// Your authorization logic
|
|
195
|
+
const response = await fetch('https://api.example.com/auth/login', {
|
|
196
|
+
method: 'POST',
|
|
197
|
+
headers: { 'Content-Type': 'application/json' },
|
|
198
|
+
body: JSON.stringify({ username, password }),
|
|
199
|
+
})
|
|
200
|
+
if (!response.ok) {
|
|
201
|
+
throw new Error('Invalid username or password')
|
|
202
|
+
}
|
|
203
|
+
const data = await response.json()
|
|
204
|
+
// Save token
|
|
205
|
+
localStorage.setItem('token', data.token)
|
|
206
|
+
},
|
|
207
|
+
}}
|
|
208
|
+
user={{
|
|
209
|
+
name: 'Administrator', // Optional: user name in header
|
|
210
|
+
onLogout: () => {
|
|
211
|
+
// Optional: logout handler
|
|
212
|
+
localStorage.removeItem('token')
|
|
213
|
+
},
|
|
214
|
+
}}
|
|
215
|
+
/>
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Form Field Types
|
|
221
|
+
|
|
222
|
+
The following field types are supported in `FormField`:
|
|
223
|
+
|
|
224
|
+
- `text` - Text field
|
|
225
|
+
- `email` - Email field
|
|
226
|
+
- `number` - Number field
|
|
227
|
+
- `password` - Password field
|
|
228
|
+
- `textarea` - Multi-line field
|
|
229
|
+
- `select` - Dropdown list (requires `options`)
|
|
230
|
+
- `checkbox` - Checkbox
|
|
231
|
+
- `radio` - Radio buttons (requires `options`)
|
|
232
|
+
|
|
233
|
+
Field configuration example:
|
|
234
|
+
|
|
235
|
+
```tsx
|
|
236
|
+
{
|
|
237
|
+
name: 'fieldName', // Field name (required)
|
|
238
|
+
label: 'Field Label', // Field label (required)
|
|
239
|
+
type: 'text', // Field type (optional, default 'text')
|
|
240
|
+
required: true, // Required field (optional)
|
|
241
|
+
placeholder: 'Hint', // Placeholder (optional)
|
|
242
|
+
disabled: false, // Disabled (optional)
|
|
243
|
+
options: [ // Options for select/radio (required for these types)
|
|
244
|
+
{ value: 'value1', label: 'Label 1' },
|
|
245
|
+
{ value: 'value2', label: 'Label 2' },
|
|
246
|
+
],
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Quick Start
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
npm install ui-admin-lib
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
```tsx
|
|
257
|
+
import { AdminPanel, CrudService } from 'ui-admin-lib'
|
|
258
|
+
import 'ui-admin-lib/styles'
|
|
259
|
+
|
|
260
|
+
const userService = new CrudService({
|
|
261
|
+
baseUrl: 'https://api.example.com/users',
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
const userModel = {
|
|
265
|
+
name: 'users',
|
|
266
|
+
label: 'Users',
|
|
267
|
+
service: userService,
|
|
268
|
+
columns: [
|
|
269
|
+
{ key: 'id', title: 'ID', dataIndex: 'id' },
|
|
270
|
+
{ key: 'name', title: 'Name', dataIndex: 'name' },
|
|
271
|
+
],
|
|
272
|
+
fields: [
|
|
273
|
+
{ name: 'name', label: 'Name', type: 'text', required: true },
|
|
274
|
+
],
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function App() {
|
|
278
|
+
return <AdminPanel models={[userModel]} />
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
## Demo Application
|
|
283
|
+
|
|
284
|
+
Run the demo application to see all features:
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
git clone <repository-url>
|
|
288
|
+
cd ui-admin-lib
|
|
289
|
+
npm install
|
|
290
|
+
npm run demo
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Open http://localhost:3000 in your browser.
|
|
294
|
+
|
|
295
|
+
**Login:**
|
|
296
|
+
- Username: `admin`
|
|
297
|
+
- Password: `admin`
|
|
298
|
+
|
|
299
|
+
## Core Components
|
|
300
|
+
|
|
301
|
+
### AdminPanel
|
|
302
|
+
Main component for creating admin panels. Accepts configuration and automatically creates:
|
|
303
|
+
- Login page
|
|
304
|
+
- Sidebar navigation
|
|
305
|
+
- Data tables
|
|
306
|
+
- Create/edit forms
|
|
307
|
+
- CRUD operations (Create, Read, Update, Delete)
|
|
308
|
+
|
|
309
|
+
### CrudService
|
|
310
|
+
Utility for working with REST API. Supports any API response formats.
|
|
311
|
+
|
|
312
|
+
### Low-level Components
|
|
313
|
+
|
|
314
|
+
### Layout
|
|
315
|
+
- `PageLayout` - Main layout with header, sidebar and content
|
|
316
|
+
- `Header` - Page header
|
|
317
|
+
- `Sidebar` - Sidebar panel
|
|
318
|
+
- `Content` - Main content area
|
|
319
|
+
|
|
320
|
+
### Form
|
|
321
|
+
- `Button` - Button (variants: primary, success, danger, ghost)
|
|
322
|
+
- `Input` - Text input field
|
|
323
|
+
- `Select` - Dropdown list
|
|
324
|
+
- `Textarea` - Multi-line input field
|
|
325
|
+
- `Checkbox` - Checkbox
|
|
326
|
+
- `Radio` - Radio button
|
|
327
|
+
- `Label` - Form field label
|
|
328
|
+
|
|
329
|
+
### Table
|
|
330
|
+
- `DataTable` - Data table with columns and rows
|
|
331
|
+
|
|
332
|
+
### Modal
|
|
333
|
+
- `Modal` - Modal dialog
|
|
334
|
+
|
|
335
|
+
### Navigation
|
|
336
|
+
- `Menu` - Navigation menu
|
|
337
|
+
- `Breadcrumbs` - Breadcrumb navigation
|
|
338
|
+
- `Tabs` - Tabs
|
|
339
|
+
|
|
340
|
+
### Utility
|
|
341
|
+
- `Card` - Card component
|
|
342
|
+
- `Toast` / `ToastContainer` - Notifications
|
|
343
|
+
- `Loading` - Loading spinner
|
|
344
|
+
- `Badge` - Badge component
|
|
345
|
+
|
|
346
|
+
## API Reference
|
|
347
|
+
|
|
348
|
+
### AdminPanel
|
|
349
|
+
|
|
350
|
+
Main component for creating admin panels.
|
|
351
|
+
|
|
352
|
+
```tsx
|
|
353
|
+
<AdminPanel
|
|
354
|
+
title?: string // Admin panel title (default: "Admin Panel")
|
|
355
|
+
logo?: React.ReactNode // Custom logo
|
|
356
|
+
models: AdminModel[] // Array of models to display
|
|
357
|
+
login?: { // Authorization configuration (optional)
|
|
358
|
+
onSubmit: (username: string, password: string) => Promise<void> | void
|
|
359
|
+
}
|
|
360
|
+
user?: { // User information (optional)
|
|
361
|
+
name?: string // User name in header
|
|
362
|
+
onLogout?: () => void // Logout handler
|
|
363
|
+
}
|
|
364
|
+
/>
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### AdminModel
|
|
368
|
+
|
|
369
|
+
Data model configuration.
|
|
370
|
+
|
|
371
|
+
```tsx
|
|
372
|
+
interface AdminModel<T = any> {
|
|
373
|
+
name: string // Unique model name
|
|
374
|
+
label: string // Display name
|
|
375
|
+
service: CrudService<T> // Service for working with API
|
|
376
|
+
columns: Column<T>[] // Table columns
|
|
377
|
+
fields: FormField[] // Form fields
|
|
378
|
+
getItemId?: (item: T) => string | number // ID getter function (optional)
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### CrudService
|
|
383
|
+
|
|
384
|
+
Class for working with REST API.
|
|
385
|
+
|
|
386
|
+
```tsx
|
|
387
|
+
new CrudService<T>({
|
|
388
|
+
baseUrl: string // Base API URL
|
|
389
|
+
getListUrl?: (params?: any) => string // URL for getting list (optional)
|
|
390
|
+
getDetailUrl?: (id) => string // URL for getting item (optional)
|
|
391
|
+
getCreateUrl?: () => string // URL for creating (optional)
|
|
392
|
+
getUpdateUrl?: (id) => string // URL for updating (optional)
|
|
393
|
+
getDeleteUrl?: (id) => string // URL for deleting (optional)
|
|
394
|
+
transformRequest?: (data) => any // Request transformation (optional)
|
|
395
|
+
transformResponse?: (data) => T // Response transformation (optional)
|
|
396
|
+
headers?: Record<string, string> // Request headers (optional)
|
|
397
|
+
})
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Methods:
|
|
401
|
+
- `getList(params?)` - Get list of items
|
|
402
|
+
- `getDetail(id)` - Get item by ID
|
|
403
|
+
- `create(data)` - Create new item
|
|
404
|
+
- `update(id, data)` - Update item
|
|
405
|
+
- `delete(id)` - Delete item
|
|
406
|
+
|
|
407
|
+
### Column
|
|
408
|
+
|
|
409
|
+
Table column configuration.
|
|
410
|
+
|
|
411
|
+
```tsx
|
|
412
|
+
interface Column<T> {
|
|
413
|
+
key: string // Unique column key
|
|
414
|
+
title: string // Column title
|
|
415
|
+
dataIndex?: string // Data field to display
|
|
416
|
+
render?: (value: any, record: T, index: number) => React.ReactNode // Custom render
|
|
417
|
+
width?: number | string // Column width
|
|
418
|
+
align?: 'left' | 'center' | 'right' // Alignment
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### FormField
|
|
423
|
+
|
|
424
|
+
Form field configuration.
|
|
425
|
+
|
|
426
|
+
```tsx
|
|
427
|
+
interface FormField {
|
|
428
|
+
name: string // Field name
|
|
429
|
+
label: string // Field label
|
|
430
|
+
type?: 'text' | 'email' | 'number' | 'password' | 'textarea' | 'select' | 'checkbox' | 'radio'
|
|
431
|
+
options?: Array<{ value: string | number; label: string }> // Options for select/radio
|
|
432
|
+
required?: boolean // Required field
|
|
433
|
+
placeholder?: string // Placeholder
|
|
434
|
+
disabled?: boolean // Disabled
|
|
435
|
+
}
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## Development
|
|
439
|
+
|
|
440
|
+
```bash
|
|
441
|
+
# Install dependencies
|
|
442
|
+
npm install
|
|
443
|
+
|
|
444
|
+
# Build library
|
|
445
|
+
npm run build
|
|
446
|
+
|
|
447
|
+
# Run demo application
|
|
448
|
+
npm run demo
|
|
449
|
+
|
|
450
|
+
# Linting
|
|
451
|
+
npm run lint
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
## Publishing to npm
|
|
455
|
+
|
|
456
|
+
```bash
|
|
457
|
+
# Make sure all changes are committed
|
|
458
|
+
git add .
|
|
459
|
+
git commit -m "Prepare for release"
|
|
460
|
+
|
|
461
|
+
# Update version (if needed)
|
|
462
|
+
npm version patch # or minor, major
|
|
463
|
+
|
|
464
|
+
# Build library
|
|
465
|
+
npm run build
|
|
466
|
+
|
|
467
|
+
# Publish
|
|
468
|
+
npm publish
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
## License
|
|
472
|
+
|
|
473
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "ui-admin-lib",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"module": "./dist/index.esm.js",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./dist/index.esm.js",
|
|
11
|
-
"require": "./dist/index.js",
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
13
|
-
},
|
|
14
|
-
"./styles": "./dist/styles.css"
|
|
15
|
-
},
|
|
16
|
-
"files": [
|
|
17
|
-
"dist",
|
|
18
|
-
"README.md"
|
|
19
|
-
],
|
|
20
|
-
"scripts": {
|
|
21
|
-
"dev": "vite",
|
|
22
|
-
"build": "vite build",
|
|
23
|
-
"preview": "vite preview",
|
|
24
|
-
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
25
|
-
"demo": "cd demo && npm install && npm run dev",
|
|
26
|
-
"demo:build": "cd demo && npm install && npm run build"
|
|
27
|
-
},
|
|
28
|
-
"peerDependencies": {
|
|
29
|
-
"react": "^18.0.0",
|
|
30
|
-
"react-dom": "^18.0.0"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@types/react": "^18.2.43",
|
|
34
|
-
"@types/react-dom": "^18.2.17",
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
36
|
-
"@typescript-eslint/parser": "^6.14.0",
|
|
37
|
-
"@vitejs/plugin-react": "^4.2.1",
|
|
38
|
-
"eslint": "^8.55.0",
|
|
39
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
40
|
-
"eslint-plugin-react-refresh": "^0.4.5",
|
|
41
|
-
"react": "^18.2.0",
|
|
42
|
-
"react-dom": "^18.2.0",
|
|
43
|
-
"typescript": "^5.2.2",
|
|
44
|
-
"vite": "^5.0.8",
|
|
45
|
-
"vite-plugin-dts": "^3.6.4"
|
|
46
|
-
},
|
|
47
|
-
"keywords": [
|
|
48
|
-
"react",
|
|
49
|
-
"admin",
|
|
50
|
-
"crud",
|
|
51
|
-
"admin-panel",
|
|
52
|
-
"dashboard",
|
|
53
|
-
"ui-library",
|
|
54
|
-
"typescript",
|
|
55
|
-
"react-components"
|
|
56
|
-
],
|
|
57
|
-
"author": "",
|
|
58
|
-
"license": "MIT",
|
|
59
|
-
"repository": {
|
|
60
|
-
"type": "git",
|
|
61
|
-
"url": ""
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "ui-admin-lib",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Library for quickly creating admin panels in React with full CRUD functionality",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.esm.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.esm.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./styles": "./dist/styles.css"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"dev": "vite",
|
|
22
|
+
"build": "vite build",
|
|
23
|
+
"preview": "vite preview",
|
|
24
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
25
|
+
"demo": "cd demo && npm install && npm run dev",
|
|
26
|
+
"demo:build": "cd demo && npm install && npm run build"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"react": "^18.0.0",
|
|
30
|
+
"react-dom": "^18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/react": "^18.2.43",
|
|
34
|
+
"@types/react-dom": "^18.2.17",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
36
|
+
"@typescript-eslint/parser": "^6.14.0",
|
|
37
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
38
|
+
"eslint": "^8.55.0",
|
|
39
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
40
|
+
"eslint-plugin-react-refresh": "^0.4.5",
|
|
41
|
+
"react": "^18.2.0",
|
|
42
|
+
"react-dom": "^18.2.0",
|
|
43
|
+
"typescript": "^5.2.2",
|
|
44
|
+
"vite": "^5.0.8",
|
|
45
|
+
"vite-plugin-dts": "^3.6.4"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"react",
|
|
49
|
+
"admin",
|
|
50
|
+
"crud",
|
|
51
|
+
"admin-panel",
|
|
52
|
+
"dashboard",
|
|
53
|
+
"ui-library",
|
|
54
|
+
"typescript",
|
|
55
|
+
"react-components"
|
|
56
|
+
],
|
|
57
|
+
"author": "",
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": ""
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|