-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/implement navbar #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
00e69d8
feat: add navbar constants
arxja a4a5a8f
feat: move main page.tsx to (root)
arxja 2bd60de
feat: add gsap and react-use
arxja 143f532
style: update styles and dark mode support
arxja 438b3f0
feat: implement navbar
arxja a610418
chore: add /pricing to the public routes
arxja 49e1c40
fix: potential issues
arxja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
| import Navbar from "@/components/Navbar"; | ||
|
|
||
| export default function RootLayout({ | ||
| children, | ||
| }: Readonly<{ | ||
| children: React.ReactNode; | ||
| }>) { | ||
| return ( | ||
| <> | ||
| <Navbar /> | ||
| {children} | ||
| </> | ||
| ); | ||
| } |
File renamed without changes.
This file contains hidden or 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 hidden or 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 hidden or 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,113 @@ | ||
| "use client"; | ||
|
|
||
| import { useAuth } from "@/hooks/useAuth"; | ||
| import { NAVBAR_ITEMS } from "@/lib/constants"; | ||
| import Link from "next/link"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import { useWindowScroll } from "react-use"; | ||
| import gsap from "gsap"; | ||
|
|
||
| const Navbar = () => { | ||
| const { user } = useAuth(); | ||
| const [isNavVisible, setIsNavVisible] = useState(true); | ||
| const { y: currentScrollY } = useWindowScroll(); | ||
| const [lastScrollY, setLastScrollY] = useState(0); | ||
| const navContainerRef = useRef<HTMLDivElement>(null); | ||
| const [prefersReducedMotion, setPrefersReducedMotion] = useState(false); | ||
|
|
||
| // Check for reduced motion preference | ||
| useEffect(() => { | ||
| const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)"); | ||
| setPrefersReducedMotion(mediaQuery.matches); | ||
|
|
||
| const handler = (e: MediaQueryListEvent) => | ||
| setPrefersReducedMotion(e.matches); | ||
| mediaQuery.addEventListener("change", handler); | ||
| return () => mediaQuery.removeEventListener("change", handler); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| const SCROLL_THRESHOLD = 10; | ||
| const HIDE_DELAY_PX = 50; | ||
|
|
||
| if (currentScrollY === 0) { | ||
| setIsNavVisible(true); | ||
| navContainerRef.current?.classList.remove("floating-nav"); | ||
| } else if (currentScrollY > lastScrollY && currentScrollY > HIDE_DELAY_PX) { | ||
| setIsNavVisible(false); | ||
| navContainerRef.current?.classList.add("floating-nav"); | ||
| } else if ( | ||
| currentScrollY < lastScrollY && | ||
| Math.abs(currentScrollY - lastScrollY) > SCROLL_THRESHOLD | ||
| ) { | ||
| setIsNavVisible(true); | ||
| navContainerRef.current?.classList.add("floating-nav"); | ||
| } | ||
|
|
||
| setLastScrollY(currentScrollY); | ||
| }, [currentScrollY, lastScrollY]); | ||
|
|
||
| useEffect(() => { | ||
| if (!navContainerRef.current) return; | ||
|
|
||
| gsap.to(navContainerRef.current, { | ||
| y: isNavVisible ? 0 : 100, | ||
| opacity: isNavVisible ? 1 : 0, | ||
| visibility: isNavVisible ? "visible" : "hidden", | ||
| duration: prefersReducedMotion ? 0 : 0.2, | ||
| pointerEvents: isNavVisible ? "auto" : "none", | ||
| }); | ||
| }, [isNavVisible, prefersReducedMotion]); | ||
|
|
||
| return ( | ||
| <div | ||
| ref={navContainerRef} | ||
| className="fixed inset-x-0 top-4 z-50 h-16 border-none transition-all duration-700 sm:inset-x-6" | ||
| > | ||
| <header className="absolute top-1/2 w-full -translate-y-1/2"> | ||
| <nav className="flex size-full items-center justify-between px-6 py-2"> | ||
| {/* Left - Logo */} | ||
| <div className="flex items-center gap-7"> | ||
| <Link | ||
| href="/" | ||
| className="flex h-10 w-10 items-center justify-center rounded-full bg-primary-500/20 text-primary-600 transition-all hover:scale-105 hover:bg-primary-500/30 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 dark:bg-primary-500/30 dark:text-primary-400" | ||
| > | ||
| {/* ToDo: change with actual logo */} | ||
| <span className="text-sm font-semibold">SaaSify</span> | ||
| </Link> | ||
| </div> | ||
|
|
||
| {/* Right - nav items & user */} | ||
| <div className="flex flex-row items-center gap-6"> | ||
| {/* nav items */} | ||
| <div className="flex flex-row gap-2"> | ||
| {NAVBAR_ITEMS.map((item, idx) => ( | ||
| <Link | ||
| className="nav-hover-btn text-sm font-medium text-text-secondary transition-colors hover:text-text-primary focus-visible:text-text-primary dark:text-text-primary dark:hover:text-primary-400 dark:focus-visible:text-primary-400" | ||
| href={item.link} | ||
| key={idx} | ||
| > | ||
| {item.name} | ||
| </Link> | ||
| ))} | ||
| </div> | ||
|
|
||
| {/* User area */} | ||
| {user ? ( | ||
| <div className="h-8 w-8 rounded-full bg-primary-500/20 ring-2 ring-primary-500/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500" /> | ||
| ) : ( | ||
| <Link | ||
| href="/sign-in" | ||
| className="rounded-lg bg-primary-500 px-4 py-1.5 text-sm font-medium text-white transition-all hover:bg-primary-600 hover:shadow-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2" | ||
| > | ||
| Login | ||
| </Link> | ||
| )} | ||
| </div> | ||
| </nav> | ||
| </header> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Navbar; | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.