From 7cce0cb6438c59dcbdc1e3fdd4a9b854967e1751 Mon Sep 17 00:00:00 2001 From: Bharath Kompally Date: Fri, 28 Jun 2024 16:47:13 +0530 Subject: [PATCH] done --- src/App.css | 2 +- src/App.js | 8 +++-- src/components/ProductPage.jsx | 54 +++++++++++++++++++++++++++++++++ src/components/ProductRow.css | 6 ++++ src/components/ProductRow.jsx | 13 ++++++++ src/components/ProductTable.css | 7 +++++ src/components/ProductTable.jsx | 19 ++++++++++++ src/components/SearchBar.jsx | 35 +++++++++++++++++++++ src/index.css | 2 +- 9 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 src/components/ProductPage.jsx create mode 100644 src/components/ProductRow.css create mode 100644 src/components/ProductRow.jsx create mode 100644 src/components/ProductTable.css create mode 100644 src/components/ProductTable.jsx create mode 100644 src/components/SearchBar.jsx diff --git a/src/App.css b/src/App.css index 74b5e05..e70a402 100644 --- a/src/App.css +++ b/src/App.css @@ -35,4 +35,4 @@ to { transform: rotate(360deg); } -} +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 3784575..b042305 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,7 @@ import logo from './logo.svg'; import './App.css'; +import ProductPage from './components/ProductPage'; + function App() { return ( @@ -18,8 +20,10 @@ function App() { Learn React + + + ); } - -export default App; +export default App; \ No newline at end of file diff --git a/src/components/ProductPage.jsx b/src/components/ProductPage.jsx new file mode 100644 index 0000000..a1323c9 --- /dev/null +++ b/src/components/ProductPage.jsx @@ -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 \ No newline at end of file diff --git a/src/components/ProductRow.css b/src/components/ProductRow.css new file mode 100644 index 0000000..3a34b01 --- /dev/null +++ b/src/components/ProductRow.css @@ -0,0 +1,6 @@ +.row{ + display:flex; + width:550px; + padding:15px; + justify-content:space-between; +} \ No newline at end of file diff --git a/src/components/ProductRow.jsx b/src/components/ProductRow.jsx new file mode 100644 index 0000000..d12239f --- /dev/null +++ b/src/components/ProductRow.jsx @@ -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 \ No newline at end of file diff --git a/src/components/ProductTable.css b/src/components/ProductTable.css new file mode 100644 index 0000000..8bd5fe7 --- /dev/null +++ b/src/components/ProductTable.css @@ -0,0 +1,7 @@ +.table{ + display:flex; + flex-wrap: wrap; + width:70%; + margin: auto; + justify-content: center; + } \ No newline at end of file diff --git a/src/components/ProductTable.jsx b/src/components/ProductTable.jsx new file mode 100644 index 0000000..74cd5eb --- /dev/null +++ b/src/components/ProductTable.jsx @@ -0,0 +1,19 @@ +import ProductRow from "./ProductRow"; +import './ProductTable.css'; + +function ProductTable(props) { + function createProduct(product) { + return ( + + ); + } + + return
{props.array.map(createProduct)}
; +} + +export default ProductTable; \ No newline at end of file diff --git a/src/components/SearchBar.jsx b/src/components/SearchBar.jsx new file mode 100644 index 0000000..a19fe53 --- /dev/null +++ b/src/components/SearchBar.jsx @@ -0,0 +1,35 @@ +import React from 'react'; + +function SearchBar({ filterText, onFilterTextChange, onInStockOnlyChange }) { + const handleFilterTextChange = (e) => { + onFilterTextChange(e.target.value); + }; + + const handleInStockOnlyChange = (e) => { + onInStockOnlyChange(e.target.checked); + }; + + return ( +
+ + + +
+ ); +} + +export default SearchBar; \ No newline at end of file diff --git a/src/index.css b/src/index.css index ec2585e..3e3b6a1 100644 --- a/src/index.css +++ b/src/index.css @@ -10,4 +10,4 @@ body { code { font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace; -} +} \ No newline at end of file