{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pagination-09",
  "title": "Pages with results per page",
  "description": "The page count, the page numbers and a select for the page size.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/pagination.json",
    "https://ui.ndekocode.dev/r/select.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-09.tsx",
      "content": "'use client';\n\nimport { LayoutGroup, motion, type Transition } from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\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 {\n  Pagination,\n  PaginationContent,\n  PaginationEllipsis,\n  PaginationItem,\n  PaginationLink,\n} from '@/registry/ndeko/ui/pagination';\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from '@/registry/ndeko/ui/select';\n\nconst FIRST_PAGE = 1;\nconst TOTAL_RESULTS = 100;\nconst PAGES_TO_DISPLAY = 5;\n\nconst PAGE_SIZES = [\n  { value: 10, label: '10 / page' },\n  { value: 20, label: '20 / page' },\n  { value: 50, label: '50 / page' },\n  { value: 100, label: '100 / page' },\n];\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 hrefOf(page: number) {\n  return `#/page/${page}`;\n}\n\nexport default function Pagination09() {\n  const [pageSize, setPageSize] = useState(10);\n  const [page, setPage] = useState(FIRST_PAGE);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const travelTransition = travelTransitionOf(shouldReduceMotion);\n  const layoutGroupId = useId();\n  const totalPages = Math.ceil(TOTAL_RESULTS / pageSize);\n  const { pages, showLeftEllipsis, showRightEllipsis } = usePagination({\n    currentPage: page,\n    totalPages,\n    paginationItemsToDisplay: PAGES_TO_DISPLAY,\n  });\n  const previousPage = page - 1;\n  const nextPage = page + 1;\n  const isFirstPage = page === FIRST_PAGE;\n  const isLastPage = page === totalPages;\n\n  function showPage(target: number) {\n    const atLeastFirst = Math.max(FIRST_PAGE, target);\n    const nextCurrent = Math.min(totalPages, atLeastFirst);\n    setPage(nextCurrent);\n  }\n\n  function goToPage(\n    event: React.MouseEvent<HTMLAnchorElement>,\n    target: number\n  ) {\n    event.preventDefault();\n    showPage(target);\n  }\n\n  function changePageSize(size: number | null) {\n    if (size === null) {\n      return;\n    }\n    setPageSize(size);\n    showPage(FIRST_PAGE);\n  }\n\n  return (\n    <div className='flex flex-wrap items-center justify-between gap-3'>\n      <p\n        className='text-muted-foreground flex-1 text-[13px] whitespace-nowrap tabular-nums'\n        aria-live='polite'\n      >\n        <span className='sr-only'>\n          Page {page} of {totalPages}\n        </span>\n        <span className='inline-flex items-baseline' aria-hidden='true'>\n          Page&nbsp;\n          <MotionNumber value={page} className='text-foreground' />\n          &nbsp;of&nbsp;\n          <MotionNumber value={totalPages} className='text-foreground' />\n        </span>\n      </p>\n      <div className='grow max-sm:order-first max-sm:basis-full'>\n        <LayoutGroup id={layoutGroupId}>\n          <Pagination>\n            <PaginationContent>\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'\n                >\n                  <ChevronLeftIcon />\n                </PaginationLink>\n              </PaginationItem>\n              {showLeftEllipsis && (\n                <PaginationItem>\n                  <PaginationEllipsis />\n                </PaginationItem>\n              )}\n              {pages.map((pageNumber) => {\n                const isCurrent = pageNumber === page;\n\n                return (\n                  <PaginationItem key={pageNumber}>\n                    <PaginationLink\n                      href={hrefOf(pageNumber)}\n                      aria-current={ariaCurrentOf(isCurrent)}\n                      onClick={(event) => goToPage(event, pageNumber)}\n                      className='rounded-full'\n                    >\n                      {isCurrent && (\n                        <motion.span\n                          layoutId='current-page'\n                          transition={travelTransition}\n                          className={CURRENT_PILL}\n                        />\n                      )}\n                      <span className='relative'>{pageNumber}</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'\n                >\n                  <ChevronRightIcon />\n                </PaginationLink>\n              </PaginationItem>\n            </PaginationContent>\n          </Pagination>\n        </LayoutGroup>\n      </div>\n      <div className='flex flex-1 justify-end'>\n        <Select\n          items={PAGE_SIZES}\n          value={pageSize}\n          onValueChange={changePageSize}\n        >\n          <SelectTrigger\n            aria-label='Results per page'\n            className='w-fit whitespace-nowrap'\n          >\n            <SelectValue />\n          </SelectTrigger>\n          <SelectContent>\n            {PAGE_SIZES.map((size) => (\n              <SelectItem key={size.value} value={size.value}>\n                {size.label}\n              </SelectItem>\n            ))}\n          </SelectContent>\n        </Select>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "pagination"
  ],
  "type": "registry:component"
}