Skip to content

Commit

Permalink
added floating nav bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ripgrim committed Sep 22, 2024
1 parent 2bc8cb3 commit 6f7c89c
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 18 deletions.
Binary file added public/image/landing/install-guide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 92 additions & 18 deletions src/app/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import Image from 'next/image'
// import { LinearBlur } from "progressive-blur"
import { Spotlight } from "@/components/ui/Spotlight";
import { FlipWords } from "@/components/ui/flip-words";
import { FloatingNav } from "@/components/ui/floating-navbar";
import ShinyGrid from "@/components/ui/ShinyGrid";
import { LucideHome, Info, ArrowDownToLine } from "lucide-react";

export default function Home() {
const router = useRouter()
Expand All @@ -20,27 +22,63 @@ export default function Home() {
}
}

const navItems = [
{
name: "Home",
link: "#home",
icon: <LucideHome className="h-4 w-4 text-neutral-500 dark:text-white" />,
},
{
name: "About",
link: "#about",
icon: <Info className="h-4 w-4 text-neutral-500 dark:text-white" />,
},
{
name: "Install App",
link: "#install",
icon: (
<ArrowDownToLine className="h-4 w-4 text-neutral-500 dark:text-white" />
),
},
];

const handleSmoothScroll = (e: React.MouseEvent<HTMLAnchorElement>, targetId: string) => {
e.preventDefault();
const targetElement = document.getElementById(targetId);
if (targetElement) {
targetElement.scrollIntoView({ behavior: 'smooth' });
}
};

const words = ["easy", "simple", "effortless"];
const preciseSynoynms = ["Precise", "Accurate", "Exact"];

return (
<>
<Spotlight
className="spotlight animate-spotlight absolute top-0 left-0 w-full h-full z-[999999] w-full"
fill="white"
/>
<div className="min-h-screen bg-black text-white overflow-hidden">
<Spotlight
className="spotlight animate-spotlight absolute top-0 left-0 w-full h-full z-[999999] w-full"
fill="white"
/>
<FloatingNav className="bg-black border-1 border-white text-white" navItems={navItems} handleSmoothScroll={handleSmoothScroll} />
<div id="home" className="min-h-screen bg-black text-white overflow-hidden">
<header className="bg-transparent container mx-auto px-4 py-6 flex justify-between items-center relative z-10">
<div className="text-2xl font-bold flex items-center bg-transparent">
<Image
src="/image/pwa/128.png"
alt="EZ Cart Logo"
width={64}
height={64}
className="inline-block"
draggable={false}
/>
EZ Cart
<div className="w-full flex flex-row justify-between items-center">
<div className="text-2xl font-bold flex items-center bg-transparent">
<Image
src="/image/pwa/128.png"
alt="EZ Cart Logo"
width={64}
height={64}
className="inline-block"
draggable={false}
/>
EZ Cart
</div>
<div className="flex flex-row">
<Button size="lg" className="rounded-full bg-white text-black hover:bg-gray-200" onClick={handleGoShopping}>
Go Shopping
</Button>
</div>
</div>
</header>

Expand Down Expand Up @@ -106,9 +144,9 @@ export default function Home() {

<div className="h-[1px] bg-neutral-900 w-[90%] mx-auto" />

<section className="container mx-auto px-4 pt-12 pb-0 text-center">
<section id="about" className="container mx-auto px-4 pt-12 pb-0 text-center">
<h2 className="text-4xl font-bold mb-4">
<FlipWords words={preciseSynoynms} duration={2000} className='text-white'/>totals with<br />your state&apos;s local sales tax
<FlipWords words={preciseSynoynms} duration={2000} className='text-white' />totals with<br />your state&apos;s local sales tax
</h2>
<p className="text-xl text-gray-400">
EZ Cart automatically applies the correct sales tax<br />for your state, ensuring accurate totals every time
Expand Down Expand Up @@ -157,6 +195,42 @@ export default function Home() {
/>
</div>
</section>

<section id="install" className="container mx-auto px-4 pt-2 pb-12 text-center">
<h2 className="text-4xl font-bold mb-4">
Use EZ Cart Offline
</h2>
<p className="text-xl text-gray-400 mb-0">
Install our app for a seamless shopping experience, even without internet
</p>
{/* <div className="flex justify-center space-x-16 mt-14">
<div className="text-center">
<h3 className="text-2xl font-bold mb-4">Desktop</h3>
<ol className="text-left list-decimal list-inside">
<li>Click the install icon in the address bar</li>
<li>Select 'Install' in the prompt</li>
</ol>
</div>
<div className="text-center">
<h3 className="text-2xl font-bold mb-4">Mobile</h3>
<ol className="text-left list-decimal list-inside">
<li>Tap the share button</li>
<li>Select 'Add to Home Screen'</li>
<li>Tap 'Add' in the top right corner</li>
</ol>
</div>
</div> */}
<div className="bg-black rounded-3xl py-0 px-8 relative overflow-hidden">
<Image
src="/image/landing/install-guide.png"
alt="EZ Cart Screenshot"
width={1600}
height={1200}
className="rounded-2xl shadow-2xl mx-auto"
draggable={false}
/>
</div>
</section>
</main>

<div className="h-[1px] bg-neutral-900 w-[90%] mx-auto" />
Expand All @@ -168,7 +242,7 @@ export default function Home() {
</div>
</footer>
</div>
<ShinyGrid className='opacity-[0.3]'/>
<ShinyGrid className='opacity-[0.3]' />
</>
)
}
4 changes: 4 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,8 @@

body{
font-family: var(--font-geist-sans) !important;
}

.floating-nav{
border: 1px solid #ffffff17;
}
119 changes: 119 additions & 0 deletions src/components/ui/floating-navbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
"use client";
import React, { useState, useEffect } from "react";
import { useRouter } from "next/navigation";
import {
motion,
AnimatePresence,
useScroll,
useMotionValueEvent,
} from "framer-motion";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import Link from "next/link";

export const FloatingNav = ({
navItems,
className,
handleSmoothScroll,
}: {
navItems: {
name: string;
link: string;
icon?: JSX.Element;
}[];
className?: string;
handleSmoothScroll: (e: React.MouseEvent<HTMLAnchorElement>, targetId: string) => void;
}) => {
const { scrollYProgress } = useScroll();

const [visible, setVisible] = useState(false);
const [lastScrollY, setLastScrollY] = useState(0);
const [scrollingDown, setScrollingDown] = useState(false);
const [scrollTimer, setScrollTimer] = useState<NodeJS.Timeout | null>(null);

useEffect(() => {
return () => {
if (scrollTimer) clearTimeout(scrollTimer);
};
}, [scrollTimer]);

const router = useRouter();

const handleGoShopping = () => {
if (localStorage.getItem("setupSkipped")) {
router.push('/cart')
} else {
router.push('/step/1')
}
}

useMotionValueEvent(scrollYProgress, "change", (current) => {
if (typeof current === "number") {
const currentScrollY = window.scrollY;
const direction = currentScrollY - lastScrollY;

if (scrollYProgress.get() < 0.05) {
setVisible(false);
} else {
if (direction < 0) {
setVisible(true);
setScrollingDown(false);
if (scrollTimer) clearTimeout(scrollTimer);
} else if (direction > 0) {
setScrollingDown(true);
if (scrollTimer) clearTimeout(scrollTimer);
const newTimer = setTimeout(() => {
if (scrollingDown) setVisible(true);
}, 1000); // Adjust this value to change how long to wait before showing nav
setScrollTimer(newTimer);
}
}

setLastScrollY(currentScrollY);
}
});

return (
<AnimatePresence mode="wait">
<motion.div
initial={{
opacity: 1,
y: -100,
}}
animate={{
y: visible ? 0 : -100,
opacity: visible ? 1 : 0,
}}
transition={{
duration: 0.2,
}}
className={cn(
"floating-nav flex max-w-fit fixed top-10 inset-x-0 mx-auto border border-white rounded-full shadow-[0px_2px_3px_-1px_rgba(0,0,0,0.1),0px_1px_0px_0px_rgba(25,28,33,0.02),0px_0px_0px_1px_rgba(25,28,33,0.08)] z-[5000] pr-2 pl-8 py-2 items-center justify-center space-x-4",
className
)}
>
{navItems.map((navItem: any, idx: number) => (
<Button
key={`button-${idx}`}
variant="ghost"
className="transition-all duration-300 rounded-full p-0 hover:bg-white/10"
>
<Link
key={`link-${idx}`}
href={navItem.link}
onClick={(e) => handleSmoothScroll(e, navItem.link.slice(1))}
className="relative text-white hover:text-white items-center flex space-x-1 px-4 py-2 w-full h-full"
>
<span className="block mr-1">{navItem.icon}</span>
<span className="hidden sm:block text-sm">{navItem.name}</span>
</Link>
</Button>
))}
<Button onClick={handleGoShopping} className="transition-all duration-300 bg-white text-black border text-sm font-medium relative border-white px-4 py-2 rounded-full hover:bg-neutral-300 hover:text-black">
<span>Go Shopping</span>
<span className="absolute inset-x-0 w-1/2 mx-auto -bottom-px bg-gradient-to-r from-transparent via-blue-500 to-transparent h-px" />
</Button>
</motion.div>
</AnimatePresence>
);
};

0 comments on commit 6f7c89c

Please sign in to comment.