Home / File/ pager.tsx — ui Source File

pager.tsx — ui Source File

Architecture documentation for pager.tsx, a tsx file in the ui codebase. 6 imports, 0 dependents.

File tsx ComponentRegistry UIPrimitives 6 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  213561a5_18fd_dd2d_4a77_5d95a3395c34["pager.tsx"]
  ba3d44f3_7b34_f9cc_6283_44817785c0df["link"]
  213561a5_18fd_dd2d_4a77_5d95a3395c34 --> ba3d44f3_7b34_f9cc_6283_44817785c0df
  ee57985e_b5cc_179b_e56e_e75bb7f2549f["generated"]
  213561a5_18fd_dd2d_4a77_5d95a3395c34 --> ee57985e_b5cc_179b_e56e_e75bb7f2549f
  d39cd1e4_1b2d_9aa2_1d29_fd0b4bfb61c3["lucide-react"]
  213561a5_18fd_dd2d_4a77_5d95a3395c34 --> d39cd1e4_1b2d_9aa2_1d29_fd0b4bfb61c3
  0f2652fe_536a_d362_981f_94cad3be1147["nav"]
  213561a5_18fd_dd2d_4a77_5d95a3395c34 --> 0f2652fe_536a_d362_981f_94cad3be1147
  9416d7da_00df_60a8_615c_4b360d3b77f8["docs"]
  213561a5_18fd_dd2d_4a77_5d95a3395c34 --> 9416d7da_00df_60a8_615c_4b360d3b77f8
  aa2f3ec6_f291_3763_88ec_65a3f5ad5939["button"]
  213561a5_18fd_dd2d_4a77_5d95a3395c34 --> aa2f3ec6_f291_3763_88ec_65a3f5ad5939
  style 213561a5_18fd_dd2d_4a77_5d95a3395c34 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import Link from "next/link"
import { Doc } from "contentlayer/generated"
import { ChevronLeft, ChevronRight } from "lucide-react"
import { NavItem, NavItemWithChildren } from "types/nav"

import { docsConfig } from "@/config/docs"
import { Button } from "@/registry/new-york/ui/button"

interface DocsPagerProps {
  doc: Doc
}

export function DocsPager({ doc }: DocsPagerProps) {
  const pager = getPagerForDoc(doc)

  if (!pager) {
    return null
  }

  return (
    <div className="flex flex-row items-center justify-between">
      {pager?.prev?.href && (
        <Button variant="ghost" asChild>
          <Link href={pager.prev.href}>
            <ChevronLeft />
            {pager.prev.title}
          </Link>
        </Button>
      )}
      {pager?.next?.href && (
        <Button variant="ghost" className="ml-auto" asChild>
          <Link href={pager.next.href}>
            {pager.next.title}
            <ChevronRight />
          </Link>
        </Button>
      )}
    </div>
  )
}

export function getPagerForDoc(doc: Doc) {
  const nav = doc.slug.startsWith("/docs/charts")
    ? docsConfig.chartsNav
    : docsConfig.sidebarNav
  const flattenedLinks = [null, ...flatten(nav), 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)
}

Subdomains

Dependencies

  • button
  • docs
  • generated
  • link
  • lucide-react
  • nav

Frequently Asked Questions

What does pager.tsx do?
pager.tsx is a source file in the ui codebase, written in tsx. It belongs to the ComponentRegistry domain, UIPrimitives subdomain.
What functions are defined in pager.tsx?
pager.tsx defines 3 function(s): DocsPager, flatten, getPagerForDoc.
What does pager.tsx depend on?
pager.tsx imports 6 module(s): button, docs, generated, link, lucide-react, nav.
Where is pager.tsx in the architecture?
pager.tsx is located at deprecated/www/components/pager.tsx (domain: ComponentRegistry, subdomain: UIPrimitives, directory: deprecated/www/components).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free