-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
241 lines (231 loc) · 11.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<!doctype html>
<html lang="en" x-data="navigation">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="An Alpine.js Markt application" />
<title>Alpine.js · Markt</title>
<link rel="icon" type="image/png" href="favicon.png" />
<link rel="stylesheet" href="src/styles/main.css" />
<script defer type="module" src="src/main.ts"></script>
</head>
<body x-data="products" class="antialiased">
<div x-data="cart">
<header class="bg-white border-b">
<div class="container mx-auto py-4 px-6">
<div class="flex justify-between items-center space-x-12">
<h1 @click="changeTab('home')" class="text-2xl font-bold text-gray-900 cursor-pointer">
Markt
</h1>
<nav class="flex flex-1 space-x-6">
<button @click="changeTab('home')"
:class="currentTab === 'home' ? 'text-blue-600 border-b-2 border-blue-600' : 'text-gray-500'"
class="py-2">
Home
</button>
<button @click="changeTab('products')"
:class="currentTab === 'products' ? 'text-blue-600 border-b-2 border-blue-600' : 'text-gray-500'"
class="py-2">
Products
</button>
</nav>
<div class="flex space-x-6 items-center">
<div x-cloak x-show="currentTab === 'products'" class="relative w-full max-w-md">
<input type="text" placeholder="Search for products..." x-model="search" @input="search"
class="hidden md:block p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-400 w-[250px]"
aria-describedby="search-help" />
<button x-cloak x-show="search" @click="clearSearch"
class="absolute inset-y-0 right-0 flex items-center pr-2">
<i class="ph ph-x text-gray-500 cursor-pointer hover:text-gray-700"></i>
</button>
</div>
<button @click="toggleCart" class="relative">
<i data-cy="cart-button" class="ph ph-shopping-cart text-2xl text-gray-800"></i>
<span x-cloak x-show="cart.length > 0" data-cy="cart-badge"
class="absolute bottom-5 left-5 bg-red-500 text-white text-xs rounded-full w-5 h-5 flex items-center justify-center">
<span x-text="cartTotalItems"></span>
</span>
</button>
</div>
</div>
</div>
</header>
<main class="container mx-auto py-6 px-6">
<div x-cloak x-show="currentTab === 'home'">
<section class="grid grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
<div class="col-span-2">
<div data-cy="product-item"
class="bg-white border border-[#E2E8F0] shadow-sm rounded-sm overflow-hidden hover:shadow-md transform hover:scale-[1.02] transition-all duration-300 flex flex-col h-full justify-between">
<div class="h-full bg-neutral-100 flex items-center justify-center">
<img class="h-[460px] object-cover" :src="products[1]?.thumbnail"
onerror="this.src='default.png';this.onerror='';" alt="Product thumbnail" />
</div>
<div class="p-4">
<h2 class="text-2xl font-bold mb-2" x-text="products[1]?.title"></h2>
<p class="text-gray-600 text-sm mt-1 mb-2">
$<span x-text="products[1]?.price"></span>
</p>
<p class="text-gray-600 mt-1 mb-4" x-text="products[1]?.description"></p>
</div>
<div class="p-4">
<button @click="addToCart(products[1])" data-cy="add-to-cart"
class="w-full bg-blue-600 text-white py-2 rounded-sm hover:bg-blue-700 transition-all">
<i class="ph ph-plus text-white text-sm"></i> Add
</button>
</div>
</div>
</div>
<div class="col-span-2 grid grid-cols-2 gap-6">
<template x-for="product in products.slice(4, 8)" :key="product.id">
<div data-cy="product-item"
class="bg-white border border-[#E2E8F0] shadow-sm rounded-sm overflow-hidden hover:shadow-md transform hover:scale-105 transition-all duration-300 flex flex-col h-full justify-between">
<div class="h-48 w-full bg-neutral-100 flex items-center justify-center">
<img class="h-full object-contain" :src="product.thumbnail"
onerror="this.src='default.png';this.onerror='';" alt="Product thumbnail" />
</div>
<div class="p-4">
<h2 class="font-semibold text-md text-gray-800" x-text="product.title"></h2>
<p class="text-gray-600 text-sm mt-1">
$<span x-text="product.price"></span>
</p>
</div>
<div class="p-4">
<button @click="addToCart(product)" data-cy="add-to-cart"
class="w-full bg-blue-600 text-white py-2 rounded-sm hover:bg-blue-700 transition-all">
<i class="ph ph-plus text-white text-sm"></i> Add
</button>
</div>
</div>
</template>
</div>
</section>
</div>
<div x-cloak x-show="currentTab === 'products'">
<div class="container mx-auto pb-6 px-6 flex justify-between h-[70px]">
<div>
<select x-model="sortByPrice"
class="p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-400">
<option value="none">Sort by Price</option>
<option value="asc">Price: Low to High</option>
<option value="desc">Price: High to Low</option>
</select>
</div>
<div x-cloak x-show="search || sortByPrice !== 'none'">
<button @click="clearFilters"
class="py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-400 px-4">
Clear Filters
</button>
</div>
</div>
<section class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6 mb-6">
<template x-if="!filteredProducts.length">
<div class="col-span-full text-center mt-12 mx-auto w-[430px]">
<h2 class="text-xl font-bold">
No Results Found for "<span x-text="search"></span>"
</h2>
<p class="mt-2 text-gray-500">
Sorry, we couldn't find any results that match your search
query. Please try refining your search.
</p>
</div>
</template>
<template x-for="product in filteredProducts" :key="product.id">
<div data-cy="product-item"
class="bg-white border border-[#E2E8F0] shadow-sm rounded-sm overflow-hidden hover:shadow-md transform hover:scale-105 transition-all duration-300 flex flex-col h-full justify-between">
<div class="h-64 w-full bg-neutral-100 flex items-center justify-center">
<img :src="product.thumbnail" alt="Product thumbnail" class="h-full object-contain" />
</div>
<div class="p-4">
<h2 class="font-semibold text-md text-gray-800" x-text="product.title"></h2>
<p class="text-gray-600 text-sm mt-1">
$<span x-text="product.price"></span>
</p>
</div>
<div class="p-4">
<button @click="addToCart(product)" data-cy="add-to-cart"
class="w-full bg-blue-600 text-white py-2 rounded-sm hover:bg-blue-700 transition-all">
<i class="ph ph-plus text-white text-sm"></i> Add
</button>
</div>
</div>
</template>
</section>
</div>
</main>
<div x-cloak x-show="cartOpen" data-cy="cart-drawer" class="fixed inset-0 z-50 flex justify-end">
<div class="bg-black bg-opacity-50 w-full h-full absolute"></div>
<div x-cloak x-show="cartOpen" @click.outside="closeCart"
x-transition:enter="transform transition ease-out duration-300" x-transition:enter-start="translate-x-full"
x-transition:enter-end="translate-x-0" x-transition:leave="transform transition ease-in duration-300"
x-transition:leave-start="translate-x-0" x-transition:leave-end="translate-x-full" class="drawer">
<h2 class="text-2xl font-bold mb-4">Shopping Cart</h2>
<button @click="closeCart" class="absolute top-4 right-4 text-gray-600">
<i class="ph ph-x text-2xl"></i>
</button>
<div x-cloak x-show="cart.length === 0" class="flex flex-col items-center justify-center text-center h-full">
<i class="ph ph-shopping-cart text-6xl text-gray-500"></i>
<h3 class="text-xl font-bold mt-2">Your cart is empty</h3>
<p class="text-gray-500 mt-2">
Looks like you haven't added anything to<br />your cart yet.
</p>
<button @click="changeTab('products'); closeCart()"
class="mt-6 bg-blue-600 text-white py-2 px-6 rounded hover:bg-blue-700 transition">
Continue shopping
</button>
</div>
<ul x-cloak x-show="cart.length > 0" class="overflow-scroll no-scrollbar">
<template x-for="item in cart" :key="item.id">
<li data-cy="cart-item" class="cart-item">
<img :src="item.thumbnail" alt="Product thumbnail" />
<div class="item-info">
<h4 x-text="item.title"></h4>
<p>
Quantity:
<button @click="item.quantity > 1 ? item.quantity-- : removeFromCart(item.id)"
class="text-gray-600 hover:text-gray-800">
<i data-cy="cart-item-minus" class="ph ph-minus text-sm"></i>
</button>
<span x-text="item.quantity"></span>
<button @click="item.quantity++" class="text-gray-600 hover:text-gray-800">
<i data-cy="cart-item-plus" class="ph ph-plus text-sm"></i>
</button>
</p>
</div>
<div class="item-price">
$<span x-text="(item.price * item.quantity).toFixed(2)"></span>
</div>
</li>
</template>
</ul>
<div x-cloak x-show="cart.length" class="total-section">
<p>
Total: <span>$<span x-text="cartTotal().toFixed(2)"></span></span>
</p>
<p class="text-gray-500">
Shipping and taxes will be added at checkout.
</p>
<button @click="clearCart" data-cy="cart-clear-button"
class="w-full bg-red-700 text-white mt-2 py-2 rounded-sm hover:bg-red-800 transition-all">
<i class="ph ph-trash text-sm"></i> Clear Cart
</button>
</div>
</div>
</div>
<div x-cloak x-show="$store.notification.product" @click="toggleCart"
class="fixed w-[400px] top-4 right-4 md:top-16 md:right-24 bg-white border border-gray-300 p-4 cursor-pointer rounded shadow-lg flex items-center space-x-4">
<div class="min-w-16 h-16 bg-neutral-100 flex items-center justify-center">
<img :src="$store.notification.product?.thumbnail" alt="Product thumbnail" class="w-16 h-16 object-contain" />
</div>
<div>
<p class="text-gray-800">
<span class="font-semibold" x-text="$store.notification.product?.title"></span> has been added to the cart!
</p>
<p class="text-gray-600 text-sm">
$<span x-text="$store.notification.product?.price"></span>
</p>
</div>
</div>
</div>
</body>
</html>