mirror of
https://github.com/vercel/commerce.git
synced 2025-03-31 01:05:53 +00:00
* Updated log * Updates to root * Updates to pnpm * successfully moved to pnpm * type issue * Local as the default provider * Upgrade dependencies * Revert to local * Upgrade React * Update node-fetch deps * Fix types * Ignore warnings * Fix missing dependency * Update pnpm-lock.yaml * Add missing @types/cookie * Upgrade dependencies * Fix missing dependencies * Update README.md Co-authored-by: Bel Curcio <curciobel@gmail.com>
34 lines
855 B
TypeScript
34 lines
855 B
TypeScript
import { FC, useState, useEffect, ReactNode } from 'react'
|
|
import throttle from 'lodash.throttle'
|
|
import cn from 'clsx'
|
|
import s from './Navbar.module.css'
|
|
|
|
const NavbarRoot: FC<{ children?: ReactNode }> = ({ children }) => {
|
|
const [hasScrolled, setHasScrolled] = useState(false)
|
|
|
|
useEffect(() => {
|
|
const handleScroll = throttle(() => {
|
|
const offset = 0
|
|
const { scrollTop } = document.documentElement
|
|
const scrolled = scrollTop > offset
|
|
|
|
if (hasScrolled !== scrolled) {
|
|
setHasScrolled(scrolled)
|
|
}
|
|
}, 200)
|
|
|
|
document.addEventListener('scroll', handleScroll)
|
|
return () => {
|
|
document.removeEventListener('scroll', handleScroll)
|
|
}
|
|
}, [hasScrolled])
|
|
|
|
return (
|
|
<div className={cn(s.root, { 'shadow-magical': hasScrolled })}>
|
|
{children}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default NavbarRoot
|