@xosen/vuetify-grid 0.0.1
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 +289 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.ts +625 -0
- package/dist/index.mjs +11944 -0
- package/dist/packages/vuetify-grid/tsconfig.tsbuildinfo +1 -0
- package/dist/vuetify-grid.css +1 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
# @xosen/vuetify-grid
|
|
2
|
+
|
|
3
|
+
Advanced data grid and list components for Vuetify 3 with built-in CRUD operations, actions, pagination, and search.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @xosen/vuetify-grid
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @xosen/vuetify-grid
|
|
11
|
+
# or
|
|
12
|
+
yarn add @xosen/vuetify-grid
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Import Components and Styles
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { XGrid, XList, XTree, SchemaList } from '@xosen/vuetify-grid';
|
|
21
|
+
import '@xosen/vuetify-grid/dist/style.css';
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### XGrid - Data Table Component
|
|
25
|
+
|
|
26
|
+
A powerful data table component with server-side or client-side data loading, sorting, filtering, and actions.
|
|
27
|
+
|
|
28
|
+
```vue
|
|
29
|
+
<template>
|
|
30
|
+
<XGrid
|
|
31
|
+
title="Users"
|
|
32
|
+
:headers="headers"
|
|
33
|
+
:on-load="loadUsers"
|
|
34
|
+
:row-actions="rowActions"
|
|
35
|
+
:toolbar-actions="toolbarActions"
|
|
36
|
+
searchable
|
|
37
|
+
refreshable
|
|
38
|
+
/>
|
|
39
|
+
</template>
|
|
40
|
+
|
|
41
|
+
<script setup lang="ts">
|
|
42
|
+
import { XGrid } from '@xosen/vuetify-grid';
|
|
43
|
+
import type { GridColumn, ActionsConfig } from '@xosen/vuetify-grid';
|
|
44
|
+
|
|
45
|
+
const headers: GridColumn[] = [
|
|
46
|
+
{ key: 'name', label: 'Name', sortable: true },
|
|
47
|
+
{ key: 'email', label: 'Email', sortable: true },
|
|
48
|
+
{ key: 'role', label: 'Role' },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
async function loadUsers(params: { page: number; limit: number; search?: string }) {
|
|
52
|
+
const response = await fetch(`/api/users?page=${params.page}&limit=${params.limit}`);
|
|
53
|
+
const data = await response.json();
|
|
54
|
+
return { data: data.users, meta: { total: data.total } };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const rowActions: ActionsConfig = {
|
|
58
|
+
edit: {
|
|
59
|
+
icon: 'mdi-pencil',
|
|
60
|
+
handler: (user) => console.log('Edit', user),
|
|
61
|
+
},
|
|
62
|
+
delete: {
|
|
63
|
+
icon: 'mdi-delete',
|
|
64
|
+
color: 'error',
|
|
65
|
+
handler: async (user) => {
|
|
66
|
+
await fetch(`/api/users/${user.id}`, { method: 'DELETE' });
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const toolbarActions: ActionsConfig = {
|
|
72
|
+
create: {
|
|
73
|
+
text: 'New User',
|
|
74
|
+
icon: 'mdi-plus',
|
|
75
|
+
handler: () => console.log('Create new user'),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
</script>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### XList - List View Component
|
|
82
|
+
|
|
83
|
+
A flexible list component using Vuetify's VDataIterator with support for custom item rendering.
|
|
84
|
+
|
|
85
|
+
```vue
|
|
86
|
+
<template>
|
|
87
|
+
<XList
|
|
88
|
+
title="Products"
|
|
89
|
+
:on-load="loadProducts"
|
|
90
|
+
:row-actions="rowActions"
|
|
91
|
+
searchable
|
|
92
|
+
>
|
|
93
|
+
<template #item="{ item }">
|
|
94
|
+
<v-list-item>
|
|
95
|
+
<v-list-item-title>{{ item.name }}</v-list-item-title>
|
|
96
|
+
<v-list-item-subtitle>{{ item.price }}</v-list-item-subtitle>
|
|
97
|
+
</v-list-item>
|
|
98
|
+
</template>
|
|
99
|
+
</XList>
|
|
100
|
+
</template>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### XTree - Tree View Component
|
|
104
|
+
|
|
105
|
+
A tree component with hierarchical data display and actions.
|
|
106
|
+
|
|
107
|
+
```vue
|
|
108
|
+
<template>
|
|
109
|
+
<XTree
|
|
110
|
+
title="File Explorer"
|
|
111
|
+
:items="fileTree"
|
|
112
|
+
:row-actions="treeActions"
|
|
113
|
+
item-title="name"
|
|
114
|
+
item-value="id"
|
|
115
|
+
item-children="children"
|
|
116
|
+
/>
|
|
117
|
+
</template>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### SchemaList - Schema-based List
|
|
121
|
+
|
|
122
|
+
Create lists using a declarative schema without writing component templates.
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { SchemaList, type ListSchema } from '@xosen/vuetify-grid';
|
|
126
|
+
|
|
127
|
+
const schema: ListSchema = {
|
|
128
|
+
title: 'Products',
|
|
129
|
+
searchable: true,
|
|
130
|
+
refreshable: true,
|
|
131
|
+
itemsPerPage: 25,
|
|
132
|
+
onLoad: async (params) => {
|
|
133
|
+
const response = await fetch(`/api/products?${new URLSearchParams(params as any)}`);
|
|
134
|
+
const data = await response.json();
|
|
135
|
+
return { data: data.products, meta: { total: data.total } };
|
|
136
|
+
},
|
|
137
|
+
rowActions: {
|
|
138
|
+
edit: { icon: 'mdi-pencil', handler: (item) => console.log('Edit', item) },
|
|
139
|
+
delete: { icon: 'mdi-delete', color: 'error', handler: deleteProduct },
|
|
140
|
+
},
|
|
141
|
+
toolbarActions: {
|
|
142
|
+
create: { text: 'New Product', icon: 'mdi-plus', handler: () => console.log('Create') },
|
|
143
|
+
},
|
|
144
|
+
noDataText: 'No products found',
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Features
|
|
149
|
+
|
|
150
|
+
### Grid Features
|
|
151
|
+
- ✅ Server-side and client-side data loading
|
|
152
|
+
- ✅ Built-in pagination
|
|
153
|
+
- ✅ Search functionality
|
|
154
|
+
- ✅ Sorting support
|
|
155
|
+
- ✅ Row and toolbar actions
|
|
156
|
+
- ✅ Loading states
|
|
157
|
+
- ✅ Customizable columns
|
|
158
|
+
- ✅ Responsive design
|
|
159
|
+
|
|
160
|
+
### Action System
|
|
161
|
+
- Icon-only or button actions
|
|
162
|
+
- Async action handlers with loading states
|
|
163
|
+
- Conditional visibility and disabled states
|
|
164
|
+
- Menu actions for overflow
|
|
165
|
+
- Success/error handling
|
|
166
|
+
|
|
167
|
+
### CRUD Operations
|
|
168
|
+
- Built-in `useCrudGrid` composable
|
|
169
|
+
- Automatic data loading and reloading
|
|
170
|
+
- Filter support
|
|
171
|
+
- Debounced search
|
|
172
|
+
- Required filters validation
|
|
173
|
+
|
|
174
|
+
## API Reference
|
|
175
|
+
|
|
176
|
+
### XGrid Props
|
|
177
|
+
|
|
178
|
+
| Prop | Type | Default | Description |
|
|
179
|
+
|------|------|---------|-------------|
|
|
180
|
+
| `title` | `string` | - | Grid title |
|
|
181
|
+
| `headers` | `GridColumn[]` | - | Column definitions |
|
|
182
|
+
| `items` | `any[]` | - | Items for client-side mode |
|
|
183
|
+
| `onLoad` | `Function` | - | Server-side data loader |
|
|
184
|
+
| `rowActions` | `ActionsConfig` | - | Row-level actions |
|
|
185
|
+
| `toolbarActions` | `ActionsConfig` | - | Toolbar actions |
|
|
186
|
+
| `searchable` | `boolean` | `false` | Enable search |
|
|
187
|
+
| `refreshable` | `boolean` | `false` | Enable refresh button |
|
|
188
|
+
| `itemsPerPage` | `number` | `10` | Items per page |
|
|
189
|
+
| `sortable` | `boolean` | `true` | Enable sorting |
|
|
190
|
+
| `hover` | `boolean` | `true` | Highlight on hover |
|
|
191
|
+
|
|
192
|
+
### GridColumn Interface
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
interface GridColumn {
|
|
196
|
+
key: string;
|
|
197
|
+
label: string;
|
|
198
|
+
sortable?: boolean;
|
|
199
|
+
width?: string | number;
|
|
200
|
+
align?: 'start' | 'center' | 'end';
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### ActionConfig Interface
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
interface ActionConfig {
|
|
208
|
+
text?: string | ((item?: any) => string);
|
|
209
|
+
icon?: string;
|
|
210
|
+
color?: string;
|
|
211
|
+
disabled?: boolean | ((item?: any) => boolean);
|
|
212
|
+
visible?: boolean | ((item?: any) => boolean);
|
|
213
|
+
handler?: (item?: any) => Promise<any> | any;
|
|
214
|
+
loading?: boolean;
|
|
215
|
+
}
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Composables
|
|
219
|
+
|
|
220
|
+
### useCrudGrid
|
|
221
|
+
|
|
222
|
+
Manages CRUD operations with pagination, search, and filtering.
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
const {
|
|
226
|
+
loading,
|
|
227
|
+
page,
|
|
228
|
+
limit,
|
|
229
|
+
items,
|
|
230
|
+
total,
|
|
231
|
+
reload,
|
|
232
|
+
loadData,
|
|
233
|
+
} = useCrudGrid({
|
|
234
|
+
onLoad: async (params) => {
|
|
235
|
+
// Fetch data
|
|
236
|
+
return { data: [], meta: { total: 0 } };
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### useActions
|
|
242
|
+
|
|
243
|
+
Manages action states and execution.
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
const { handleActionClick, isActionVisible, isActionDisabled } = useActions({
|
|
247
|
+
onError: (error) => console.error(error),
|
|
248
|
+
});
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Styling
|
|
252
|
+
|
|
253
|
+
The package includes pre-built CSS. Import it in your main file:
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
import '@xosen/vuetify-grid/dist/style.css';
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## TypeScript Support
|
|
260
|
+
|
|
261
|
+
Full TypeScript support with exported types:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import type {
|
|
265
|
+
GridColumn,
|
|
266
|
+
ListSchema,
|
|
267
|
+
ActionConfig,
|
|
268
|
+
ActionsConfig,
|
|
269
|
+
CrudGridOptions,
|
|
270
|
+
LoadParams,
|
|
271
|
+
} from '@xosen/vuetify-grid';
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Development
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
# Build the package
|
|
278
|
+
pnpm build
|
|
279
|
+
|
|
280
|
+
# Type check
|
|
281
|
+
pnpm type-check
|
|
282
|
+
|
|
283
|
+
# Clean build artifacts
|
|
284
|
+
pnpm clean
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## License
|
|
288
|
+
|
|
289
|
+
MIT
|