Add components
This commit is contained in:
58
src/App.js
58
src/App.js
@@ -1,25 +1,43 @@
|
||||
import logo from './logo.svg';
|
||||
import { Component } from 'react'
|
||||
import './App.css';
|
||||
import { CardList } from './components/card-list/card-list.component'
|
||||
import { SearchBox } from './components/search-box/search-box.component'
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>
|
||||
Edit <code>src/App.js</code> and save to reload.
|
||||
</p>
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React
|
||||
</a>
|
||||
</header>
|
||||
</div>
|
||||
);
|
||||
class App extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
monsters: [],
|
||||
searchField: ''
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
fetch('https://jsonplaceholder.typicode.com/users')
|
||||
.then(response => response.json()).then(
|
||||
users => this.setState({ monsters: users })
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
const { monsters, searchField } = this.state;
|
||||
const filteredMonsters = monsters.filter(monster =>
|
||||
monster.name.toLowerCase().includes(searchField.toLowerCase())
|
||||
);
|
||||
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<SearchBox
|
||||
placeholder='Search Monsters'
|
||||
handleChange={e => this.setState({ searchField: e.target.value })}
|
||||
/>
|
||||
<CardList monsters={filteredMonsters} />
|
||||
</div >
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
||||
14
src/components/card-list/card-list.component.jsx
Normal file
14
src/components/card-list/card-list.component.jsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import { Card } from '../card/card.component'
|
||||
|
||||
|
||||
import './card-list.styles.css'
|
||||
|
||||
export const CardList = (props) => {
|
||||
return <div className='card-list'> {
|
||||
props.monsters.map(monster => {
|
||||
return <Card key={monster.id} monster={monster} />
|
||||
})
|
||||
}</div>
|
||||
}
|
||||
|
||||
8
src/components/card-list/card-list.styles.css
Normal file
8
src/components/card-list/card-list.styles.css
Normal file
@@ -0,0 +1,8 @@
|
||||
.card-list {
|
||||
width: 85vw;
|
||||
margin: 0 auto;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr 1fr 1fr;
|
||||
grid-gap: 20px;
|
||||
}
|
||||
|
||||
13
src/components/card/card.component.jsx
Normal file
13
src/components/card/card.component.jsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
|
||||
import './card.styles.css'
|
||||
|
||||
export const Card = props => {
|
||||
return (
|
||||
<div className='card-container'>
|
||||
<img alt="monser" src={`https://robohash.org/${props.monster.id}?set=set2`}></img>
|
||||
<h2>{props.monster.name}</h2>
|
||||
<p>{props.monster.email}</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
23
src/components/card/card.styles.css
Normal file
23
src/components/card/card.styles.css
Normal file
@@ -0,0 +1,23 @@
|
||||
.card-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #95dada;
|
||||
border: 1px solid grey;
|
||||
border-radius: 5px;
|
||||
padding: 25px;
|
||||
cursor: pointer;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
backface-visibility: hidden;
|
||||
transform: translateZ(0);
|
||||
transition: transform 0.25s ease-out;
|
||||
}
|
||||
|
||||
.card-container:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.card-container img {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: 200px;
|
||||
}
|
||||
15
src/components/search-box/search-box.component.jsx
Normal file
15
src/components/search-box/search-box.component.jsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
|
||||
import './search-box.styles.css'
|
||||
|
||||
export const SearchBox = ({ placeholder, handleChange }) => {
|
||||
return (
|
||||
<input
|
||||
className="search"
|
||||
type='search'
|
||||
placeholder={placeholder}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
9
src/components/search-box/search-box.styles.css
Normal file
9
src/components/search-box/search-box.styles.css
Normal file
@@ -0,0 +1,9 @@
|
||||
.search {
|
||||
-webkit-appearance: none;
|
||||
border: none;
|
||||
outline: none;
|
||||
padding: 10px;
|
||||
width: 150px;
|
||||
line-height: 30px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
Reference in New Issue
Block a user