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

Mm 005 header v2 #7

Merged
merged 18 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
23 changes: 18 additions & 5 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { render, screen } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import App from './App';
import "@testing-library/jest-dom";
import Hamburger from './Hamburgerbutton';


// remove this test when real tests are added
test('renders header', () => {
render(<App />);
const header = screen.getAllByText(/MarsioKart/i);
expect(header[0]).toBeInTheDocument();
});
const header = screen.getByText(/MarsioKart/i);
expect(header).toBeInTheDocument();
});

test('calls onClick when Hamburger button is clicked', () => {
const handleClick = jest.fn();
render(<Hamburger onClick={handleClick} label="Click Me" />);

const button = screen.getByText('Click Me');
fireEvent.click(button);

expect(handleClick).toHaveBeenCalledTimes(1);
});

3 changes: 3 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import React from 'react';
import {BrowserRouter as Router, Routes, Route} from 'react-router-dom';
import './App.scss';
import Home from './Home/Home';
import Header from './header';
import { Quiz } from './Quiz/Quiz';
import Footer from './Footer/Footer';


function App() {
return (
<div className="App">
<Router>
<h1>MarsioKart</h1>
<div><Header/></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove the <div>s from this line and just have <Header/> it will be easier for a screen reader to see what is happening and translate it - please can you do that?

<Routes>
<Route path='/'
element={<Home/>}/>
Expand Down
18 changes: 18 additions & 0 deletions src/Hamburgerbutton.scss
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great and is nice and clear - in order to prevent the src folder from being too full of separate files (and therefore harder to read through) please can you create a Hamburgerbutton folder and put this file and Hamburgerbusston.tsx in it

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.hamburger {
display: flex;
flex-direction: column;
justify-content: space-around;
width: 30px;
height: 30px;
background: transparent;
border: none;
cursor: pointer;
}

.line {
width: 100%;
height: 3px;
background-color: black;
transition: all 0.3s ease;
}

27 changes: 27 additions & 0 deletions src/Hamburgerbutton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';
import './Hamburgerbutton.scss'; // styling for the hmauburger button icon

interface HamburgerProps {
onClick: () => void;
label: string;

}

const Hamburger: React.FC<HamburgerProps> = ({ onClick , label}) => {

const handleClick = () => {
onClick();
};

return (
<button onClick={handleClick} className="hamburger">
{/* draw the 3 lines which make up the hmburger */}
{label}
<div className="line" />
<div className="line" />
<div className="line" />
</button>
);
};

export default Hamburger;
16 changes: 16 additions & 0 deletions src/header.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above - please can you also create a Header folder and put this file in it

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import Hamburger from './Hamburgerbutton';

const Header: React.FC = () => {
const handleHamburgerClick = () => {
console.log('Hamburger menu clicked!');
};

return (
<div className="App">
<Hamburger onClick={handleHamburgerClick} label={""}/>
</div>
);
};

export default Header;
Loading