From 40a0d103098aea0c6f5ecb54e495199d4f4d65d6 Mon Sep 17 00:00:00 2001 From: beetlejuice96 Date: Mon, 1 Apr 2024 20:21:18 -0300 Subject: [PATCH] add icons and refactor navbar to support mobile view --- components/IconBars/IconBars.stories.tsx | 14 +++ components/IconBars/IconBars.test.tsx | 22 +++++ components/IconBars/IconBars.tsx | 24 +++++ components/Navbar/Navbar.tsx | 120 +++++++++++++++++++---- 4 files changed, 159 insertions(+), 21 deletions(-) create mode 100644 components/IconBars/IconBars.stories.tsx create mode 100644 components/IconBars/IconBars.test.tsx create mode 100644 components/IconBars/IconBars.tsx diff --git a/components/IconBars/IconBars.stories.tsx b/components/IconBars/IconBars.stories.tsx new file mode 100644 index 00000000..c9706750 --- /dev/null +++ b/components/IconBars/IconBars.stories.tsx @@ -0,0 +1,14 @@ +import { Meta, StoryObj } from "@storybook/react"; +import IconBars from "./IconBars"; +export default { + title: "Iconos/Bars", + component: IconBars, +} as Meta; +export const DefaultIconBars: StoryObj = { + args: {}, +}; +export const WhiteIconBars: StoryObj = { + args: { + className: "fill-white", + }, +}; diff --git a/components/IconBars/IconBars.test.tsx b/components/IconBars/IconBars.test.tsx new file mode 100644 index 00000000..e694d436 --- /dev/null +++ b/components/IconBars/IconBars.test.tsx @@ -0,0 +1,22 @@ +import { render, screen } from "@testing-library/react"; +import IconBars from "./IconBars"; + +describe("XMark", () => { + it("IconBars renders correctly", () => { + render(); + }); + + it("XMark component adds className prop", () => { + const className = "fill-white"; + render(); + const svgElement = screen.getByTestId(className); + expect(svgElement).toHaveClass(className); + }); + + it("XMark has aria-hidden attribute", () => { + const className = "fill-white"; + render(); + const svgElement = screen.getByTestId(className); + expect(svgElement).toHaveAttribute("aria-hidden", "true"); + }); +}); diff --git a/components/IconBars/IconBars.tsx b/components/IconBars/IconBars.tsx new file mode 100644 index 00000000..18957a64 --- /dev/null +++ b/components/IconBars/IconBars.tsx @@ -0,0 +1,24 @@ +type IconBarsProps = { + className?: string; +}; + +const IconBars = ({ className }: IconBarsProps) => { + return ( + + ); +}; + +export default IconBars; diff --git a/components/Navbar/Navbar.tsx b/components/Navbar/Navbar.tsx index 41db5b28..668ea064 100644 --- a/components/Navbar/Navbar.tsx +++ b/components/Navbar/Navbar.tsx @@ -1,40 +1,100 @@ "use client"; +import React from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; -import React from "react"; +import { Disclosure } from "@headlessui/react"; import type { NavbarLink } from "types/layout"; import { Logo } from "../Logo/Logo"; +import XMark from "components/XMark/XMark"; +import IconBars from "components/IconBars/IconBars"; interface NavbarLinkProps extends React.HTMLProps { route: string; } -interface NavbarProps extends Partial> { +interface NavbarProps { links: NavbarLink[]; } -export const Navbar = ({ links, ...props }: NavbarProps) => { +export const Navbar = ({ links }: NavbarProps) => { const pathname = usePathname(); const isCurrentIndex = pathname === "/"; + return ( - + + {({ open, close }) => ( + <> +
+ + + + + {/* Mobile menu open button*/} + + {!open && ( +
+

+ MenĂº +

+
+ )} +
+ + {/* nav items desktop */} +
    + {links.map(({ url, name }) => ( + + {name} + + ))} +
+ + {/* nav items mobile */} + + {/* Mobile menu close button*/} + {open && ( +
+ +
+

+ Cerrar +

+
+
+
+ )} +
+ {links.map(({ url, name }) => ( + close()} + > + {name} + + ))} +
+
+
+ + )} +
); }; @@ -62,3 +122,21 @@ export const NavbarItem = ({ children, route, ...props }: NavbarLinkProps) => { ); }; + +const NavBarItemMobile = ({ children, route, ...props }: NavbarLinkProps) => { + const pathname = usePathname(); + const isCurrent = pathname === route; + + return ( +
  • + + {children} + +
  • + ); +};