Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,267 changes: 948 additions & 319 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"tailwindcss": "^3.4.15"
}
}
35 changes: 2 additions & 33 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,11 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>

</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>

<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
38 changes: 0 additions & 38 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +0,0 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.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;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
29 changes: 8 additions & 21 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import logo from './logo.svg';
import './App.css';
import "./index.css";
import ProductsPage from './components/ProductsPage';

function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
return (
<div className="App min-h-screen bg-gray-100 p-5">
<ProductsPage />
</div>
);
}

export default App;
export default App;
12 changes: 12 additions & 0 deletions src/components/ProductRow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function ProductRow({ product }) {
return (
<tr style={{ color: product.inStock ? 'black' : 'red' }}>
<td className="py-2 px-4 border-b">{product.name}</td>
<td className="py-2 px-4 border-b">{product.category}</td>
<td className="py-2 px-4 border-b">{product.price}</td>
<td className="py-2 px-4 border-b">{product.inStock ? 'Yes' : 'No'}</td>
</tr>
);
}

export default ProductRow;
23 changes: 23 additions & 0 deletions src/components/ProductTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ProductRow from './ProductRow';

function ProductTable({ products }) {
return (
<table className="min-w-full bg-white border border-gray-300">
<thead>
<tr className="bg-gray-200">
<th className="py-2 px-4 border-b">Name</th>
<th className="py-2 px-4 border-b">Category</th>
<th className="py-2 px-4 border-b">Price</th>
<th className="py-2 px-4 border-b">In Stock</th>
</tr>
</thead>
<tbody>
{products.map((product) => (
<ProductRow key={product.name} product={product} />
))}
</tbody>
</table>
);
}

export default ProductTable;
31 changes: 31 additions & 0 deletions src/components/ProductsPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { 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 filteredProducts = products.filter(product => {
const matchesSearchTerm = product.name.toLowerCase().includes(searchTerm.toLowerCase());
const matchesInStock = !inStockOnly || product.inStock;
return matchesSearchTerm && matchesInStock;
});

return (
<div>
<h1 className="text-2xl font-bold mb-4">Root Store</h1>
<SearchBar
searchTerm={searchTerm}
setSearchTerm={setSearchTerm}
inStockOnly={inStockOnly}
setInStockOnly={setInStockOnly}
/>
<ProductTable products={filteredProducts} />
</div>
);
}

export default ProductsPage;
24 changes: 24 additions & 0 deletions src/components/SearchBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function SearchBar({ searchTerm, setSearchTerm, inStockOnly, setInStockOnly }) {
return (
<div className="mb-4">
<input
type="text"
placeholder="Search..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="border border-gray-300 rounded p-2 mr-2"
/>
<label className="flex items-center">
<input
type="checkbox"
checked={inStockOnly}
onChange={(e) => setInStockOnly(e.target.checked)}
className="mr-1"
/>
Only show products in stock
</label>
</div>
);
}

export default SearchBar;
16 changes: 3 additions & 13 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
@tailwind base;
@tailwind components;
@tailwind utilities;
1 change: 0 additions & 1 deletion src/logo.svg

This file was deleted.

8 changes: 8 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,js}"],
theme: {
extend: {},
},
plugins: [],
}