-
-
Notifications
You must be signed in to change notification settings - Fork 109
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
Navbar mobile refactored design #1568
Changes from all commits
6287291
6a5955b
2d40fbf
7864744
c1984cd
f8cabec
00c2132
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { useTranslation } from "next-i18next" | ||
import React, { FC, useState } from "react" | ||
import React, { useState } from "react" | ||
import Image from "react-bootstrap/Image" | ||
import styled from "styled-components" | ||
import { SignInWithButton, signOutAndRedirectToHome, useAuth } from "./auth" | ||
import { Container, Nav, Navbar, NavDropdown } from "./bootstrap" | ||
import { useProfile } from "./db" | ||
import { Col, Nav, Navbar, NavDropdown } from "./bootstrap" | ||
import { | ||
Avatar, | ||
NavbarLinkBills, | ||
|
@@ -20,122 +21,132 @@ import { | |
NavbarLinkWhyUse | ||
} from "./NavbarComponents" | ||
|
||
const NavBarBoxContainer: FC< | ||
React.PropsWithChildren<{ className?: string }> | ||
> = ({ children, className }) => { | ||
return ( | ||
<div | ||
className={`d-flex flex-row align-items-start justify-content-between w-100`} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} | ||
export const MobileNav: React.FC<React.PropsWithChildren<unknown>> = () => { | ||
const BlackCollapse = styled(() => { | ||
return ( | ||
<Navbar.Collapse id="basic-navbar-nav" className="bg-black mt-2 ps-4"> | ||
{/* while MAPLE is trying to do away with inline styling, * | ||
* both styled-components and bootstrap classes have been * | ||
* ignoring height properties for some reason */} | ||
<div style={{ height: "100vh" }}> | ||
{whichMenu == "site" ? <SiteLinks /> : <ProfileLinks />} | ||
</div> | ||
</Navbar.Collapse> | ||
) | ||
})` | ||
.bg-black { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Could this just use the bootstrap provided |
||
background-color: black; | ||
} | ||
` | ||
|
||
const NavBarBox: FC<React.PropsWithChildren<{ className?: string }>> = ({ | ||
children, | ||
className | ||
}) => { | ||
return ( | ||
<div | ||
className={`col d-flex justify-content-start align-items-center ${className}`} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} | ||
const ProfileLinks = () => { | ||
return ( | ||
<Nav className="my-4 d-flex align-items-start"> | ||
<NavbarLinkViewProfile /> | ||
<NavbarLinkEditProfile | ||
handleClick={() => { | ||
closeNav() | ||
}} | ||
/> | ||
<NavbarLinkSignOut | ||
handleClick={() => { | ||
closeNav() | ||
void signOutAndRedirectToHome() | ||
}} | ||
/> | ||
</Nav> | ||
) | ||
} | ||
|
||
const SiteLinks = () => { | ||
return ( | ||
<Nav className="my-4"> | ||
<NavbarLinkBills handleClick={closeNav} /> | ||
<NavbarLinkTestimony handleClick={closeNav} /> | ||
<NavDropdown className={"navLink-primary"} title={t("about")}> | ||
<NavbarLinkGoals handleClick={closeNav} /> | ||
<NavbarLinkTeam handleClick={closeNav} /> | ||
<NavbarLinkSupport handleClick={closeNav} /> | ||
<NavbarLinkFAQ handleClick={closeNav} /> | ||
</NavDropdown> | ||
|
||
<NavDropdown className={"navLink-primary"} title={t("learn")}> | ||
<NavbarLinkEffective handleClick={closeNav} /> | ||
<NavbarLinkProcess handleClick={closeNav} /> | ||
<NavbarLinkWhyUse handleClick={closeNav} /> | ||
</NavDropdown> | ||
</Nav> | ||
) | ||
} | ||
|
||
export const MobileNav: React.FC<React.PropsWithChildren<unknown>> = () => { | ||
const { authenticated } = useAuth() | ||
const [isExpanded, setIsExpanded] = useState(false) | ||
const [whichMenu, setWhichMenu] = useState("site") | ||
const { t } = useTranslation(["common", "auth"]) | ||
|
||
const toggleNav = () => setIsExpanded(!isExpanded) | ||
const closeNav = () => setIsExpanded(false) | ||
const toggleSite = () => { | ||
if (isExpanded && whichMenu == "profile") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: for these toggles, if we're setting |
||
setWhichMenu("site") | ||
} else { | ||
setWhichMenu("site") | ||
setIsExpanded(!isExpanded) | ||
} | ||
} | ||
|
||
const toggleAvatar = () => { | ||
if (isExpanded && whichMenu == "site") { | ||
setWhichMenu("profile") | ||
} else { | ||
setWhichMenu("profile") | ||
setIsExpanded(!isExpanded) | ||
} | ||
} | ||
|
||
const result = useProfile() | ||
let isOrg = result?.profile?.role === "organization" | ||
const closeNav = () => setIsExpanded(false) | ||
|
||
return ( | ||
<Navbar | ||
bg="secondary" | ||
variant="dark" | ||
sticky="top" | ||
expand={false} | ||
expanded={isExpanded} | ||
className={`w-100 ${isExpanded ? "pb-0" : ""}`} | ||
data-bs-theme="dark" | ||
expand="lg" | ||
expanded={isExpanded} | ||
> | ||
<Container fluid> | ||
<NavBarBoxContainer> | ||
<NavBarBox> | ||
<Navbar expand={false} expanded={isExpanded}> | ||
<Navbar.Brand> | ||
<Navbar.Toggle aria-controls="topnav" onClick={toggleNav} /> | ||
</Navbar.Brand> | ||
<Navbar.Collapse id="topnav"> | ||
<Nav className="me-auto"> | ||
<NavbarLinkBills handleClick={closeNav} /> | ||
<NavbarLinkTestimony handleClick={closeNav} /> | ||
|
||
<NavDropdown className={"navLink-primary"} title={t("about")}> | ||
<NavbarLinkGoals handleClick={closeNav} /> | ||
<NavbarLinkTeam handleClick={closeNav} /> | ||
<NavbarLinkSupport handleClick={closeNav} /> | ||
<NavbarLinkFAQ handleClick={closeNav} /> | ||
</NavDropdown> | ||
|
||
<NavDropdown className={"navLink-primary"} title={t("learn")}> | ||
<NavbarLinkEffective handleClick={closeNav} /> | ||
<NavbarLinkProcess handleClick={closeNav} /> | ||
<NavbarLinkWhyUse handleClick={closeNav} /> | ||
</NavDropdown> | ||
</Nav> | ||
</Navbar.Collapse> | ||
</Navbar> | ||
</NavBarBox> | ||
|
||
<NavbarLinkLogo /> | ||
|
||
<NavBarBox className={`justify-content-end`}> | ||
<Navbar | ||
expand={false} | ||
expanded={isExpanded} | ||
variant="dark" | ||
bg="secondary" | ||
collapseOnSelect={true} | ||
className="d-flex justify-content-end" | ||
> | ||
{authenticated ? ( | ||
<> | ||
<Navbar.Brand onClick={toggleNav}> | ||
<Nav.Link className="p-0 text-white"> | ||
<Avatar isOrg={isOrg} /> | ||
</Nav.Link> | ||
</Navbar.Brand> | ||
<Navbar.Collapse id="profile-nav"> | ||
<Nav className="me-4 d-flex align-items-end"> | ||
<NavbarLinkViewProfile /> | ||
<NavbarLinkEditProfile | ||
handleClick={() => { | ||
closeNav() | ||
}} | ||
/> | ||
<NavbarLinkSignOut | ||
handleClick={() => { | ||
closeNav() | ||
void signOutAndRedirectToHome() | ||
}} | ||
/> | ||
</Nav> | ||
</Navbar.Collapse> | ||
</> | ||
<Col className="ms-3 ps-2"> | ||
<Navbar.Brand onClick={toggleSite}> | ||
{isExpanded && whichMenu == "site" ? ( | ||
<Image | ||
src="/Union.svg" | ||
alt="x" | ||
width="35" | ||
height="35" | ||
className="ms-2" | ||
/> | ||
) : ( | ||
<Navbar.Toggle aria-controls="basic-navbar-nav" /> | ||
)} | ||
</Navbar.Brand> | ||
</Col> | ||
<Col className="d-flex justify-content-center"> | ||
<NavbarLinkLogo handleClick={closeNav} /> | ||
</Col> | ||
<Col className="d-flex justify-content-end me-3 pe-2"> | ||
{authenticated ? ( | ||
<Navbar.Brand onClick={toggleAvatar}> | ||
<Nav.Link className="p-0 text-white"> | ||
{isExpanded && whichMenu == "profile" ? ( | ||
<Image src="/Union.svg" alt="x" width="35" height="35" /> | ||
) : ( | ||
<SignInWithButton /> | ||
<Avatar /> | ||
)} | ||
</Navbar> | ||
</NavBarBox> | ||
</NavBarBoxContainer> | ||
</Container> | ||
</Nav.Link> | ||
</Navbar.Brand> | ||
) : ( | ||
<SignInWithButton /> | ||
)} | ||
</Col> | ||
|
||
<BlackCollapse /> | ||
</Navbar> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sadly setting specific heights aren't covered by bootstrap. Weird that styled-components aren't respecting that - not worth digging into here, but thanks for the heads up to look out for this issue in the future.
That said, why do we need to set a specific height here? Shouldn't the menu just be the height of the links list, whichever set of links we're dealing with?