From 71664d7fb8b0710bae4b275bc786d47e11fc705f Mon Sep 17 00:00:00 2001 From: Laura Beatris <48022589+LauraBeatris@users.noreply.github.com> Date: Wed, 4 Nov 2020 09:00:47 -0300 Subject: [PATCH] Add presence animation to mobile navbar links --- components/Header/MobileNavbar.tsx | 100 ++++++++++++++++++----------- 1 file changed, 64 insertions(+), 36 deletions(-) diff --git a/components/Header/MobileNavbar.tsx b/components/Header/MobileNavbar.tsx index 9dd9f02..d4d47dd 100644 --- a/components/Header/MobileNavbar.tsx +++ b/components/Header/MobileNavbar.tsx @@ -1,4 +1,5 @@ import React, { useRef, useState } from "react"; +import { AnimatePresence, motion } from "framer-motion"; import { Link } from "react-scroll"; import Image from "next/image"; import useOnClickOutside from "use-onclickoutside"; @@ -6,23 +7,41 @@ import { AiOutlineClose } from "react-icons/ai"; import { headerNavbarLinks } from "./constants"; +const navbarMotionStyles = { + exit: { + left: "100%", + opacity: 0, + }, + initial: { + right: 0, + opacity: 1, + }, + animate: { + opacity: 1, + }, +}; + const NavbarMobile: React.FC = () => { const [isNavbarMobileOpen, setIsNavbarMobileOpen] = useState(false); const navElementRef = useRef(null); - const toggleNavbarMobile = (): void => { - setIsNavbarMobileOpen(prev => !prev); + const openNavbarMobile = (): void => { + setIsNavbarMobileOpen(true); + }; + + const closeNavbarMobile = (): void => { + setIsNavbarMobileOpen(false); }; - useOnClickOutside(navElementRef, toggleNavbarMobile); + useOnClickOutside(navElementRef, closeNavbarMobile); return ( <> - { - isNavbarMobileOpen && ( - - ) - } + + + ) + } + ); };