{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pagination-08",
  "title": "Grouped pages",
  "description": "Page numbers joined into one segmented control; a flat fill travels to the current page.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.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",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/pagination/pagination-08.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 {\n  ChevronLeftIcon,\n  ChevronRightIcon,\n  EllipsisIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button, buttonVariants } from '@/registry/ndeko/ui/button';\nimport {\n  Pagination,\n  PaginationContent,\n  PaginationItem,\n} from '@/registry/ndeko/ui/pagination';\n\nconst FIRST_PAGE = 1;\nconst TOTAL_PAGES = 10;\nconst PAGES_TO_DISPLAY = 5;\n\nconst SEGMENT = 'rounded-none tabular-nums focus-visible:z-10';\n\nconst CURRENT_FILL =\n  'bg-foreground/[0.06] dark:bg-foreground/10 absolute inset-0';\n\nconst TRAVEL_TRANSITION: Transition = {\n  type: 'spring',\n  bounce: 0,\n  duration: 0.3,\n};\nconst INSTANT_TRANSITION: Transition = { duration: 0 };\n\nconst EDGE_SEGMENT =\n  'data-disabled:text-foreground/30 data-disabled:opacity-100';\n\nconst ELLIPSIS_SEGMENT = cn(\n  buttonVariants({ variant: 'outline', size: 'icon' }),\n  'text-muted-foreground pointer-events-none rounded-none'\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\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\nexport default function Pagination08() {\n  const layoutGroupId = useId();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const travelTransition = travelTransitionOf(shouldReduceMotion);\n  const [currentPage, setCurrentPage] = useState(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 goToPage(event: React.MouseEvent<HTMLAnchorElement>, page: number) {\n    event.preventDefault();\n    const target = clampPage(page);\n    setCurrentPage(target);\n  }\n\n  return (\n    <LayoutGroup id={layoutGroupId}>\n      <Pagination>\n        <PaginationContent className='gap-0 -space-x-px'>\n          <PaginationItem>\n            <Button\n              variant='outline'\n              size='icon'\n              nativeButton={false}\n              disabled={isFirstPage}\n              className={cn(SEGMENT, EDGE_SEGMENT, 'rounded-s-full')}\n              render={\n                <a\n                  href={hrefOf(previousPage)}\n                  aria-label='Go to previous page'\n                  onClick={(event) => goToPage(event, previousPage)}\n                />\n              }\n            >\n              <ChevronLeftIcon />\n            </Button>\n          </PaginationItem>\n          {showLeftEllipsis && (\n            <PaginationItem>\n              <span aria-hidden='true' className={ELLIPSIS_SEGMENT}>\n                <EllipsisIcon />\n              </span>\n            </PaginationItem>\n          )}\n          {pages.map((page) => {\n            const isCurrent = page === currentPage;\n\n            return (\n              <PaginationItem key={page}>\n                <Button\n                  variant='outline'\n                  size='icon'\n                  nativeButton={false}\n                  className={SEGMENT}\n                  render={\n                    <a\n                      href={hrefOf(page)}\n                      aria-current={ariaCurrentOf(isCurrent)}\n                      onClick={(event) => goToPage(event, page)}\n                    />\n                  }\n                >\n                  {isCurrent && (\n                    <motion.span\n                      layoutId='current-page'\n                      transition={travelTransition}\n                      className={CURRENT_FILL}\n                    />\n                  )}\n                  <span className='relative'>{page}</span>\n                </Button>\n              </PaginationItem>\n            );\n          })}\n          {showRightEllipsis && (\n            <PaginationItem>\n              <span aria-hidden='true' className={ELLIPSIS_SEGMENT}>\n                <EllipsisIcon />\n              </span>\n            </PaginationItem>\n          )}\n          <PaginationItem>\n            <Button\n              variant='outline'\n              size='icon'\n              nativeButton={false}\n              disabled={isLastPage}\n              className={cn(SEGMENT, EDGE_SEGMENT, 'rounded-e-full')}\n              render={\n                <a\n                  href={hrefOf(nextPage)}\n                  aria-label='Go to next page'\n                  onClick={(event) => goToPage(event, nextPage)}\n                />\n              }\n            >\n              <ChevronRightIcon />\n            </Button>\n          </PaginationItem>\n        </PaginationContent>\n      </Pagination>\n    </LayoutGroup>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "pagination"
  ],
  "type": "registry:component"
}