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
23 changes: 20 additions & 3 deletions src/components/Country.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import React from 'react'

const Country = () => {
export const Country = ({name ,flag , population , region , capital}) => {
return (
// TODO: Country component
<div>Country</div>
<div className="country scale-effect">
<img src={flag} className="country-flag"></img>
<div className="country-info">
<div className="country-brief">
<p>{name}</p>
<p>{population}</p>
<p>{region}</p>
<p>{capital}</p>
</div>
</div>
</div>
)
}

export default Country
export default Country


// "name": "Åland Islands",
// "flag": "https://flagcdn.com/w320/ax.png",
// "population": 21225,
Copy link
Member

Choose a reason for hiding this comment

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

Remove this

// "region": "Europe",
// "capital": "Mariehamn"
35 changes: 30 additions & 5 deletions src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
import React from "react";
import React, { useState } from "react";
import {Country} from "../components/Country"
import data from '../assets/CountriesData.json'


const Home = () => {
const [cards, setCards]=useState(data)
const onSearch=(e)=>{
const newData= data.filter((card)=>card.name.toLowerCase().includes(e.target.value.toLowerCase()));
console.log(newData)
setCards(newData);

}

return (
// TODO: Home page
// Render Country component (components/Country.jsx) for each country
// Take data from (assets/CountriesData.json)
<div>Home</div>
<div>
<input type="text" className="search-input" placeholder="Search for a country..." onChange={onSearch}></input>
<div className="countries-grid">
{ cards.map((card)=>{
return (
<Country
key={card.name}
name={card.name}
Copy link
Member

Choose a reason for hiding this comment

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

You can add another props to you Card component like this :

export const Country = ({ name, flag, population, region, capital, ...props }) => { 
  return (
    <div {...props}>
      <img src={flag} alt={`${name} flag`} width="100" />
      <h2>{name}</h2>
      <p>Population: {population.toLocaleString()}</p>
      <p>Region: {region}</p>
      <p>Capital: {capital}</p>
    </div>
  );
};

Then all you need to do it call you component like this:

<Country
     //Your props goes in here
      {...country}}
>

flag={card.flag}
population={card.population}
region={card.region}
capital={card.capital}> </Country>
)
})

}
</div>
</div>
);
};

Expand Down