Skip to content

Commit

Permalink
Add dropdown nav for about pages
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyi committed Dec 13, 2024
1 parent 28ba2e4 commit 74c79e9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 21 deletions.
22 changes: 22 additions & 0 deletions site/SiteAbout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from "react"

export const ABOUT_LINKS = [
{ title: "About Us", href: "/about" },
{ title: "Organization", href: "/organization" },
{ title: "Funding", href: "/funding" },
{ title: "Team", href: "/team" },
{ title: "Jobs", href: "/jobs" },
{ title: "FAQs", href: "/faqs" },
]

export function SiteAbout() {
return (
<ul>
{ABOUT_LINKS.map(({ title, href }) => (
<li key={href}>
<a href={href}>{title}</a>
</li>
))}
</ul>
)
}
16 changes: 14 additions & 2 deletions site/SiteMobileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CategoryWithEntries } from "@ourworldindata/utils"
import classnames from "classnames"
import { SiteNavigationToggle } from "./SiteNavigationToggle.js"
import { Menu } from "./SiteNavigation.js"
import { SiteAbout } from "./SiteAbout.js"
import { SiteResources } from "./SiteResources.js"
import { SiteMobileCategory } from "./SiteMobileCategory.js"

Expand Down Expand Up @@ -68,9 +69,20 @@ export const SiteMobileMenu = ({
</SiteNavigationToggle>
</li>
<li>
<a href="/about" className="section__header">
<SiteNavigationToggle
ariaLabel="Toggle about menu"
isActive={menu === Menu.About}
onToggle={() =>
toggleMenu(
menu === Menu.About ? Menu.Topics : Menu.About
)
}
dropdown={<SiteAbout />}
withCaret={true}
className="SiteNavigationToggle--lvl1"
>
About
</a>
</SiteNavigationToggle>
</li>
<li>
<a href="/donate" className="donate">
Expand Down
13 changes: 11 additions & 2 deletions site/SiteNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
OwidGdocType,
getOwidGdocFromJSON,
} from "@ourworldindata/utils"
import { SiteAbout } from "./SiteAbout.js"
import { SiteResources } from "./SiteResources.js"
import { SiteSearchNavigation } from "./SiteSearchNavigation.js"
import { SiteMobileMenu } from "./SiteMobileMenu.js"
Expand Down Expand Up @@ -174,8 +175,16 @@ export const SiteNavigation = ({
Resources
</SiteNavigationToggle>
</li>
<li>
<a href="/about">About</a>
<li className="with-relative-dropdown">
<SiteNavigationToggle
ariaLabel="Toggle about menu"
isActive={menu === Menu.About}
onToggle={() => toggleMenu(Menu.About)}
dropdown={<SiteAbout />}
withCaret={true}
>
About
</SiteNavigationToggle>
</li>
</ul>
</nav>
Expand Down
27 changes: 10 additions & 17 deletions site/gdocs/pages/AboutPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@ import { isEmpty } from "lodash"
import * as React from "react"

import { OwidGdocAboutInterface } from "@ourworldindata/types"
import { ABOUT_LINKS } from "../../SiteAbout.js"
import { ArticleBlocks } from "../components/ArticleBlocks.js"
import Footnotes from "../components/Footnotes.js"

const NAV_LINKS = [
{ title: "About Us", href: "/about" },
{ title: "Organization", href: "/organization" },
{ title: "Funding", href: "/funding" },
{ title: "Team", href: "/team" },
{ title: "Jobs", href: "/jobs" },
{ title: "FAQs", href: "/faqs" },
]

export default function AboutPage({ content, slug }: OwidGdocAboutInterface) {
return (
<main className="about-page centered-article-container grid grid-cols-12-full-width">
Expand All @@ -39,21 +31,22 @@ function AboutNav({ slug }: { slug: string }) {
return (
<nav className="about-nav grid grid-cols-12-full-width col-start-1 col-end-limit">
<ul className="about-nav-list col-start-2 col-end-14 col-sm-start-1">
{NAV_LINKS.map(({ title, href }) => (
<li key={href}>
<h2>
{ABOUT_LINKS.map(({ title, href }) => {
const isActive = href === `/${slug}`
return (
<li key={href}>
<a
className={cx("about-nav-link", {
"about-nav-link--is-active":
href === `/${slug}`,
"about-nav-link--is-active": isActive,
})}
href={href}
aria-current={isActive ? "page" : undefined}
>
{title}
</a>
</h2>
</li>
))}
</li>
)
})}
</ul>
</nav>
)
Expand Down

0 comments on commit 74c79e9

Please sign in to comment.