Skip to content

Commit

Permalink
Add price and category filters
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVanDerSchans committed Apr 7, 2024
1 parent 4d5a8c8 commit 2b0c437
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/components/Filters/Filters.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.filters {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
font-weight: 700;
}

.filters > div {
display: flex;
gap: 1rem;
outline: 'none'
}
37 changes: 37 additions & 0 deletions src/components/Filters/Filters.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { useState } from 'react'
import './Filters.css'

export function Filters () {
const [minPrice, setMinPrice] = useState(0)

const handleChangeMinPrice = (event) => {
setMinPrice(event.target.value)
}

return (
<section className="filters">

<div>
<label htmlFor="price">Min. price</label>
<input
type="range"
id="price"
min='0'
max='1000'
onChange={handleChangeMinPrice}
/>
<span>{minPrice}</span>
</div>

<div>
<label htmlFor="category">Category</label>
<select id="category">
<option value="all">All</option>
<option value="laptops">Laptops</option>
<option value="smartphones">Smartphones</option>
</select>
</div>

</section>
)
}
11 changes: 11 additions & 0 deletions src/components/Header/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Filters } from "../Filters/Filters"

export function Header () {
return (
<header>
<h1>Shopping ReactCart</h1>

<Filters />
</header>
)
}
2 changes: 1 addition & 1 deletion src/components/Products/Products.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/prop-types */
import './Products.css'
import { AddToCartIcon } from '../Icons/Icons.jsx'
import { AddToCartIcon } from '../Icons/Icons'

export function Products ({ products }) {
return (
Expand Down
3 changes: 2 additions & 1 deletion src/components/app/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState } from 'react'
import { Header } from '../Header/Header'
import { products as initialProducts } from '../../mocks/products.json'
import { Products } from '../Products/Products'
import './App.css'
Expand Down Expand Up @@ -27,7 +28,7 @@ function App() {
return (
<>
<div>
<h1>Shopping cart</h1>
<Header />

<Products products={filteredProducts}/>
</div>
Expand Down

0 comments on commit 2b0c437

Please sign in to comment.