Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
18 changes: 2 additions & 16 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const App = () => {
};

return (
<div className="App">
<div className={theme === 'light' ? 'App light' : 'App dark'}>
<Header theme={theme} toggleTheme={toggleTheme} />
<Route
exact
Expand All @@ -63,21 +63,7 @@ const App = () => {
path="/:country"
component={() => <h1>Country details page should go HERE</h1>}
/>
{/* Added for demonstration purposes */}
{/* <h1>Search By Name</h1>
Searching for Spain: {searchByName(countries, 'Spain')}
<h1>Search By Name</h1>
Searching for foo: {searchByName(countries, 'foo')}
<h1>Countries</h1> */}
{/* <Dropdown
buttonText="Filter by Region"
list={[]}
selectedItem={region}
onSelect={setRegion}
theme={theme}
/>
<h1>{region}</h1> */}
{/* Added for demonstration purposes END*/}

</div>
);
};
Expand Down
23 changes: 23 additions & 0 deletions src/components/CardBottom/CardBottom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";

import styles from "./CardBottom.module.scss";

const CardBottom = props => (
<div className={styles.CardBottom}>
<h1>{props.name}</h1>
<ul>
<li key={props.alpha3Code}>
<strong>Population:&nbsp;</strong>{props.population}<br />
</li>
<li key={props.alpha3Code}>
<strong>Region:&nbsp;</strong>{props.region}<br />
</li>
<li key={props.alpha3Code}>
<strong>Capital:&nbsp;</strong>{props.capital}<br />
</li>
</ul>
</div>
)


export default CardBottom;
9 changes: 9 additions & 0 deletions src/components/CardBottom/CardBottom.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.CardBottom {
padding-top: 3em;
padding-bottom: 4em;
padding-left: 2em;
}

ul {
list-style-type: none;
}
26 changes: 18 additions & 8 deletions src/components/Country/Country.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ import Flag from "../Flag/Flag";

const Country = props => (
<div className={`${styles.Country} ${props.theme === "light" ? styles.light : styles.dark}`}>

<Flag flag={props.flag} />
<h1>{props.name}</h1>
<ul>


<img className={styles.Flag} src={props.flag} alt={props.name} />
<div className={styles.infoBlock}>
<h1>{props.name}</h1>
<ul>
<li>
<strong>Population:&nbsp;</strong>{props.population}<br />
<strong>Population:&nbsp;</strong>
{props.population}
<br />
</li>
<li>
<strong>Region:&nbsp;</strong>{props.region}<br />
<strong>Region:&nbsp;</strong>
{props.region}
<br />
</li>
<li>
<strong>Capital:&nbsp;</strong>{props.capital}<br />
<strong>Capital:&nbsp;</strong>
{props.capital}
<br />
</li>
</ul>
</ul>
</div>

</div>
)

Expand Down
40 changes: 27 additions & 13 deletions src/components/Country/Country.module.scss
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
@import '../../global.styles.scss';

.Country {
margin: auto;
width: 80%;
padding-bottom: 20px;
display: grid;
border-radius: $border-radius;
box-shadow: $element-box-shadow-light;
overflow: hidden;
cursor: pointer;
img {
width: 100%;
}
h1 {
font-size: 1.1rem;
}
ul {
list-style-type: none;
margin-top: 0.5rem;
}
li {
font-size: 0.9rem;
display: flex;
}
strong {
font-weight: $medium;
}
}
h1 {
margin-left: 20px;
}
ul {
list-style-type: none;
}
li {
.infoBlock {
padding: 1rem 1.5rem 1.5rem 1.5rem;
display: flex;
margin-left: 20px;
flex-direction: column;
justify-content: space-around;
}
.light {
background-color: $white;
color: $very-dark-blue-text;
}

.dark {
color: $white;

background-color: $dark-blue;
color: $white;
box-shadow: $element-box-shadow-dark;
}
65 changes: 61 additions & 4 deletions src/components/Flag/Flag.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,66 @@
import React from "react";
import React, { useState, useEffect } from 'react';
import axios from 'axios';

import styles from "./Flag.module.scss";

const Flag = props => (
<img className={styles.Flag} src={props.flag} alt={props.name}/>
)

function idealAspectRatio({width, height}) {
const aspectRatio = width / height;
if (aspectRatio > 1.5 && aspectRatio <= 1.8){
return false;
}
return true;
}

function getMeta(url){
return new Promise((resolve, reject) => {
let img = new Image();
img.onload = () => resolve(img);
img.onerror = reject;
img.src = url;
});
}

async function getImage(url){
let img = await getMeta(url);
const dimensions = {
width: img.width,
height: img.height
}
return dimensions;
}

function Flag (props) {

const altText = `${props.name} flag`;
const [ratio, setRatio] = useState([]);

useEffect(() => {
getImage(props.flag).then(res => {
const response = res;
setRatio(response);
});
// stop the component from re-rendering since props.flag does not change
},[props.flag]);


const ideal = (idealAspectRatio(ratio));
const classNameText = (ideal ? 'standard' : 'standard');
console.log(classNameText);



return (

<img
className={ideal ? styles.standard : styles.standard}
src={props.flag}
alt={altText}
/>
)

}



export default Flag;
7 changes: 6 additions & 1 deletion src/components/Flag/Flag.module.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
@import '../../global.styles.scss';

.Flag {
.standard {
width: 100%;
height: 100%;
}

.resize {
object-fit: cover;
}
25 changes: 25 additions & 0 deletions src/components/Grid/Grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react";

import Country from "../Country/Country";


import styles from "./Grid.module.scss";

const Grid = props => (
<div className={styles.Grid}>
{props.countries.map(country => (
<Country
key={country.alpha3Code}
theme={props.theme}
flag={country.flag}
name={country.name}
population={country.population}
region={country.region}
capital={country.capital}
/>
))}
</div>
)


export default Grid;
8 changes: 8 additions & 0 deletions src/components/Grid/Grid.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@import '../../global.styles.scss';

.Grid {
display: grid;
grid-gap: 3em;
grid-template-columns: repeat(4, 300px);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be responsive, please check comments on global.styles.scss

grid-auto-rows: 400px;
}
27 changes: 16 additions & 11 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
/* css reset */
* {
box-sizing: border-box;
padding: 0;
margin: 0;
max-width: 100%;
box-sizing: border-box;
padding: 0;
margin: 0;
max-width: 100%;
}

body {
margin: 0;
/* Global Font Family Set to Project Specified */
font-family: 'Nunito Sans', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
margin: 0;
/* Global Font Family Set to Project Specified */
font-family: 'Nunito Sans', sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
box-sizing: border-box;

display: flex;
justify-content: center;
align-items: center;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}