-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
0ccccca
3eef594
c7d8a82
245c1f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
} | ||
|
||
.country { | ||
margin-top: 2.5rem; | ||
position: relative; | ||
width: 100%; | ||
border-radius: $border-radius; | ||
|
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) => { | ||
return ( | ||
<Link to={`/details/${country.name}`} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. save the route |
||
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const CountryFlag = (country) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
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; |
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={'/'}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. save the home page route |
||
<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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
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; |
There was a problem hiding this comment.
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.
Another way to do it is to use destruct and specify the arguments in the props.