Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

Header.tsx

62 lines2.3 KB

1import { useCartStore } from '~/e-Commerce/store/cartStore'
2​
3export function Header() {
4 const totalItems = useCartStore((state) => state.totalItems)
5 const totalPrice = useCartStore((state) => state.totalPrice)
6​
7 return (
8 <header className="border-6 border-dashed border-green-500 rounded-xl p-4 bg-white shadow-lg mb-8">
9 <div className="flex items-center justify-between">
10 <div className="flex items-center gap-3">
11 <span className="text-2xl">🎸</span>
12 <h1 className="text-2xl font-bold text-gray-900">
13 TanStack Music Store
14 </h1>
15 </div>
16​
17 <div className="flex items-center gap-4">
18 <p className="text-gray-600 hidden sm:block">
19 Premium instruments powered by Server Components
20 </p>
21​
22 {/* Cart Button */}
23 <button className="relative flex items-center gap-2 bg-gray-900 text-white px-4 py-2 rounded-lg hover:bg-gray-800 transition-colors">
24 <svg
25 className="w-5 h-5"
26 fill="none"
27 stroke="currentColor"
28 viewBox="0 0 24 24"
29 >
30 <path
31 strokeLinecap="round"
32 strokeLinejoin="round"
33 strokeWidth={2}
34 d="M3 3h2l.4 2M7 13h10l4-8H5.4M7 13L5.4 5M7 13l-2.293 2.293c-.63.63-.184 1.707.707 1.707H17m0 0a2 2 0 100 4 2 2 0 000-4zm-8 2a2 2 0 11-4 0 2 2 0 014 0z"
35 />
36 </svg>
37 <span className="font-semibold">Cart</span>
38​
39 {/* Item count badge */}
40 {totalItems > 0 && (
41 <span className="absolute -top-2 -right-2 bg-red-500 text-white text-xs font-bold rounded-full w-6 h-6 flex items-center justify-center animate-pulse">
42 {totalItems}
43 </span>
44 )}
45 </button>
46 </div>
47 </div>
48​
49 {/* Cart summary (when items in cart) */}
50 {totalItems > 0 && (
51 <div className="mt-3 pt-3 border-t border-gray-200 flex items-center justify-end gap-4 text-sm">
52 <span className="text-gray-600">
53 {totalItems} item{totalItems !== 1 ? 's' : ''} in cart
54 </span>
55 <span className="font-bold text-gray-900">
56 Total: ${totalPrice.toFixed(2)}
57 </span>
58 </div>
59 )}
60 </header>
61 )