diff --git a/src/App.js b/src/App.js index 3784575..0dc2a48 100644 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,32 @@ -import logo from './logo.svg'; import './App.css'; +import "./App.css"; +import ProductsPage from "./components/ProductsPage"; + + function App() { return (
- logo -

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

+ - Learn React + +
+ + +
); + + + } export default App; diff --git a/src/components/ProductPage.css b/src/components/ProductPage.css new file mode 100644 index 0000000..1ff6f20 --- /dev/null +++ b/src/components/ProductPage.css @@ -0,0 +1,8 @@ +/* src/components/ProductsPage.css */ + +.checkbox-container { + margin-top: 10px; + } + + + diff --git a/src/components/ProductPage.js b/src/components/ProductPage.js new file mode 100644 index 0000000..f83b83a --- /dev/null +++ b/src/components/ProductPage.js @@ -0,0 +1,60 @@ +import React, { useState } from "react"; +import jsonData from "../data.json"; +import ProductTable from "./ProductTable"; +import SearchBar from "./SearchBar"; +import "./ProductsPage.css" + +function ProductsPage() { + const [query, setQuery] = useState(''); + const [filterProducts, setFilterProducts] = useState(jsonData); + const [inStockOnly, setInStockOnly] = useState(false); + + function setSearch(val) { + return new Promise((resolve) => { + setQuery(val); + resolve(val); + }); + } + + function handleChange(e) { + setSearch(e.target.value) + .then((value) => { + setFilterProducts( + jsonData.filter((val) => + val.name.split(" ").some((word) => + word.toLowerCase().startsWith(value) + ) + ) + ); + }) + .catch((err) => { + console.log(err); + }); + } + + function handleCheckboxChange() { + setInStockOnly(!inStockOnly); + + // Use the updated value of inStockOnly in the filter function + setFilterProducts( + jsonData.filter((product) => (!inStockOnly ? product.inStock : true)) + ); + } + + return ( +
+ + + +
+ ); +} + +export default ProductsPage; diff --git a/src/components/ProductRow.js b/src/components/ProductRow.js new file mode 100644 index 0000000..875b487 --- /dev/null +++ b/src/components/ProductRow.js @@ -0,0 +1,20 @@ +import React from 'react' +import './table.css' + +const ProductRow = ({productprop}) => { + return ( + + + {productprop.name} + + {productprop.price} + + + + + ) +} + +export default ProductRow diff --git a/src/components/ProductTable.js b/src/components/ProductTable.js new file mode 100644 index 0000000..f45c8b3 --- /dev/null +++ b/src/components/ProductTable.js @@ -0,0 +1,31 @@ +import React from 'react' +import ProductRow from './ProductRow' +// import './table.css' +import './table.css' + +const ProductTable = ({products}) => { + return ( +
+
+ + + + + + + + + + {products.map((product)=>( + + + ))} + + +
NamePrice
+
+
+ ) +} + +export default ProductTable diff --git a/src/components/SearchBar.js b/src/components/SearchBar.js new file mode 100644 index 0000000..34428ef --- /dev/null +++ b/src/components/SearchBar.js @@ -0,0 +1,23 @@ +import React from 'react' + + +const SearchBar = ({dvalue,onchange}) => { + + const dstyle = { + width:'60%', + height:'40px', + marginTop:'30px' + + } + return ( +
+ +

Store

+

Search

+ + +
+ ) +} + +export default SearchBar diff --git a/src/components/Table.css b/src/components/Table.css new file mode 100644 index 0000000..e77ed57 --- /dev/null +++ b/src/components/Table.css @@ -0,0 +1,31 @@ +*{ + margin: 50; + padding: 90; + + box-sizing: border-box; + font-family: sans-serif; +} + +.body{ + min-height: 10vh; + display: flex; + justify-content: center; + margin-top: 50px; +} + +table{ + width: 10%; + border-collapse: collapse; +} +th, td{ + padding-left: 20rem; + padding-right: 15rem; + padding-top: 1rem; + padding-bottom: 0.5rem; + +} + +thead{ + background-color: rgb(238, 162, 197); + +}