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

Shay Mashiah's React version for Countries assigment #11

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link
rel="stylesheet"
href="https://site-assets.fontawesome.com/releases/v6.0.0/css/all.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
Expand Down
70 changes: 69 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"react-router-dom": "^7.1.1"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
Expand Down
9 changes: 8 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import "../src/assets/css/details.css";
import "../src/assets/css/main.css";
import "../src/assets/scss/common.scss";
import Home from "./pages/Home";
import Details from "./pages/Details";
import { BrowserRouter as Router, Route, Routes } from "react-router-dom";

function App() {
return (
<>
<Home />
<Router>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/details/:countryName" element={<Details />} />
</Routes>
</Router>
</>
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/assets/css/details.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ body {
column-gap: 12px;
}


.country-details {
width: 100%;
}



@media (min-width: 64em) {
.country-details {
display: flex;
Expand All @@ -44,7 +47,7 @@ body {
.country-flag {
flex-shrink: 0;
width: 450px;
max-width: 450px;
max-width: 320px;
max-height: 350px;
box-shadow: 0 2px 15px rgba(0, 0, 0, 0.08);
overflow: hidden;
Expand All @@ -69,14 +72,14 @@ body {
padding: 40px 0;
}

.country-info h1 {
.country-info h2 {
color: #111517;
margin-bottom: 30px;
}

.country-info strong {
text-transform: capitalize;
color: #111517;
color:#111517;
}

.country-info strong.warning {
Expand Down
1 change: 1 addition & 0 deletions src/assets/scss/_countries-grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
}

.country {
margin-top: 2.5rem;
position: relative;
width: 100%;
border-radius: $border-radius;
Expand Down
1 change: 1 addition & 0 deletions src/assets/scss/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
padding: 1.25rem 0; // 20px
box-shadow: $box-shadow;
transition: $fast-transition;
margin-bottom: 3rem;

.container {
display: flex;
Expand Down
21 changes: 21 additions & 0 deletions src/components/Card.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import '../assets/css/common.css';
import countriesData from '../assets/CountriesData.json';
import {Link} from 'react-router-dom';
import CountryFlag from './CountryFlag';
import CountryInfo from './CountryInfo.jsx';

const Card = (country) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The convention is to use props to describe the argument that passed to the component.

const Card = (props) => {

Another way to do it is to use destruct and specify the arguments in the props.

const Card = ({name, flag, population, capital, region}) => {

return (
<Link to={`/details/${country.name}`}
Copy link
Contributor

Choose a reason for hiding this comment

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

save the route /details as a const variable in a const.js file and use it here

key={country.name}
className="country">

<CountryFlag flag={country.flag} name={country.name} />

<CountryInfo name={country.name} population={country.population} region={country.region} capital={country.capital} />

</Link>
);
};

export default Card;
9 changes: 9 additions & 0 deletions src/components/CountryFlag.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const CountryFlag = (country) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

As same as before (countries -> props / {...})

return (
<div className="country-flag">
<img src={country.flag} alt={country.name} />
</div>
);
}

export default CountryFlag;
21 changes: 21 additions & 0 deletions src/components/CountryInfo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const CountryInfo = (country) => {
return (
<div className="country-info">
<h2 className="country-title">{country.name}</h2>
<ul className="country-data-list">
<li>
<strong>Population:</strong> {country.population}
</li>
<li>
<strong>Region:</strong> {country.region}
</li>
<li>
<strong>Capital:</strong> {country.capital}
</li>
</ul>
</div>

);
}

export default CountryInfo;
31 changes: 31 additions & 0 deletions src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import '../assets/css/common.css'
import {Link} from 'react-router-dom';

const Header = () => {
const toggleDarkMode = () => {
document.body.classList.toggle('dark-theme');
};

return (
<header className='header'>
<div className="container">
<div className="logo">
<Link to={'/'}>
Copy link
Contributor

Choose a reason for hiding this comment

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

save the home page route / as a const variable in const.js and use it here

<h1>Where in the world?</h1>
</Link>
</div>
<button
type="button"
aria-label="Theme Switcher Button"
className="theme-toggle flex flex-jc-sb flex-ai-c"
onClick={toggleDarkMode}
>
<i className="fa-regular fa-moon theme-icon"></i>
<span className="theme-text">Dark Mode</span>
</button>
</div>
</header>
)
}

export default Header
18 changes: 5 additions & 13 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,27 @@ a:hover {

body {
margin: 0;
display: flex;
place-items: center;
/* display: flex;
place-items: center; */
Comment on lines +27 to +28
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the comment

min-width: 320px;
min-height: 100vh;
}

h1 {
font-size: 3.2em;
font-size: 4.6em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-size: 10em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}


@media (prefers-color-scheme: light) {
:root {
Expand Down
42 changes: 42 additions & 0 deletions src/pages/Details.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import '../assets/css/details.css';
import '../assets/css/main.css';
import Header from "../components/Header";
import CountryFlag from '../components/CountryFlag';
import CountryInfo from '../components/CountryInfo';
import countriesData from '../assets/CountriesData.json';
import { useParams, Link } from 'react-router-dom';

const Details = () => {
const { countryName } = useParams();
const country = countriesData.find((c) => c.name === countryName);

return (
<>
<Header />
<div className="back-button">
<div className="container">
<Link to="/" className="btn btn-back btn-with-icon">
<i className="fa-solid fa-arrow-left"></i>
Back
</Link>
</div>
</div>
<main className="main">
<div className="container">
<section className="country-details">
<CountryFlag flag={country.flag} name={country.name} />
<CountryInfo
name={country.name}
population={country.population}
region={country.region}
capital={country.capital}

/>
</section>
</div>
</main>
</>
);
};

export default Details;
Loading