-
Notifications
You must be signed in to change notification settings - Fork 0
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 #21 from JumboCode/DropDownWrapper
Drop down wrapper
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 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
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 |
---|---|---|
@@ -1 +1,35 @@ | ||
// TODO (Togzhan & Yi & Aryaa): Create a dropdown component | ||
import React, { useState } from 'react'; | ||
|
||
const Dropdown = ({ label, children }) => { | ||
//use isOpen to keep track of whether the dropdown menu is visible | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<div | ||
// style below for menu | ||
className="absolute inline-block" | ||
|
||
//If the mouse is on the menu, turn state to true, otherwise false | ||
onClick={() => { | ||
if(isOpen) { | ||
setIsOpen(false); | ||
} else{ | ||
setIsOpen(true); | ||
} | ||
} | ||
} | ||
> | ||
<button className="dropdown-button text-right">{label}</button> | ||
{isOpen && ( | ||
// style below for children | ||
<div className="absolute text-right flex flex-col"> | ||
{children} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Dropdown; | ||
|
||
|