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
46 changes: 16 additions & 30 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,24 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
.App{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
.ProductTable{
width: 500px;
display: flex;
flex-direction: column;
justify-content: center;

}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
thead,tr,th,td{
text-align: center;
padding: 10px;
width: 50%;
border: 1px solid black;
}

thead{
background-color: gray;
}
15 changes: 2 additions & 13 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import logo from './logo.svg';
import './App.css';
import ProductsPage from "./components/ProductsPage";

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>
<ProductsPage/>
</header>
</div>
);
Expand Down
10 changes: 10 additions & 0 deletions src/components/ProductRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function ProductRow({product}) {
return <>
<tr>
<td>{product.name}</td>
<td>{product.price}</td>
</tr>
</>
}

export default ProductRow;
20 changes: 20 additions & 0 deletions src/components/ProductTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import ProductRow from "./ProductRow";

function ProductTable({products, searchValue, onlyShowInStock}) {
return <div>
<table>
<thead>
<th>Name</th>
<th>Price</th>
</thead>

{products
.filter((product)=>product.name.toLowerCase().includes(searchValue.toLowerCase()))
.filter((product)=>onlyShowInStock ? product.inStock : true )
.map((product)=> <ProductRow product={product}/>)}

</table>
</div>
}

export default ProductTable;
16 changes: 16 additions & 0 deletions src/components/ProductsPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import SearchBar from "./SearchBar";
import ProductTable from "./ProductTable";
import products from "../data.json"
import { useState } from "react";

function ProductsPage() {
const [searchValue, setSearchValue] = useState("");
const [onlyShowInStock, setOnlyShowInStock] = useState(false);

return <div>
<SearchBar searchValue={searchValue} setSearchValue={setSearchValue} onlyShowInStock={onlyShowInStock} setOnlyShowInStock={setOnlyShowInStock}/>
<ProductTable products={products} searchValue={searchValue} onlyShowInStock={onlyShowInStock}/>
</div>
}

export default ProductsPage;
14 changes: 14 additions & 0 deletions src/components/SearchBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function SearchBar({searchValue, setSearchValue, onlyShowInStock, setOnlyShowInStock}) {
const searchValueHandler=(e)=>{setSearchValue(e.target.value)};
const checkboxValueHandler=()=>{setOnlyShowInStock(!onlyShowInStock)};

return <div>
<label>Search: </label>
<input value={searchValue} type="text" onChange={searchValueHandler}></input>

<label>Only show items in stock? </label>
<input value={onlyShowInStock} type="checkbox" onChange={checkboxValueHandler}/>
</div>
}

export default SearchBar;