docs/components/Footer.tsx

139 lines
3.7 KiB
TypeScript
Raw Permalink Normal View History

2024-07-22 11:49:47 +02:00
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
2024-07-22 17:54:58 +02:00
import { Icon } from "@iconify-icon/react";
import type { ReactNode } from "react";
2024-07-22 11:49:47 +02:00
import { Button } from "./Button";
import { navigation } from "./Navigation";
function PageLink({
label,
page,
previous = false,
}: {
label: string;
page: { href: string; title: string };
previous?: boolean;
}) {
return (
<>
<Button
href={page.href}
aria-label={`${label}: ${page.title}`}
variant="secondary"
arrow={previous ? "left" : "right"}
>
{label}
</Button>
<Link
href={page.href}
tabIndex={-1}
aria-hidden="true"
className="text-base font-semibold text-zinc-900 transition hover:text-zinc-600 dark:text-white dark:hover:text-zinc-300"
>
{page.title}
</Link>
</>
);
}
function PageNavigation() {
const pathname = usePathname();
const allPages = navigation.flatMap((group) => group.links);
const currentPageIndex = allPages.findIndex(
(page) => page.href === pathname,
);
if (currentPageIndex === -1) {
return null;
}
const previousPage = allPages[currentPageIndex - 1];
const nextPage = allPages[currentPageIndex + 1];
if (!(previousPage || nextPage)) {
return null;
}
return (
<div className="flex">
{previousPage && (
<div className="flex flex-col items-start gap-3">
<PageLink
label="Previous"
page={previousPage}
previous={true}
/>
</div>
)}
{nextPage && (
<div className="ml-auto flex flex-col items-end gap-3">
<PageLink label="Next" page={nextPage} />
</div>
)}
</div>
);
}
function SocialLink({
href,
2024-07-22 17:54:58 +02:00
icon,
2024-07-22 11:49:47 +02:00
children,
}: {
href: string;
2024-07-22 17:54:58 +02:00
icon: string;
2024-07-22 11:49:47 +02:00
children: ReactNode;
}) {
return (
2024-07-27 15:37:58 +02:00
<Link
href={href}
className="group"
target="_blank"
rel="noopener noreferrer"
>
2024-07-22 11:49:47 +02:00
<span className="sr-only">{children}</span>
2024-07-22 17:54:58 +02:00
<Icon
icon={icon}
className="h-5 w-5 fill-zinc-700 transition group-hover:fill-zinc-900 dark:group-hover:fill-zinc-500"
/>
2024-07-22 11:49:47 +02:00
</Link>
);
}
function SmallPrint() {
return (
<div className="flex flex-col items-center justify-between gap-5 border-t border-zinc-900/5 pt-8 sm:flex-row dark:border-white/5">
2024-07-22 17:54:58 +02:00
<p className="text-xs text-zinc-600 dark:text-zinc-400 prose dark:prose-invert">
&copy; Copyright {new Date().getFullYear()}. Licensed under{" "}
<a
href="https://creativecommons.org/licenses/by-sa/4.0/deed.en"
rel="noopener noreferrer"
target="_blank"
>
CC BY-SA 4.0
</a>
.
2024-07-22 11:49:47 +02:00
</p>
<div className="flex gap-4">
2024-07-27 15:37:58 +02:00
<SocialLink
href="https://github.com/versia-pub"
2024-07-27 15:37:58 +02:00
icon="mdi:github"
>
Find us on GitHub
2024-07-22 11:49:47 +02:00
</SocialLink>
</div>
</div>
);
}
export function Footer() {
return (
<footer className="mx-auto w-full max-w-2xl space-y-10 pb-16 lg:max-w-5xl">
<PageNavigation />
<SmallPrint />
</footer>
);
}