antd-crud-table 0.4.0 β 0.5.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 +48 -89
- package/dist/CrudTable-DUfRGJW2.js +524 -0
- package/dist/CrudTable-TTRqkEoZ.cjs +1 -0
- package/dist/CrudTable.cjs +1 -1
- package/dist/CrudTable.d.ts +2 -2
- package/dist/CrudTable.js +3 -306
- package/dist/CrudTableLazy.cjs +1 -1
- package/dist/CrudTableLazy.d.ts +1 -1
- package/dist/CrudTableLazy.js +1 -1
- package/dist/exportData.cjs +12 -12
- package/dist/exportData.js +13 -17
- package/dist/fields/registry.d.ts +38 -0
- package/dist/hooks/useCrudTable.d.ts +2 -1
- package/dist/hooks/useCrudTable.test.d.ts +1 -0
- package/dist/hooks/useLocalStorageCrud.d.ts +5 -0
- package/dist/hooks/useLocalStorageCrud.test.d.ts +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +6 -0
- package/dist/useCrudTable-CEY_riQg.cjs +1 -0
- package/dist/useCrudTable-DpF-oZHz.js +246 -0
- package/dist/useCrudTable.cjs +1 -1
- package/dist/useCrudTable.js +2 -235
- package/dist/useLocalStorageCrud.cjs +1 -1
- package/dist/useLocalStorageCrud.js +29 -176
- package/dist/utils/exportData.d.ts +5 -1
- package/dist/utils/exportData.test.d.ts +1 -0
- package/dist/utils/query.d.ts +13 -0
- package/dist/utils/query.test.d.ts +1 -0
- package/package.json +26 -11
package/README.md
CHANGED
|
@@ -4,21 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
`antd-crud-table` is a highly flexible and powerful React library built using `antd` and `@ant-design/pro-components`. It provides both a declarative component-based approach and a modern hook-based architecture for creating editable, paginated tables with form support, data fetching, sorting, filtering, and custom rendering. Perfect for building admin dashboards and data management UIs with minimal boilerplate.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## π API Reference
|
|
8
8
|
|
|
9
|
-
###
|
|
9
|
+
### CrudTable Props
|
|
10
10
|
|
|
11
11
|
| Prop | Type | Description |
|
|
12
12
|
|------|------|-------------|
|
|
13
13
|
| `title` | `string` | Table header title |
|
|
14
14
|
| `rowKey` | `keyof T` | Unique identifier for each row |
|
|
15
|
-
| `columns` | `CrudColumn<T>[]` | Column definitions with
|
|
15
|
+
| `columns` | `CrudColumn<T>[]` | Column definitions with |
|
|
16
16
|
| `hookConfig` | `UseCrudTableConfig<T>` | Hook configuration for data operations |
|
|
17
17
|
| `defaultPageSize?` | `number` | Initial page size (default: 10) |
|
|
18
18
|
| `enableBulkOperations?` | `boolean` | Enable bulk select/delete (default: false) |
|
|
19
19
|
| `customActions?` | `(record, actions) => ReactNode[]` | Custom row actions |ased Architecture**
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
Latest version introduces a powerful hook-based architecture with multiple data source strategies:
|
|
22
22
|
- **Static Data**: Perfect for prototypes and small datasets
|
|
23
23
|
- **API Integration**: REST API support with automatic request handling
|
|
24
24
|
- **Custom Operations**: Full control with GraphQL, IndexedDB, or custom logic
|
|
@@ -43,14 +43,14 @@ npm install react react-dom antd @ant-design/pro-components
|
|
|
43
43
|
|
|
44
44
|
Choose your preferred approach:
|
|
45
45
|
|
|
46
|
-
### Modern Approach
|
|
46
|
+
### Modern Approach - Hook-Based
|
|
47
47
|
|
|
48
48
|
```tsx
|
|
49
|
-
import {
|
|
49
|
+
import { CrudTable } from 'antd-crud-table';
|
|
50
50
|
|
|
51
51
|
// Static data example
|
|
52
52
|
const UserManagement = () => (
|
|
53
|
-
<
|
|
53
|
+
<CrudTable<User>
|
|
54
54
|
title="User Management"
|
|
55
55
|
rowKey="id"
|
|
56
56
|
hookConfig={{
|
|
@@ -110,13 +110,13 @@ const UserTable = () => (
|
|
|
110
110
|
|
|
111
111
|
---
|
|
112
112
|
|
|
113
|
-
## π― **Enhanced Features
|
|
113
|
+
## π― **Enhanced Features**
|
|
114
114
|
|
|
115
115
|
### 1. **Multiple Data Source Strategies**
|
|
116
116
|
|
|
117
117
|
#### Static Data (Perfect for Prototyping)
|
|
118
118
|
```tsx
|
|
119
|
-
<
|
|
119
|
+
<CrudTable
|
|
120
120
|
hookConfig={{
|
|
121
121
|
staticData: mockUsers,
|
|
122
122
|
optimisticUpdates: true,
|
|
@@ -127,7 +127,7 @@ const UserTable = () => (
|
|
|
127
127
|
|
|
128
128
|
#### API Integration (Production Ready)
|
|
129
129
|
```tsx
|
|
130
|
-
<
|
|
130
|
+
<CrudTable
|
|
131
131
|
hookConfig={{
|
|
132
132
|
api: {
|
|
133
133
|
baseUrl: 'https://api.example.com',
|
|
@@ -164,7 +164,7 @@ const UserTable = () => (
|
|
|
164
164
|
|
|
165
165
|
#### Custom Operations (Maximum Flexibility)
|
|
166
166
|
```tsx
|
|
167
|
-
<
|
|
167
|
+
<CrudTable
|
|
168
168
|
hookConfig={{
|
|
169
169
|
operations: {
|
|
170
170
|
getList: async (params) => {
|
|
@@ -188,7 +188,7 @@ const UserTable = () => (
|
|
|
188
188
|
|
|
189
189
|
#### Bulk Operations
|
|
190
190
|
```tsx
|
|
191
|
-
<
|
|
191
|
+
<CrudTable
|
|
192
192
|
enableBulkOperations={true}
|
|
193
193
|
// Automatically adds bulk select and delete functionality
|
|
194
194
|
/>
|
|
@@ -196,7 +196,7 @@ const UserTable = () => (
|
|
|
196
196
|
|
|
197
197
|
#### Custom Actions
|
|
198
198
|
```tsx
|
|
199
|
-
<
|
|
199
|
+
<CrudTable
|
|
200
200
|
customActions={(record, actions) => [
|
|
201
201
|
<Button
|
|
202
202
|
key="export"
|
|
@@ -214,7 +214,7 @@ const UserTable = () => (
|
|
|
214
214
|
/>
|
|
215
215
|
```
|
|
216
216
|
|
|
217
|
-
####
|
|
217
|
+
#### Validation
|
|
218
218
|
```tsx
|
|
219
219
|
columns={[
|
|
220
220
|
{
|
|
@@ -452,7 +452,7 @@ const UserTable = () => {
|
|
|
452
452
|
const userCrud = useUserCrud();
|
|
453
453
|
|
|
454
454
|
return (
|
|
455
|
-
<
|
|
455
|
+
<CrudTable
|
|
456
456
|
title="Users"
|
|
457
457
|
rowKey="id"
|
|
458
458
|
hookConfig={userCrud}
|
|
@@ -465,7 +465,7 @@ const OfflineTable = () => {
|
|
|
465
465
|
const offlineCrud = useLocalStorageCrud<User>('users-cache', 'id', mockUsers);
|
|
466
466
|
|
|
467
467
|
return (
|
|
468
|
-
<
|
|
468
|
+
<CrudTable
|
|
469
469
|
title="Offline Users"
|
|
470
470
|
rowKey="id"
|
|
471
471
|
hookConfig={offlineCrud}
|
|
@@ -482,7 +482,7 @@ const RealtimeTable = () => {
|
|
|
482
482
|
);
|
|
483
483
|
|
|
484
484
|
return (
|
|
485
|
-
<
|
|
485
|
+
<CrudTable
|
|
486
486
|
title="Realtime Users"
|
|
487
487
|
rowKey="id"
|
|
488
488
|
hookConfig={realtimeCrud}
|
|
@@ -506,8 +506,6 @@ const RealtimeTable = () => {
|
|
|
506
506
|
- π§° **Full TypeScript Support** with generics
|
|
507
507
|
- π **Field-Level Edit Controls**
|
|
508
508
|
- π§Ό **Professional UI** with row differentiation
|
|
509
|
-
|
|
510
|
-
### Enhanced Features (Experimental)
|
|
511
509
|
- πͺ **Hook-Based Architecture** with `useCrudTable`
|
|
512
510
|
- π **Multiple Data Sources**: Static, API, or custom operations
|
|
513
511
|
- β‘ **Built-in State Management**: Loading, error states, optimistic updates
|
|
@@ -522,7 +520,7 @@ const RealtimeTable = () => {
|
|
|
522
520
|
|
|
523
521
|
## API Reference
|
|
524
522
|
|
|
525
|
-
###
|
|
523
|
+
### CrudTable Props
|
|
526
524
|
|
|
527
525
|
| Prop | Type | Description |
|
|
528
526
|
|------|------|-------------|
|
|
@@ -534,19 +532,46 @@ const RealtimeTable = () => {
|
|
|
534
532
|
| `enableBulkOperations?` | `boolean` | Enable bulk select/delete (default: false) |
|
|
535
533
|
| `customActions?` | `(record, actions) => ReactNode[]` | Custom row actions |
|
|
536
534
|
|
|
537
|
-
### CrudColumn<T>
|
|
535
|
+
### CrudColumn<T>
|
|
538
536
|
|
|
539
537
|
| Prop | Type | Description |
|
|
540
538
|
|------|------|-------------|
|
|
541
539
|
| `dataIndex` | `keyof T` | Field key in your data |
|
|
542
540
|
| `title` | `string` | Column header text |
|
|
543
|
-
| `fieldType` | `FieldType` |
|
|
541
|
+
| `fieldType` | `FieldType` | See the field type table below (default: `"string"`) |
|
|
544
542
|
| `fieldEditable?` | `boolean` | Whether field can be edited (default: true) |
|
|
545
543
|
| `searchable?` | `boolean` | Whether field appears in search (default: true) |
|
|
546
544
|
| `enumOptions?` | `Record<string, {text: string, color?: string}>` | Options for enum fields |
|
|
547
545
|
| `customRender?` | `(value, record) => ReactNode` | Custom display renderer |
|
|
548
546
|
| `formConfig?` | `FormConfig` | Form field configuration |
|
|
549
547
|
|
|
548
|
+
### Field Types
|
|
549
|
+
|
|
550
|
+
| `fieldType` | Stored as | Table cell | Form control |
|
|
551
|
+
|-------------|-----------|------------|--------------|
|
|
552
|
+
| `string` (default) | `string` | text | `Input` |
|
|
553
|
+
| `textarea` | `string` | ellipsised text | `Input.TextArea` |
|
|
554
|
+
| `email` | `string` | `mailto:` link (validated) | `Input` |
|
|
555
|
+
| `url` | `string` | link (validated) | `Input` |
|
|
556
|
+
| `password` | `string` | masked, excluded from search | `Input.Password` |
|
|
557
|
+
| `number` | `number` | localized number | `InputNumber` |
|
|
558
|
+
| `money` | `number` | currency (via ProTable intl) | `InputNumber` |
|
|
559
|
+
| `percent` | `number` | percentage | `InputNumber` 0β100 |
|
|
560
|
+
| `rating` | `number` | stars | `Rate` |
|
|
561
|
+
| `progress` | `number` | progress bar | `InputNumber` 0β100 |
|
|
562
|
+
| `date` | ISO string | `YYYY-MM-DD HH:mm` | `DatePicker` |
|
|
563
|
+
| `time` | `HH:mm:ss` string | time | `TimePicker` |
|
|
564
|
+
| `dateRange` | `[startISO, endISO]` | `start ~ end` | `RangePicker` |
|
|
565
|
+
| `boolean` | `boolean` | Yes/No tag | `Switch` |
|
|
566
|
+
| `enum` | `string` | colored tag | `Select` |
|
|
567
|
+
| `tags` | `string[]` | tag list | `Select mode="tags"` |
|
|
568
|
+
| `image` | URL string | 48px preview | `Input` (URL, validated) |
|
|
569
|
+
| `color` | hex string | swatch + code | `ColorPicker` |
|
|
570
|
+
| `json` | object | inline code | validated `Input.TextArea` |
|
|
571
|
+
| `custom` | anything | `customRender` | `formConfig.component` |
|
|
572
|
+
|
|
573
|
+
Every field type is one entry in the exported `fieldRegistry` (`lib/fields/registry.tsx`), declaring its cell render, form control, implied validation rules and recordβform value conversion in one place.
|
|
574
|
+
|
|
550
575
|
### FormConfig
|
|
551
576
|
|
|
552
577
|
| Prop | Type | Description |
|
|
@@ -588,16 +613,6 @@ Choose one approach:
|
|
|
588
613
|
}
|
|
589
614
|
```
|
|
590
615
|
|
|
591
|
-
### Legacy CrudTable Props (Original)
|
|
592
|
-
|
|
593
|
-
| Prop | Type | Description |
|
|
594
|
-
|------|------|-------------|
|
|
595
|
-
| `columns` | `CrudColumn<T>[]` | Column definitions |
|
|
596
|
-
| `service` | `CrudService<T>` | Service object with CRUD methods |
|
|
597
|
-
| `rowKey` | `keyof T` | Unique key for each row |
|
|
598
|
-
| `title` | `string` | Table header title |
|
|
599
|
-
| `defaultPageSize?` | `number` | Optional default page size (default: 5) |
|
|
600
|
-
|
|
601
616
|
---
|
|
602
617
|
|
|
603
618
|
## π Styling
|
|
@@ -614,68 +629,12 @@ Customize row striping using `.row-differentiator` in `CrudTable.css`:
|
|
|
614
629
|
|
|
615
630
|
## π Notes
|
|
616
631
|
|
|
617
|
-
- Date fields are handled via `dayjs` in the form and
|
|
632
|
+
- Date fields are handled via `dayjs` (already required by antd) in both the form and display.
|
|
618
633
|
- All requests are async with error handling via `antd`'s `message` API.
|
|
619
634
|
- Add your own export logic or additional toolbar buttons as needed.
|
|
620
635
|
|
|
621
636
|
---
|
|
622
637
|
|
|
623
|
-
## π Migration Guide
|
|
624
|
-
|
|
625
|
-
### Upgrading from Original to Experimental
|
|
626
|
-
|
|
627
|
-
**Original (Service-Based):**
|
|
628
|
-
```tsx
|
|
629
|
-
<CrudTable
|
|
630
|
-
title="Users"
|
|
631
|
-
rowKey="id"
|
|
632
|
-
service={UserService}
|
|
633
|
-
columns={columns}
|
|
634
|
-
/>
|
|
635
|
-
```
|
|
636
|
-
|
|
637
|
-
**Experimental (Hook-Based):**
|
|
638
|
-
```tsx
|
|
639
|
-
<CrudTableExperimental
|
|
640
|
-
title="Users"
|
|
641
|
-
rowKey="id"
|
|
642
|
-
hookConfig={{
|
|
643
|
-
operations: UserService, // Reuse existing service
|
|
644
|
-
// Or choose new approaches:
|
|
645
|
-
// staticData: users,
|
|
646
|
-
// api: { baseUrl: '/api' },
|
|
647
|
-
}}
|
|
648
|
-
columns={columns}
|
|
649
|
-
/>
|
|
650
|
-
```
|
|
651
|
-
|
|
652
|
-
### Breaking Changes in Experimental
|
|
653
|
-
- β
**Fully backward compatible**: Original components still work
|
|
654
|
-
- π **New import**: `CrudTableExperimental` for enhanced version
|
|
655
|
-
- ποΈ **Service β hookConfig**: More flexible configuration
|
|
656
|
-
- π **Enhanced props**: Additional optional features
|
|
657
|
-
|
|
658
|
-
### Lazy Loading Options
|
|
659
|
-
|
|
660
|
-
For better performance with code splitting:
|
|
661
|
-
|
|
662
|
-
```tsx
|
|
663
|
-
// Standard lazy loading
|
|
664
|
-
import { CrudTableLazy } from 'antd-crud-table';
|
|
665
|
-
|
|
666
|
-
// Experimental lazy loading
|
|
667
|
-
import { CrudTableExperimentalLazy } from 'antd-crud-table';
|
|
668
|
-
|
|
669
|
-
<CrudTableExperimentalLazy
|
|
670
|
-
title="Users"
|
|
671
|
-
rowKey="id"
|
|
672
|
-
hookConfig={hookConfig}
|
|
673
|
-
columns={columns}
|
|
674
|
-
/>
|
|
675
|
-
```
|
|
676
|
-
|
|
677
|
-
---
|
|
678
|
-
|
|
679
638
|
## π¨ Column Type Examples
|
|
680
639
|
|
|
681
640
|
### String Field
|