@kaushalparajuli/react-crud-ui 1.0.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 +321 -0
- package/dist/index.cjs +237 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +14717 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +1 -0
- package/package.json +92 -0
package/README.md
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# @yaj/react-crud-ui
|
|
2
|
+
|
|
3
|
+
A comprehensive React CRUD and UI component library with Zustand store integration.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🎨 **20+ UI Components** - Button, Card, Badge, Dialog, Select, Tabs, and more
|
|
8
|
+
- 📊 **CRUD Components** - DataTable, CrudList, CrudForm, CrudDetail
|
|
9
|
+
- 🔄 **Zustand Store Factory** - Create CRUD stores with minimal code
|
|
10
|
+
- 🎯 **Form Components** - QInput, QSelect, QSwitch, QSearchSelect with validation
|
|
11
|
+
- 📱 **Responsive** - Mobile-first design with Tailwind CSS
|
|
12
|
+
- 🌙 **Dark Mode** - Built-in dark mode support via CSS variables
|
|
13
|
+
- âš¡ **TypeScript Ready** - Full TypeScript support
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @yaj/react-crud-ui
|
|
19
|
+
# or
|
|
20
|
+
yarn add @yaj/react-crud-ui
|
|
21
|
+
# or
|
|
22
|
+
pnpm add @yaj/react-crud-ui
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Peer Dependencies
|
|
26
|
+
|
|
27
|
+
Make sure you have these peer dependencies installed:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install react react-dom react-router-dom zustand
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 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 '@yaj/react-crud-ui/styles.css'
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Configure Tailwind (Optional)
|
|
44
|
+
|
|
45
|
+
If you're using Tailwind CSS in your project, add the package to your content paths:
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
// tailwind.config.js
|
|
49
|
+
module.exports = {
|
|
50
|
+
content: [
|
|
51
|
+
'./src/**/*.{js,jsx,ts,tsx}',
|
|
52
|
+
'./node_modules/@yaj/react-crud-ui/dist/**/*.{js,cjs}',
|
|
53
|
+
],
|
|
54
|
+
// ... rest of config
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
### UI Components
|
|
61
|
+
|
|
62
|
+
```jsx
|
|
63
|
+
import { Button, Card, CardHeader, CardTitle, CardContent, Badge } from '@yaj/react-crud-ui'
|
|
64
|
+
|
|
65
|
+
function MyComponent() {
|
|
66
|
+
return (
|
|
67
|
+
<Card>
|
|
68
|
+
<CardHeader>
|
|
69
|
+
<CardTitle>My Card</CardTitle>
|
|
70
|
+
</CardHeader>
|
|
71
|
+
<CardContent>
|
|
72
|
+
<Badge variant="success">Active</Badge>
|
|
73
|
+
<Button onClick={() => alert('Clicked!')}>Click Me</Button>
|
|
74
|
+
</CardContent>
|
|
75
|
+
</Card>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Form Components
|
|
81
|
+
|
|
82
|
+
```jsx
|
|
83
|
+
import { QInput, QSelect, QSwitch, QForm } from '@yaj/react-crud-ui'
|
|
84
|
+
|
|
85
|
+
function MyForm() {
|
|
86
|
+
const handleSubmit = (e) => {
|
|
87
|
+
const formData = new FormData(e.target)
|
|
88
|
+
console.log(Object.fromEntries(formData))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<QForm onSubmit={handleSubmit}>
|
|
93
|
+
<QInput
|
|
94
|
+
label="Name"
|
|
95
|
+
name="name"
|
|
96
|
+
placeholder="Enter name"
|
|
97
|
+
required
|
|
98
|
+
/>
|
|
99
|
+
<QSelect
|
|
100
|
+
label="Status"
|
|
101
|
+
name="status"
|
|
102
|
+
options={[
|
|
103
|
+
{ value: 'active', label: 'Active' },
|
|
104
|
+
{ value: 'inactive', label: 'Inactive' },
|
|
105
|
+
]}
|
|
106
|
+
/>
|
|
107
|
+
<QSwitch
|
|
108
|
+
label="Is Published"
|
|
109
|
+
name="is_published"
|
|
110
|
+
/>
|
|
111
|
+
<Button type="submit">Save</Button>
|
|
112
|
+
</QForm>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### DataTable
|
|
118
|
+
|
|
119
|
+
```jsx
|
|
120
|
+
import { DataTable } from '@yaj/react-crud-ui'
|
|
121
|
+
|
|
122
|
+
const columns = [
|
|
123
|
+
{ header: 'Name', accessor: 'name', sortable: true },
|
|
124
|
+
{ header: 'Email', accessor: 'email' },
|
|
125
|
+
{
|
|
126
|
+
header: 'Status',
|
|
127
|
+
accessor: 'status',
|
|
128
|
+
render: (row) => <Badge>{row.status}</Badge>
|
|
129
|
+
},
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
const actions = [
|
|
133
|
+
{ label: 'View', icon: Eye, onClick: (row) => console.log('View', row) },
|
|
134
|
+
{ label: 'Edit', icon: Pencil, onClick: (row) => console.log('Edit', row) },
|
|
135
|
+
{ label: 'Delete', icon: Trash2, variant: 'destructive', onClick: (row) => console.log('Delete', row) },
|
|
136
|
+
]
|
|
137
|
+
|
|
138
|
+
function UserTable() {
|
|
139
|
+
return (
|
|
140
|
+
<DataTable
|
|
141
|
+
data={users}
|
|
142
|
+
columns={columns}
|
|
143
|
+
actions={actions}
|
|
144
|
+
searchable
|
|
145
|
+
onSearchChange={(search) => console.log(search)}
|
|
146
|
+
currentPage={1}
|
|
147
|
+
totalPages={10}
|
|
148
|
+
onPageChange={(page) => console.log(page)}
|
|
149
|
+
/>
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### CrudList
|
|
155
|
+
|
|
156
|
+
```jsx
|
|
157
|
+
import { CrudList } from '@yaj/react-crud-ui'
|
|
158
|
+
|
|
159
|
+
function ProductList() {
|
|
160
|
+
const columns = [
|
|
161
|
+
{ header: 'Name', accessor: 'name', sortable: true },
|
|
162
|
+
{ header: 'Price', accessor: 'price', format: (v) => `$${v}` },
|
|
163
|
+
]
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<CrudList
|
|
167
|
+
title="Products"
|
|
168
|
+
description="Manage your products"
|
|
169
|
+
data={products}
|
|
170
|
+
columns={columns}
|
|
171
|
+
onCreate={() => navigate('/products/create')}
|
|
172
|
+
onEdit={(item) => navigate(`/products/${item.id}/edit`)}
|
|
173
|
+
onDelete={(item) => deleteProduct(item.id)}
|
|
174
|
+
itemName="product"
|
|
175
|
+
/>
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### CrudForm
|
|
181
|
+
|
|
182
|
+
```jsx
|
|
183
|
+
import { CrudForm } from '@yaj/react-crud-ui'
|
|
184
|
+
import { z } from 'zod'
|
|
185
|
+
|
|
186
|
+
const schema = z.object({
|
|
187
|
+
name: z.string().min(1, 'Name is required'),
|
|
188
|
+
price: z.number().min(0, 'Price must be positive'),
|
|
189
|
+
is_active: z.boolean(),
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
const fields = [
|
|
193
|
+
{ name: 'name', label: 'Name', type: 'text', required: true },
|
|
194
|
+
{ name: 'price', label: 'Price', type: 'number', required: true },
|
|
195
|
+
{ name: 'description', label: 'Description', type: 'textarea', colSpan: 2 },
|
|
196
|
+
{ name: 'is_active', label: 'Active', type: 'switch' },
|
|
197
|
+
]
|
|
198
|
+
|
|
199
|
+
function ProductForm() {
|
|
200
|
+
return (
|
|
201
|
+
<CrudForm
|
|
202
|
+
title="Create Product"
|
|
203
|
+
fields={fields}
|
|
204
|
+
validationSchema={schema}
|
|
205
|
+
onSubmit={(data) => console.log(data)}
|
|
206
|
+
onCancel={() => navigate(-1)}
|
|
207
|
+
columns={2}
|
|
208
|
+
/>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Create CRUD Store with Zustand
|
|
214
|
+
|
|
215
|
+
```jsx
|
|
216
|
+
import { create } from 'zustand'
|
|
217
|
+
import { createCrudStore } from '@yaj/react-crud-ui'
|
|
218
|
+
import { apiClient } from './api'
|
|
219
|
+
|
|
220
|
+
// Create a product store
|
|
221
|
+
const useProductStore = create(
|
|
222
|
+
createCrudStore({
|
|
223
|
+
name: 'products',
|
|
224
|
+
apiClient,
|
|
225
|
+
endpoint: '/api/products',
|
|
226
|
+
})
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
// Use in component
|
|
230
|
+
function ProductPage() {
|
|
231
|
+
const {
|
|
232
|
+
items,
|
|
233
|
+
loading,
|
|
234
|
+
fetchList,
|
|
235
|
+
create,
|
|
236
|
+
update,
|
|
237
|
+
delete: deleteItem,
|
|
238
|
+
page,
|
|
239
|
+
setPage,
|
|
240
|
+
} = useProductStore()
|
|
241
|
+
|
|
242
|
+
useEffect(() => {
|
|
243
|
+
fetchList()
|
|
244
|
+
}, [page])
|
|
245
|
+
|
|
246
|
+
return (
|
|
247
|
+
<CrudList
|
|
248
|
+
data={items}
|
|
249
|
+
loading={loading}
|
|
250
|
+
// ...
|
|
251
|
+
/>
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Components Reference
|
|
257
|
+
|
|
258
|
+
### UI Components
|
|
259
|
+
|
|
260
|
+
| Component | Description |
|
|
261
|
+
|-----------|-------------|
|
|
262
|
+
| `Button` | Button with variants (default, destructive, outline, secondary, ghost, link) |
|
|
263
|
+
| `Card` | Card container with Header, Content, Footer |
|
|
264
|
+
| `Badge` | Badge/Tag with variants |
|
|
265
|
+
| `Input` | Text input field |
|
|
266
|
+
| `Textarea` | Multi-line text input |
|
|
267
|
+
| `Select` | Dropdown select |
|
|
268
|
+
| `SearchSelect` | Searchable dropdown select |
|
|
269
|
+
| `Checkbox` | Checkbox input |
|
|
270
|
+
| `Switch` | Toggle switch |
|
|
271
|
+
| `Dialog` | Modal dialog |
|
|
272
|
+
| `Tabs` | Tab navigation |
|
|
273
|
+
| `QTabs` | Simplified tabs |
|
|
274
|
+
| `Avatar` | User avatar |
|
|
275
|
+
| `Tooltip` | Tooltip |
|
|
276
|
+
| `DropdownMenu` | Dropdown menu |
|
|
277
|
+
| `Alert` | Alert message |
|
|
278
|
+
| `Table` | Table elements |
|
|
279
|
+
| `Separator` | Visual separator |
|
|
280
|
+
| `Skeleton` | Loading skeleton |
|
|
281
|
+
| `ScrollArea` | Custom scrollable area |
|
|
282
|
+
|
|
283
|
+
### Form Components
|
|
284
|
+
|
|
285
|
+
| Component | Description |
|
|
286
|
+
|-----------|-------------|
|
|
287
|
+
| `QInput` | Input with label and error handling |
|
|
288
|
+
| `QTextarea` | Textarea with label and error handling |
|
|
289
|
+
| `QSelect` | Select with label and error handling |
|
|
290
|
+
| `QSearchSelect` | Searchable select with label and error handling |
|
|
291
|
+
| `QSwitch` | Switch with label |
|
|
292
|
+
| `QCheckbox` | Checkbox with label |
|
|
293
|
+
| `QForm` | Form wrapper |
|
|
294
|
+
|
|
295
|
+
### CRUD Components
|
|
296
|
+
|
|
297
|
+
| Component | Description |
|
|
298
|
+
|-----------|-------------|
|
|
299
|
+
| `DataTable` | Data table with sorting, filtering, pagination |
|
|
300
|
+
| `CrudList` | Complete CRUD list with actions |
|
|
301
|
+
| `CrudForm` | Dynamic form for create/edit |
|
|
302
|
+
| `CrudDetail` | Detail view component |
|
|
303
|
+
| `Pagination` | Pagination controls |
|
|
304
|
+
| `Loading` | Loading indicators |
|
|
305
|
+
| `EmptyState` | Empty state displays |
|
|
306
|
+
| `Modal` | Modal dialogs |
|
|
307
|
+
|
|
308
|
+
### Utilities
|
|
309
|
+
|
|
310
|
+
| Function | Description |
|
|
311
|
+
|----------|-------------|
|
|
312
|
+
| `cn` | Tailwind class merge utility |
|
|
313
|
+
| `formatDate` | Format date string |
|
|
314
|
+
| `formatDateTime` | Format datetime string |
|
|
315
|
+
| `formatCurrency` | Format currency |
|
|
316
|
+
| `debounce` | Debounce function |
|
|
317
|
+
| `createCrudStore` | Zustand store factory |
|
|
318
|
+
|
|
319
|
+
## License
|
|
320
|
+
|
|
321
|
+
MIT
|