Files
supabase/apps/design-system/components/pager.tsx
kemal.earth b97e41e20b chore(design-system): tidy up mobile styling (#41267)
* feat: tidy up header on mobile

* fix: graceful searchbar header

* fix: header classes and unused elements

* feat: trim down logo on header

* fix: logos again

* chore: remove dead code

* fix: classic dark logo header

* fix: page padding tidy ups

* fix: some font sizing

* feat: updated homepage cards

* fix: toc layout

* fix: toc again

* feat: homepage cards all the same size

* fix: footer paddings

* fix: pager if only 1 directional item

* fix: sidebar padding issues

* chore: killing all the defaults

* fix: import for side nav

* fix: sidebar complaining about dialog title

* fix: homepage paddings

* fix: killing one more default export

* feat: update colours icon to francescos

* fix: loose repeated copy
2025-12-12 10:08:48 +00:00

74 lines
2.4 KiB
TypeScript

import Link from 'next/link'
import { Doc } from 'contentlayer/generated'
import { NavItem, NavItemWithChildren } from '@/types/nav'
import { docsConfig } from '@/config/docs'
import { cn } from '@/lib/utils'
import { ChevronLeft, ChevronRight } from 'lucide-react'
interface DocsPagerProps {
doc: Doc
}
export function DocsPager({ doc }: DocsPagerProps) {
const pager = getPagerForDoc(doc)
if (!pager) {
return null
}
const hasBoth = pager?.prev?.href && pager?.next?.href
return (
<div className={cn('flex flex-row items-center', hasBoth ? 'justify-between' : 'justify-end')}>
{pager?.prev?.href && (
<Link
href={pager.prev.href}
className="flex gap-3 text-foreground-light hover:text-foreground group"
>
<ChevronLeft className="mr-2 h-4 w-4 self-end mb-1 text-foreground-muted group-hover:text-foreground-lighter" />
<div className="flex flex-col gap-1">
<span className="text-xs font-mono uppercase tracking-wider text-foreground-muted group-hover:text-foreground-lighter">
Previous
</span>
{pager.prev.title}
</div>
</Link>
)}
{pager?.next?.href && (
<Link
href={pager.next.href}
className="flex gap-3 text-foreground-light hover:text-foreground group"
>
<div className="flex flex-col gap-1">
<span className="text-xs font-mono uppercase tracking-wider text-foreground-muted group-hover:text-foreground-lighter">
Next
</span>
{pager.next.title}
</div>
<ChevronRight className="ml-2 h-4 w-4 self-end mb-1 text-foreground-muted group-hover:text-foreground-lighter" />
</Link>
)}
</div>
)
}
export function getPagerForDoc(doc: Doc) {
const flattenedLinks = [null, ...flatten(docsConfig.sidebarNav), null]
const activeIndex = flattenedLinks.findIndex((link) => doc.slug === link?.href)
const prev = activeIndex !== 0 ? flattenedLinks[activeIndex - 1] : null
const next = activeIndex !== flattenedLinks.length - 1 ? flattenedLinks[activeIndex + 1] : null
return {
prev,
next,
}
}
export function flatten(links: NavItemWithChildren[]): NavItem[] {
return links
.reduce<NavItem[]>((flat, link) => {
return flat.concat(link.items?.length ? flatten(link.items) : link)
}, [])
.filter((link) => !link?.disabled)
}