diff --git a/Components/ProductPage.js b/Components/ProductPage.js new file mode 100644 index 0000000..03d8574 --- /dev/null +++ b/Components/ProductPage.js @@ -0,0 +1,54 @@ +import data from '../data.json' +import ProductTable from './ProductTable' +import React from 'react'; + +function ProductPage() +{ + const [list, setList]=React.useState(data) + function Search(arr ,text) + { + let len=text.length + console.log(text) + if(len === 0) + { + setList(data) + } + else + { + let filteredArray=arr.filter((l) => { + if(l.name.substring(0,len).toLowerCase() === text.toLowerCase()) + return true + else + return false + }) + setList(filteredArray) + } + } + function showStocks(e) + { + if(e.target.checked) + { + let filteredArray=list.filter((l) => l.inStock) + setList(filteredArray) + } + else + { + let text=document.getElementById('srch').value + Search(data ,text) + } + } + return
+

STORE

+
+ Search(list ,e.target.value)} style={{width:'400px' , padding:'6px', fontSize:'20px'}}/> +
+
+ + Only show products in stock +
+ +
+} +export default ProductPage diff --git a/Components/ProductRow.css b/Components/ProductRow.css new file mode 100644 index 0000000..962c893 --- /dev/null +++ b/Components/ProductRow.css @@ -0,0 +1,6 @@ +.row{ + display:flex; + width:550px; + padding:15px; + justify-content:space-between; +} diff --git a/Components/ProductRow.js b/Components/ProductRow.js new file mode 100644 index 0000000..37b8baf --- /dev/null +++ b/Components/ProductRow.js @@ -0,0 +1,13 @@ +import './ProductRow.css' + +function ProductRow(props) +{ + let color='red'; + if(props.stock) + color='green' + return
+

{props.name}

+

{props.price}

+
+} +export default ProductRow diff --git a/Components/ProductTable.css b/Components/ProductTable.css new file mode 100644 index 0000000..c24ddc3 --- /dev/null +++ b/Components/ProductTable.css @@ -0,0 +1,7 @@ +.table{ + display:flex; + flex-wrap: wrap; + width:70%; + margin: auto; + justify-content: center; + } diff --git a/Components/ProductTable.js b/Components/ProductTable.js new file mode 100644 index 0000000..bb8b0a2 --- /dev/null +++ b/Components/ProductTable.js @@ -0,0 +1,18 @@ +import ProductRow from "./ProductRow" +import './ProductTable.css' +function ProductTable(props) +{ + function createProduct(pro) + { + return + } + return
+ {(props.array).map((pro)=>createProduct(pro))} +
+} + +export default ProductTable diff --git a/src/App.js b/src/App.js index 3784575..1fe0570 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,8 @@ import logo from './logo.svg'; import './App.css'; +import "./App.css"; +import ProductsPage from "./components/ProductsPage"; + function App() { return ( @@ -16,6 +19,11 @@ function App() { rel="noopener noreferrer" > Learn React + +
+ + +