Skip to content

Commit 4d37ce0

Browse files
committed
complete burger menu
1 parent ce38a40 commit 4d37ce0

File tree

1 file changed

+66
-11
lines changed

1 file changed

+66
-11
lines changed

components/LinkMenu.tsx

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React, { useState } from "react";
22
import Link from "next/link";
3-
import styled from "styled-components";
3+
import styled, { css } from "styled-components";
4+
5+
interface OpenMenuProps {
6+
isOpen: boolean;
7+
}
48

59
const Navbar = styled.nav`
610
position: fixed;
@@ -47,23 +51,61 @@ const HamburgerLines = styled.div`
4751
height: 23px;
4852
width: 35px;
4953
position: absolute;
50-
top: 5px;
54+
top: 15px;
5155
left: 20px;
5256
z-index: 2;
5357
}
5458
`;
5559

56-
const Line = styled.span`
60+
const LineOne = styled.span<OpenMenuProps>`
61+
@media (max-width: 768px) {
62+
display: block;
63+
height: 4px;
64+
width: 100%;
65+
border-radius: 10px;
66+
background: #333;
67+
transform-origin: 0% 0%;
68+
transition: transform 0.4s ease-in-out;
69+
${({ isOpen }) =>
70+
isOpen &&
71+
css`
72+
transform: rotate(35deg);
73+
`}
74+
}
75+
`;
76+
const LineTwo = styled.span<OpenMenuProps>`
5777
@media (max-width: 768px) {
5878
display: block;
5979
height: 4px;
6080
width: 100%;
6181
border-radius: 10px;
6282
background: #333;
83+
transition: transform 0.2s ease-in-out;
84+
${({ isOpen }) =>
85+
isOpen &&
86+
css`
87+
transform: scaleY(0);
88+
`}
89+
}
90+
`;
91+
const LineThree = styled.span<OpenMenuProps>`
92+
@media (max-width: 768px) {
93+
display: block;
94+
height: 4px;
95+
width: 100%;
96+
border-radius: 10px;
97+
background: #333;
98+
transform-origin: 0% 100%;
99+
transition: transform 0.4s ease-in-out;
100+
${({ isOpen }) =>
101+
isOpen &&
102+
css`
103+
transform: rotate(-35deg);
104+
`}
63105
}
64106
`;
65107

66-
const MenuItems = styled.ul`
108+
const MenuItems = styled.ul<OpenMenuProps>`
67109
order: 2;
68110
display: flex;
69111
@media (max-width: 768px) {
@@ -75,9 +117,15 @@ const MenuItems = styled.ul`
75117
display: flex;
76118
flex-direction: column;
77119
margin-left: -40px;
120+
margin-top: 0;
78121
padding-left: 50px;
79122
transition: transform 0.5s ease-in-out;
80123
box-shadow: 5px 0px 10px 0px #aaa;
124+
${({ isOpen }) =>
125+
isOpen &&
126+
css`
127+
transform: translateX(0);
128+
`}
81129
}
82130
`;
83131

@@ -131,15 +179,22 @@ const Logo = styled.h1`
131179
`;
132180

133181
const LinkMenu: React.FC = () => {
182+
const [isOpen, setIsOpen] = useState(false);
134183
return (
135-
<Navbar className="navbar">
136-
<NavbarContainer className="navbar-container container">
137-
<HamburgerLines className="hamburger-lines">
138-
<Line className="line line1"></Line>
139-
<Line className="line line2"></Line>
140-
<Line className="line line3"></Line>
184+
<Navbar>
185+
<NavbarContainer>
186+
<HamburgerLines
187+
onClick={() => {
188+
setIsOpen(!isOpen);
189+
console.log("clicked", isOpen);
190+
}}
191+
>
192+
<LineOne isOpen={isOpen}></LineOne>
193+
<LineTwo isOpen={isOpen}></LineTwo>
194+
<LineThree isOpen={isOpen}></LineThree>
141195
</HamburgerLines>
142-
<MenuItems>
196+
197+
<MenuItems isOpen={isOpen}>
143198
<MenuItem>
144199
<MenuItemLink href="#home">Home</MenuItemLink>
145200
</MenuItem>

0 commit comments

Comments
 (0)