-
Notifications
You must be signed in to change notification settings - Fork 132
/
Nav.js
34 lines (31 loc) · 984 Bytes
/
Nav.js
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
import Link from 'next/link'
import { useContext } from 'react'
import { CartContext } from '../context/shopContext'
import MiniCart from './MiniCart'
export default function Nav() {
const { cart, cartOpen, setCartOpen } = useContext(CartContext)
let cartQuantity = 0
cart.map(item => {
return (cartQuantity += item?.variantQuantity)
})
return (
<header className="border-b sticky top-0 z-20 bg-white">
<div className="flex items-center justify-between max-w-6xl pt-4 pb-2 px-4 mx-auto lg:max-w-screen-xl">
<Link href="/" passHref>
<a className="cursor-pointer">
<span className="text-lg pt-1 font-bold">
Shopify + Next.js
</span>
</a>
</Link>
<a
className="text-md font-bold cursor-pointer"
onClick={() => setCartOpen(!cartOpen)}
>
Cart ({cartQuantity})
</a>
<MiniCart cart={cart} />
</div>
</header>
)
}