-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #518 from evershopcommerce/dev
Dev
- Loading branch information
Showing
5 changed files
with
383 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import './Filter.scss'; | ||
|
||
export default function Filter({ title, options, selectedOption }) { | ||
const [show, setShow] = React.useState(false); | ||
|
||
return ( | ||
<div className="filter-container"> | ||
<button | ||
type="button" | ||
onClick={() => setShow(!show)} | ||
className="flex gap-1 justify-center items-center" | ||
> | ||
<span>{selectedOption || title}</span> | ||
{!show && ( | ||
<svg | ||
width="6" | ||
height="5" | ||
viewBox="0 0 118 106" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M54.6478 2.69522C56.5621 -0.689529 61.4379 -0.689535 63.3522 2.69521L117.134 97.7885C119.019 101.122 116.611 105.25 112.782 105.25H5.21828C1.38899 105.25 -1.01899 101.122 0.866121 97.7886L54.6478 2.69522Z" | ||
fill="#2F2F2F" | ||
/> | ||
</svg> | ||
)} | ||
|
||
{show && ( | ||
<svg | ||
width="6" | ||
height="5" | ||
viewBox="0 0 118 106" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M63.3522 103.305C61.4379 106.69 56.5621 106.69 54.6478 103.305L0.866142 8.21144C-1.01897 4.8783 1.38901 0.749989 5.2183 0.749989L112.782 0.749998C116.611 0.749999 119.019 4.8783 117.134 8.21144L63.3522 103.305Z" | ||
fill="#2F2F2F" | ||
/> | ||
</svg> | ||
)} | ||
</button> | ||
{show && ( | ||
<ul> | ||
{options.map((option) => ( | ||
<li key={option.value}> | ||
<a | ||
href="#" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
option.onSelect(); | ||
}} | ||
> | ||
{option.label} | ||
</a> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
); | ||
} | ||
|
||
Filter.propTypes = { | ||
title: PropTypes.string, | ||
options: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
label: PropTypes.string, | ||
value: PropTypes.string, | ||
onSelect: PropTypes.func | ||
}) | ||
), | ||
selectedOption: PropTypes.string | ||
}; | ||
|
||
Filter.defaultProps = { | ||
title: '', | ||
options: [], | ||
selectedOption: '' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
.filter-container { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
position: relative; | ||
} | ||
|
||
.filter-container button { | ||
background: none; | ||
border-bottom: 1px solid #ccc; | ||
color: var(--color-text); | ||
font-size: 1.5rem; | ||
text-align: left; | ||
font-size: 12px; | ||
padding: 0 5px; | ||
text-transform: capitalize; | ||
} | ||
|
||
.filter-container ul { | ||
list-style: none; | ||
padding: 10px; | ||
position: absolute; | ||
background: white; | ||
border: 1px solid #ccc; | ||
border-radius: 0.5rem; | ||
box-shadow: 0 0 0.5rem rgba(0, 0, 0, 0.1); | ||
z-index: 1; | ||
top: 100%; | ||
left: 0; | ||
width: max-content; | ||
} | ||
|
||
.filter-container ul li { | ||
padding: 3px 5px; | ||
text-transform: capitalize; | ||
&:hover { | ||
background: #f9f9f9; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.