diff --git a/src/App.css b/src/App.css
index 74b5e05..654e542 100644
--- a/src/App.css
+++ b/src/App.css
@@ -2,37 +2,38 @@
text-align: center;
}
-.App-logo {
- height: 40vmin;
- pointer-events: none;
+h1 {
+ color: #333;
}
-@media (prefers-reduced-motion: no-preference) {
- .App-logo {
- animation: App-logo-spin infinite 20s linear;
- }
+div {
+ margin-bottom: 20px;
}
-.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;
+input {
+ margin-right: 10px;
}
-.App-link {
- color: #61dafb;
+table {
+ width: 100%;
+ border-collapse: collapse;
+ margin-top: 10px;
}
-@keyframes App-logo-spin {
- from {
- transform: rotate(0deg);
- }
- to {
- transform: rotate(360deg);
- }
+th, td {
+ border: 1px solid #ddd;
+ padding: 8px;
+ text-align: left;
}
+
+th {
+ background-color: #f2f2f2;
+}
+
+tr:nth-child(even) {
+ background-color: #f9f9f9;
+}
+
+tr:hover {
+ background-color: #ddd;
+}
\ No newline at end of file
diff --git a/src/App.js b/src/App.js
index 3784575..683d9ef 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,25 +1,14 @@
-import logo from './logo.svg';
+import React from 'react';
import './App.css';
+import ProductsPage from './components/ProductsPage';
+
function App() {
return (
);
}
-export default App;
+export default App;
\ No newline at end of file
diff --git a/src/components/ProductTable.js b/src/components/ProductTable.js
new file mode 100644
index 0000000..ba11055
--- /dev/null
+++ b/src/components/ProductTable.js
@@ -0,0 +1,30 @@
+import React, { useState } from 'react';
+import ProductRow from './ProductsRow';
+
+const ProductTable = ({ products, searchTerm, inStockOnly }) => {
+ const filteredProducts = products
+ .filter((product) =>
+ product.name.toLowerCase().includes(searchTerm.toLowerCase())
+ )
+ .filter((product) => (inStockOnly ? product.inStock : true));
+
+ return (
+
+
+
+
+ Name
+ Price
+
+
+
+ {filteredProducts.map((product, index) => (
+
+ ))}
+
+
+
+ );
+};
+
+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..d56d95b
--- /dev/null
+++ b/src/components/ProductsPage.js
@@ -0,0 +1,36 @@
+import React, { useState } from 'react';
+import jsonData from './data.json';
+import SearchBar from './SearchBar';
+import ProductTable from './ProductTable';
+
+function ProductsPage() {
+ const [products, setProducts] = useState(jsonData);
+ const [searchTerm, setSearchTerm] = useState('');
+ const [inStockOnly, setInStockOnly] = useState(false);
+
+ const handleSearchChange = (search) => {
+ setSearchTerm(search);
+ };
+
+ const handleStockChange = (stockStatus) => {
+ setInStockOnly(stockStatus);
+ };
+
+ return (
+
+ );
+}
+
+export default ProductsPage;
\ No newline at end of file
diff --git a/src/components/ProductsRow.js b/src/components/ProductsRow.js
new file mode 100644
index 0000000..6badb85
--- /dev/null
+++ b/src/components/ProductsRow.js
@@ -0,0 +1,17 @@
+import React from 'react';
+
+const ProductRow = ({ product }) => {
+ const { name, category, price, inStock } = product;
+ const rowStyle = {
+ color: inStock ? 'black' : 'red',
+ };
+
+ return (
+
+ {name}
+ {price}
+
+ );
+};
+
+export default ProductRow;
\ No newline at end of file
diff --git a/src/components/SearchBar.js b/src/components/SearchBar.js
new file mode 100644
index 0000000..42941f7
--- /dev/null
+++ b/src/components/SearchBar.js
@@ -0,0 +1,31 @@
+import React from 'react';
+
+const SearchBar = ({ onSearchChange, onStockChange, inStockOnly }) => {
+ const handleSearchChange = (event) => {
+ onSearchChange(event.target.value);
+ };
+
+ const handleStockChange = (event) => {
+ onStockChange(event.target.checked);
+ };
+
+ return (
+
+
+
+
+ Only show products in stock
+
+
+ );
+};
+
+export default SearchBar;
\ No newline at end of file
diff --git a/src/data.json b/src/components/data.json
similarity index 100%
rename from src/data.json
rename to src/components/data.json