# Pagination

Page links built from UI95 buttons with pixel arrows.

Source: https://www.ui95.dev/ui/pagination

## Examples

```tsx
import {
  Pagination,
  PaginationContent,
  PaginationEllipsis,
  PaginationItem,
  PaginationLink,
  PaginationNext,
  PaginationPrevious,
} from "@/components/ui/pagination"

import type { ShowcaseDemo } from "../types"

export const demo: ShowcaseDemo = {
  span: "wide",
  variants: [
    {
      label: "default",
      render: () => (
        <Pagination>
          <PaginationContent>
            <PaginationItem>
              <PaginationPrevious href="#" />
            </PaginationItem>
            <PaginationItem>
              <PaginationLink href="#">1</PaginationLink>
            </PaginationItem>
            <PaginationItem>
              <PaginationLink href="#" isActive>
                2
              </PaginationLink>
            </PaginationItem>
            <PaginationItem>
              <PaginationLink href="#">3</PaginationLink>
            </PaginationItem>
            <PaginationItem>
              <PaginationEllipsis />
            </PaginationItem>
            <PaginationItem>
              <PaginationNext href="#" />
            </PaginationItem>
          </PaginationContent>
        </Pagination>
      ),
    },
  ],
}
```

## Installation

```bash
npx shadcn@latest add https://www.ui95.dev/r/pagination.json
```

Run it in a Radix shadcn project that already has the UI95 theme.

Dependencies:

```bash
npm install cn
```

Add these items first:

- [button](https://www.ui95.dev/ui/button)
- [pixel-glyphs](https://www.ui95.dev/ui/pixel-glyphs)

`components/ui/pagination.tsx`

```tsx
import { cn } from "cn"
import * as React from "react"

import { Button } from "@/components/ui/button"
import { ChevronGlyph } from "@/components/ui/pixel-glyphs"

function Pagination({ className, ...props }: React.ComponentProps<"nav">) {
  return (
    <nav
      role="navigation"
      aria-label="pagination"
      data-slot="pagination"
      className={cn("mx-auto flex w-full justify-center", className)}
      {...props}
    />
  )
}

function PaginationContent({
  className,
  ...props
}: React.ComponentProps<"ul">) {
  return (
    <ul
      data-slot="pagination-content"
      className={cn("flex items-center gap-1", className)}
      {...props}
    />
  )
}

function PaginationItem({ ...props }: React.ComponentProps<"li">) {
  return <li data-slot="pagination-item" {...props} />
}

type PaginationLinkProps = {
  isActive?: boolean
} & Pick<React.ComponentProps<typeof Button>, "size"> &
  React.ComponentProps<"a">

function PaginationLink({
  className,
  isActive,
  size = "icon",
  ...props
}: PaginationLinkProps) {
  return (
    <Button
      asChild
      variant={isActive ? "default" : "ghost"}
      size={size}
      className={cn(isActive && "bg-foreground text-card", className)}
    >
      <a
        aria-current={isActive ? "page" : undefined}
        data-slot="pagination-link"
        data-active={isActive}
        {...props}
      />
    </Button>
  )
}

function PaginationPrevious({
  className,
  text = "Previous",
  ...props
}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
  return (
    <PaginationLink
      aria-label="Go to previous page"
      size="default"
      className={cn("pl-2!", className)}
      {...props}
    >
      <ChevronGlyph direction="left" data-icon="inline-start" className="cn-rtl-flip" />
      <span className="hidden sm:block">{text}</span>
    </PaginationLink>
  )
}

function PaginationNext({
  className,
  text = "Next",
  ...props
}: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
  return (
    <PaginationLink
      aria-label="Go to next page"
      size="default"
      className={cn("pr-2!", className)}
      {...props}
    >
      <span className="hidden sm:block">{text}</span>
      <ChevronGlyph direction="right" data-icon="inline-end" className="cn-rtl-flip" />
    </PaginationLink>
  )
}

function PaginationEllipsis({
  className,
  ...props
}: React.ComponentProps<"span">) {
  return (
    <span
      aria-hidden
      data-slot="pagination-ellipsis"
      className={cn(
        "flex size-9 items-center justify-center",
        className
      )}
      {...props}
    >
      <svg
        viewBox="0 0 11 3"
        shapeRendering="crispEdges"
        fill="currentColor"
        aria-hidden="true"
        className="h-[9px] w-[33px]"
      >
        <rect x="0" y="0" width="3" height="3" />
        <rect x="4" y="0" width="3" height="3" />
        <rect x="8" y="0" width="3" height="3" />
      </svg>
      <span className="sr-only">More pages</span>
    </span>
  )
}

export {
  Pagination,
  PaginationContent,
  PaginationEllipsis,
  PaginationItem,
  PaginationLink,
  PaginationNext,
  PaginationPrevious,
}
```

## API reference

### Pagination

No props of its own. It forwards the props of the element or primitive it wraps.

### PaginationContent

No props of its own. It forwards the props of the element or primitive it wraps.

### PaginationEllipsis

No props of its own. It forwards the props of the element or primitive it wraps.

### PaginationItem

No props of its own. It forwards the props of the element or primitive it wraps.

### PaginationLink

| Prop | Type | Default |
| --- | --- | --- |
| `isActive` | `boolean` | - |
| `size` | `"sm" \| "lg" \| "default" \| "xs" \| "icon" \| "icon-xs" \| "icon-sm" \| "icon-lg"` | `"icon"` |

### PaginationNext

| Prop | Type | Default |
| --- | --- | --- |
| `isActive` | `boolean` | - |
| `size` | `"sm" \| "lg" \| "default" \| "xs" \| "icon" \| "icon-xs" \| "icon-sm" \| "icon-lg"` | - |
| `text` | `string` | `"Next"` |

### PaginationPrevious

| Prop | Type | Default |
| --- | --- | --- |
| `isActive` | `boolean` | - |
| `size` | `"sm" \| "lg" \| "default" \| "xs" \| "icon" \| "icon-xs" \| "icon-sm" \| "icon-lg"` | - |
| `text` | `string` | `"Previous"` |

## Sounds

- `button.press`
- `button.release`
