diff --git a/src/App.css b/src/App.css index 74b5e05..eba4de9 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,39 @@ .App { text-align: center; + box-sizing: border-box; } -.App-logo { - height: 40vmin; - pointer-events: none; +.search-bar { + display: flex; + flex-direction: column; + align-items: center; + font-size: 1rem; + margin-bottom: 50px } -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } +.search-bar p { + margin: 0; + font-size: 1.3rem } -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; +#search { + width: 800px; + padding: 10px; + font-size: 1rem } -.App-link { - color: #61dafb; +.checkBox-container { + margin-top: 10px } -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +.product-table { + /* display: flex; + align-items: center; + flex-direction: column; */ + margin: auto; + width: 800px } + +thead { + background-color: gray; +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 3784575..9daf085 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,11 @@ -import logo from './logo.svg'; import './App.css'; +import ProductsPage from './components/ProductsPage'; + function App() { return ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
+
+
); } diff --git a/src/components/ProductTable.js b/src/components/ProductTable.js new file mode 100644 index 0000000..c558d86 --- /dev/null +++ b/src/components/ProductTable.js @@ -0,0 +1,26 @@ +import React from "react"; + +function ProductTable(props) { + + return ( + + + + + + + + + {props.products.map((product) => { + return ( + + + + + ) + })} + +
NamePrice
{product.name}{product.price}
+ ) +} +export default ProductTable; \ No newline at end of file diff --git a/src/components/ProductsPage.js b/src/components/ProductsPage.js new file mode 100644 index 0000000..8153650 --- /dev/null +++ b/src/components/ProductsPage.js @@ -0,0 +1,35 @@ +import { useState } from 'react'; +import jsonData from '../data.json'; +import SearchBar from './SearchBar'; +import ProductTable from './ProductTable'; + +function ProductsPage() { + + const [searchQuery, setSearchQuery] = useState(''); + const [onlyInStock, setOnlyInStock] = useState(false); + + const handleSearchChange = (query) => { + setSearchQuery(query); + }; + + const handleInStockChange = (event) => { + setOnlyInStock(event.target.checked); + }; + + const filteredProducts = jsonData.filter((product) => { + const matchesSearchQuery = product.name.toLowerCase().includes(searchQuery.toLowerCase()); + const matchesStockFilter = !onlyInStock || product.inStock; + return matchesSearchQuery && matchesStockFilter; + }); + + + return ( +
+

Root Store

+ + +
+ ) + +}; +export default ProductsPage; \ No newline at end of file diff --git a/src/components/SearchBar.js b/src/components/SearchBar.js new file mode 100644 index 0000000..05ff5b4 --- /dev/null +++ b/src/components/SearchBar.js @@ -0,0 +1,17 @@ +import React from "react"; + +function SearchBar(props) { + + return ( +
+

Search

+ props.onSearchChange(e.target.value)} /> +
+ + Only show products available +
+
+ ) +} + +export default SearchBar; \ No newline at end of file