generated from acdh-oeaw/template-app-next
-
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.
- Loading branch information
1 parent
550caff
commit 9f263c0
Showing
4 changed files
with
130 additions
and
38 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"use client"; | ||
import { useTranslations } from "next-intl"; | ||
import { type ReactNode, useId, useState } from "react"; | ||
|
||
import { AppNavLink } from "@/components/app-nav-link"; | ||
import type { LinkProps } from "@/components/link"; | ||
import { createHref } from "@/lib/create-href"; | ||
import { otherCategories, proseCategories } from "@/lib/model"; | ||
|
||
import { DisclosureButton } from "./disclosure-button"; | ||
|
||
export function AppHeaderNavMenu(): ReactNode { | ||
const t = useTranslations("AppHeader"); | ||
const catt = useTranslations("BernhardCategories"); | ||
|
||
const links = { | ||
home: { href: createHref({ pathname: "/" }), label: t("links.home") }, | ||
languages: { | ||
href: createHref({ pathname: "/languages" }), | ||
label: t("links.languages"), | ||
}, | ||
translators: { | ||
href: createHref({ pathname: "/translators" }), | ||
label: t("links.translators"), | ||
}, | ||
search: { | ||
href: createHref({ pathname: "/search" }), | ||
label: t("links.search"), | ||
}, | ||
} satisfies Record<string, { href: LinkProps["href"]; label: string }>; | ||
|
||
const worksMenu = useId(); | ||
const [worksMenuOpen, setWorksMenuOpen] = useState(false); | ||
const proseMenu = useId(); | ||
const [proseMenuOpen, setProseMenuOpen] = useState(false); | ||
|
||
return ( | ||
<nav aria-label={t("navigation-primary")}> | ||
<ul className="flex h-10 items-center gap-4 text-sm" role="list"> | ||
{Object.entries(links).map(([id, link]) => { | ||
return ( | ||
<li key={id}> | ||
<AppNavLink href={link.href}>{link.label}</AppNavLink> | ||
</li> | ||
); | ||
})} | ||
<li> | ||
<DisclosureButton | ||
controls={worksMenu} | ||
label={t("links.works")} | ||
setState={setWorksMenuOpen} | ||
state={worksMenuOpen} | ||
/> | ||
</li> | ||
</ul> | ||
{worksMenuOpen ? ( | ||
<ul className="flex h-10 items-center gap-4 text-sm" id={worksMenu} role="list"> | ||
<li> | ||
<DisclosureButton | ||
controls={proseMenu} | ||
label={catt("prose")} | ||
setState={setProseMenuOpen} | ||
state={proseMenuOpen} | ||
/> | ||
</li> | ||
{otherCategories.map((c) => { | ||
return ( | ||
<AppNavLink | ||
key={c} | ||
href={`/works/${c}`} | ||
onClick={() => { | ||
setProseMenuOpen(false); | ||
}} | ||
> | ||
{catt(c)} | ||
</AppNavLink> | ||
); | ||
})} | ||
</ul> | ||
) : null} | ||
{worksMenuOpen && proseMenuOpen ? ( | ||
<ul className="flex h-10 items-center gap-4 text-sm" id={proseMenu} role="list"> | ||
{proseCategories.map((c) => { | ||
return ( | ||
<AppNavLink key={c} href={`/works/${c}`}> | ||
{catt(c)} | ||
</AppNavLink> | ||
); | ||
})} | ||
</ul> | ||
) : null} | ||
</nav> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { ReactNode } from "react"; | ||
|
||
interface DisclosureButtonProps { | ||
controls: string; | ||
label: string; | ||
state: boolean; | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
setState: Function; | ||
} | ||
|
||
export function DisclosureButton(props: DisclosureButtonProps): ReactNode { | ||
const toggleState = () => { | ||
props.setState(!props.state); | ||
}; | ||
return ( | ||
<button | ||
aria-controls={props.controls} | ||
aria-expanded={props.state} | ||
onClick={toggleState} | ||
type="button" | ||
> | ||
{props.label} | ||
</button> | ||
); | ||
} |