import { ArrowLeft, ArrowRight } from "lucide-react"
import type * as React from "react"
import { textVariants } from "~/components/ui/text"
import { cn } from "~/lib/utils"
/*
* The end of a page or a site. Any of its parts, in this order: a pager to the
* previous and next pages, columns of titled links, and a bar of small print.
*
* <Footer>
* <FooterPager>
* <FooterPagerLink direction="previous" href="…">…</FooterPagerLink>
* <FooterPagerLink direction="next" href="…">…</FooterPagerLink>
* </FooterPager>
* <FooterColumns>
* <FooterSection title="…">
* <FooterLink href="…">…</FooterLink>
* </FooterSection>
* </FooterColumns>
* <FooterBar>…</FooterBar>
* </Footer>
*/
/** The footer landmark, ruled off from what's above it. */
function Footer({ className, ...props }: React.ComponentProps<"footer">) {
return (
<footer
data-slot="footer"
className={cn("flex flex-col gap-2xl border-t border-border pt-2xl", className)}
{...props}
/>
)
}
/** The previous and next pages, side by side. Named "Pages" unless you name it. */
function FooterPager({
"aria-label": label = "Pages",
className,
...props
}: React.ComponentProps<"nav">) {
return (
<nav
data-slot="footer-pager"
aria-label={label}
className={cn("grid gap-md sm:grid-cols-2", className)}
{...props}
/>
)
}
type FooterPagerLinkProps = React.ComponentProps<"a"> & {
/** Which way it goes. A lone `next` still sits on the right. */
direction: "previous" | "next"
}
/** A page before or after this one: which way it is, small, over its name. */
function FooterPagerLink({ direction, className, children, ...props }: FooterPagerLinkProps) {
const Arrow = direction === "previous" ? ArrowLeft : ArrowRight
return (
<a
data-slot="footer-pager-link"
data-direction={direction}
rel={direction === "previous" ? "prev" : "next"}
className={cn(
"group/pager flex min-w-0 flex-col gap-3xs rounded-lg border border-border px-lg py-md outline-none",
"hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/30",
"data-[direction=next]:items-end data-[direction=next]:text-right sm:data-[direction=next]:col-start-2",
className,
)}
{...props}
>
<span
className={cn(
textVariants({ size: "xs", tone: "muted" }),
"inline-flex items-center gap-xs group-data-[direction=next]/pager:flex-row-reverse [&_svg]:size-3.5",
)}
>
<Arrow aria-hidden="true" />
{direction === "previous" ? "Previous" : "Next"}
</span>
<span className={cn(textVariants({ size: "sm", weight: "medium" }), "max-w-full truncate")}>
{children}
</span>
</a>
)
}
/** Sections of links in columns, as many as fit. */
function FooterColumns({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="footer-columns"
className={cn("grid grid-cols-2 gap-xl sm:grid-cols-3 lg:grid-cols-4", className)}
{...props}
/>
)
}
type FooterSectionProps = Omit<React.ComponentProps<"nav">, "title"> & {
/** A short heading, shown small and in capitals. It names the section's landmark. */
title: string
}
/** A titled list of links. */
function FooterSection({ title, className, children, ...props }: FooterSectionProps) {
return (
<nav
data-slot="footer-section"
aria-label={title}
className={cn("flex flex-col gap-sm", className)}
{...props}
>
<h2 className={textVariants({ size: "xs", weight: "medium", caps: true, tone: "muted" })}>
{title}
</h2>
<ul className="flex flex-col gap-xs">{children}</ul>
</nav>
)
}
/** A link in a section. */
function FooterLink({ className, children, ...props }: React.ComponentProps<"a">) {
return (
<li>
<a
data-slot="footer-link"
className={cn(
textVariants({ size: "sm", tone: "muted" }),
"transition-colors outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/30",
className,
)}
{...props}
>
{children}
</a>
</li>
)
}
/** The small print along the bottom: a name or notice, then anything else at the far end. */
function FooterBar({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="footer-bar"
className={cn(
textVariants({ size: "xs", tone: "muted" }),
"flex flex-wrap items-center justify-between gap-x-lg gap-y-xs [&_a]:transition-colors [&_a]:hover:text-foreground",
className,
)}
{...props}
/>
)
}
export { Footer, FooterBar, FooterColumns, FooterLink, FooterPager, FooterPagerLink, FooterSection }
export type { FooterPagerLinkProps, FooterSectionProps }