{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pagination-12",
  "title": "Go to page",
  "description": "Page numbers next to a field that jumps to a typed page.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/label.json",
    "https://ui.ndekocode.dev/r/pagination.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-pagination.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/pagination/pagination-12.tsx",
      "content": "'use client';\n\nimport { LayoutGroup, motion, type Transition } from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { usePagination } from '@/registry/ndeko/hooks/use-pagination';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { ChevronLeftIcon, ChevronRightIcon } from '@/registry/ndeko/lib/icons';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Label } from '@/registry/ndeko/ui/label';\nimport {\n  Pagination,\n  PaginationContent,\n  PaginationEllipsis,\n  PaginationItem,\n  PaginationLink,\n} from '@/registry/ndeko/ui/pagination';\n\nconst FIRST_PAGE = 1;\nconst TOTAL_PAGES = 10;\nconst PAGES_TO_DISPLAY = 5;\n\nconst TRAVEL_TRANSITION: Transition = {\n  type: 'spring',\n  bounce: 0,\n  duration: 0.3,\n};\nconst INSTANT_TRANSITION: Transition = { duration: 0 };\n\nconst CURRENT_PILL =\n  'bg-card hairline-ring ring-foreground/12 dark:bg-foreground/[0.04] dark:ring-foreground/15 absolute inset-0 rounded-full shadow-[0_1px_2px_rgb(0_0_0/0.05)]';\n\nfunction travelTransitionOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT_TRANSITION;\n  }\n  return TRAVEL_TRANSITION;\n}\n\nfunction ariaCurrentOf(isCurrent: boolean) {\n  if (isCurrent) {\n    return 'page' as const;\n  }\n  return undefined;\n}\n\nfunction clampPage(page: number) {\n  const atLeastFirst = Math.max(FIRST_PAGE, page);\n  return Math.min(TOTAL_PAGES, atLeastFirst);\n}\n\nfunction hrefOf(page: number) {\n  return `#/page/${page}`;\n}\n\nexport default function Pagination12() {\n  const id = useId();\n  const layoutGroupId = useId();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const travelTransition = travelTransitionOf(shouldReduceMotion);\n  const [currentPage, setCurrentPage] = useState(FIRST_PAGE);\n  const [typedPage, setTypedPage] = useState(String(FIRST_PAGE));\n  const { pages, showLeftEllipsis, showRightEllipsis } = usePagination({\n    currentPage,\n    totalPages: TOTAL_PAGES,\n    paginationItemsToDisplay: PAGES_TO_DISPLAY,\n  });\n  const previousPage = currentPage - 1;\n  const nextPage = currentPage + 1;\n  const isFirstPage = currentPage === FIRST_PAGE;\n  const isLastPage = currentPage === TOTAL_PAGES;\n\n  function showPage(page: number) {\n    const target = clampPage(page);\n    setCurrentPage(target);\n    setTypedPage(String(target));\n  }\n\n  function goToPage(event: React.MouseEvent<HTMLAnchorElement>, page: number) {\n    event.preventDefault();\n    showPage(page);\n  }\n\n  function updateTypedPage(event: React.ChangeEvent<HTMLInputElement>) {\n    setTypedPage(event.target.value);\n  }\n\n  function commitTypedPage() {\n    const requestedPage = Number.parseInt(typedPage, 10);\n    if (Number.isNaN(requestedPage)) {\n      setTypedPage(String(currentPage));\n      return;\n    }\n    showPage(requestedPage);\n  }\n\n  function goToTypedPage(event: React.FormEvent<HTMLFormElement>) {\n    event.preventDefault();\n    commitTypedPage();\n  }\n\n  return (\n    <div className='flex flex-wrap items-center justify-center gap-x-4 gap-y-3 sm:justify-between'>\n      <LayoutGroup id={layoutGroupId}>\n        <Pagination className='mx-0 w-auto'>\n          <PaginationContent className='max-sm:gap-0.5'>\n            <PaginationItem>\n              <PaginationLink\n                href={hrefOf(previousPage)}\n                aria-label='Go to previous page'\n                isDisabled={isFirstPage}\n                onClick={(event) => goToPage(event, previousPage)}\n                className='rounded-full max-sm:size-8'\n              >\n                <ChevronLeftIcon />\n              </PaginationLink>\n            </PaginationItem>\n            {showLeftEllipsis && (\n              <PaginationItem>\n                <PaginationEllipsis />\n              </PaginationItem>\n            )}\n            {pages.map((page) => {\n              const isCurrent = page === currentPage;\n\n              return (\n                <PaginationItem key={page}>\n                  <PaginationLink\n                    href={hrefOf(page)}\n                    aria-current={ariaCurrentOf(isCurrent)}\n                    onClick={(event) => goToPage(event, page)}\n                    className='rounded-full max-sm:size-8'\n                  >\n                    {isCurrent && (\n                      <motion.span\n                        layoutId='current-page'\n                        transition={travelTransition}\n                        className={CURRENT_PILL}\n                      />\n                    )}\n                    <span className='relative'>{page}</span>\n                  </PaginationLink>\n                </PaginationItem>\n              );\n            })}\n            {showRightEllipsis && (\n              <PaginationItem>\n                <PaginationEllipsis />\n              </PaginationItem>\n            )}\n            <PaginationItem>\n              <PaginationLink\n                href={hrefOf(nextPage)}\n                aria-label='Go to next page'\n                isDisabled={isLastPage}\n                onClick={(event) => goToPage(event, nextPage)}\n                className='rounded-full max-sm:size-8'\n              >\n                <ChevronRightIcon />\n              </PaginationLink>\n            </PaginationItem>\n          </PaginationContent>\n        </Pagination>\n      </LayoutGroup>\n      <form onSubmit={goToTypedPage} className='flex items-center gap-3'>\n        <Label htmlFor={id} className='whitespace-nowrap'>\n          Go to page\n        </Label>\n        <Input\n          id={id}\n          inputMode='numeric'\n          autoComplete='off'\n          value={typedPage}\n          onChange={updateTypedPage}\n          onBlur={commitTypedPage}\n          className='w-14 text-center tabular-nums'\n        />\n      </form>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "pagination"
  ],
  "type": "registry:component"
}