react-admin-crud-manager 1.0.10 → 1.0.11

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
@@ -53,162 +53,225 @@ Below is a complete reference of the public props accepted by this package (type
53
53
  `<Crud config={config} />`
54
54
  - `config` (object) — required. Top-level configuration object used by the CRUD page.
55
55
 
56
- Key properties of `config` (types & accepted values):
57
-
58
- - `title` string (required)
59
- - `description` — string (optional)
60
- - `buttonText` string (optional)
61
- - `fetchData` function (required)
62
- - Signature: async ({ search, rows_per_page, current_page, ...filters }) => Promise<{ data: Array, pagination?: { current_page: number, rows_per_page: number, total_pages: number, total_records: number } }>
63
- - The component expects `resp.data` (array) and optional `resp.pagination` when server-side pagination is used.
64
- - `isStaticData` boolean (default: false)
65
- - If true, add/edit/delete are applied client-side on local state instead of re-fetching.
66
- - `tableConfig` object (required) — see "Table / tableConfig" below.
67
- - `modalConfig` object — see "Modal / modalConfig" below.
68
- - `filterConfig` — object — used by the filter drawer (see Form field schema below).
56
+ #### Key properties of `config`
57
+
58
+ | Property | Type | Required | Description |
59
+ |----------|------|----------|-------------|
60
+ | `title` | string | Yes | Title of the CRUD page |
61
+ | `description` | string | No | Optional description text |
62
+ | `buttonText` | string | No | Custom text for action buttons |
63
+ | `fetchData` | function | Yes | Async function to fetch data. Signature: `async ({ search, rows_per_page, current_page, ...filters }) => Promise<{ data: Array, pagination?: { current_page: number, rows_per_page: number, total_pages: number, total_records: number } }>`. Component expects `resp.data` (array) and optional `resp.pagination` for server-side pagination. |
64
+ | `isStaticData` | boolean | No | Default: `false`. If true, add/edit/delete apply client-side instead of re-fetching |
65
+ | `tableConfig` | object | Yes | Table configuration [see tableConfig](#tableconfig-configuration) |
66
+ | `modalConfig` | object | No | Modal definitions [see modalConfig](#modalconfig-definitions) |
67
+ | `filterConfig` | object | No | Filter drawer configuration [see Form Field Schema](#form-field-schema) |
69
68
 
70
69
  ---
71
70
 
72
- ### Table / `tableConfig` (inside `config`)
73
- Type: object
74
-
75
- Common keys:
76
- - `table_head` array of column objects (required)
77
- - `data` — array — rows shown in the table
78
- - `loading` booleanshow skeleton when true
79
- - `search` object: { enabled?: boolean, placeholder?: string, useServerSideSearch?: boolean, searchKeys?: string[] }
80
- - `filter` object: { enabled?: boolean, useServerSideFilters?: boolean }
81
- - `pagination` object: { enabled?: boolean, rows_per_page?: number, useServerSidePagination?: boolean, current_page?: number, total_pages?: number, total_records?: number }
82
- - `emptyMessage` string message when no rows
83
- - `onMenuAction` function(actionType: string, item: object)
84
- - `setServerSidePaginationData` function used to update server-side pagination/search state
85
- - `onFilterApply` function(filters: object)
86
- - `filterConfig` object (fields array) rendered in the FilterDrawer
87
-
88
- Table column object (`table_head[]`) accepted keys:
89
- - `key` — string (required) — property name in row objects
90
- - `title` string — column header
91
- - `type` — string — accepted values: (plain default) | `index` | `group` | `chip` | `date` | `avatar` | `menu_actions`
92
- - `imageKey`, `titleKey`, `subtitleKey` string used by `group`/`avatar` types
93
- - `onClickDetails` — boolean — if true clicking the cell triggers a view action
94
- - `variant` string used for chips (`contained` | `outline` | `soft`)
95
- - `chipOptions` array of { value: string|number|boolean, label: string, color?: string }
96
- - `defaultColor` string default chip color key (e.g., `green`)
97
- - `className` string custom class for cell
98
- - `format` string date format (e.g. `DD MMM YYYY`)
99
- - `menuList` array of menu action objects: { title: string, type: string, variant?: string, icon?: ReactNode }
100
- - `render` function(row, rowIndex) custom renderer; if present it overrides built-in renderers
71
+ ### tableConfig Configuration
72
+
73
+ #### Table Configuration Keys
74
+
75
+ | Key | Type | Required | Description |
76
+ |-----|------|----------|-------------|
77
+ | `table_head` | array of column objects | Yes | Column definitions [see Table column object](#table-column-object-table_head) |
78
+ | `data` | array | No | Rows shown in the table |
79
+ | `loading` | boolean | No | Show skeleton loader when true |
80
+ | `search` | object | No | `{ enabled?: boolean, placeholder?: string, useServerSideSearch?: boolean, searchKeys?: string[] }` |
81
+ | `filter` | object | No | `{ enabled?: boolean, useServerSideFilters?: boolean }` |
82
+ | `pagination` | object | No | `{ enabled?: boolean, rows_per_page?: number, useServerSidePagination?: boolean, current_page?: number, total_pages?: number, total_records?: number }` |
83
+ | `emptyMessage` | string | No | Message shown when table has no rows |
84
+ | `onMenuAction` | function | No | Callback: `(actionType: string, item: object)` |
85
+ | `setServerSidePaginationData` | function | No | Used to update server-side pagination/search state |
86
+ | `onFilterApply` | function | No | Callback: `(filters: object)` |
87
+ | `filterConfig` | object | No | Fields array rendered in the FilterDrawer |
88
+
89
+ #### Table Column Object (`table_head[]`)
90
+
91
+ | Key | Type | Required | Description |
92
+ |-----|------|----------|-------------|
93
+ | `key` | string | Yes | Property name in row objects |
94
+ | `title` | string | No | Column header text |
95
+ | `type` | string | No | Column type: `plain` (default), `index`, `group`, `chip`, `date`, `avatar`, `menu_actions` |
96
+ | `imageKey` | string | No | Used with `group`/`avatar` types |
97
+ | `titleKey` | string | No | Used with `group`/`avatar` types |
98
+ | `subtitleKey` | string | No | Used with `group`/`avatar` types |
99
+ | `onClickDetails` | boolean | No | If true, clicking cell triggers view action |
100
+ | `variant` | string | No | For chips: `contained`, `outline`, `soft` |
101
+ | `chipOptions` | array | No | Array of `{ value: string|number|boolean, label: string, color?: string }` |
102
+ | `defaultColor` | string | No | Default chip color key (e.g., `green`) |
103
+ | `className` | string | No | Custom CSS class for cell |
104
+ | `format` | string | No | Date format (e.g., `DD MMM YYYY`) |
105
+ | `menuList` | array | No | Menu action objects: `{ title, type, variant?, icon? }` |
106
+ | `render` | function | No | Custom renderer: `(row, rowIndex) => ReactNode`. Overrides built-in renderers |
101
107
 
102
108
  ---
103
109
 
104
- ### Modal / `modalConfig`
105
- `modalConfig` groups modal definitions used by the CRUD page.
106
-
107
- Common modal shapes:
108
- - `addModal`, `editModal` (object)
109
- - `title` — string (required)
110
- - `size` string (`sm` | `md` | `lg` | `xl` | `full`) (default `md`)
111
- - `formClass` string (optional)
112
- - `formFields` array of form-field objects (see Form schema)
113
- - `handleSubmit` function(formData) required; should perform API call and return an object used by the parent (see notes)
114
- - `actionButtons` array of actionButton objects ({ type, label, color, variant, onClick, disabled, className })
115
-
116
- - `deleteModal` (object)
117
- - `title` — string
118
- - `size` — string
119
- - `confirmText` string
120
- - `referenceKey` — string — key of selectedItem to show as reference in delete dialog
121
- - `action` function(selectedItem) function called to perform delete (should return a response used by the parent)
122
- - `actionButtons` array of actionButton objects
123
-
124
- - `viewModal` (object)
125
- - `title` string (required)
126
- - `size` string
127
- - `component` — React component (elementType) — optional, receives `data` prop when provided
128
- - `fields` array of view-field objects (see View fields below)
129
- - `footer` — { cancelButton?: boolean, cancelText?: string }
130
-
131
- Notes on modal handlers (expected response shapes):
132
- - `addModal.handleSubmit` should return an object containing `newObject` (the created row) so Crud can insert it into the list when `isStaticData` is true or refresh server-side listing.
133
- - `editModal.handleSubmit` should return `{ newObject, targetObject }` where `targetObject` identifies which row was updated.
134
- - `deleteModal.action` should return an object containing `targetObject` (the deleted row) or an appropriate success response.
110
+ ### modalConfig Definitions
111
+
112
+ #### Add & Edit Modal (`addModal`, `editModal`)
113
+
114
+ | Property | Type | Required | Description |
115
+ |----------|------|----------|-------------|
116
+ | `title` | string | Yes | Modal title |
117
+ | `size` | string | No | Modal size: `sm`, `md` (default), `lg`, `xl`, `full` |
118
+ | `formClass` | string | No | Custom CSS class for form |
119
+ | `formFields` | array | Yes | Form field objects [see Form Field Schema](#form-field-schema) |
120
+ | `handleSubmit` | function | Yes | Async callback: `(formData) => Promise<{ newObject, targetObject? }>`. For add: return `{ newObject }`. For edit: return `{ newObject, targetObject }` |
121
+ | `actionButtons` | array | No | Action button objects: `[{ type, label, color, variant, onClick, disabled, className }]` |
122
+
123
+ #### Delete Modal (`deleteModal`)
124
+
125
+ | Property | Type | Required | Description |
126
+ |----------|------|----------|-------------|
127
+ | `title` | string | No | Modal title |
128
+ | `size` | string | No | Modal size: `sm`, `md` (default), `lg`, `xl`, `full` |
129
+ | `confirmText` | string | No | Confirmation message text |
130
+ | `referenceKey` | string | No | Property key of selectedItem to display as reference |
131
+ | `action` | function | Yes | Async callback: `(selectedItem) => Promise<{ targetObject }>`. Should return the deleted row |
132
+ | `actionButtons` | array | No | Action button objects: `[{ type, label, color, variant, onClick, disabled, className }]` |
133
+
134
+ #### View Modal (`viewModal`)
135
+
136
+ | Property | Type | Required | Description |
137
+ |----------|------|----------|-------------|
138
+ | `title` | string | Yes | Modal title |
139
+ | `size` | string | No | Modal size: `sm`, `md` (default), `lg`, `xl`, `full` |
140
+ | `component` | React component | No | Custom component to render. Receives `data` prop with row data |
141
+ | `fields` | array | No | View field objects for displaying data |
142
+ | `footer` | object | No | `{ cancelButton?: boolean, cancelText?: string }` |
135
143
 
136
144
  ---
137
145
 
138
- ### Form / Form fields (used by `modalConfig.*.formFields` and `filterConfig.fields`)
139
- Form fields follow the `formFieldType` shape used throughout the UI. Each field is an object with these keys:
140
-
141
- Common field keys (all field types):
142
- - `key` string (required) — the property name for form data
143
- - `label` — string — human-readable label
144
- - `type` string (required) accepted values:
145
- - `text` (default input), `number`, `email`, `password`, `select`, `checkbox`, `switch`, `phone`, `textarea`, `image`, `tinyEditor`
146
- - `required` boolean
147
- - `minLength` number
148
- - `parentClass` string grid class (e.g. `col-span-6`)
149
- - `placeholder` string
150
- - `disabled` boolean
151
-
152
- Type-specific keys:
153
- - select
154
- - `options` — array of { value: string|number|boolean, label: string }
155
- - `multiple` — boolean — allow multiple selection
156
- - `search` — boolean — show search inside dropdown
157
- - `dropdownMaxHeight` — string (CSS height value)
158
- - checkbox
159
- - `options` array of { value, label }
160
- - `multiple` — boolean — when true allows selecting multiple values (component prop `multiSelect`)
161
- - switch
162
- - `options` optional array of radio-like options [{ label, value }]
163
- - `text` optional description text shown next to the switch
164
- - phone
165
- - `countriesList` — boolean — show country selector
166
- - `defaultCountry` — string (ISO country code like `US`)
167
- - `search` — boolean — enable searching countries
168
- - `placeholder` string
169
- - textarea
170
- - `rows` number
171
- - image
172
- - `accept` — string (default: `image/*`)
173
- - `dragDrop` — boolean
174
- - tinyEditor
175
- - `editorKey` string (TinyMCE api key)
176
- - `fontFamily` — string
177
- - `height` — number
178
- - `imageUploadHandler` function(blobInfo) => Promise<string> (returns URL)
179
-
180
- Return values / onSubmit handlers
181
- - `onSubmit(formData)` receives an object keyed by `field.key` values.
146
+ ### Form Field Schema
147
+
148
+ Used by `modalConfig.*.formFields` and `filterConfig.fields`. Form fields follow the `formFieldType` shape used throughout the UI.
149
+
150
+ #### Common Field Keys (All Types)
151
+
152
+ | Key | Type | Required | Description |
153
+ |-----|------|----------|-------------|
154
+ | `key` | string | Yes | Property name for form data |
155
+ | `label` | string | No | Human-readable label |
156
+ | `type` | string | Yes | Field type: `text`, `number`, `email`, `password`, `select`, `checkbox`, `switch`, `phone`, `textarea`, `image`, `tinyEditor` |
157
+ | `required` | boolean | No | Field is required for form submission |
158
+ | `minLength` | number | No | Minimum character length |
159
+ | `parentClass` | string | No | Tailwind grid class (e.g., `col-span-6`) |
160
+ | `placeholder` | string | No | Placeholder text |
161
+ | `disabled` | boolean | No | Field is disabled |
162
+
163
+ #### Type-Specific Keys
164
+
165
+ ##### Select Field
166
+
167
+ | Key | Type | Description |
168
+ |-----|------|-------------|
169
+ | `options` | array | `{ value: string|number|boolean, label: string }[]` |
170
+ | `multiple` | boolean | Allow multiple selections |
171
+ | `search` | boolean | Show search input inside dropdown |
172
+ | `dropdownMaxHeight` | string | CSS height value (e.g., `300px`) |
173
+
174
+ ##### Checkbox Field
175
+
176
+ | Key | Type | Description |
177
+ |-----|------|-------------|
178
+ | `options` | array | `{ value, label }[]` |
179
+ | `multiple` | boolean | Allow selecting multiple values (component prop: `multiSelect`) |
180
+
181
+ ##### Switch Field
182
+
183
+ | Key | Type | Description |
184
+ |-----|------|-------------|
185
+ | `options` | array | Optional radio-like options: `[{ label, value }]` |
186
+ | `text` | string | Description text shown next to switch |
187
+
188
+ ##### Phone Field
189
+
190
+ | Key | Type | Description |
191
+ |-----|------|-------------|
192
+ | `countriesList` | boolean | Show country selector |
193
+ | `defaultCountry` | string | ISO country code (e.g., `US`) |
194
+ | `search` | boolean | Enable searching countries |
195
+ | `placeholder` | string | Placeholder text |
196
+
197
+ ##### Textarea Field
198
+
199
+ | Key | Type | Description |
200
+ |-----|------|-------------|
201
+ | `rows` | number | Number of visible rows |
202
+
203
+ ##### Image Field
204
+
205
+ | Key | Type | Description |
206
+ |-----|------|-------------|
207
+ | `accept` | string | MIME type filter (default: `image/*`) |
208
+ | `dragDrop` | boolean | Enable drag-and-drop upload |
209
+
210
+ ##### TinyEditor Field
211
+
212
+ | Key | Type | Description |
213
+ |-----|------|-------------|
214
+ | `editorKey` | string | TinyMCE API key |
215
+ | `fontFamily` | string | Default font family |
216
+ | `height` | number | Editor height in pixels |
217
+ | `imageUploadHandler` | function | `(blobInfo) => Promise<string>`. Returns image URL |
218
+
219
+ #### Return Values / onSubmit Handler
220
+
221
+ `onSubmit(formData)` receives an object keyed by `field.key` values.
182
222
 
183
223
  ---
184
224
 
185
225
  ### Small/UI components (props summary)
186
- - `Button` props
187
- - `variant` `contained` | `outlined` | `text` (default `contained`)
188
- - `color` — `primary` | `success` | `error` | `default`
189
- - `size` `sm` | `md` | `lg` | `xl` | `default`
190
- - `fullWidth` boolean
191
- - `className`, `onClick`, `type`, `disabled` (standard button props)
192
-
193
- - `Chip` props
194
- - `label` — string (required)
195
- - `variant` — `contained` | `outline` | `soft` (default `contained`)
196
- - `color` — `blue` | `teal` | `purple` | `yellow` | `green` | `red` | `gray`
197
-
198
- - `Modal` props (when used directly)
199
- - `isOpen` boolean
200
- - `onClose` function
201
- - `icon` React node
202
- - `title` — string
203
- - `size` `sm` | `md` | `lg` | `xl` | `full`
204
- - `actionButtons` array of { type, label, color, variant, onClick, disabled }
205
- - `loadingBtn` boolean
206
-
207
- - `FilterDrawer` props
208
- - `isOpen` — boolean
209
- - `onClose` function
210
- - `config` — object (fields array — same `formFieldType`)
211
- - `onApply` function(filters: object)
226
+
227
+ | Component | Key Props | Purpose |
228
+ |-----------|-----------|----------|
229
+ | **Button** | `variant`, `color`, `size`, `fullWidth`, `className`, `onClick`, `type`, `disabled` | Reusable button with multiple style variants (`contained`, `outlined`, `text`) and colors |
230
+ | **Chip** | `label`, `variant`, `color` | Display small labeled badges with `contained`, `outline`, or `soft` styles |
231
+ | **Modal** | `isOpen`, `onClose`, `icon`, `title`, `size`, `actionButtons`, `loadingBtn` | Modal dialog for forms, confirmations, and views with flexible sizing |
232
+ | **FilterDrawer** | `isOpen`, `onClose`, `config`, `onApply` | Side panel for applying filters with customizable form fields |
233
+
234
+ #### Button Props
235
+
236
+ | Prop | Type | Default | Description |
237
+ |------|------|---------|-------------|
238
+ | `variant` | string | `contained` | Style variant: `contained`, `outlined`, `text` |
239
+ | `color` | string | `primary` | Color: `primary`, `success`, `error`, `default` |
240
+ | `size` | string | `default` | Size: `sm`, `md`, `lg`, `xl`, `default` |
241
+ | `fullWidth` | boolean | `false` | Stretch button to full width |
242
+ | `className` | string | | Custom CSS class |
243
+ | `onClick` | function | | Click event handler |
244
+ | `type` | string | `button` | HTML button type: `button`, `submit`, `reset` |
245
+ | `disabled` | boolean | `false` | Disable button interaction |
246
+
247
+ #### Chip Props
248
+
249
+ | Prop | Type | Default | Description |
250
+ |------|------|---------|-------------|
251
+ | `label` | string | Required | Badge text |
252
+ | `variant` | string | `contained` | Style variant: `contained`, `outline`, `soft` |
253
+ | `color` | string | `blue` | Color: `blue`, `teal`, `purple`, `yellow`, `green`, `red`, `gray` |
254
+
255
+ #### Modal Props (Direct Usage)
256
+
257
+ | Prop | Type | Description |
258
+ |------|------|-------------|
259
+ | `isOpen` | boolean | Show/hide modal |
260
+ | `onClose` | function | Callback when modal closes |
261
+ | `icon` | React node | Icon element displayed in modal header |
262
+ | `title` | string | Modal title |
263
+ | `size` | string | Size: `sm`, `md`, `lg`, `xl`, `full` |
264
+ | `actionButtons` | array | `[{ type, label, color, variant, onClick, disabled }]` |
265
+ | `loadingBtn` | boolean | Show loading state on action button |
266
+
267
+ #### FilterDrawer Props
268
+
269
+ | Prop | Type | Description |
270
+ |------|------|-------------|
271
+ | `isOpen` | boolean | Show/hide filter drawer |
272
+ | `onClose` | function | Callback when drawer closes |
273
+ | `config` | object | Fields array using `formFieldType` schema |
274
+ | `onApply` | function | Callback: `(filters: object) => void` |
212
275
 
213
276
  ---
214
277
 
@@ -241,8 +304,5 @@ const fetchData = async ({ search, rows_per_page, current_page }) => {
241
304
 
242
305
  ---
243
306
 
244
- If you want me to add a TypeScript declaration snippet or a props table per component (or to document `table_head` examples), tell me which parts to expand and I will add them. ✅
245
-
246
-
247
307
  ## License
248
308
  MIT