Skip to content

Commit

Permalink
Add function to open drawer on brand click in mobile (#360)
Browse files Browse the repository at this point in the history
* Add function to open drawer on brand click in mobile

* Destructure props for Mobile header
  • Loading branch information
skanderm authored Mar 14, 2024
1 parent d16aa34 commit 78ae741
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
26 changes: 19 additions & 7 deletions ui/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import wordmark from "@/public/wordmark/wordmark-white.svg";
import { displayDesktopOnly, displayMobileOnly } from "@/styles/responsive";
import { analytics } from "@/utils/analytics";

export default function Header() {
export default function Header({
onBrandClick,
}: {
onBrandClick?: () => void;
}) {
return (
<AppBar
position="static"
Expand All @@ -38,15 +42,20 @@ export default function Header() {
}}
>
<Toolbar>
<Mobile />
<Mobile onBrandClick={onBrandClick} />
<Desktop />
</Toolbar>
</AppBar>
);
}

function Mobile(props: { window?: () => Window }) {
const { window } = props;
function Mobile({
window,
onBrandClick,
}: {
window?: () => Window;
onBrandClick?: () => void;
}) {
const drawerWidth = "100%";
const [menuIsOpen, setMenuOpen] = useState(false);

Expand Down Expand Up @@ -96,7 +105,7 @@ function Mobile(props: { window?: () => Window }) {
>
{menuIsOpen ? <Close /> : <Menu />}
</IconButton>
<Brand />
<Brand onClick={onBrandClick} />
</Box>
<nav>
<Drawer
Expand Down Expand Up @@ -252,7 +261,7 @@ function Desktop() {
);
}

function Brand() {
function Brand({ onClick }: { onClick?: () => void }) {
return (
<Typography variant="h6" noWrap overflow="visible">
<Link
Expand All @@ -265,7 +274,10 @@ function Brand() {
alignItems: "center",
justifyContent: "center",
}}
onClick={() => analytics.nav.logoClicked()}
onClick={() => {
if (onClick) onClick();
analytics.nav.logoClicked();
}}
>
<Image
src={wordmark.src}
Expand Down
6 changes: 5 additions & 1 deletion ui/src/components/layouts/MapLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ function MapLayout({ children }: { children: ReactNode }) {
flexDirection: "column",
}}
>
<Header />
<Header
onBrandClick={() => {
setDrawerOpen(true);
}}
/>
<Box sx={{ flexGrow: 1, display: "flex" }}>
<Drawer
setOpen={setDrawerOpen}
Expand Down

0 comments on commit 78ae741

Please sign in to comment.