@@ -11,8 +11,8 @@ Example
11
11
12
12
``` svelte example
13
13
<script lang="ts">
14
- import { ProductDrawer } from ' flowbite-svelte-admin-dashboard' ;
15
- import { Button, Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell } from ' flowbite-svelte' ;
14
+ import { ProductDrawer } from " flowbite-svelte-admin-dashboard" ;
15
+ import { Button, Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell } from " flowbite-svelte" ;
16
16
17
17
// Types
18
18
interface Product {
@@ -28,87 +28,87 @@ Example
28
28
// State
29
29
let drawerOpen = false;
30
30
let productData: Partial<Product> | undefined;
31
- let drawerTitle = '' ;
31
+ let drawerTitle = "" ;
32
32
let editingProductId: number | null = null;
33
33
34
34
// Products database
35
35
let products: Product[] = [
36
36
{
37
37
id: 1,
38
- name: ' iPhone 15 Pro' ,
39
- price: ' 1199' ,
40
- technology: ' APPLE' ,
41
- category: ' SMARTPHONE' ,
42
- description: ' Latest iPhone with titanium design and A17 Pro chip' ,
43
- discount: '5'
38
+ name: " iPhone 15 Pro" ,
39
+ price: " 1199" ,
40
+ technology: " APPLE" ,
41
+ category: " SMARTPHONE" ,
42
+ description: " Latest iPhone with titanium design and A17 Pro chip" ,
43
+ discount: "5"
44
44
},
45
45
{
46
46
id: 2,
47
- name: ' MacBook Air M3' ,
48
- price: ' 1299' ,
49
- technology: ' APPLE' ,
50
- category: ' LAPTOP' ,
51
- description: ' Lightweight laptop with M3 chip and 18-hour battery life' ,
52
- discount: '10'
47
+ name: " MacBook Air M3" ,
48
+ price: " 1299" ,
49
+ technology: " APPLE" ,
50
+ category: " LAPTOP" ,
51
+ description: " Lightweight laptop with M3 chip and 18-hour battery life" ,
52
+ discount: "10"
53
53
},
54
54
{
55
55
id: 3,
56
- name: ' Samsung Galaxy S24' ,
57
- price: ' 899' ,
58
- technology: ' SAMSUNG' ,
59
- category: ' SMARTPHONE' ,
60
- description: ' AI-powered smartphone with excellent camera' ,
61
- discount: ''
56
+ name: " Samsung Galaxy S24" ,
57
+ price: " 899" ,
58
+ technology: " SAMSUNG" ,
59
+ category: " SMARTPHONE" ,
60
+ description: " AI-powered smartphone with excellent camera" ,
61
+ discount: ""
62
62
}
63
63
];
64
64
65
65
// Form configuration
66
66
const additionalFields = [
67
67
{
68
- name: ' technology' ,
69
- label: ' Technology/Brand' ,
70
- placeholder: ' Select brand' ,
68
+ name: " technology" ,
69
+ label: " Technology/Brand" ,
70
+ placeholder: " Select brand" ,
71
71
options: [
72
- { value: ' APPLE' , label: ' Apple' },
73
- { value: ' SAMSUNG' , label: ' Samsung' },
74
- { value: ' GOOGLE' , label: ' Google' },
75
- { value: ' MICROSOFT' , label: ' Microsoft' }
72
+ { value: " APPLE" , label: " Apple" },
73
+ { value: " SAMSUNG" , label: " Samsung" },
74
+ { value: " GOOGLE" , label: " Google" },
75
+ { value: " MICROSOFT" , label: " Microsoft" }
76
76
]
77
77
},
78
78
{
79
- name: ' category' ,
80
- label: ' Category' ,
81
- placeholder: ' Select category' ,
79
+ name: " category" ,
80
+ label: " Category" ,
81
+ placeholder: " Select category" ,
82
82
options: [
83
- { value: ' SMARTPHONE' , label: ' Smartphone' },
84
- { value: ' LAPTOP' , label: ' Laptop' },
85
- { value: ' TABLET' , label: ' Tablet' },
86
- { value: ' ACCESSORY' , label: ' Accessory' }
83
+ { value: " SMARTPHONE" , label: " Smartphone" },
84
+ { value: " LAPTOP" , label: " Laptop" },
85
+ { value: " TABLET" , label: " Tablet" },
86
+ { value: " ACCESSORY" , label: " Accessory" }
87
87
]
88
88
},
89
89
{
90
- name: ' discount' ,
91
- label: ' Discount' ,
92
- placeholder: ' No discount' ,
90
+ name: " discount" ,
91
+ label: " Discount" ,
92
+ placeholder: " No discount" ,
93
93
options: [
94
- { value: '5' , label: ' 5% Off' },
95
- { value: '10' , label: ' 10% Off' },
96
- { value: '15' , label: ' 15% Off' },
97
- { value: '20' , label: ' 20% Off' },
98
- { value: '25' , label: ' 25% Off' }
94
+ { value: "5" , label: " 5% Off" },
95
+ { value: "10" , label: " 10% Off" },
96
+ { value: "15" , label: " 15% Off" },
97
+ { value: "20" , label: " 20% Off" },
98
+ { value: "25" , label: " 25% Off" }
99
99
]
100
100
}
101
101
];
102
102
103
103
// Helper function to get form data
104
- function getFormData(formData: FormData): Omit<Product, 'id' > {
104
+ function getFormData(formData: FormData): Omit<Product, "id" > {
105
105
return {
106
- name: String(formData.get(' name' ) || '' ),
107
- price: String(formData.get(' price' ) || '' ),
108
- technology: String(formData.get(' technology' ) || '' ),
109
- category: String(formData.get(' category' ) || '' ),
110
- description: String(formData.get(' description' ) || '' ),
111
- discount: String(formData.get(' discount' ) || '' )
106
+ name: String(formData.get(" name" ) || "" ),
107
+ price: String(formData.get(" price" ) || "" ),
108
+ technology: String(formData.get(" technology" ) || "" ),
109
+ category: String(formData.get(" category" ) || "" ),
110
+ description: String(formData.get(" description" ) || "" ),
111
+ discount: String(formData.get(" discount" ) || "" )
112
112
};
113
113
}
114
114
@@ -121,7 +121,7 @@ Example
121
121
function addNewProduct() {
122
122
editingProductId = null;
123
123
productData = undefined;
124
- drawerTitle = ' Add New Product' ;
124
+ drawerTitle = " Add New Product" ;
125
125
drawerOpen = true;
126
126
}
127
127
@@ -135,7 +135,7 @@ Example
135
135
description: product.description,
136
136
discount: product.discount
137
137
};
138
- drawerTitle = ' Edit Product' ;
138
+ drawerTitle = " Edit Product" ;
139
139
drawerOpen = true;
140
140
}
141
141
@@ -147,21 +147,21 @@ Example
147
147
technology: product.technology,
148
148
category: product.category,
149
149
description: product.description,
150
- discount: ''
150
+ discount: ""
151
151
};
152
- drawerTitle = ' Duplicate Product' ;
152
+ drawerTitle = " Duplicate Product" ;
153
153
drawerOpen = true;
154
154
}
155
155
156
156
function createFromTemplate(category: string, technology: string) {
157
157
editingProductId = null;
158
158
productData = {
159
- name: '' ,
160
- price: '' ,
159
+ name: "" ,
160
+ price: "" ,
161
161
technology: technology,
162
162
category: category,
163
163
description: `New ${category.toLowerCase()} product`,
164
- discount: ''
164
+ discount: ""
165
165
};
166
166
drawerTitle = `Add New ${category}`;
167
167
drawerOpen = true;
@@ -176,15 +176,15 @@ Example
176
176
if (editingProductId !== null) {
177
177
// Update existing product
178
178
products = products.map((product) => (product.id === editingProductId ? { ...product, ...data } : product));
179
- console.log(' Updated product:' , editingProductId);
179
+ console.log(" Updated product:" , editingProductId);
180
180
} else {
181
181
// Create new product
182
182
const newProduct: Product = {
183
183
id: generateNewId(),
184
184
...data
185
185
};
186
186
products = [...products, newProduct];
187
- console.log(' Created new product:' , newProduct);
187
+ console.log(" Created new product:" , newProduct);
188
188
}
189
189
190
190
// Reset and close
@@ -194,9 +194,9 @@ Example
194
194
}
195
195
196
196
function deleteProduct(productId: number) {
197
- if (confirm(' Are you sure you want to delete this product?' )) {
197
+ if (confirm(" Are you sure you want to delete this product?" )) {
198
198
products = products.filter((p) => p.id !== productId);
199
- console.log(' Deleted product:' , productId);
199
+ console.log(" Deleted product:" , productId);
200
200
}
201
201
}
202
202
</script>
@@ -208,12 +208,12 @@ Example
208
208
</div>
209
209
210
210
<!-- Quick templates -->
211
- <div class="mb-6 rounded bg-gray-50 p-4 dark:bg-gray-900 ">
211
+ <div class="mb-6 rounded p-4">
212
212
<h3 class="mb-2 font-semibold dark:text-white">Quick Templates:</h3>
213
213
<div class="flex gap-2">
214
- <Button color="lime" onclick={() => createFromTemplate(' SMARTPHONE', ' APPLE' )}>iPhone Template</Button>
215
- <Button color="indigo" onclick={() => createFromTemplate(' SMARTPHONE', ' SAMSUNG' )}>Samsung Phone</Button>
216
- <Button color="cyan" onclick={() => createFromTemplate(' LAPTOP', ' APPLE' )}>MacBook Template</Button>
214
+ <Button color="lime" onclick={() => createFromTemplate(" SMARTPHONE", " APPLE" )}>iPhone Template</Button>
215
+ <Button color="indigo" onclick={() => createFromTemplate(" SMARTPHONE", " SAMSUNG" )}>Samsung Phone</Button>
216
+ <Button color="cyan" onclick={() => createFromTemplate(" LAPTOP", " APPLE" )}>MacBook Template</Button>
217
217
</div>
218
218
</div>
219
219
@@ -235,11 +235,11 @@ Example
235
235
<TableBodyCell>${product.price}</TableBodyCell>
236
236
<TableBodyCell>{product.technology}</TableBodyCell>
237
237
<TableBodyCell>{product.category}</TableBodyCell>
238
- <TableBodyCell>{product.discount ? `${product.discount}%` : ' None' }</TableBodyCell>
238
+ <TableBodyCell>{product.discount ? `${product.discount}%` : " None" }</TableBodyCell>
239
239
<TableBodyCell class="space-x-2">
240
- <button onclick={() => editProduct(product)} class="text-sm text-blue-600 hover:text-blue-800"> Edit </button>
241
- <button onclick={() => duplicateProduct(product)} class="text-sm text-green-600 hover:text-green-800"> Duplicate </button>
242
- <button onclick={() => deleteProduct(product.id)} class="text-sm text-red-600 hover:text-red-800"> Delete </button>
240
+ <button onclick={() => editProduct(product)} class="text-sm text-blue-600 hover:text-blue-800 dark:text-blue-200 bg-gray-100 dark:bg-gray-600"> Edit</button>
241
+ <button onclick={() => duplicateProduct(product)} class="text-sm text-green-600 hover:text-green-800 dark:text-green-600 bg-gray-100 dark:bg-gray-600 "> Duplicate</button>
242
+ <button onclick={() => deleteProduct(product.id)} class="text-sm text-red-600 hover:text-red-800 dark:text-red-600 bg-gray-100 dark:bg-gray-600"> Delete</button>
243
243
</TableBodyCell>
244
244
</TableBodyRow>
245
245
{/each}
0 commit comments