From 0767206dcf463062ae91859e94ee96c3d000ab21 Mon Sep 17 00:00:00 2001 From: Gowtham Jangiti Date: Sun, 13 Oct 2024 16:30:18 +0530 Subject: [PATCH] Completed --- src/App.js | 18 ++------ src/components/ProductRow.js | 12 ++++++ src/components/ProductTable.js | 27 ++++++++++++ src/components/ProductsPage.js | 50 ++++++++++++++++++++++ src/components/SearchBar.js | 16 +++++++ src/components/style.css | 77 ++++++++++++++++++++++++++++++++++ 6 files changed, 185 insertions(+), 15 deletions(-) create mode 100644 src/components/ProductRow.js create mode 100644 src/components/ProductTable.js create mode 100644 src/components/ProductsPage.js create mode 100644 src/components/SearchBar.js create mode 100644 src/components/style.css diff --git a/src/App.js b/src/App.js index 3784575..0d40dd4 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 - -
+

Store

+
); } diff --git a/src/components/ProductRow.js b/src/components/ProductRow.js new file mode 100644 index 0000000..7bad542 --- /dev/null +++ b/src/components/ProductRow.js @@ -0,0 +1,12 @@ +import React from "react"; + +function ProductRow({ product }) { + return ( + + {product.name} + {product.price} + + ); +} + +export default ProductRow; \ No newline at end of file diff --git a/src/components/ProductTable.js b/src/components/ProductTable.js new file mode 100644 index 0000000..7fa9bbc --- /dev/null +++ b/src/components/ProductTable.js @@ -0,0 +1,27 @@ +import React from 'react' +import './css/style.css' + +function ProductTable({ products }) { + return ( + + + + + + + + + {products.map((product) => ( + + + + + ))} + +
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..3162db5 --- /dev/null +++ b/src/components/ProductsPage.js @@ -0,0 +1,50 @@ +import React, { useState } from "react"; +import SearchBar from "./SearchBar"; +import ProductTable from "./ProductTable"; +import data from "../data.json"; +import "./css/style.css"; + +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 = data.filter((product) => { + const matchesSearchQuery = product.name + .toLowerCase() + .includes(searchQuery.toLowerCase()); + const matchesStockFilter = !onlyInStock || product.inStock; + return matchesSearchQuery && matchesStockFilter; + }); + + return ( +
+
Search
+ +
+ + +
+
+ +
+
+ ); +} + +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..4daf0d2 --- /dev/null +++ b/src/components/SearchBar.js @@ -0,0 +1,16 @@ +import React from 'react' +import './css/style.css' + +function SearchBar({ searchQuery, onSearchChange }) { + return ( +
+ onSearchChange(e.target.value)} + /> +
+ ); +} + +export default SearchBar \ No newline at end of file diff --git a/src/components/style.css b/src/components/style.css new file mode 100644 index 0000000..1aff55f --- /dev/null +++ b/src/components/style.css @@ -0,0 +1,77 @@ +.table-wrapper { + display: flex; + justify-content: center; + align-items: center; + width: 1500px; + margin-left: 0px; + padding-left: 200px; + } + + table { + width: 100%; + max-width: 2000px; + border-collapse: collapse; + } + + table th:first-child + { + width: 100%; + padding-left: 0px; + padding-right: -300px; + } + + table th:nth-child(2) { + width: 300px; + margin-left: 500px; +} + + table th:first-child, + table th:nth-child(2) + { + background-color: rgb(209, 213, 222); + color: grey; + } + + table th, + table td { + padding-top: 20px; + padding-bottom: 20px; + padding-right: 300px; + text-align: center; + } + + td:first-child { + width: 300px; + padding-left: 0px; + } + + table th:nth-child(2) { + width: 150px; + padding-right: -200px; + } + + th:last-child, + .search-bar { + width: 100%; + margin-bottom: 20px; +} + +.search-bar input { + width: 80%; + padding: 8px; + box-sizing: border-box; +} + +div.search-title { + padding-bottom: 15px !important; +} + +.in-stock-filter { + padding-bottom: 50px; +} + + +.out-of-stock { + color: red; + +}