组件

Pagination

Page links as drawn buttons: each number is a Button around your own link, the page you are on is a block of highlighter, the arrows and the ellipsis are hand-drawn. It is just links, so it works with any router, or with plain hrefs and no JavaScript at all.

安装

terminal
npx shadcn@latest add @wobko/pagination

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Default

The shadcn demo: Previous, three numbers with the second current, an ellipsis, Next. The current page is a block of highlighter; point at another and it wears the wash.

Controlled, with gaps

Nine pages with the classic windowing: the first and last always show, the current page has a neighbor on each side, the rest fold into ellipses. Previous is inert on page 1 and Next on page 9; the links have real hrefs, so open in a new tab works.

Simple pager

Previous, a line of text, Next: for a feed or a list you page through. Sizes are Button sizes; here the arrows are square icon buttons with a label of their own, and a load-more link uses the large size.

Table footer (composed)

A real use: twenty-three notebooks, five to a page. The range under the table and the current number follow the page, and the links keep real hrefs for people who open them in a new tab.

Demo

Official `pagination-demo`, part for part. Only the hrefs differ: a bare `#` would send the docs router home, so each link points at an in-page anchor. The current page is a block of highlighter; the others wear it when pointed at.

API 参考

PaginationLink

A page link: `<Button asChild>` around an `<a>`, so it is drawn (ghost, or secondary when active) and keeps your `href`, `target` and handlers. `buttonVariants()` on a bare anchor would give layout without the drawing, which is why this wraps a Button.

属性类型默认值说明
isActivebooleanfalseThe current page: a block of highlighter, `aria-current="page"`, `data-active`.
size"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg""icon"A Button size. A page number is a square icon button.
disabledbooleanfalseFor a link that goes nowhere (the first page's Previous): drawn dashed, `aria-disabled`, out of the tab order, its click swallowed (your onClick does not run).

无障碍

  • A `nav` landmark labeled "pagination" holding a list of links. The current page has `aria-current="page"`; it is also bold-on-highlighter, so it does not rely on color.
  • Previous and Next carry `aria-label`s that name their destination, so they read the same when the word is hidden on a phone. Give number links an accessible name of their own when the bare number is ambiguous (`aria-label="Page 3"`).
  • A disabled link is `aria-disabled`, removed from the tab order and drawn as the dashed alternative; its click is prevented and your `onClick` is not called.
  • Each link is at least 36 px square (32 compact, 28 calm), a tab stop with the theme's drawn blue focus ring. Being plain anchors, they work without JavaScript and with any router.

源码

CLI 会复制进你项目的文件。

正在加载源码