@ui-sdk/react 0.0.0-stage → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/accordion.d.ts +331 -0
  4. package/dist/accordion.js +25 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/agent.js +8 -0
  7. package/dist/alert-dialog.d.ts +56 -0
  8. package/dist/alert-dialog.js +45 -0
  9. package/dist/async-options.d.ts +22 -0
  10. package/dist/async-options.js +56 -0
  11. package/dist/autocomplete.d.ts +102 -0
  12. package/dist/autocomplete.js +195 -0
  13. package/dist/avatar.d.ts +301 -0
  14. package/dist/avatar.js +17 -0
  15. package/dist/button.d.ts +21 -0
  16. package/dist/button.js +45 -0
  17. package/dist/calendar-context.d.ts +10 -0
  18. package/dist/calendar-context.js +9 -0
  19. package/dist/calendar.d.ts +80 -0
  20. package/dist/calendar.js +257 -0
  21. package/dist/carousel.d.ts +52 -0
  22. package/dist/carousel.js +151 -0
  23. package/dist/checkbox.d.ts +24 -0
  24. package/dist/checkbox.js +98 -0
  25. package/dist/children.d.ts +38 -0
  26. package/dist/children.js +63 -0
  27. package/dist/collapsible.d.ts +302 -0
  28. package/dist/collapsible.js +19 -0
  29. package/dist/color-picker.d.ts +72 -0
  30. package/dist/color-picker.js +133 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +22 -0
  33. package/dist/combobox.d.ts +152 -0
  34. package/dist/combobox.js +338 -0
  35. package/dist/command.d.ts +88 -0
  36. package/dist/command.js +233 -0
  37. package/dist/controller-target.d.ts +3 -0
  38. package/dist/controller-target.js +59 -0
  39. package/dist/date-input.d.ts +19 -0
  40. package/dist/date-input.js +58 -0
  41. package/dist/date-picker.d.ts +47 -0
  42. package/dist/date-picker.js +310 -0
  43. package/dist/date.d.ts +2 -0
  44. package/dist/date.js +60 -0
  45. package/dist/dialog-parts.d.ts +23 -0
  46. package/dist/dialog-parts.js +142 -0
  47. package/dist/dialog.d.ts +57 -0
  48. package/dist/dialog.js +32 -0
  49. package/dist/drawer.d.ts +70 -0
  50. package/dist/drawer.js +158 -0
  51. package/dist/editor-context.d.ts +4 -0
  52. package/dist/editor-context.js +9 -0
  53. package/dist/field-context.d.ts +47 -0
  54. package/dist/field-context.js +87 -0
  55. package/dist/field.d.ts +49 -0
  56. package/dist/field.js +169 -0
  57. package/dist/file-input.d.ts +46 -0
  58. package/dist/file-input.js +170 -0
  59. package/dist/form-inputs.d.ts +5 -0
  60. package/dist/form-inputs.js +22 -0
  61. package/dist/gesture.d.ts +1 -0
  62. package/dist/gesture.js +16 -0
  63. package/dist/history.d.ts +2 -0
  64. package/dist/history.js +12 -0
  65. package/dist/hover-card.d.ts +33 -0
  66. package/dist/hover-card.js +84 -0
  67. package/dist/image-cropper.d.ts +333 -0
  68. package/dist/image-cropper.js +37 -0
  69. package/dist/image.d.ts +2 -0
  70. package/dist/image.js +6 -0
  71. package/dist/input.d.ts +22 -0
  72. package/dist/input.js +51 -0
  73. package/dist/label.d.ts +294 -0
  74. package/dist/label.js +9 -0
  75. package/dist/list-items.d.ts +15 -0
  76. package/dist/list-items.js +39 -0
  77. package/dist/list-text.d.ts +4 -0
  78. package/dist/list-text.js +15 -0
  79. package/dist/listbox.d.ts +56 -0
  80. package/dist/listbox.js +122 -0
  81. package/dist/menu.d.ts +116 -0
  82. package/dist/menu.js +426 -0
  83. package/dist/menubar-context.d.ts +4 -0
  84. package/dist/menubar-context.js +7 -0
  85. package/dist/menubar.d.ts +11 -0
  86. package/dist/menubar.js +32 -0
  87. package/dist/meter.d.ts +312 -0
  88. package/dist/meter.js +30 -0
  89. package/dist/navigation-menu.d.ts +61 -0
  90. package/dist/navigation-menu.js +169 -0
  91. package/dist/number-input.d.ts +44 -0
  92. package/dist/number-input.js +185 -0
  93. package/dist/number.d.ts +2 -0
  94. package/dist/number.js +40 -0
  95. package/dist/observe.d.ts +2 -0
  96. package/dist/observe.js +8 -0
  97. package/dist/otp-input.d.ts +29 -0
  98. package/dist/otp-input.js +94 -0
  99. package/dist/overlays.d.ts +26 -0
  100. package/dist/overlays.js +82 -0
  101. package/dist/pagination.d.ts +336 -0
  102. package/dist/pagination.js +71 -0
  103. package/dist/password-input.d.ts +23 -0
  104. package/dist/password-input.js +65 -0
  105. package/dist/popover.d.ts +54 -0
  106. package/dist/popover.js +151 -0
  107. package/dist/popup.d.ts +41 -0
  108. package/dist/popup.js +180 -0
  109. package/dist/preferences.d.ts +35 -0
  110. package/dist/preferences.js +93 -0
  111. package/dist/primitive.d.ts +2 -0
  112. package/dist/primitive.js +14 -0
  113. package/dist/progress.d.ts +312 -0
  114. package/dist/progress.js +30 -0
  115. package/dist/radio.d.ts +22 -0
  116. package/dist/radio.js +86 -0
  117. package/dist/rating.d.ts +20 -0
  118. package/dist/rating.js +94 -0
  119. package/dist/render-element.d.ts +35 -0
  120. package/dist/render-element.js +103 -0
  121. package/dist/resizable.d.ts +302 -0
  122. package/dist/resizable.js +23 -0
  123. package/dist/scroll-area.d.ts +324 -0
  124. package/dist/scroll-area.js +49 -0
  125. package/dist/segmented-control.d.ts +24 -0
  126. package/dist/segmented-control.js +78 -0
  127. package/dist/segmented-input.d.ts +15 -0
  128. package/dist/segmented-input.js +48 -0
  129. package/dist/select.d.ts +125 -0
  130. package/dist/select.js +330 -0
  131. package/dist/separator.d.ts +290 -0
  132. package/dist/separator.js +9 -0
  133. package/dist/shortcuts.d.ts +32 -0
  134. package/dist/shortcuts.js +61 -0
  135. package/dist/slider.d.ts +38 -0
  136. package/dist/slider.js +163 -0
  137. package/dist/switch.d.ts +15 -0
  138. package/dist/switch.js +39 -0
  139. package/dist/tabs.d.ts +331 -0
  140. package/dist/tabs.js +28 -0
  141. package/dist/text-control.d.ts +22 -0
  142. package/dist/text-control.js +24 -0
  143. package/dist/text-match.d.ts +2 -0
  144. package/dist/text-match.js +8 -0
  145. package/dist/textarea.d.ts +10 -0
  146. package/dist/textarea.js +48 -0
  147. package/dist/time-input.d.ts +19 -0
  148. package/dist/time-input.js +63 -0
  149. package/dist/timeline.d.ts +327 -0
  150. package/dist/timeline.js +31 -0
  151. package/dist/toast-parts.d.ts +63 -0
  152. package/dist/toast-parts.js +144 -0
  153. package/dist/toast.d.ts +2 -0
  154. package/dist/toast.js +22 -0
  155. package/dist/toggle.d.ts +23 -0
  156. package/dist/toggle.js +76 -0
  157. package/dist/token-input.d.ts +35 -0
  158. package/dist/token-input.js +100 -0
  159. package/dist/toolbar-context.d.ts +6 -0
  160. package/dist/toolbar-context.js +16 -0
  161. package/dist/toolbar.d.ts +38 -0
  162. package/dist/toolbar.js +63 -0
  163. package/dist/tooltip.d.ts +39 -0
  164. package/dist/tooltip.js +108 -0
  165. package/dist/tree.d.ts +51 -0
  166. package/dist/tree.js +150 -0
  167. package/dist/trigger-menu.d.ts +83 -0
  168. package/dist/trigger-menu.js +167 -0
  169. package/dist/use-primitive.d.ts +178 -0
  170. package/dist/use-primitive.js +674 -0
  171. package/dist/waterfall.d.ts +80 -0
  172. package/dist/waterfall.js +108 -0
  173. package/docs/README.md +89 -0
  174. package/docs/agents.md +1523 -0
  175. package/docs/components/accordion.md +1391 -0
  176. package/docs/components/alert-dialog.md +850 -0
  177. package/docs/components/autocomplete.md +1963 -0
  178. package/docs/components/avatar.md +252 -0
  179. package/docs/components/button.md +444 -0
  180. package/docs/components/calendar.md +1687 -0
  181. package/docs/components/carousel.md +1244 -0
  182. package/docs/components/checkbox.md +1069 -0
  183. package/docs/components/collapsible.md +567 -0
  184. package/docs/components/color-picker.md +736 -0
  185. package/docs/components/combobox.md +3647 -0
  186. package/docs/components/command.md +1573 -0
  187. package/docs/components/date-input.md +608 -0
  188. package/docs/components/date-picker.md +1266 -0
  189. package/docs/components/dialog.md +1469 -0
  190. package/docs/components/drawer.md +1197 -0
  191. package/docs/components/field.md +549 -0
  192. package/docs/components/file-input.md +609 -0
  193. package/docs/components/hover-card.md +514 -0
  194. package/docs/components/image-cropper.md +579 -0
  195. package/docs/components/input.md +301 -0
  196. package/docs/components/label.md +217 -0
  197. package/docs/components/listbox.md +1130 -0
  198. package/docs/components/menu.md +1286 -0
  199. package/docs/components/menubar.md +455 -0
  200. package/docs/components/meter.md +304 -0
  201. package/docs/components/navigation-menu.md +1581 -0
  202. package/docs/components/number-input.md +1086 -0
  203. package/docs/components/otp-input.md +565 -0
  204. package/docs/components/pagination.md +648 -0
  205. package/docs/components/password-input.md +737 -0
  206. package/docs/components/popover.md +1552 -0
  207. package/docs/components/preferences.md +220 -0
  208. package/docs/components/progress.md +443 -0
  209. package/docs/components/radio.md +846 -0
  210. package/docs/components/rating.md +458 -0
  211. package/docs/components/resizable.md +982 -0
  212. package/docs/components/scroll-area.md +980 -0
  213. package/docs/components/segmented-control.md +465 -0
  214. package/docs/components/select.md +2133 -0
  215. package/docs/components/separator.md +243 -0
  216. package/docs/components/slider.md +1169 -0
  217. package/docs/components/switch.md +613 -0
  218. package/docs/components/tabs.md +1014 -0
  219. package/docs/components/textarea.md +318 -0
  220. package/docs/components/time-input.md +231 -0
  221. package/docs/components/timeline.md +677 -0
  222. package/docs/components/toast.md +1395 -0
  223. package/docs/components/toggle.md +541 -0
  224. package/docs/components/token-input.md +1007 -0
  225. package/docs/components/toolbar.md +787 -0
  226. package/docs/components/tooltip.md +884 -0
  227. package/docs/components/tree.md +1346 -0
  228. package/docs/components/trigger-menu.md +1257 -0
  229. package/docs/components/waterfall.md +754 -0
  230. package/docs/controllers.md +89 -0
  231. package/docs/core.md +8027 -0
  232. package/docs/custom-parts.md +120 -0
  233. package/docs/first-component.md +83 -0
  234. package/docs/forms.md +148 -0
  235. package/docs/hooks/async-options.md +366 -0
  236. package/docs/hooks/shortcuts.md +221 -0
  237. package/docs/installation.md +45 -0
  238. package/docs/introduction.md +32 -0
  239. package/docs/lists-and-menus.md +170 -0
  240. package/docs/llms.txt +1844 -0
  241. package/docs/parts-and-composition.md +93 -0
  242. package/docs/popups.md +117 -0
  243. package/docs/rendering.md +121 -0
  244. package/docs/server-rendering.md +253 -0
  245. package/docs/state-and-events.md +105 -0
  246. package/docs/styling-and-animation.md +176 -0
  247. package/package.json +333 -3
@@ -0,0 +1,648 @@
1
+ # Pagination
2
+
3
+ Navigate pages with buttons, links, or your router.
4
+
5
+ ```tsx title="basic.tsx"
6
+ "use client"
7
+
8
+ import {
9
+ Pagination,
10
+ PaginationEllipsis,
11
+ PaginationItem,
12
+ PaginationLink,
13
+ PaginationList,
14
+ PaginationNext,
15
+ PaginationPrevious,
16
+ } from "@ui-sdk/react/pagination"
17
+ import { ChevronLeftIcon, ChevronRightIcon, EllipsisIcon } from "lucide-react"
18
+ import { useLog } from "./log"
19
+
20
+ function Example() {
21
+ const log = useLog()
22
+
23
+ return (
24
+ <Pagination
25
+ aria-label="Pagination"
26
+ pageCount={10}
27
+ onPageChange={(page, details) => log(`Page ${page} (${details.reason})`)}
28
+ >
29
+ <PaginationList>
30
+ {({ items }) => (
31
+ <>
32
+ <PaginationItem>
33
+ <PaginationPrevious data-variant="ghost">
34
+ <ChevronLeftIcon />
35
+ <span data-slot="visually-hidden">Previous</span>
36
+ </PaginationPrevious>
37
+ </PaginationItem>
38
+ {items.map((item) => (
39
+ <PaginationItem key={item}>
40
+ {typeof item === "number" ? (
41
+ <PaginationLink data-variant="ghost" page={item} />
42
+ ) : (
43
+ <PaginationEllipsis>
44
+ <EllipsisIcon />
45
+ </PaginationEllipsis>
46
+ )}
47
+ </PaginationItem>
48
+ ))}
49
+ <PaginationItem>
50
+ <PaginationNext data-variant="ghost">
51
+ <span data-slot="visually-hidden">Next</span>
52
+ <ChevronRightIcon />
53
+ </PaginationNext>
54
+ </PaginationItem>
55
+ </>
56
+ )}
57
+ </PaginationList>
58
+ </Pagination>
59
+ )
60
+ }
61
+
62
+ export { Example }
63
+ ```
64
+
65
+ Choose a page, or use Previous and Next. The console logs each page and its reason, and the step at either end stays focusable as a button.
66
+
67
+ ## Installation
68
+
69
+ ```bash
70
+ npm install @ui-sdk/react @ui-sdk/core
71
+ ```
72
+
73
+ ## Composition
74
+
75
+ Use the following composition to build a `Pagination`:
76
+
77
+ ```text
78
+ Pagination
79
+ └── PaginationList
80
+ ├── PaginationItem
81
+ │ └── PaginationPrevious
82
+ ├── PaginationItem
83
+ │ └── PaginationLink
84
+ ├── PaginationItem
85
+ │ └── PaginationEllipsis
86
+ ├── PaginationItem
87
+ │ └── PaginationLink
88
+ └── PaginationItem
89
+ └── PaginationNext
90
+ ```
91
+
92
+ Name the navigation with `aria-label`, then put the page links and steps in a list.
93
+
94
+ `items` contains page numbers and the strings `"ellipsis-start"` and `"ellipsis-end"`. Render a link for each number and an ellipsis for each gap. Key entries by the item itself so a page link keeps its element as the range moves.
95
+
96
+ `PaginationLink` shows its page number unless you supply children. The current link gets `aria-current="page"` and `data-current`. `PaginationEllipsis` shows “…” and is hidden from screen readers.
97
+
98
+ Give Previous, Next, First, and Last text or an `aria-label`. At an end, a step gets `aria-disabled="true"` and `data-disabled` and stops changing the page. As a button, it stays in the tab order.
99
+
100
+ ## Usage
101
+
102
+ Import the parts and put them together:
103
+
104
+ ```tsx
105
+ "use client"
106
+
107
+ import {
108
+ Pagination,
109
+ PaginationEllipsis,
110
+ PaginationItem,
111
+ PaginationLink,
112
+ PaginationList,
113
+ PaginationNext,
114
+ PaginationPrevious,
115
+ } from "@ui-sdk/react/pagination"
116
+
117
+ function PageNavigation() {
118
+ return (
119
+ <Pagination aria-label="Pagination" pageCount={10}>
120
+ <PaginationList>
121
+ {({ items }) => (
122
+ <>
123
+ <PaginationItem>
124
+ <PaginationPrevious>Previous</PaginationPrevious>
125
+ </PaginationItem>
126
+ {items.map((item) => (
127
+ <PaginationItem key={item}>
128
+ {typeof item === "number" ? (
129
+ <PaginationLink page={item} />
130
+ ) : (
131
+ <PaginationEllipsis />
132
+ )}
133
+ </PaginationItem>
134
+ ))}
135
+ <PaginationItem>
136
+ <PaginationNext>Next</PaginationNext>
137
+ </PaginationItem>
138
+ </>
139
+ )}
140
+ </PaginationList>
141
+ </Pagination>
142
+ )
143
+ }
144
+
145
+ export { PageNavigation }
146
+ ```
147
+
148
+ ## Total and Page Size
149
+
150
+ Instead of `pageCount`, pass `total`, how many items there are, and `pageSize`, how many fit on a page (10 by default). Pagination calculates the page count, with a minimum of one. This example resets to page 1 when the page size changes.
151
+
152
+ A page past the end, like after the count shrinks, reads as the last page.
153
+
154
+ ```tsx title="total.tsx"
155
+ "use client"
156
+
157
+ import {
158
+ Pagination,
159
+ PaginationEllipsis,
160
+ PaginationItem,
161
+ PaginationLink,
162
+ PaginationList,
163
+ PaginationNext,
164
+ PaginationPrevious,
165
+ } from "@ui-sdk/react/pagination"
166
+ import { ChevronLeftIcon, ChevronRightIcon, EllipsisIcon } from "lucide-react"
167
+ import * as React from "react"
168
+ import { useLog } from "./log"
169
+
170
+ function Example() {
171
+ const log = useLog()
172
+ const [page, setPage] = React.useState(2)
173
+ const [pageSize, setPageSize] = React.useState(20)
174
+ const total = 95
175
+
176
+ return (
177
+ <div data-slot="stack">
178
+ <div data-slot="row">
179
+ <p>
180
+ Showing {(page - 1) * pageSize + 1}–{Math.min(page * pageSize, total)}{" "}
181
+ of {total}
182
+ </p>
183
+ <label data-slot="label">
184
+ Rows per page
185
+ <select
186
+ value={pageSize}
187
+ onChange={(event) => {
188
+ setPageSize(Number(event.target.value))
189
+ setPage(1)
190
+ log(`${event.target.value} rows per page`)
191
+ }}
192
+ >
193
+ <option value={10}>10</option>
194
+ <option value={20}>20</option>
195
+ <option value={50}>50</option>
196
+ </select>
197
+ </label>
198
+ </div>
199
+ <Pagination
200
+ aria-label="Pagination"
201
+ total={total}
202
+ pageSize={pageSize}
203
+ page={page}
204
+ onPageChange={(next) => {
205
+ setPage(next)
206
+ log(`Page ${next}`)
207
+ }}
208
+ >
209
+ <PaginationList>
210
+ {({ items }) => (
211
+ <>
212
+ <PaginationItem>
213
+ <PaginationPrevious data-variant="ghost">
214
+ <ChevronLeftIcon />
215
+ <span data-slot="visually-hidden">Previous</span>
216
+ </PaginationPrevious>
217
+ </PaginationItem>
218
+ {items.map((item) => (
219
+ <PaginationItem key={item}>
220
+ {typeof item === "number" ? (
221
+ <PaginationLink data-variant="ghost" page={item} />
222
+ ) : (
223
+ <PaginationEllipsis>
224
+ <EllipsisIcon />
225
+ </PaginationEllipsis>
226
+ )}
227
+ </PaginationItem>
228
+ ))}
229
+ <PaginationItem>
230
+ <PaginationNext data-variant="ghost">
231
+ <span data-slot="visually-hidden">Next</span>
232
+ <ChevronRightIcon />
233
+ </PaginationNext>
234
+ </PaginationItem>
235
+ </>
236
+ )}
237
+ </PaginationList>
238
+ </Pagination>
239
+ </div>
240
+ )
241
+ }
242
+
243
+ export { Example }
244
+ ```
245
+
246
+ Choose a page, then change Rows per page. The console logs each change, and a new size starts again at page 1.
247
+
248
+ ## Simple
249
+
250
+ With only a few pages, the range has no gaps, so you can write the links out and leave the steps off.
251
+
252
+ ```tsx
253
+ <Pagination aria-label="Pagination" pageCount={5}>
254
+ <PaginationList>
255
+ {[1, 2, 3, 4, 5].map((page) => (
256
+ <PaginationItem key={page}>
257
+ <PaginationLink page={page} />
258
+ </PaginationItem>
259
+ ))}
260
+ </PaginationList>
261
+ </Pagination>
262
+ ```
263
+
264
+ ## Links
265
+
266
+ Pass `getHref` to map each page to a URL. Page links and steps then render as anchors.
267
+
268
+ ```tsx
269
+ <Pagination
270
+ aria-label="Pagination"
271
+ pageCount={10}
272
+ getHref={(page) => `/posts?page=${page}`}
273
+ >
274
+ ...
275
+ </Pagination>
276
+ ```
277
+
278
+ Server-rendered anchors work before JavaScript loads. A normal click changes the page and follows the URL. Modifier clicks and middle clicks leave pagination state alone so the browser can open the link elsewhere.
279
+
280
+ A step at its end loses its `href` and leaves the tab order, but keeps focus if it already had it. During navigation, its original `href` stays in place so Next cannot accidentally follow the next page's URL.
281
+
282
+ ## Router Links
283
+
284
+ Render your router's link to page on the client. Pass it to `render`, like `render={<Link />}`; it receives the part's props, with the `href` from [`getHref`](#links). The pagination's click handler runs first: when a change is canceled or a step is at its end, it calls `preventDefault()`, and the router leaves the link alone.
285
+
286
+ Read the page from the URL, like your router's search params, so the route [controls](#controlled) the pagination.
287
+
288
+ ```tsx
289
+ const page = Number(searchParams.get("page") ?? 1)
290
+
291
+ <Pagination aria-label="Pagination" pageCount={10} page={page} getHref={(page) => `?page=${page}`}>
292
+ <PaginationList>
293
+ {({ items }) =>
294
+ items.map((item) => (
295
+ <PaginationItem key={item}>
296
+ {typeof item === "number" ? (
297
+ <PaginationLink page={item} render={<Link />} />
298
+ ) : (
299
+ <PaginationEllipsis />
300
+ )}
301
+ </PaginationItem>
302
+ ))
303
+ }
304
+ </PaginationList>
305
+ </Pagination>
306
+ ```
307
+
308
+ ## Controlled
309
+
310
+ Pass `page` and `onPageChange` to control the pagination.
311
+
312
+ ```tsx
313
+ const [page, setPage] = React.useState(1)
314
+
315
+ <Pagination aria-label="Pagination" pageCount={10} page={page} onPageChange={setPage}>
316
+ ...
317
+ </Pagination>
318
+ ```
319
+
320
+ Every change carries a [reason](#reasons): `item-press` for a page, `previous-press`, `next-press`, `first-press` or `last-press` for a step, and `imperative` from a [controller](#controller). Call `details.cancel()` to keep the page, like while a form has unsaved changes. A canceled change also stops a link from navigating.
321
+
322
+ ## Default Page
323
+
324
+ `defaultPage` is the page it starts on, when uncontrolled. It's 1 by default.
325
+
326
+ ```tsx
327
+ <Pagination aria-label="Pagination" pageCount={10} defaultPage={5}>
328
+ ...
329
+ </Pagination>
330
+ ```
331
+
332
+ ## Siblings
333
+
334
+ `siblings` is how many pages show on each side of the current one, 1 by default. Near an end, the window slides over instead of shrinking, keeping the range length stable. A gap of one page shows that page instead of an ellipsis.
335
+
336
+ ```tsx
337
+ <Pagination
338
+ aria-label="Pagination"
339
+ pageCount={20}
340
+ defaultPage={10}
341
+ siblings={2}
342
+ >
343
+ ...
344
+ </Pagination>
345
+ ```
346
+
347
+ ## Boundaries
348
+
349
+ `boundaries` is how many pages always show at each end, 1 by default.
350
+
351
+ ```tsx
352
+ <Pagination
353
+ aria-label="Pagination"
354
+ pageCount={20}
355
+ defaultPage={10}
356
+ boundaries={2}
357
+ >
358
+ ...
359
+ </Pagination>
360
+ ```
361
+
362
+ ## Paging from Anywhere
363
+
364
+ A [controller](#controller), from `createPaginationController()`, pages the pagination from anywhere, like buttons elsewhere on the page or a keyboard shortcut, without controlling it. Pass it as `controller`.
365
+
366
+ ```tsx
367
+ const [pagination] = React.useState(() => createPaginationController())
368
+
369
+ <button onClick={() => pagination.next()}>Next Page</button>
370
+ <Pagination aria-label="Pagination" pageCount={10} controller={pagination}>
371
+ ...
372
+ </Pagination>
373
+ ```
374
+
375
+ ## Your Own Markup
376
+
377
+ `paginationRange({ page, pageCount, siblings, boundaries })` is the range the parts use, as a pure function. It runs anywhere, like on the server, in an email or for a UI that isn't a list of pages. In a Server Component, import it from `@ui-sdk/core/pagination`. Here it keeps a strip of slide dots the same length however many slides there are.
378
+
379
+ ```tsx
380
+ import { paginationRange } from "@ui-sdk/core/pagination"
381
+
382
+ const items = paginationRange({ page: slide, pageCount: 20, siblings: 2, boundaries: 1 })
383
+
384
+ <div role="group" aria-label="Slides">
385
+ {items.map((item) =>
386
+ typeof item === "number" ? (
387
+ <button
388
+ key={item}
389
+ aria-label={`Slide ${item}`}
390
+ aria-current={item === slide ? "true" : undefined}
391
+ onClick={() => setSlide(item)}
392
+ />
393
+ ) : (
394
+ <span key={item} aria-hidden />
395
+ ),
396
+ )}
397
+ </div>
398
+ ```
399
+
400
+ ## Custom Rendering
401
+
402
+ Every part takes `render`. Pass an element and its props merge with the part's, or a function that receives the props and the part's state. `className`, `style` and `children` can be functions of the same state: whether a link is `current`, and for a step, the `page` it goes to and whether it's `disabled`.
403
+
404
+ ```tsx title="render.tsx"
405
+ "use client"
406
+
407
+ import {
408
+ Pagination,
409
+ PaginationEllipsis,
410
+ PaginationItem,
411
+ PaginationLink,
412
+ PaginationList,
413
+ PaginationNext,
414
+ PaginationPrevious,
415
+ } from "@ui-sdk/react/pagination"
416
+ import { ArrowLeftIcon, ArrowRightIcon } from "lucide-react"
417
+
418
+ function Example() {
419
+ return (
420
+ <Pagination aria-label="Pagination" pageCount={10}>
421
+ <PaginationList>
422
+ {({ items }) => (
423
+ <>
424
+ <PaginationItem>
425
+ <PaginationPrevious
426
+ aria-label="Previous page"
427
+ render={(props, state) => (
428
+ <button {...props} title={ state.disabled ? undefined : `Go to page ${state.page}` } />
429
+ )}
430
+ >
431
+ {(state) => (
432
+ <>
433
+ <ArrowLeftIcon aria-hidden="true" />
434
+ {!state.disabled && (
435
+ <span aria-hidden="true">{state.page}</span>
436
+ )}
437
+ </>
438
+ )}
439
+ </PaginationPrevious>
440
+ </PaginationItem>
441
+ {items.map((item) => (
442
+ <PaginationItem key={item}>
443
+ {typeof item === "number" ? (
444
+ <PaginationLink page={item}>
445
+ {(state) =>
446
+ state.current ? `Page ${state.page}` : state.page
447
+ }
448
+ </PaginationLink>
449
+ ) : (
450
+ <PaginationEllipsis />
451
+ )}
452
+ </PaginationItem>
453
+ ))}
454
+ <PaginationItem>
455
+ <PaginationNext
456
+ aria-label="Next page"
457
+ render={(props, state) => (
458
+ <button {...props} title={ state.disabled ? undefined : `Go to page ${state.page}` } />
459
+ )}
460
+ >
461
+ {(state) => (
462
+ <>
463
+ {!state.disabled && (
464
+ <span aria-hidden="true">{state.page}</span>
465
+ )}
466
+ <ArrowRightIcon aria-hidden="true" />
467
+ </>
468
+ )}
469
+ </PaginationNext>
470
+ </PaginationItem>
471
+ </>
472
+ )}
473
+ </PaginationList>
474
+ </Pagination>
475
+ )
476
+ }
477
+
478
+ export { Example }
479
+ ```
480
+
481
+ Choose a page. The current page widens to say Page 3, and each arrow shows the page it goes to.
482
+
483
+ ## Styling
484
+
485
+ Parts are unstyled. Style them through the attributes they render, which are the same in every framework: `aria-current="page"` or `data-current` on the current page's link, and `aria-disabled` or `data-disabled` on a step at its end.
486
+
487
+ Each part has a `data-slot`, such as `pagination-link`, and its state attributes are listed under [Data Attributes](#data-attributes). The root, list, items and ellipsis have none.
488
+
489
+ ## Data Attributes
490
+
491
+ ### PaginationLink
492
+ `[data-slot="pagination-link"]`
493
+
494
+ - `data-current`: Present on the current page's link, beside `aria-current="page"`.
495
+
496
+ ### PaginationPrevious
497
+ `[data-slot="pagination-previous"]`
498
+
499
+ - `data-disabled`: Present on a step at the end it goes to, beside `aria-disabled`. It stays focusable and does nothing.
500
+
501
+ ### PaginationNext
502
+ `[data-slot="pagination-next"]`
503
+
504
+ - `data-disabled`: Present on a step at the end it goes to, beside `aria-disabled`. It stays focusable and does nothing.
505
+
506
+ ### PaginationFirst
507
+ `[data-slot="pagination-first"]`
508
+
509
+ - `data-disabled`: Present on a step at the end it goes to, beside `aria-disabled`. It stays focusable and does nothing.
510
+
511
+ ### PaginationLast
512
+ `[data-slot="pagination-last"]`
513
+
514
+ - `data-disabled`: Present on a step at the end it goes to, beside `aria-disabled`. It stays focusable and does nothing.
515
+
516
+ ## API Reference
517
+
518
+ Props and callbacks are the same as below, as React props.
519
+
520
+ ### Pagination
521
+
522
+ - `page?` (`number`): The current page, from 1. Pass it to control the pagination.
523
+ - `defaultPage?` (`number`): The page it starts on, when uncontrolled.
524
+ - `onPageChange?` (`((page: number, details: ChangeDetails<PaginationPageChangeReason>) => void)`): Runs when the page wants to change: a page link (`"item-press"`), the Previous, Next, First or Last part, or a controller (`"imperative"`). `details.cancel()` keeps the page, and stops a link from navigating.
525
+ - `pageCount?` (`number`): How many pages there are. Or pass `total` and `pageSize`.
526
+ - `total?` (`number`): How many items there are, for `pageCount` from `pageSize`.
527
+ - `pageSize?` (`number`): How many items fit on a page, with `total`.
528
+ - `siblings?` (`number`): How many pages show on each side of the current one.
529
+ - `boundaries?` (`number`): How many pages always show at each end.
530
+ - `getHref?` (`((page: number) => string)`): The URL of a page. With it, parts are links: they navigate, open in a new tab with a modifier key, and work before JavaScript loads. Without it, they're buttons.
531
+ - `controller?` (`object`): Pages it from anywhere. Create one with `createPaginationController()`.
532
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
533
+
534
+ ### PaginationLink
535
+
536
+ - `page` (`number`): The page the link goes to, from 1.
537
+
538
+ `PaginationList`, `PaginationItem`, `PaginationPrevious`, `PaginationNext`, `PaginationFirst`, `PaginationLast` and `PaginationEllipsis` take no props of their own.
539
+
540
+ ### State
541
+
542
+ What render functions, state-based class names and slots receive, per part.
543
+
544
+ `Pagination` and `PaginationList`:
545
+
546
+ - `page` (`number`): The current page, from 1.
547
+ - `pageCount` (`number`): How many pages there are.
548
+ - `items` (`PaginationRangeItem[]`): The pages to show, with an ellipsis for each gap. Render a PaginationLink or a PaginationEllipsis for each.
549
+
550
+ `PaginationLink`:
551
+
552
+ - `page` (`number`): The page it goes to, from its `page` prop.
553
+ - `current` (`boolean`): Whether it's the current page.
554
+
555
+ `PaginationPrevious`, `PaginationNext`, `PaginationFirst` and `PaginationLast`:
556
+
557
+ - `page` (`number`): The page it goes to.
558
+ - `disabled` (`boolean`): Whether it's at the end it goes to, so it does nothing.
559
+
560
+ ### Reasons
561
+
562
+ `details.reason` says why the page changed.
563
+
564
+ - `item-press` (`MouseEvent | KeyboardEvent`): A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
565
+ - `previous-press` (`MouseEvent | KeyboardEvent`): A pagination's or a carousel's Previous part was pressed.
566
+ - `next-press` (`MouseEvent | KeyboardEvent`): A pagination's or a carousel's Next part was pressed.
567
+ - `first-press` (`MouseEvent | KeyboardEvent`): A pagination's First part was pressed.
568
+ - `last-press` (`MouseEvent | KeyboardEvent`): A pagination's Last part was pressed.
569
+ - `imperative` (`none`): A controller or `api` call, or a property set on a web component.
570
+
571
+ ### Controller
572
+
573
+ Create one with `createPaginationController()` and pass it as `controller`.
574
+
575
+ Every write method takes an optional `{ reason, event }`, passed to `onPageChange`, and returns `false` when the change is canceled or there's nowhere to go.
576
+
577
+ - `getPage()` (`() => number`): The current page, from 1.
578
+ - `getPageCount()` (`() => number`): How many pages there are.
579
+ - `setPage(page, options?)` (`(page: number, options?: PaginationChangeOptions | undefined) => boolean`): Goes to a page, clamped to the range. Returns false when canceled or already there.
580
+ - `next(options?)` (`(options?: PaginationChangeOptions | undefined) => boolean`): Goes to the next page. Returns false on the last page.
581
+ - `previous(options?)` (`(options?: PaginationChangeOptions | undefined) => boolean`): Goes to the previous page. Returns false on the first page.
582
+ - `first(options?)` (`(options?: PaginationChangeOptions | undefined) => boolean`): Goes to the first page.
583
+ - `last(options?)` (`(options?: PaginationChangeOptions | undefined) => boolean`): Goes to the last page.
584
+
585
+ ### Events
586
+
587
+ Callbacks get the new page first, then the details.
588
+
589
+ | Prop | On | Receives |
590
+ | -------------- | ------------ | ----------------------------------------------------------- |
591
+ | `onPageChange` | `Pagination` | `(page, details)`: the new page, and the [reason](#reasons) |
592
+
593
+ ## Accessibility
594
+
595
+ There's no WAI-ARIA pattern for pagination. It follows the common practice: a `navigation` landmark named with `aria-label`, a list of links or buttons, and `aria-current="page"` on the current one. The list keeps the `list` role even when styled without bullets, which Safari would otherwise drop.
596
+
597
+ ### Focus
598
+
599
+ Steps rendered as buttons stay focusable at the ends. A clicked page link keeps focus as the range moves; the primitive also tries to restore focus to that page or step if rendering replaces its element. Key range entries by their value rather than their index.
600
+
601
+ ### Tested Behavior
602
+
603
+ Every line below is an automated test.
604
+
605
+ - The pagination is a named navigation landmark with a list of pages.
606
+ - The first page is current to start with, or the default page.
607
+ - Pressing a page goes there.
608
+ - Enter on a focused page goes there.
609
+ - Space on a focused page goes there.
610
+ - Next and Previous step one page.
611
+ - First and Last go to the ends.
612
+ - First and Previous say they're disabled on the first page, and do nothing.
613
+ - Next and Last say they're disabled on the last page, and do nothing.
614
+ - A single page has nothing to step to.
615
+ - Siblings and boundaries widen the range.
616
+ - Ellipses are hidden from screen readers.
617
+ - With getHref, pages and steps are links to their pages.
618
+ - A link at an end has no href and says it's disabled.
619
+ - Pressing a link goes to its page and follows it.
620
+ - A change can be canceled.
621
+ - A canceled change stops a link from navigating.
622
+ - The controller pages it from outside.
623
+ - A controlled pagination follows its owner. React and Vue only.
624
+
625
+ Runs in React, Vue and web components.
626
+
627
+ Beyond the baseline:
628
+
629
+ - Pressing Next onto the last page keeps focus on Next.
630
+ - Pressing Previous onto the first page keeps focus on Previous.
631
+ - Paging through every page with the keyboard never loses focus.
632
+ - Pressing a page keeps focus on it while the range moves around it.
633
+ - Focus comes back to the same part when the list renders again from scratch. React and Vue only.
634
+ - The list has the same number of entries on every page, so nothing shifts under the pointer.
635
+ - A gap of one page shows that page instead of an ellipsis.
636
+ - A link pressed with a modifier opens elsewhere and leaves the page as it is.
637
+ - The list keeps its list role when styled without bullets.
638
+ - Steps at the ends stay in the tab order and say they're disabled.
639
+ - A Next link goes to the next page, not past it, even after the page renders again.
640
+ - A Next link onto the last page still goes there, though it ends there.
641
+
642
+ Runs in React, Vue and web components.
643
+
644
+ Screen readers hear the same thing in each tested framework, recorded by a virtual screen reader:
645
+
646
+ - Announcements while paging with a keyboard.
647
+
648
+ Runs in React, Vue and web components.