mirror of
https://github.com/vercel/commerce.git
synced 2025-07-24 18:51:23 +00:00
.vscode
assets
components
auth
cart
checkout
common
Avatar
FeatureBar
Footer
Head
HomeAllProductsGrid
I18nWidget
Layout
Navbar
Searchbar
SidebarLayout
UserNav
MenuSidebarView
DropdownMenu.module.css
DropdownMenu.tsx
UserNav.module.css
UserNav.tsx
index.ts
index.ts
icons
product
ui
wishlist
search.tsx
config
framework
lib
pages
public
.editorconfig
.env.template
.eslintrc
.gitignore
.prettierignore
.prettierrc
README.md
codegen.bigcommerce.json
codegen.json
commerce.config.json
global.d.ts
license.md
next-env.d.ts
next.config.js
package-lock.json
package.json
postcss.config.js
swell-js.d.ts
tailwind.config.js
tsconfig.json
* Setup Mobile Menu Sidebar * Setup Basic Mobile Menu Items Styling * Implement full width styling for mobile devices * Cleanup Co-authored-by: Nine <at059214@Abdurahmans-MacBook-Pro.local>
92 lines
2.6 KiB
TypeScript
92 lines
2.6 KiB
TypeScript
import { FC } from 'react'
|
|
import Link from 'next/link'
|
|
import cn from 'classnames'
|
|
import type { LineItem } from '@commerce/types/cart'
|
|
import useCart from '@framework/cart/use-cart'
|
|
import useCustomer from '@framework/customer/use-customer'
|
|
import { Avatar } from '@components/common'
|
|
import { Heart, Bag } from '@components/icons'
|
|
import { useUI } from '@components/ui/context'
|
|
import Button from '@components/ui/Button'
|
|
import DropdownMenu from './DropdownMenu'
|
|
import s from './UserNav.module.css'
|
|
import Menu from '@components/icons/Menu'
|
|
|
|
interface Props {
|
|
className?: string
|
|
}
|
|
|
|
const countItem = (count: number, item: LineItem) => count + item.quantity
|
|
|
|
const UserNav: FC<Props> = ({ className }) => {
|
|
const { data } = useCart()
|
|
const { data: customer } = useCustomer()
|
|
const { toggleSidebar, closeSidebarIfPresent, openModal, setSidebarView } =
|
|
useUI()
|
|
const itemsCount = data?.lineItems.reduce(countItem, 0) ?? 0
|
|
|
|
return (
|
|
<nav className={cn(s.root, className)}>
|
|
<ul className={s.list}>
|
|
{process.env.COMMERCE_CART_ENABLED && (
|
|
<li className={s.item}>
|
|
<Button
|
|
className={s.item}
|
|
variant="naked"
|
|
onClick={() => {
|
|
setSidebarView('CART_VIEW')
|
|
toggleSidebar()
|
|
}}
|
|
aria-label={`Cart items: ${itemsCount}`}
|
|
>
|
|
<Bag />
|
|
{itemsCount > 0 && (
|
|
<span className={s.bagCount}>{itemsCount}</span>
|
|
)}
|
|
</Button>
|
|
</li>
|
|
)}
|
|
{process.env.COMMERCE_WISHLIST_ENABLED && (
|
|
<li className={s.item}>
|
|
<Link href="/wishlist">
|
|
<a onClick={closeSidebarIfPresent} aria-label="Wishlist">
|
|
<Heart />
|
|
</a>
|
|
</Link>
|
|
</li>
|
|
)}
|
|
{process.env.COMMERCE_CUSTOMERAUTH_ENABLED && (
|
|
<li className={s.item}>
|
|
{customer ? (
|
|
<DropdownMenu />
|
|
) : (
|
|
<button
|
|
className={s.avatarButton}
|
|
aria-label="Menu"
|
|
onClick={() => openModal()}
|
|
>
|
|
<Avatar />
|
|
</button>
|
|
)}
|
|
</li>
|
|
)}
|
|
<li className={s.mobileMenu}>
|
|
<Button
|
|
className={s.item}
|
|
variant="naked"
|
|
onClick={() => {
|
|
setSidebarView('MOBILEMENU_VIEW')
|
|
toggleSidebar()
|
|
}}
|
|
aria-label="Menu"
|
|
>
|
|
<Menu />
|
|
</Button>
|
|
</li>
|
|
</ul>
|
|
</nav>
|
|
)
|
|
}
|
|
|
|
export default UserNav
|