-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dropdown, search box and register button
- Loading branch information
Showing
3 changed files
with
150 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useState } from 'react'; | ||
|
||
const Dropdown = ({ options, onSelect }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [selectedOption, setSelectedOption] = useState(null); | ||
|
||
const toggleDropdown = () => setIsOpen(!isOpen); | ||
|
||
const handleOptionClick = (option) => { | ||
setSelectedOption(option); | ||
setIsOpen(false); | ||
onSelect(option); | ||
}; | ||
|
||
return ( | ||
<div className="relative inline-block w-24 sm:w-32"> | ||
<button | ||
onClick={toggleDropdown} | ||
className="w-full bg-lime text-sm sm:text-base text-black py-2 px-1 sm:px-3 rounded-lg flex justify-between items-center" | ||
> | ||
{selectedOption ? selectedOption.label : 'All'} | ||
<svg | ||
className={`w-4 h-4 ml-1 sm:ml-2 transition-transform duration-200 ${ | ||
isOpen ? 'rotate-180' : '' | ||
}`} | ||
fill="none" | ||
stroke="currentColor" | ||
viewBox="0 0 24 24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth={2} | ||
d="M19 9l-7 7-7-7" | ||
/> | ||
</svg> | ||
</button> | ||
|
||
{isOpen && ( | ||
<ul className="absolute left-0 top-full w-full mt-2 bg-white border border-zinc-500 rounded-lg overflow-hidden shadow-lg z-10"> | ||
{options.map((option, index) => ( | ||
<li | ||
key={index} | ||
className="px-4 py-2 hover:bg-zinc-100 cursor-pointer" | ||
onClick={() => handleOptionClick(option)} | ||
> | ||
{option.label} | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Dropdown; |