{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-pagination-nav",
  "type": "registry:ui",
  "title": "react-tw/pagination-nav.tsx",
  "description": "Carbon `PaginationNav` as React + Tailwind, the look and rules of `<ui-pagination-nav>` (core/pagination-nav): Copied from @purpurabog/ui 2.3.0; the package is the maintained source, this copy is yours to change. Icons from the Carbon Design System (Apache-2.0, © IBM Corp.; see THIRD-PARTY-NOTICES.md in the package).",
  "dependencies": [
    "@purpurabog/ui@^2.3.0"
  ],
  "registryDependencies": [
    "@kanok-ui/core-i18n",
    "@kanok-ui/core-pagination-nav",
    "@kanok-ui/core-position",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-icon-button",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/pagination-nav.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/pagination-nav.tsx",
      "content": "import type { ComponentProps } from 'react';\nimport type { NavItem, NavSize } from '../core/pagination-nav.ts';\nimport type { Placement } from '../core/position.ts';\nimport type { PaginationMessages } from '../core/i18n.ts';\nimport { PaginationNav as PaginationNavPrimitive } from '@purpurabog/ui/headless';\nimport { IconButton } from './icon-button.tsx';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\n\nexport interface PaginationNavProps extends Omit<ComponentProps<'nav'>, 'onChange'> {\n    /** The current page, 0-based as Carbon's (controlled). */\n    page?: number;\n    defaultPage?: number;\n    /** After the user chose a page (0-based). */\n    onChange?: (page: number) => void;\n    totalItems: number;\n    /** Page items in the row (at least 4). */\n    itemsShown?: number;\n    /** Previous on the first page goes to the last, Next on the last to the first. */\n    loop?: boolean;\n    /** The \"…\" selects can't be opened. */\n    disableOverflow?: boolean;\n    size?: NavSize;\n    tooltipPlacement?: Placement;\n    lang?: string;\n}\n\n// the field heights (--ui-field-height-*, as <ui-pagination-nav>), the number centred in them\nconst HEIGHT = {\n    sm: 'h-field-sm min-w-field-sm py-[calc((var(--ui-field-height-sm)-14px)/2)]',\n    md: 'h-field-md min-w-field-md py-[calc((var(--ui-field-height-md)-14px)/2)]',\n    lg: 'h-field-lg min-w-field-lg py-[calc((var(--ui-field-height-lg)-14px)/2)]',\n} as const;\nconst DIRECTION = { sm: 'sm', md: 'md', lg: 'lg' } as const;\n\n/** Carbon .cds--pagination-nav__page: body-compact-01 at line-height 1; hover background-hover, the ring on :focus; the current one semibold with a 16 × 4 underline. */\nfunction pageClasses(size: NavSize, active: boolean) {\n    return cn(\n        // a page button's corners: the button setting (--ui-button-radius)\n        'relative m-0 box-border block rounded-[var(--ui-button-radius,0px)] border-0 bg-transparent px-1 text-center text-ink type-body-sm leading-none! cursor-pointer select-none',\n        HEIGHT[size],\n        'outline-[length:var(--ui-focus-width,2px)] [outline-offset:var(--ui-focus-offset,-2px)] outline-solid outline-transparent focus:outline-focus focus:not-focus-visible:outline-[color:var(--ui-pointer-focus,var(--ui-focus))] [@media(any-hover:hover)]:hover:bg-canvas-hover',\n        'transition-[background-color,color] duration-(--ui-duration-moderate) ease-carbon',\n        \"after:absolute after:bottom-0 after:start-1/2 after:block after:h-[var(--ui-pagination-nav-mark-height,0.25rem)] after:w-0 after:bg-border-interactive after:opacity-0 after:content-[''] after:transition-[width] after:duration-(--ui-duration-moderate) after:ease-carbon motion-reduce:after:transition-none\",\n        active && 'font-semibold! after:start-[calc(50%-8px)] after:w-4 after:opacity-100 forced-colors:after:bg-[Highlight]',\n        'disabled:pointer-events-none disabled:bg-transparent disabled:text-[color-mix(in_srgb,var(--ui-ink-muted)_50%,transparent)] disabled:outline-none',\n    );\n}\n\n// Carbon's CaretLeft / CaretRight and OverflowMenuHorizontal (32 grid at 16px)\nconst caret = (d: string) => (\n    <svg viewBox=\"0 0 32 32\" aria-hidden=\"true\" className=\"size-4 fill-current rtl:[transform:rotate(0.5turn)]\">\n        <path d={d} />\n    </svg>\n);\n\n/**\n * Carbon `PaginationNav` as React + Tailwind, the look and rules of `<ui-pagination-nav>` (core/pagination-nav):\n * numbered pages between Previous and Next, the pages that don't fit folded into \"…\" selects. `page` is 0-based, as\n * Carbon's; each page is a button (`aria-current=\"page\"` on the current one) and the change is announced.\n */\nexport function PaginationNav({ page, defaultPage = 0, onChange, totalItems, itemsShown = 10, loop = false, disableOverflow = false, size = 'lg', tooltipPlacement = 'bottom', lang, className, ...rest }: Readonly<PaginationNavProps>) {\n    const t = useTranslation(lang).pagination;\n    return (\n        <PaginationNavPrimitive.Root\n            {...rest}\n            page={page}\n            defaultPage={defaultPage}\n            onChange={onChange}\n            totalItems={totalItems}\n            itemsShown={itemsShown}\n            loop={loop}\n            disableOverflow={disableOverflow}\n            size={size}\n            aria-label={t.navLabel}\n            className={cn('block', className)}\n        >\n            <NavRow size={size} tooltipPlacement={tooltipPlacement} t={t} />\n        </PaginationNavPrimitive.Root>\n    );\n}\n\n/** One item of the row: a page button, or the \"…\" select of the pages folded away. */\nfunction NavEntry({ entry, size, t }: Readonly<{ entry: NavItem; size: NavSize; t: PaginationMessages }>) {\n    if (entry.kind === 'page') {\n        return (\n            <li>\n                <PaginationNavPrimitive.Page page={entry.page} className={pageClasses(size, entry.active)}>\n                    <span className=\"sr-only\">{entry.active ? t.navActivePage : t.navPage}</span>\n                    {entry.page + 1}\n                </PaginationNavPrimitive.Page>\n            </li>\n        );\n    }\n    return (\n        <li className=\"relative\">\n            <PaginationNavPrimitive.Overflow\n                from={entry.from}\n                count={entry.count}\n                aria-label={t.navSelect}\n                className={cn(pageClasses(size, false), 'peer appearance-none text-transparent [font-size:var(--ui-field-font-size,14px)]! [text-indent:calc(50%-4.5px)] [&>option]:bg-surface-1 [&>option]:text-ink')}\n            />\n            <div className=\"pointer-events-none absolute inset-0\">\n                <svg viewBox=\"0 0 32 32\" aria-hidden=\"true\" className=\"absolute start-[calc(50%-8px)] top-[calc(50%-4px)] size-4 fill-ink peer-disabled:fill-[color-mix(in_srgb,var(--ui-ink-muted)_50%,transparent)]\">\n                    <circle cx=\"8\" cy=\"16\" r=\"2\" />\n                    <circle cx=\"16\" cy=\"16\" r=\"2\" />\n                    <circle cx=\"24\" cy=\"16\" r=\"2\" />\n                </svg>\n            </div>\n        </li>\n    );\n}\n\n/** Previous, the pages and the overflows, Next, and the announcement (the state is the primitive's). */\nfunction NavRow({ size, tooltipPlacement, t }: Readonly<{ size: NavSize; tooltipPlacement: Placement; t: PaginationMessages }>) {\n    const ctx = PaginationNavPrimitive.usePaginationNavContext();\n    return (\n        <>\n            <ul className=\"m-0 flex list-none items-center p-0\">\n                <li>\n                    <IconButton kind=\"ghost\" size={DIRECTION[size]} label={t.navPrevious} tooltipPlacement={tooltipPlacement} disabled={ctx.stepDisabled(-1)} onClick={() => ctx.step(-1)}>\n                        {caret('M20 24 10 16 20 8z')}\n                    </IconButton>\n                </li>\n                {ctx.items.map((entry) => (\n                    <NavEntry key={entry.kind === 'page' ? `page-${entry.page}` : `overflow-${entry.from}`} entry={entry} size={size} t={t} />\n                ))}\n                <li>\n                    <IconButton kind=\"ghost\" size={DIRECTION[size]} label={t.navNext} tooltipPlacement={tooltipPlacement} disabled={ctx.stepDisabled(1)} onClick={() => ctx.step(1)}>\n                        {caret('M12 8 22 16 12 24z')}\n                    </IconButton>\n                </li>\n            </ul>\n            <PaginationNavPrimitive.Status className=\"sr-only\">{t.navStatus.replace('{page}', String(ctx.page + 1)).replace('{total}', String(ctx.total))}</PaginationNavPrimitive.Status>\n        </>\n    );\n}\n"
    }
  ]
}
