navbar good enough

This commit is contained in:
3zachm 2022-12-12 04:25:11 -08:00
parent ff575b3d64
commit 0a6b969902
2 changed files with 59 additions and 40 deletions

View file

@ -2,7 +2,7 @@ import Link from "next/link";
import { useState, Fragment } from "react"; import { useState, Fragment } from "react";
import { NavTemplate } from "../../layouts/NavTemplates"; import { NavTemplate } from "../../layouts/NavTemplates";
import Image from "next/image"; import Image from "next/image";
import { m, Variants } from "framer-motion"; import { AnimatePresence, m, Variants } from "framer-motion";
interface NavProps { interface NavProps {
options: NavTemplate[]; options: NavTemplate[];
@ -37,16 +37,16 @@ const itemAnimation: Variants = {
function NavBar({ options }: NavProps) { function NavBar({ options }: NavProps) {
const [navList, setNavList] = useState(options); const [navList, setNavList] = useState(options);
const [active, setActive] = useState(false); const [isActive, setActive] = useState(false);
return ( return (
<m.div <m.div
className="pointer-events-none fixed inline-grid w-screen grid-cols-2 p-2 pt-7 font-plusJakarta text-2xl sm:p-7 lg:grid-cols-3" className="pointer-events-none fixed inline-grid w-screen grid-cols-2 font-plusJakarta text-2xl lg:grid-cols-3"
initial="initial" initial="initial"
animate="animate" animate="animate"
variants={containerAnimation} variants={containerAnimation}
> >
<m.div <m.div
className="mr-auto flex flex-row items-center justify-center" className="mr-auto flex flex-row items-center justify-center p-2 sm:p-7"
variants={itemAnimation} variants={itemAnimation}
> >
<m.div <m.div
@ -102,10 +102,9 @@ function NavBar({ options }: NavProps) {
viewBox="0 0 330 330" viewBox="0 0 330 330"
x={0} x={0}
y={0} y={0}
animate={{ rotate: active ? 180 : 0 }} animate={{ rotate: isActive ? 180 : 0 }}
onClick={() => { onClick={() => {
setActive(!active); setActive(!isActive);
console.log(active);
}} }}
> >
<m.path <m.path
@ -126,26 +125,45 @@ function NavBar({ options }: NavProps) {
))} ))}
</m.div> </m.div>
<m.div <m.div
className="ml-auto flex flex-row items-center justify-center" className="ml-auto flex flex-row items-center justify-center p-2 sm:p-7"
variants={itemAnimation} variants={itemAnimation}
> >
<p className="pointer-events-auto select-none pr-5 text-white"> <p className="pointer-events-auto select-none pr-5 text-white">
Login blah Login WIP
</p> </p>
<div className="h-10 w-10 rounded-full bg-white"></div> <div className="h-10 w-10 rounded-full bg-white"></div>
</m.div> </m.div>
<m.div <AnimatePresence mode="wait">
// hiddden by default, when active is true, animate in {isActive && (
className="pointer-events-auto z-10 mt-5 bg-zinc-800 md:max-w-[75%] lg:hidden" <m.div
initial={{ opacity: 0 }} // hiddden by default, when active is true, animate in
animate={{ opacity: active ? 1 : 0 }} className="pointer-events-auto z-10 flex w-screen flex-col items-center overflow-hidden bg-zinc-800 bg-opacity-70 pt-5 backdrop-blur lg:hidden"
transition={{ duration: 0.5 }} // have it take up the entire screen, animate in by expanding from the bottom of the nav bar to the bottom of the screen
> // TODO: struggled with getting children staggers/delays to work
{navList.map((nav, index) => ( initial={{ height: 0 }}
// TODO: stylize -- I have a flight in 4 hours and its 3:04 am animate={{ height: "100vh" }}
<Fragment key={index}>{nav.content}</Fragment> exit={{ height: 0 }}
))} transition={{ duration: 0.5 }}
</m.div> >
{navList.map((nav, index) => (
<m.div
key={index}
custom={index}
className="pointer-events-auto flex w-[90%] flex-row items-center justify-center border-t-[1px] border-b-[1px] border-zinc-700 p-4"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
whileHover={{ backgroundColor: "rgba(0, 0, 0, 0.4)" }}
transition={{ duration: 0.3 }}
onClick={() => {
setActive(false);
}}
>
{nav.content}
</m.div>
))}
</m.div>
)}
</AnimatePresence>
</m.div> </m.div>
); );
} }

View file

@ -10,28 +10,29 @@ const DefaultNavOption = ({
href: string; href: string;
}): ReactElement => { }): ReactElement => {
return ( return (
<m.div <Link href={href} key={label} className="w-full text-center">
initial={{ <m.div
scale: 1, initial={{
}} scale: 1,
whileHover={{ }}
transition: { whileHover={{
duration: 0.2, scale: 1.05,
}, transition: {
}} duration: 0.2,
whileTap={{ },
scale: 0.95, }}
transition: { whileTap={{
duration: 0.2, scale: 0.95,
}, transition: {
}} duration: 0.2,
> },
<Link href={href} key={label}> }}
>
<p className="pointer-events-auto relative select-none pl-3 pr-3 font-plusJakarta text-white md:pl-5 md:pr-5"> <p className="pointer-events-auto relative select-none pl-3 pr-3 font-plusJakarta text-white md:pl-5 md:pr-5">
{label} {label}
</p> </p>
</Link> </m.div>
</m.div> </Link>
); );
}; };