Skip to content

Commit 5a5aef1

Browse files
committed
docs: pagination
1 parent 2c14a3e commit 5a5aef1

File tree

6 files changed

+80
-7
lines changed

6 files changed

+80
-7
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Pagination, usePagination } from '@ark-ui/solid/pagination'
2+
import { For } from 'solid-js'
3+
4+
export const Link = () => {
5+
const pagination = usePagination({
6+
type: 'link',
7+
count: 100,
8+
pageSize: 10,
9+
siblingCount: 2,
10+
})
11+
12+
const getHref = (page: number | null) => (page != null ? `/page=${page}` : '/')
13+
14+
return (
15+
<Pagination.RootProvider value={pagination}>
16+
<a {...pagination().getPrevTriggerProps()} href={getHref(pagination().previousPage)}>
17+
Previous
18+
</a>
19+
<For each={pagination().pages}>
20+
{(page, index) =>
21+
page.type === 'page' ? (
22+
<a {...pagination().getItemProps(page)} href={getHref(page.value)}>
23+
{page.value}
24+
</a>
25+
) : (
26+
<span {...pagination().getEllipsisProps({ index: index() })}>&#8230;</span>
27+
)
28+
}
29+
</For>
30+
<a {...pagination().getNextTriggerProps()} href={getHref(pagination().nextPage)}>
31+
Next
32+
</a>
33+
</Pagination.RootProvider>
34+
)
35+
}

packages/solid/src/components/pagination/pagination.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export { Context } from './examples/context'
1111
export { Controlled } from './examples/controlled'
1212
export { Customized } from './examples/customized'
1313
export { DataSlicing } from './examples/data-slicing'
14+
export { Link } from './examples/link'
1415
export { PageRange } from './examples/page-range'
1516
export { PageSizeControl } from './examples/page-size-control'
1617
export { RootProvider } from './examples/root-provider'

packages/svelte/src/lib/components/pagination/examples/link.svelte

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
const id = $props.id()
55
const pagination = usePagination({
66
id,
7-
count: 5000,
7+
type: 'link',
8+
count: 100,
89
pageSize: 10,
910
siblingCount: 2,
1011
})
1112
1213
const getHref = (page: number | null) => (page != null ? `/page=${page}` : '/')
1314
</script>
1415

15-
<button onclick={() => pagination().goToNextPage()}>Next Page</button>
16-
1716
<Pagination.RootProvider value={pagination}>
18-
<a {...pagination().getPrevTriggerProps()} href={getHref(pagination().previousPage)}>Previous</a>
19-
17+
<a {...pagination().getPrevTriggerProps()} href={getHref(pagination().previousPage)}>
18+
Previous
19+
</a>
2020
{#each pagination().pages as page, index (index)}
2121
{#if page.type === 'page'}
2222
<a {...pagination().getItemProps(page)} href={getHref(page.value)}>
@@ -26,6 +26,7 @@
2626
<span {...pagination().getEllipsisProps({ index })}>&#8230;</span>
2727
{/if}
2828
{/each}
29-
30-
<a {...pagination().getNextTriggerProps()} href={getHref(pagination().nextPage)}>Next</a>
29+
<a {...pagination().getNextTriggerProps()} href={getHref(pagination().nextPage)}>
30+
Next
31+
</a>
3132
</Pagination.RootProvider>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script setup lang="ts">
2+
import { Pagination, usePagination } from '@ark-ui/vue/pagination'
3+
4+
const pagination = usePagination({
5+
type: 'link',
6+
count: 100,
7+
pageSize: 10,
8+
siblingCount: 2,
9+
})
10+
11+
const getHref = (page: number | null) => (page != null ? `/page=${page}` : '/')
12+
</script>
13+
14+
<template>
15+
<Pagination.RootProvider :value="pagination">
16+
<a v-bind="pagination.getPrevTriggerProps()" :href="getHref(pagination.previousPage)">Previous</a>
17+
<template v-for="(page, index) in pagination.pages" :key="index">
18+
<a v-if="page.type === 'page'" v-bind="pagination.getItemProps(page)" :href="getHref(page.value)">
19+
{{ page.value }}
20+
</a>
21+
<span v-else v-bind="pagination.getEllipsisProps({ index })">&#8230;</span>
22+
</template>
23+
<a v-bind="pagination.getNextTriggerProps()" :href="getHref(pagination.nextPage)">Next</a>
24+
</Pagination.RootProvider>
25+
</template>

packages/vue/src/components/pagination/pagination.stories.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Basic from './examples/basic.vue'
33
import Context from './examples/context.vue'
44
import Customized from './examples/customized.vue'
55
import DataSlicing from './examples/data-slicing.vue'
6+
import Link from './examples/link.vue'
67
import PageRange from './examples/page-range.vue'
78
import PageSizeControl from './examples/page-size-control.vue'
89
import RootProvider from './examples/root-provider.vue'
@@ -21,6 +22,9 @@ import RootProvider from './examples/root-provider.vue'
2122
<Variant title="DataSlicing">
2223
<DataSlicing />
2324
</Variant>
25+
<Variant title="Link">
26+
<Link />
27+
</Variant>
2428
<Variant title="PageRange">
2529
<PageRange />
2630
</Variant>

website/src/content/pages/components/pagination.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ select element to change the page size.
6363

6464
<Example id="page-size-control" />
6565

66+
### Link Pagination
67+
68+
Create pagination with link navigation for better SEO and accessibility. This example shows how to use the pagination
69+
component with anchor links instead of buttons.
70+
71+
<Example id="link" />
72+
6673
### Root Provider
6774

6875
The `RootProvider` component provides a context for the pagination. It accepts the value of the `usePagination` hook.

0 commit comments

Comments
 (0)