-
Notifications
You must be signed in to change notification settings - Fork 702
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
89 additions
and
21 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
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,59 @@ | ||
"use client"; | ||
|
||
import { Fragment, ReactNode, useEffect } from "react"; | ||
import { Popover } from "@headlessui/react"; | ||
import { Icon } from "@tremor/react"; | ||
import { AiOutlineMenu, AiOutlineClose } from "react-icons/ai"; | ||
import { usePathname } from "next/navigation"; | ||
|
||
type CloseMenuOnRouteChangeProps = { | ||
closeMenu: () => void; | ||
}; | ||
|
||
const CloseMenuOnRouteChange = ({ closeMenu }: CloseMenuOnRouteChangeProps) => { | ||
const pathname = usePathname(); | ||
|
||
useEffect(() => { | ||
closeMenu(); | ||
}, [pathname, closeMenu]); | ||
|
||
return null; | ||
}; | ||
|
||
type MenuButtonProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export const Menu = ({ children }: MenuButtonProps) => { | ||
return ( | ||
<Popover as={Fragment}> | ||
{({ close: closeMenu }) => ( | ||
<> | ||
<div className="p-3 w-full block lg:hidden"> | ||
<Popover.Button className="p-1 hover:bg-gray-200 font-medium rounded-lg hover:text-orange-500 focus:ring focus:ring-orange-300"> | ||
<Icon icon={AiOutlineMenu} color="orange" /> | ||
</Popover.Button> | ||
</div> | ||
|
||
<aside className="bg-gray-50 col-span-1 border-r border-gray-300 h-full hidden lg:block"> | ||
<nav className="flex flex-col h-full">{children}</nav> | ||
</aside> | ||
|
||
<CloseMenuOnRouteChange closeMenu={closeMenu} /> | ||
<Popover.Panel | ||
className="bg-gray-50 col-span-1 border-r border-gray-300 z-50 h-screen fixed inset-0" | ||
as="nav" | ||
> | ||
<div className="p-3 fixed top-0 right-0 "> | ||
<Popover.Button className="p-1 hover:bg-gray-200 font-medium rounded-lg hover:text-orange-500 focus:ring focus:ring-orange-300"> | ||
<Icon icon={AiOutlineClose} color="orange" /> | ||
</Popover.Button> | ||
</div> | ||
|
||
{children} | ||
</Popover.Panel> | ||
</> | ||
)} | ||
</Popover> | ||
); | ||
}; |
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