-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MM-112-menuoptions: display menu items on/off when hamburger is clicked
- Loading branch information
Purbai
committed
Jul 31, 2024
1 parent
9dd8173
commit a6da30a
Showing
8 changed files
with
121 additions
and
43 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 was deleted.
Oops, something went wrong.
File renamed without changes.
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,40 @@ | ||
import React, { useState } from 'react'; | ||
import './Hamburgerbutton.scss'; // styling for the hmauburger button icon | ||
import Menu from './Menu' | ||
import { menuItems } from './MenuItems'; | ||
|
||
interface HamburgerProps { | ||
// onClick: () => void; | ||
// label: string; | ||
|
||
} | ||
|
||
const Hamburger: React.FC<HamburgerProps> = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const handleClick = () => { | ||
// menu items display/not display on click | ||
setIsOpen(!isOpen); | ||
console.log('Hamburger menu display options!'); | ||
<Menu items={menuItems} /> | ||
}; | ||
|
||
return ( | ||
<div> | ||
<button onClick={handleClick} className="hamburger" data-testid="toggle-button"> | ||
{/* draw the 3 lines which make up the hmburger */} | ||
<div className="line" /> | ||
<div className="line" /> | ||
<div className="line" /> | ||
</button> | ||
{/* display the menu list of clicked/unclicked */} | ||
{isOpen && ( | ||
<div className="menu"> | ||
<Menu items={menuItems} /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Hamburger; |
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,30 @@ | ||
import React from 'react'; | ||
|
||
interface MenuItem { | ||
label: string; | ||
link: string; | ||
} | ||
|
||
interface MenuProps { | ||
items: MenuItem[]; | ||
} | ||
|
||
const Menu: React.FC<MenuProps> = ({ items }) => { | ||
return ( | ||
<div> | ||
<h1>Menu </h1> | ||
<nav> | ||
<ul> | ||
{items.map((item, index) => ( | ||
<li key={index}> | ||
<a href={item.link}>{item.label}</a> | ||
</li> | ||
))} | ||
</ul> | ||
</nav> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Menu; | ||
|
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,10 @@ | ||
import React from 'react'; | ||
|
||
// list of the menu options that will be displayed when clicking on hamburger button | ||
export const menuItems = [ | ||
{ label: 'Home', link: '/' }, | ||
{ label: 'Quiz', link: '' }, | ||
{ label: 'Leader board', link: '' }, | ||
{ label: 'Your Mars Rover Collection', link: '' }, | ||
{ label: 'Your Achievements', link: '' }, | ||
]; |
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