-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial work on custom select component
- Loading branch information
1 parent
ba19680
commit d88974e
Showing
4 changed files
with
90 additions
and
22 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,47 @@ | ||
import React, { useState } from "react"; | ||
|
||
type CustomSelectProps = { | ||
options: string[]; | ||
value: string; | ||
onChange: (value: string) => void; | ||
}; | ||
|
||
const CustomSelect: React.FC<CustomSelectProps> = ({ | ||
options, | ||
value, | ||
onChange, | ||
}) => { | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
|
||
const toggleDropdown = () => setIsOpen(!isOpen); | ||
const handleOptionClick = (value: string) => { | ||
onChange(value); | ||
setIsOpen(false); | ||
}; | ||
|
||
return ( | ||
<div className="relative"> | ||
<div | ||
className="block w-full px-3 py-2 border border-gray-300 rounded-md bg-gray-200 cursor-pointer" | ||
onClick={toggleDropdown} | ||
> | ||
{value} | ||
</div> | ||
{isOpen && ( | ||
<div className="absolute w-full mt-1 bg-white border border-gray-300 rounded-md shadow-lg z-10"> | ||
{options.map((option, index) => ( | ||
<div | ||
key={index} | ||
className="px-3 py-2 hover:bg-gray-100 cursor-pointer" | ||
onClick={() => handleOptionClick(option)} | ||
> | ||
{option} | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CustomSelect; |
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