Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop down wrapper #21

Merged
merged 10 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@

import './App.css'
import Home from './pages/Home'
import React from 'react';
import Dropdown from './components/Dropdown'

function App() {
const App = () => {
return (
<>
<Home />
</>
)
}
<div>
<Dropdown label="More">
<a href="#level5"> Level 5 </a>
<a href="#level5"> Level 6 </a>
<a href="#conversation"> Conversation </a>
</Dropdown>
</div>
);
};

export default App
export default App;
36 changes: 35 additions & 1 deletion src/components/Dropdown.jsx
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
class="absolute inline-block"
myix765 marked this conversation as resolved.
Show resolved Hide resolved

//If the mouse is on the menu, turn state to true, otherwise false
onClick={() => {
if(isOpen) {
setIsOpen(false);
} else{
setIsOpen(true);
}
}
}
>
<button class="dropdown-button text-right">{label}</button>
{isOpen && (
// style below for children
<div class="absolute text-right flex flex-col">
{children}
</div>
)}
</div>
);
};

export default Dropdown;