{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tw-pagination",
  "type": "registry:ui",
  "title": "react-tw/pagination.tsx",
  "description": "Carbon `Pagination` as a React + Tailwind component, the look and rules of `<ui-pagination>` (core/pagination): 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",
    "@kanok-ui/tw-i18n",
    "@kanok-ui/tw-theme",
    "@kanok-ui/tw-utils"
  ],
  "files": [
    {
      "path": "src/react-tw/pagination.tsx",
      "type": "registry:ui",
      "target": "components/ui/react-tw/pagination.tsx",
      "content": "import { useId, type CSSProperties, type ComponentProps } from 'react';\nimport { fillText } from '../core/pagination.ts';\nimport type { PaginationMessages } from '../core/i18n.ts';\nimport { Pagination as PaginationPrimitive } from '@purpurabog/ui/headless';\nimport { useTranslation } from './lib/i18n.ts';\nimport { cn } from './lib/utils.ts';\n\n/**\n * Carbon `Pagination` as a React + Tailwind component, the look and rules of `<ui-pagination>` (core/pagination):\n * \"Items per page\" (a borderless select), the item range, the page select (\"page N\"), \"of N pages\"\n * and previous / next. Heights sm 32 / md 40 / lg 48 on the layer with a 1px top border. A new page\n * size goes back to page 1 (Carbon). Reaching the first or last page moves focus to the other arrow.\n * With `pagesUnknown` the page select becomes text and Next disables only with `isLastPage`.\n * Texts are templates: `{min}`, `{max}`, `{total}`, `{page}`.\n */\nexport type PaginationChange = PaginationPrimitive.PaginationChange;\n\nexport interface PaginationProps extends Omit<ComponentProps<'div'>, 'page' | 'defaultPage' | 'pageSize' | 'defaultPageSize' | 'pageSizes' | 'totalItems' | 'pagesUnknown' | 'isLastPage' | 'size' | 'disabled' | 'onChange' | 'itemsPerPageText' | 'itemRangeText' | 'itemText' | 'pageRangeText' | 'pageText' | 'pageSelectLabel' | 'previousLabel' | 'nextLabel' | 'lang' | 'className'> {\n    page?: number;\n    defaultPage?: number;\n    pageSize?: number;\n    defaultPageSize?: number;\n    /** Choices of the page-size select; empty hides it. */\n    pageSizes?: number[];\n    totalItems?: number;\n    pagesUnknown?: boolean;\n    /** With `pagesUnknown`: this is the last page. */\n    isLastPage?: boolean;\n    size?: 'sm' | 'md' | 'lg';\n    disabled?: boolean;\n    /** After the user changed the page or the page size. */\n    onChange?: (change: PaginationChange) => void;\n    itemsPerPageText?: string;\n    itemRangeText?: string;\n    /** Range text while the total is unknown. */\n    itemText?: string;\n    pageRangeText?: string;\n    /** Each page option, and the page text while unknown. */\n    pageText?: string;\n    pageSelectLabel?: string;\n    previousLabel?: string;\n    nextLabel?: string;\n    lang?: string;\n    className?: string;\n}\n\n/** The field heights (--ui-field-height-*), as <ui-pagination>. */\nconst HEIGHT = { sm: 'var(--ui-field-height-sm, 32px)', md: 'var(--ui-field-height-md, 40px)', lg: 'var(--ui-field-height-lg, 48px)' } as const;\n\nconst caretLeft = <path d=\"M10 11.8 6.2 8 10 4.2 10.7 5 7.7 8l3 3z\" />;\nconst caretRight = <path d=\"m6 11.8 3.8-3.8L6 4.2 5.3 5l3 3-3 3z\" />;\n\nconst selectClasses = cn(\n    'peer m-0 box-border h-full cursor-pointer appearance-none rounded-[var(--ui-pagination-select-radius,0px)] [border-block:var(--ui-pagination-select-border,0_solid_var(--ui-hairline))] bg-transparent ps-4 pe-9 text-ink [font:inherit] [font-size:var(--ui-field-font-size,14px)]! [letter-spacing:inherit]',\n    'outline-[length:var(--ui-focus-width,2px)] -outline-offset-2 outline-transparent hover:bg-ghost-hover focus:outline-focus',\n    'disabled:cursor-not-allowed disabled:bg-transparent disabled:text-ink-disabled',\n);\n\nfunction Chevron() {\n    return (\n        <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\" className=\"pointer-events-none absolute end-4 top-1/2 size-4 -translate-y-1/2 fill-ink peer-disabled:fill-ink-disabled\">\n            <path d=\"M8 11 3 6l.7-.7L8 9.6l4.3-4.3.7.7z\" />\n        </svg>\n    );\n}\n\nexport function Pagination({\n    page,\n    defaultPage = 1,\n    pageSize,\n    defaultPageSize = 10,\n    pageSizes = [10, 25, 50],\n    totalItems = 0,\n    pagesUnknown = false,\n    isLastPage = false,\n    size = 'md',\n    disabled = false,\n    onChange,\n    itemsPerPageText,\n    itemRangeText,\n    itemText,\n    pageRangeText,\n    pageText,\n    pageSelectLabel,\n    previousLabel,\n    nextLabel,\n    lang,\n    className,\n    ...rest\n}: Readonly<PaginationProps>) {\n    const t = useTranslation(lang).pagination;\n    const id = useId();\n    return (\n        <PaginationPrimitive.Root\n            {...rest}\n            page={page}\n            defaultPage={defaultPage}\n            pageSize={pageSize}\n            defaultPageSize={defaultPageSize}\n            totalItems={totalItems}\n            pagesUnknown={pagesUnknown}\n            isLastPage={isLastPage}\n            disabled={disabled}\n            onChange={onChange}\n            style={{ ...rest.style, ...({ '--_h': HEIGHT[size] } as CSSProperties) }}\n            className={cn('block font-sans', className)}\n        >\n            <PaginationBar id={id} pageSizes={pageSizes} texts={{ itemsPerPageText, itemRangeText, itemText, pageRangeText, pageText, pageSelectLabel, previousLabel, nextLabel }} t={t} />\n        </PaginationPrimitive.Root>\n    );\n}\n\ntype PaginationTexts = Pick<PaginationProps, 'itemsPerPageText' | 'itemRangeText' | 'itemText' | 'pageRangeText' | 'pageText' | 'pageSelectLabel' | 'previousLabel' | 'nextLabel'>;\n\nconst control = cn(\n    'm-0 box-border flex size-(--_h) cursor-pointer items-center justify-center [border-block:0_solid_var(--ui-hairline)] [border-inline-end:0_solid_var(--ui-hairline)] [border-inline-start:var(--ui-pagination-divider,1px_solid_var(--ui-hairline))] rounded-[var(--ui-pagination-button-radius,0px)] bg-transparent p-0 text-ink',\n    'transition-[outline,background-color] duration-(--ui-duration-moderate) ease-carbon hover:bg-ghost-hover',\n    'outline-none focus-visible:outline-[length:var(--ui-focus-width,2px)] focus-visible:outline-solid focus-visible:[outline-offset:var(--ui-focus-offset,-2px)] focus-visible:outline-focus',\n    'disabled:cursor-not-allowed disabled:bg-transparent disabled:text-ink-disabled [&_svg]:size-4 [&_svg]:fill-current',\n);\n\n/** Narrower than 672px (Carbon's md breakpoint, measured on the bar): hidden; only the item range and the arrows stay (as the Lit ui-pagination). */\nconst wide = '@max-[41.98rem]:hidden';\n\n/** The bar: page size, range, page select, page count and the arrows (the state is the primitive's). */\nfunction PaginationBar({ id, pageSizes, texts, t }: Readonly<{ id: string; pageSizes: number[]; texts: PaginationTexts; t: PaginationMessages }>) {\n    const { itemsPerPageText, itemRangeText, itemText, pageRangeText, pageText, pageSelectLabel, previousLabel, nextLabel } = texts;\n    const ctx = PaginationPrimitive.usePaginationContext();\n    const { min, max, pagesUnknown } = ctx;\n    const range = pagesUnknown ? fillText(itemText ?? t.items, { min, max }) : fillText(itemRangeText ?? t.itemRange, { min, max, total: ctx.totalItems });\n    return (\n        <div\n            className={cn(\n                // --ui-pagination-*: Carbon's divided slab on the layer; a design can lay out open, rounded controls instead\n                '@container box-border flex min-h-(--_h) w-full items-center justify-between [border-inline:0_solid_var(--ui-hairline)] [border-block-end:0_solid_var(--ui-hairline)] [border-block-start:var(--ui-pagination-border,1px_solid_var(--ui-hairline))] bg-[var(--ui-pagination-background,var(--ui-surface-1))] text-ink type-body-sm',\n                'forced-colors:border forced-colors:border-[CanvasText]',\n            )}\n        >\n            <div className=\"flex h-(--_h) items-center gap-[var(--ui-pagination-gap,normal)] @max-[41.98rem]:min-w-0\">\n                {pageSizes.length > 0 ? (\n                    <>\n                        <label htmlFor={`${id}-size`} className={cn('ps-4 whitespace-nowrap text-ink-muted', wide)}>\n                            {itemsPerPageText ?? t.itemsPerPage}\n                        </label>\n                        <span className={cn('relative h-full', wide)}>\n                            <PaginationPrimitive.PageSizeSelect id={`${id}-size`} pageSizes={pageSizes} className={cn(selectClasses, '[border-inline-start:var(--ui-pagination-select-border,0_solid_var(--ui-hairline))] [border-inline-end:var(--ui-pagination-select-border,var(--ui-pagination-divider,1px_solid_var(--ui-hairline)))]')} />\n                            <Chevron />\n                        </span>\n                    </>\n                ) : null}\n                <span className=\"px-4 whitespace-nowrap text-[var(--ui-pagination-range-ink,var(--ui-ink))] @max-[41.98rem]:overflow-hidden @max-[41.98rem]:text-ellipsis\">{range}</span>\n            </div>\n            <div className=\"flex h-(--_h) items-center gap-[var(--ui-pagination-gap,normal)]\">\n                {pagesUnknown ? (\n                    <span className={cn('px-4 whitespace-nowrap text-ink-muted', wide)}>{fillText(pageText ?? t.page, { page: ctx.page })}</span>\n                ) : (\n                    <>\n                        <span className={cn('relative h-full', wide)}>\n                            <PaginationPrimitive.PageSelect aria-label={pageSelectLabel ?? t.pageNumber} renderPage={(p) => fillText(pageText ?? t.page, { page: p })} className={cn(selectClasses, '[border-inline-end:var(--ui-pagination-select-border,0_solid_var(--ui-hairline))] [border-inline-start:var(--ui-pagination-select-border,var(--ui-pagination-divider,1px_solid_var(--ui-hairline)))]')} />\n                            <Chevron />\n                        </span>\n                        <span className={cn('px-4 whitespace-nowrap text-ink-muted', wide)}>{fillText(pageRangeText ?? t.pageRange, { total: ctx.pageCount, page: ctx.page })}</span>\n                    </>\n                )}\n                <PaginationPrimitive.Prev aria-label={previousLabel ?? t.previousPage} className={control}>\n                    <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n                        {caretLeft}\n                    </svg>\n                </PaginationPrimitive.Prev>\n                <PaginationPrimitive.Next aria-label={nextLabel ?? t.nextPage} className={control}>\n                    <svg viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n                        {caretRight}\n                    </svg>\n                </PaginationPrimitive.Next>\n            </div>\n        </div>\n    );\n}\n"
    }
  ]
}
