-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7feb5a
commit 6a255a5
Showing
7 changed files
with
174 additions
and
7 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,55 @@ | ||
.filtering-container { | ||
position: relative; | ||
display: inline-block; | ||
padding-bottom: 10px; | ||
} | ||
|
||
.dropdown-toggle { | ||
padding: 10px 10px; | ||
padding-right: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
background-color: #fff; | ||
color: #333; | ||
cursor: pointer; | ||
font-size: 14px; | ||
text-align: left; | ||
width: 130px; | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
} | ||
|
||
.dropdown-toggle:hover { | ||
background-color: #f0f0f0; | ||
} | ||
|
||
.dropdown-arrow { | ||
border: none; | ||
background: none; | ||
cursor: pointer; | ||
font-size: 15px; | ||
margin-left: 1px; | ||
margin-right: 10px; | ||
} | ||
|
||
.dropdown-menu { | ||
position: absolute; | ||
background-color: #fff; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
margin-top: 5px; | ||
z-index: 1000; | ||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.dropdown-item { | ||
padding: 10px 15px; | ||
cursor: pointer; | ||
font-size: 14px; | ||
color: #333; | ||
} | ||
|
||
.dropdown-item:hover { | ||
background-color: #f0f0f0; | ||
} |
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,65 @@ | ||
import React, { useState } from 'react'; | ||
import './Filtering.css'; | ||
|
||
const Filtering = ({ onFilterChange }) => { | ||
const [isOpen, setIsOpen] = useState(false); // State to toggle dropdown open/close | ||
const [selectedOption, setSelectedOption] = useState('Sort by'); // Initial state | ||
const [sortOrder, setSortOrder] = useState('asc'); // Track sort order (asc/desc) | ||
|
||
const toggleDropdown = () => { | ||
setIsOpen(!isOpen); // Toggle dropdown open/close state | ||
}; | ||
|
||
const toggleSortOrder = () => { | ||
// Toggle sort order only if an option is selected | ||
if (selectedOption !== 'Sort by') { | ||
const newSortOrder = sortOrder === 'asc' ? 'desc' : 'asc'; | ||
setSortOrder(newSortOrder); | ||
onFilterChange(selectedOption, newSortOrder); // Trigger filtering with new order | ||
} | ||
}; | ||
|
||
const handleOptionClick = (option) => { | ||
// Handle filter option selection | ||
setSelectedOption(option); | ||
onFilterChange(option, sortOrder); // Call the parent function with selected filter and order | ||
setIsOpen(false); // Collapse the dropdown after selection | ||
}; | ||
|
||
return ( | ||
<div className="filtering-container"> | ||
<div className="dropdown"> | ||
{/* Make the entire button clickable for toggling dropdown */} | ||
<button onClick={toggleDropdown} className="dropdown-toggle"> | ||
{selectedOption} | ||
{/* Render the up/down arrow next to selected option */} | ||
{selectedOption !== 'Sort by' && ( | ||
<span onClick={(e) => { e.stopPropagation(); toggleSortOrder(); }}> | ||
{sortOrder === 'asc' ? ' ↑' : ' ↓'} | ||
</span> | ||
)} | ||
<span className="dropdown-arrow">▼</span> | ||
</button> | ||
|
||
{isOpen && ( | ||
<div className="dropdown-menu"> | ||
<div onClick={() => handleOptionClick('Date Modified')} className="dropdown-item"> | ||
Date Modified | ||
</div> | ||
<div onClick={() => handleOptionClick('Date Created')} className="dropdown-item"> | ||
Date Created | ||
</div> | ||
<div onClick={() => handleOptionClick('Alphabetical')} className="dropdown-item"> | ||
Alphabetical | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Filtering; | ||
|
||
|
||
|
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 |
---|---|---|
|
@@ -31,3 +31,7 @@ export default function Search({ onSearch }) { | |
</div> | ||
); | ||
} | ||
|
||
|
||
|
||
|
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
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