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