@bomjan133/react-crud-ui 1.2.5 → 1.2.6

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.
@@ -1,333 +1,333 @@
1
- # Getting Started with @sujanbomjan/react-crud-ui
2
-
3
- A comprehensive React CRUD and UI component library with Zustand store integration.
4
-
5
- ## Table of Contents
6
- 1. [Installation](#installation)
7
- 2. [Quick Setup](#quick-setup)
8
- 3. [Project Structure](#project-structure)
9
- 4. [Creating Your First CRUD Module](#creating-your-first-crud-module)
10
-
11
- ---
12
-
13
- ## Installation
14
-
15
- ```bash
16
- npm install @sujanbomjan/react-crud-ui
17
- # or
18
- yarn add @sujanbomjan/react-crud-ui
19
- # or
20
- pnpm add @sujanbomjan/react-crud-ui
21
- ```
22
-
23
- ### Peer Dependencies
24
-
25
- Make sure you have these peer dependencies installed:
26
-
27
- ```bash
28
- npm install react react-dom react-router-dom zustand axios
29
- ```
30
-
31
- ---
32
-
33
- ## Quick Setup
34
-
35
- ### 1. Import Styles
36
-
37
- Add the styles to your main entry file (e.g., `main.jsx` or `App.jsx`):
38
-
39
- ```jsx
40
- import '@sujanbomjan/react-crud-ui/styles.css'
41
- ```
42
-
43
- ### 2. Configure Tailwind v4 (Optional)
44
-
45
- If you're using Tailwind CSS v4 in your project:
46
-
47
- **index.css:**
48
- ```css
49
- @import "tailwindcss";
50
-
51
- @theme {
52
- /* Light theme - Clean white/gray palette */
53
- --color-background: #ffffff;
54
- --color-foreground: #09090b;
55
- --color-card: #ffffff;
56
- --color-card-foreground: #09090b;
57
- --color-popover: #ffffff;
58
- --color-popover-foreground: #09090b;
59
- --color-primary: #000000;
60
- --color-primary-foreground: #fef2f2;
61
- --color-secondary: #f4f4f5;
62
- --color-secondary-foreground: #18181b;
63
- --color-muted: #f4f4f5;
64
- --color-muted-foreground: #71717a;
65
- --color-accent: #f4f4f5;
66
- --color-accent-foreground: #18181b;
67
- --color-destructive: #ef4444;
68
- --color-destructive-foreground: #fafafa;
69
- --color-border: #e4e4e7;
70
- --color-input: #e4e4e7;
71
- --color-ring: #000000;
72
-
73
- /* Sidebar specific */
74
- --color-sidebar: #fafafa;
75
- --color-sidebar-foreground: #3f3f46;
76
- --color-sidebar-primary: #000000;
77
- --color-sidebar-primary-foreground: #fafafa;
78
- --color-sidebar-accent: #f4f4f5;
79
- --color-sidebar-accent-foreground: #18181b;
80
- --color-sidebar-border: #e5e7eb;
81
-
82
- /* Border radius */
83
- --radius-sm: 0.25rem;
84
- --radius-md: 0.375rem;
85
- --radius-lg: 0.5rem;
86
- }
87
- ```
88
-
89
- ### 3. Set up API Client
90
-
91
- Create an axios client for API calls:
92
-
93
- **src/lib/apiClient.js:**
94
- ```js
95
- import axios from 'axios';
96
-
97
- const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000/api/v1';
98
-
99
- const apiClient = axios.create({
100
- baseURL: API_BASE_URL,
101
- headers: { 'Content-Type': 'application/json' },
102
- });
103
-
104
- // Add auth token to requests
105
- apiClient.interceptors.request.use((config) => {
106
- const token = localStorage.getItem('auth_token');
107
- if (token) {
108
- config.headers.Authorization = `Bearer ${token}`;
109
- }
110
- return config;
111
- });
112
-
113
- // Handle auth errors
114
- apiClient.interceptors.response.use(
115
- (response) => response,
116
- (error) => {
117
- if (error.response?.status === 401) {
118
- localStorage.removeItem('auth_token');
119
- window.location.href = '/login';
120
- }
121
- return Promise.reject({
122
- message: error.response?.data?.error || error.message,
123
- status: error.response?.status,
124
- data: error.response?.data,
125
- });
126
- }
127
- );
128
-
129
- export default apiClient;
130
- ```
131
-
132
- ---
133
-
134
- ## Project Structure
135
-
136
- Recommended project structure when using this package:
137
-
138
- ```
139
- src/
140
- ├── App.jsx # Main app component
141
- ├── main.jsx # Entry point
142
- ├── index.css # Global styles (Tailwind)
143
- │
144
- ├── pages/ # Page components (by module)
145
- │ ├── auth/
146
- │ │ └── LoginPage.jsx
147
- │ ├── dashboard/
148
- │ │ └── DashboardPage.jsx
149
- │ ├── users/
150
- │ │ ├── UserListPage.jsx
151
- │ │ ├── UserFormPage.jsx
152
- │ │ └── UserDetailPage.jsx
153
- │ └── products/
154
- │ ├── ProductListPage.jsx
155
- │ ├── ProductFormPage.jsx
156
- │ └── ProductDetailPage.jsx
157
- │
158
- ├── routes/
159
- │ ├── index.jsx # Main router
160
- │ ├── guards.jsx # Protected/Public route guards
161
- │ └── modules/
162
- │ ├── userRoutes.js
163
- │ └── productRoutes.js
164
- │
165
- ├── stores/
166
- │ ├── createCrudStore.js # Import from package or customize
167
- │ ├── useAuthStore.js # Auth state
168
- │ ├── useUIStore.js # UI state (toasts, modals, sidebar)
169
- │ ├── useUserStore.js
170
- │ └── useProductStore.js
171
- │
172
- ├── components/
173
- │ └── layouts/
174
- │ ├── MainLayout.jsx # Uses DashboardLayout from package
175
- │ └── AuthLayout.jsx # Uses AuthLayout from package
176
- │
177
- ├── hooks/
178
- │ └── useUI.js # Toast, modal, sidebar hooks
179
- │
180
- └── lib/
181
- ├── apiClient.js # Axios instance
182
- └── utils.js # Utility functions
183
- ```
184
-
185
- ---
186
-
187
- ## Creating Your First CRUD Module
188
-
189
- ### Method 1: Using the CLI (Recommended)
190
-
191
- ```bash
192
- npx @sujanbomjan/react-crud-ui generate product
193
- ```
194
-
195
- This creates:
196
- - `src/pages/products/ProductListPage.jsx`
197
- - `src/pages/products/ProductFormPage.jsx`
198
- - `src/pages/products/ProductDetailPage.jsx`
199
- - `src/routes/modules/productRoutes.js`
200
- - `src/stores/useProductStore.js`
201
-
202
- ### Method 2: Manual Setup
203
-
204
- **1. Create the Store:**
205
-
206
- ```js
207
- // src/stores/useProductStore.js
208
- import { createCrudStore } from '@sujanbomjan/react-crud-ui';
209
-
210
- const defaultFormValues = {
211
- name: '',
212
- description: '',
213
- price: 0,
214
- is_active: true,
215
- };
216
-
217
- const useProductStore = createCrudStore('product', '/products/', defaultFormValues);
218
-
219
- export default useProductStore;
220
- ```
221
-
222
- **2. Create the List Page:**
223
-
224
- ```jsx
225
- // src/pages/products/ProductListPage.jsx
226
- import { CrudList, Badge } from '@sujanbomjan/react-crud-ui';
227
- import useProductStore from '@/stores/useProductStore';
228
-
229
- const columns = [
230
- { key: 'name', label: 'Name', sortable: true },
231
- { key: 'price', label: 'Price', render: (v) => `$${v}` },
232
- {
233
- key: 'is_active',
234
- label: 'Status',
235
- render: (v) => <Badge variant={v ? 'success' : 'secondary'}>{v ? 'Active' : 'Inactive'}</Badge>,
236
- },
237
- ];
238
-
239
- export default function ProductListPage() {
240
- const store = useProductStore();
241
-
242
- return (
243
- <CrudList
244
- title="Products"
245
- description="Manage products"
246
- createPath="/products/create"
247
- editPath="/products"
248
- store={store}
249
- columns={columns}
250
- searchPlaceholder="Search products..."
251
- getDeleteItemName={(item) => item?.name}
252
- />
253
- );
254
- }
255
- ```
256
-
257
- **3. Create the Form Page:**
258
-
259
- ```jsx
260
- // src/pages/products/ProductFormPage.jsx
261
- import { Box } from 'lucide-react';
262
- import { CrudForm, QInput, QTextarea, QSwitch } from '@sujanbomjan/react-crud-ui';
263
- import useProductStore from '@/stores/useProductStore';
264
-
265
- export default function ProductFormPage() {
266
- const { form, setFormField } = useProductStore();
267
-
268
- return (
269
- <CrudForm
270
- title="Product"
271
- description="Enter product information"
272
- icon={Box}
273
- listPath="/products"
274
- useStore={useProductStore}
275
- >
276
- <QInput
277
- name="name"
278
- label="Name"
279
- value={form.values.name || ''}
280
- onChange={(val) => setFormField('name', val)}
281
- error={form.errors.name}
282
- placeholder="Enter name"
283
- required
284
- />
285
- <QTextarea
286
- name="description"
287
- label="Description"
288
- value={form.values.description || ''}
289
- onChange={(val) => setFormField('description', val)}
290
- rows={4}
291
- />
292
- <QInput
293
- name="price"
294
- label="Price"
295
- type="number"
296
- value={form.values.price || 0}
297
- onChange={(val) => setFormField('price', parseFloat(val))}
298
- />
299
- <QSwitch
300
- label="Active"
301
- checked={form.values.is_active ?? true}
302
- onChange={(val) => setFormField('is_active', val)}
303
- />
304
- </CrudForm>
305
- );
306
- }
307
- ```
308
-
309
- **4. Create Routes:**
310
-
311
- ```jsx
312
- // src/routes/modules/productRoutes.js
313
- import ProductListPage from '@/pages/products/ProductListPage';
314
- import ProductFormPage from '@/pages/products/ProductFormPage';
315
-
316
- const productRoutes = [
317
- { path: '/products', element: <ProductListPage /> },
318
- { path: '/products/create', element: <ProductFormPage /> },
319
- { path: '/products/:id/edit', element: <ProductFormPage /> },
320
- ];
321
-
322
- export default productRoutes;
323
- ```
324
-
325
- ---
326
-
327
- ## Next Steps
328
-
329
- - [UI Components Guide](./2_UI_COMPONENTS.md) - Learn about all available UI components
330
- - [CRUD Components Guide](./3_CRUD_COMPONENTS.md) - Deep dive into CRUD components
331
- - [Form Components Guide](./4_FORM_COMPONENTS.md) - Form fields and validation
332
- - [Layout Components Guide](./5_LAYOUT_COMPONENTS.md) - Dashboard and Auth layouts
333
- - [Store Factory Guide](./6_STORE_FACTORY.md) - Creating and customizing stores
1
+ # Getting Started with @bomjan133/react-crud-ui
2
+
3
+ A comprehensive React CRUD and UI component library with Zustand store integration.
4
+
5
+ ## Table of Contents
6
+ 1. [Installation](#installation)
7
+ 2. [Quick Setup](#quick-setup)
8
+ 3. [Project Structure](#project-structure)
9
+ 4. [Creating Your First CRUD Module](#creating-your-first-crud-module)
10
+
11
+ ---
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install @bomjan133/react-crud-ui
17
+ # or
18
+ yarn add @bomjan133/react-crud-ui
19
+ # or
20
+ pnpm add @bomjan133/react-crud-ui
21
+ ```
22
+
23
+ ### Peer Dependencies
24
+
25
+ Make sure you have these peer dependencies installed:
26
+
27
+ ```bash
28
+ npm install react react-dom react-router-dom zustand axios
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Quick Setup
34
+
35
+ ### 1. Import Styles
36
+
37
+ Add the styles to your main entry file (e.g., `main.jsx` or `App.jsx`):
38
+
39
+ ```jsx
40
+ import '@bomjan133/react-crud-ui/styles.css'
41
+ ```
42
+
43
+ ### 2. Configure Tailwind v4 (Optional)
44
+
45
+ If you're using Tailwind CSS v4 in your project:
46
+
47
+ **index.css:**
48
+ ```css
49
+ @import "tailwindcss";
50
+
51
+ @theme {
52
+ /* Light theme - Clean white/gray palette */
53
+ --color-background: #ffffff;
54
+ --color-foreground: #09090b;
55
+ --color-card: #ffffff;
56
+ --color-card-foreground: #09090b;
57
+ --color-popover: #ffffff;
58
+ --color-popover-foreground: #09090b;
59
+ --color-primary: #000000;
60
+ --color-primary-foreground: #fef2f2;
61
+ --color-secondary: #f4f4f5;
62
+ --color-secondary-foreground: #18181b;
63
+ --color-muted: #f4f4f5;
64
+ --color-muted-foreground: #71717a;
65
+ --color-accent: #f4f4f5;
66
+ --color-accent-foreground: #18181b;
67
+ --color-destructive: #ef4444;
68
+ --color-destructive-foreground: #fafafa;
69
+ --color-border: #e4e4e7;
70
+ --color-input: #e4e4e7;
71
+ --color-ring: #000000;
72
+
73
+ /* Sidebar specific */
74
+ --color-sidebar: #fafafa;
75
+ --color-sidebar-foreground: #3f3f46;
76
+ --color-sidebar-primary: #000000;
77
+ --color-sidebar-primary-foreground: #fafafa;
78
+ --color-sidebar-accent: #f4f4f5;
79
+ --color-sidebar-accent-foreground: #18181b;
80
+ --color-sidebar-border: #e5e7eb;
81
+
82
+ /* Border radius */
83
+ --radius-sm: 0.25rem;
84
+ --radius-md: 0.375rem;
85
+ --radius-lg: 0.5rem;
86
+ }
87
+ ```
88
+
89
+ ### 3. Set up API Client
90
+
91
+ Create an axios client for API calls:
92
+
93
+ **src/lib/apiClient.js:**
94
+ ```js
95
+ import axios from 'axios';
96
+
97
+ const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000/api/v1';
98
+
99
+ const apiClient = axios.create({
100
+ baseURL: API_BASE_URL,
101
+ headers: { 'Content-Type': 'application/json' },
102
+ });
103
+
104
+ // Add auth token to requests
105
+ apiClient.interceptors.request.use((config) => {
106
+ const token = localStorage.getItem('auth_token');
107
+ if (token) {
108
+ config.headers.Authorization = `Bearer ${token}`;
109
+ }
110
+ return config;
111
+ });
112
+
113
+ // Handle auth errors
114
+ apiClient.interceptors.response.use(
115
+ (response) => response,
116
+ (error) => {
117
+ if (error.response?.status === 401) {
118
+ localStorage.removeItem('auth_token');
119
+ window.location.href = '/login';
120
+ }
121
+ return Promise.reject({
122
+ message: error.response?.data?.error || error.message,
123
+ status: error.response?.status,
124
+ data: error.response?.data,
125
+ });
126
+ }
127
+ );
128
+
129
+ export default apiClient;
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Project Structure
135
+
136
+ Recommended project structure when using this package:
137
+
138
+ ```
139
+ src/
140
+ ├── App.jsx # Main app component
141
+ ├── main.jsx # Entry point
142
+ ├── index.css # Global styles (Tailwind)
143
+ │
144
+ ├── pages/ # Page components (by module)
145
+ │ ├── auth/
146
+ │ │ └── LoginPage.jsx
147
+ │ ├── dashboard/
148
+ │ │ └── DashboardPage.jsx
149
+ │ ├── users/
150
+ │ │ ├── UserListPage.jsx
151
+ │ │ ├── UserFormPage.jsx
152
+ │ │ └── UserDetailPage.jsx
153
+ │ └── products/
154
+ │ ├── ProductListPage.jsx
155
+ │ ├── ProductFormPage.jsx
156
+ │ └── ProductDetailPage.jsx
157
+ │
158
+ ├── routes/
159
+ │ ├── index.jsx # Main router
160
+ │ ├── guards.jsx # Protected/Public route guards
161
+ │ └── modules/
162
+ │ ├── userRoutes.js
163
+ │ └── productRoutes.js
164
+ │
165
+ ├── stores/
166
+ │ ├── createCrudStore.js # Import from package or customize
167
+ │ ├── useAuthStore.js # Auth state
168
+ │ ├── useUIStore.js # UI state (toasts, modals, sidebar)
169
+ │ ├── useUserStore.js
170
+ │ └── useProductStore.js
171
+ │
172
+ ├── components/
173
+ │ └── layouts/
174
+ │ ├── MainLayout.jsx # Uses DashboardLayout from package
175
+ │ └── AuthLayout.jsx # Uses AuthLayout from package
176
+ │
177
+ ├── hooks/
178
+ │ └── useUI.js # Toast, modal, sidebar hooks
179
+ │
180
+ └── lib/
181
+ ├── apiClient.js # Axios instance
182
+ └── utils.js # Utility functions
183
+ ```
184
+
185
+ ---
186
+
187
+ ## Creating Your First CRUD Module
188
+
189
+ ### Method 1: Using the CLI (Recommended)
190
+
191
+ ```bash
192
+ npx @bomjan133/react-crud-ui generate product
193
+ ```
194
+
195
+ This creates:
196
+ - `src/pages/products/ProductListPage.jsx`
197
+ - `src/pages/products/ProductFormPage.jsx`
198
+ - `src/pages/products/ProductDetailPage.jsx`
199
+ - `src/routes/modules/productRoutes.js`
200
+ - `src/stores/useProductStore.js`
201
+
202
+ ### Method 2: Manual Setup
203
+
204
+ **1. Create the Store:**
205
+
206
+ ```js
207
+ // src/stores/useProductStore.js
208
+ import { createCrudStore } from '@bomjan133/react-crud-ui';
209
+
210
+ const defaultFormValues = {
211
+ name: '',
212
+ description: '',
213
+ price: 0,
214
+ is_active: true,
215
+ };
216
+
217
+ const useProductStore = createCrudStore('product', '/products/', defaultFormValues);
218
+
219
+ export default useProductStore;
220
+ ```
221
+
222
+ **2. Create the List Page:**
223
+
224
+ ```jsx
225
+ // src/pages/products/ProductListPage.jsx
226
+ import { CrudList, Badge } from '@bomjan133/react-crud-ui';
227
+ import useProductStore from '@/stores/useProductStore';
228
+
229
+ const columns = [
230
+ { key: 'name', label: 'Name', sortable: true },
231
+ { key: 'price', label: 'Price', render: (v) => `$${v}` },
232
+ {
233
+ key: 'is_active',
234
+ label: 'Status',
235
+ render: (v) => <Badge variant={v ? 'success' : 'secondary'}>{v ? 'Active' : 'Inactive'}</Badge>,
236
+ },
237
+ ];
238
+
239
+ export default function ProductListPage() {
240
+ const store = useProductStore();
241
+
242
+ return (
243
+ <CrudList
244
+ title="Products"
245
+ description="Manage products"
246
+ createPath="/products/create"
247
+ editPath="/products"
248
+ store={store}
249
+ columns={columns}
250
+ searchPlaceholder="Search products..."
251
+ getDeleteItemName={(item) => item?.name}
252
+ />
253
+ );
254
+ }
255
+ ```
256
+
257
+ **3. Create the Form Page:**
258
+
259
+ ```jsx
260
+ // src/pages/products/ProductFormPage.jsx
261
+ import { Box } from 'lucide-react';
262
+ import { CrudForm, QInput, QTextarea, QSwitch } from '@bomjan133/react-crud-ui';
263
+ import useProductStore from '@/stores/useProductStore';
264
+
265
+ export default function ProductFormPage() {
266
+ const { form, setFormField } = useProductStore();
267
+
268
+ return (
269
+ <CrudForm
270
+ title="Product"
271
+ description="Enter product information"
272
+ icon={Box}
273
+ listPath="/products"
274
+ useStore={useProductStore}
275
+ >
276
+ <QInput
277
+ name="name"
278
+ label="Name"
279
+ value={form.values.name || ''}
280
+ onChange={(val) => setFormField('name', val)}
281
+ error={form.errors.name}
282
+ placeholder="Enter name"
283
+ required
284
+ />
285
+ <QTextarea
286
+ name="description"
287
+ label="Description"
288
+ value={form.values.description || ''}
289
+ onChange={(val) => setFormField('description', val)}
290
+ rows={4}
291
+ />
292
+ <QInput
293
+ name="price"
294
+ label="Price"
295
+ type="number"
296
+ value={form.values.price || 0}
297
+ onChange={(val) => setFormField('price', parseFloat(val))}
298
+ />
299
+ <QSwitch
300
+ label="Active"
301
+ checked={form.values.is_active ?? true}
302
+ onChange={(val) => setFormField('is_active', val)}
303
+ />
304
+ </CrudForm>
305
+ );
306
+ }
307
+ ```
308
+
309
+ **4. Create Routes:**
310
+
311
+ ```jsx
312
+ // src/routes/modules/productRoutes.js
313
+ import ProductListPage from '@/pages/products/ProductListPage';
314
+ import ProductFormPage from '@/pages/products/ProductFormPage';
315
+
316
+ const productRoutes = [
317
+ { path: '/products', element: <ProductListPage /> },
318
+ { path: '/products/create', element: <ProductFormPage /> },
319
+ { path: '/products/:id/edit', element: <ProductFormPage /> },
320
+ ];
321
+
322
+ export default productRoutes;
323
+ ```
324
+
325
+ ---
326
+
327
+ ## Next Steps
328
+
329
+ - [UI Components Guide](./2_UI_COMPONENTS.md) - Learn about all available UI components
330
+ - [CRUD Components Guide](./3_CRUD_COMPONENTS.md) - Deep dive into CRUD components
331
+ - [Form Components Guide](./4_FORM_COMPONENTS.md) - Form fields and validation
332
+ - [Layout Components Guide](./5_LAYOUT_COMPONENTS.md) - Dashboard and Auth layouts
333
+ - [Store Factory Guide](./6_STORE_FACTORY.md) - Creating and customizing stores