Skip to content
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

feat: add custom drawer for mobile devices #52

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions components/Drawer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Link from "next/link";

import { AiOutlineClose } from "react-icons/ai";

import { useAuth } from "../Auth";
import { useTheme } from "../Theme";

import DarkModeToggle from "../DarkModeToggle";

export const Drawer = ({ isOpen, onClickClose, landing }) => {
const { user } = useAuth();
const { isDark } = useTheme();

return (
<div className={`${isDark && !landing ? "dark" : "light"}`}>
<nav
className={`py-10 bg-white dark:bg-dark h-screen flex flex-col justify-between fixed top-0 right-0 w-9/12 z-50 transition ease-in-out duration-100 transform : ;
${isOpen ? "translate-x-0" : "translate-x-full"}`}
>
<div className="flex flex-col">
<button onClick={onClickClose} className="m-3 self-end">
<AiOutlineClose size={36} color={isDark && "white"} />
</button>

<ul className="flex flex-col items-center text-xl gap-6 uppercase mt-2">
<li className="cursor-pointer dark:text-white hover:text-primary">
<Link href="/curriculum">Currículo</Link>
</li>
<li className="cursor-pointer dark:text-white hover:text-primary">
<Link href="/projects">Projetos</Link>
</li>
<li className="cursor-pointer dark:text-white hover:text-primary">
<Link href="/team">Equipa</Link>
</li>
<li className="cursor-pointer dark:text-white hover:text-primary">
<Link href="/blog"> Blog </Link>
</li>
<li>
<DarkModeToggle visible={!landing} />
</li>
</ul>
</div>

{user ? (
<div className="text-bold text-lg dark:text-white text-center">
Hello, {user.first_name} {user.last_name}
</div>
) : (
<div className="mx-auto">
<Link href="/login">
<a className="bg-primary text-white rounded px-16 py-4 transform duration-300 uppercase hover:bg-purple-600">
Login
</a>
</Link>
</div>
)}
</nav>

{/* OVERLAY */}
<div
onClick={onClickClose}
className={`${
!isOpen && "hidden"
} bg-gray-400 dark:bg-gray-50 fixed top-0 bottom-0 right-0 left-0 z-40 opacity-80`}
/>
</div>
);
};
51 changes: 19 additions & 32 deletions landing/Header/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { useState } from "react";
import Image from "next/image";
import { Drawer } from "antd";
import { MenuOutlined } from "@ant-design/icons";
import { useAuth } from "~/components/Auth";
import Link from "next/link";
import { useTheme } from "../../components/Theme";
import DarkModeToggle from "../../components/DarkModeToggle";

import { AiOutlineMenu } from "react-icons/ai";

import { useAuth } from "~/components/Auth";
import { useTheme } from "~/components/Theme";
import DarkModeToggle from "~/components/DarkModeToggle";
import { Drawer } from "~/components/Drawer";

function Header({ landing = false }) {
const { user } = useAuth();
const [isDrawerVisible, setVisibleDrawer] = useState(false);
const { isDark } = useTheme();

const [isDrawerOpen, setIsDrawerOpen] = useState(false);

const closeDrawer = () => setIsDrawerOpen(false);

return (
<section className={isDark && !landing ? "dark" : "light"}>
<div className="dark:bg-dark">
Expand Down Expand Up @@ -54,34 +60,15 @@ function Header({ landing = false }) {
</li>
</ul>
<div className="flex md:hidden flex-1 justify-end px-2">
<button
onClick={() => setVisibleDrawer(true)}
type="button"
className="bg-primary text-white text-xl inline-flex items-center justify-center p-2 transform duration-300 rounded-md hover:text-white hover:bg-purple-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-white"
>
<MenuOutlined />
<button onClick={() => setIsDrawerOpen(true)} type="button">
<AiOutlineMenu size={36} color={isDark && "white"} />
</button>

<Drawer
className="flex md:hidden"
placement="right"
closable={false}
onClose={() => setVisibleDrawer(false)}
visible={isDrawerVisible}
zIndex={20}
>
<ul className="flex flex-col items-center text-xl gap-6 uppercase">
<li className="cursor-pointer hover:text-primary">
Currículo
</li>
<li className="cursor-pointer hover:text-primary">
Projetos
</li>
<li className="cursor-pointer hover:text-primary">Equipa</li>
<li className="cursor-pointer hover:text-primary">
<Link href="/blog"> Blog </Link>
</li>
</ul>
</Drawer>
isOpen={isDrawerOpen}
onClickClose={closeDrawer}
landing={landing}
/>
</div>
</nav>
</header>
Expand Down
Loading