-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: layout + responsivenes improvements + custom scroll hook
- Loading branch information
Showing
10 changed files
with
115 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use client'; | ||
|
||
import useScrollCallback from '@/lib/hooks/use-scroll-callback'; | ||
import { cn } from '@/lib/utils'; | ||
import { useState } from 'react'; | ||
|
||
interface NavbarProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
const Navbar = ({ children }: NavbarProps) => { | ||
const [isAtTop, setIsAtTop] = useState(true); | ||
useScrollCallback({ | ||
callback: (offsetTop) => { | ||
setIsAtTop(offsetTop < 10); | ||
}, | ||
}); | ||
return ( | ||
<div | ||
className={cn( | ||
'container sticky top-0 z-10 flex items-center justify-between gap-x-8 px-8 py-4 transition-colors', | ||
!isAtTop && 'bg-gradient-to-b from-background to-transparent', | ||
)}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Navbar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect } from 'react'; | ||
|
||
interface UseScrollCallbackProps { | ||
ref?: React.RefObject<HTMLElement>; | ||
callback: (offsetTop: number) => void; | ||
} | ||
|
||
const useScrollCallback = ({ ref, callback }: UseScrollCallbackProps) => { | ||
useEffect(() => { | ||
// Determine the scrollable element | ||
const scrollableElement = ref?.current || window; | ||
|
||
const handleScroll = () => { | ||
if (scrollableElement instanceof Window) { | ||
// Handle scroll for window | ||
callback(window.scrollY || document.documentElement.scrollTop); | ||
} else if (scrollableElement instanceof HTMLElement) { | ||
// Handle scroll for HTMLElement | ||
callback(scrollableElement.scrollTop); | ||
} | ||
}; | ||
|
||
scrollableElement.addEventListener('scroll', handleScroll); | ||
|
||
return () => { | ||
scrollableElement.removeEventListener('scroll', handleScroll); | ||
}; | ||
}, [callback, ref]); | ||
}; | ||
|
||
export default useScrollCallback; |