Skip to content

Commit 3191796

Browse files
committed
replace custom dropdown menu with headless ui menu component
1 parent 85caacd commit 3191796

4 files changed

Lines changed: 102 additions & 81 deletions

File tree

package-lock.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"validate": "concurrently --kill-others-on-fail -g -p \"[{name}]\" -n \"prettier,lint,typecheck,build\" \"npm:prettier:check -s\" \"npm:lint -s\" \"npm:typecheck -s\" \"npm:build -s -- --no-lint\""
1515
},
1616
"dependencies": {
17+
"@headlessui/react": "^1.7.3",
1718
"next": "12.3.1",
1819
"react": "18.1.0",
1920
"react-dom": "18.1.0"

src/components/HeroHeader/DropdownMenu.tsx

Lines changed: 73 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,81 @@ import infoIcon from '../../../public/img/info-icon.svg';
44
import calendarIcon from '../../../public/img/calendar-icon.svg';
55
import contactIcon from '../../../public/img/contact-icon.svg';
66
import { ABOUT, CONTACT, EVENTS } from '../../util/routeConstants';
7-
import LinkButton from '../LinkButton/LinkButton';
7+
import menuIcon from '../../../public/img/menu-icon.svg';
8+
import closeIcon from '../../../public/img/close-icon.svg';
9+
import { Menu } from '@headlessui/react';
810

9-
interface DropdownMenuProps {
10-
onCloseMenu: () => void;
11-
}
12-
13-
export default function DropdownMenu({ onCloseMenu }: DropdownMenuProps) {
11+
export default function DropdownMenu() {
1412
return (
15-
<div className="bg-white rounded-[10px] overflow-hidden w-[158px] h-fit absolute top-14 right-5 shadow-[0_0_50px_-12px_rgb(0,0,0,0.25)]">
16-
<ul>
17-
<li className="">
18-
<a
19-
href={ABOUT}
20-
className="w-full p-[10px] flex justify-start items-center"
21-
onClick={() => onCloseMenu()}
22-
>
23-
<Image src={infoIcon} alt="" width={25} height={22} />
24-
<p className="inline-block ml-[10px]">About us</p>
25-
</a>
26-
</li>
27-
<li className="">
28-
<a
29-
href={EVENTS}
30-
className="w-full p-[10px] flex justify-start items-center"
31-
onClick={() => onCloseMenu()}
32-
>
33-
<Image src={calendarIcon} alt="" width={25} height={22} />
34-
<p className="inline-block ml-[10px]">Events</p>
35-
</a>
36-
</li>
37-
<li className="">
38-
<a
39-
href={CONTACT}
40-
className="w-full p-[10px] flex justify-start items-center"
41-
onClick={() => onCloseMenu()}
42-
>
43-
<Image src={contactIcon} alt="" width={25} height={25} />
44-
<p className="inline-block ml-[10px]">Contact</p>
45-
</a>
46-
</li>
47-
</ul>
48-
<div className="">
49-
<LinkButton
50-
className="flex justify-center items-center bg-[#12A04E] text-white w-full font-montserrat text-xs py-[10px]"
51-
href="https://bit.ly/joinreactdevske"
52-
target="_blank"
53-
rel="noopener noreferrer"
54-
onClick={() => onCloseMenu()}
55-
>
56-
Join React.JS Kenya
57-
</LinkButton>
13+
<Menu>
14+
<Menu.Button>
15+
{({ open }) =>
16+
open ? (
17+
<div className="inline-flex justify-center items-center w-[30px] ">
18+
<Image src={closeIcon} alt="" width={20} height={20} />
19+
</div>
20+
) : (
21+
<Image src={menuIcon} alt="" width={30} height={30} />
22+
)
23+
}
24+
</Menu.Button>
25+
<div className="bg-white rounded-[10px] overflow-hidden w-[158px] h-fit absolute top-14 right-5 shadow-[0_0_50px_-12px_rgb(0,0,0,0.25)]">
26+
<Menu.Items>
27+
<Menu.Item>
28+
{({ active }) => (
29+
<a
30+
href={ABOUT}
31+
className={`w-full p-[10px] flex justify-start items-center ${
32+
active && 'bg-green-100'
33+
}`}
34+
>
35+
<Image src={infoIcon} alt="" width={25} height={22} />
36+
<p className="inline-block ml-[10px]">About us</p>
37+
</a>
38+
)}
39+
</Menu.Item>
40+
<Menu.Item>
41+
{({ active }) => (
42+
<a
43+
href={EVENTS}
44+
className={`w-full p-[10px] flex justify-start items-center ${
45+
active && 'bg-green-100'
46+
}`}
47+
>
48+
<Image src={calendarIcon} alt="" width={25} height={22} />
49+
<p className="inline-block ml-[10px]">Events</p>
50+
</a>
51+
)}
52+
</Menu.Item>
53+
<Menu.Item>
54+
{({ active }) => (
55+
<a
56+
href={CONTACT}
57+
className={`w-full p-[10px] flex justify-start items-center ${
58+
active && 'bg-green-100'
59+
}`}
60+
>
61+
<Image src={contactIcon} alt="" width={25} height={25} />
62+
<p className="inline-block ml-[10px]">Contact</p>
63+
</a>
64+
)}
65+
</Menu.Item>
66+
<Menu.Item>
67+
{({ active }) => (
68+
<a
69+
className={`flex justify-center items-center bg-[#12A04E] text-white w-full font-montserrat text-xs py-[10px] ${
70+
active && 'bg-green-500'
71+
}`}
72+
href="https://bit.ly/joinreactdevske"
73+
target="_blank"
74+
rel="noopener noreferrer"
75+
>
76+
Join React.JS Kenya
77+
</a>
78+
)}
79+
</Menu.Item>
80+
</Menu.Items>
5881
</div>
59-
</div>
82+
</Menu>
6083
);
6184
}

src/components/HeroHeader/MobileHero.tsx

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import Image from 'next/image';
2-
import React, { useState } from 'react';
2+
import React from 'react';
33
import Logo from '../Logo';
44
import githubIcon from '../../../public/img/github-logo.svg';
5-
import menuIcon from '../../../public/img/menu-icon.svg';
6-
import closeIcon from '../../../public/img/close-icon.svg';
75
import DropdownMenu from './DropdownMenu';
86
import LinkButton from '../LinkButton/LinkButton';
7+
import Link from 'next/link';
8+
import { HOME } from '../../util/routeConstants';
99

1010
export default function MobileHero() {
11-
const [menuOpen, setMenuOpen] = useState(false);
12-
13-
const openMenu = () => setMenuOpen(true);
14-
const closeMenu = () => setMenuOpen(false);
15-
1611
return (
1712
<div className="relative">
1813
<div className="mx-6 pt-2 pb-5 flex justify-between">
19-
<Logo size={60} />
14+
<Link href={HOME}>
15+
<a>
16+
<Logo size={60} />
17+
</a>
18+
</Link>
2019
<a
2120
target="_blank"
2221
href="https://github.com/reactdeveloperske/reactdevske-website"
@@ -25,29 +24,8 @@ export default function MobileHero() {
2524
>
2625
<Image src={githubIcon} alt="" width={35} height={35} />
2726
</a>
28-
{menuOpen ? (
29-
<div className="inline-flex justify-center items-center w-[30px] ">
30-
<Image
31-
src={closeIcon}
32-
alt=""
33-
width={20}
34-
height={20}
35-
className="cursor-pointer"
36-
onClick={closeMenu}
37-
/>
38-
</div>
39-
) : (
40-
<Image
41-
src={menuIcon}
42-
alt=""
43-
width={30}
44-
height={30}
45-
className="cursor-pointer"
46-
onClick={openMenu}
47-
/>
48-
)}
27+
<DropdownMenu />
4928
</div>
50-
{menuOpen && <DropdownMenu onCloseMenu={closeMenu} />}
5129
<div>
5230
<h1 className="font-robotoMono font-medium text-4xl text-center mb-2">
5331
ReactDevsKe

0 commit comments

Comments
 (0)