File tree Expand file tree Collapse file tree 6 files changed +80
-7
lines changed
website/src/content/pages/components Expand file tree Collapse file tree 6 files changed +80
-7
lines changed Original file line number Diff line number Diff line change
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 ( ) } ) } > …</ span >
27
+ )
28
+ }
29
+ </ For >
30
+ < a { ...pagination ( ) . getNextTriggerProps ( ) } href = { getHref ( pagination ( ) . nextPage ) } >
31
+ Next
32
+ </ a >
33
+ </ Pagination . RootProvider >
34
+ )
35
+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ export { Context } from './examples/context'
11
11
export { Controlled } from './examples/controlled'
12
12
export { Customized } from './examples/customized'
13
13
export { DataSlicing } from './examples/data-slicing'
14
+ export { Link } from './examples/link'
14
15
export { PageRange } from './examples/page-range'
15
16
export { PageSizeControl } from './examples/page-size-control'
16
17
export { RootProvider } from './examples/root-provider'
Original file line number Diff line number Diff line change 4
4
const id = $props .id ()
5
5
const pagination = usePagination ({
6
6
id ,
7
- count: 5000 ,
7
+ type: ' link' ,
8
+ count: 100 ,
8
9
pageSize: 10 ,
9
10
siblingCount: 2 ,
10
11
})
11
12
12
13
const getHref = (page : number | null ) => (page != null ? ` /page=${page } ` : ' /' )
13
14
</script >
14
15
15
- <button onclick ={() => pagination ().goToNextPage ()}>Next Page</button >
16
-
17
16
<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 >
20
20
{#each pagination ().pages as page , index (index )}
21
21
{#if page .type === ' page' }
22
22
<a {...pagination ().getItemProps (page )} href ={getHref (page .value )}>
26
26
<span {...pagination ().getEllipsisProps ({ index })}>…</span >
27
27
{/if }
28
28
{/each }
29
-
30
- <a {...pagination ().getNextTriggerProps ()} href ={getHref (pagination ().nextPage )}>Next</a >
29
+ <a {...pagination ().getNextTriggerProps ()} href ={getHref (pagination ().nextPage )}>
30
+ Next
31
+ </a >
31
32
</Pagination .RootProvider >
Original file line number Diff line number Diff line change
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 })" >… ; </span >
22
+ </template >
23
+ <a v-bind =" pagination.getNextTriggerProps()" :href =" getHref(pagination.nextPage)" >Next</a >
24
+ </Pagination .RootProvider >
25
+ </template >
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Basic from './examples/basic.vue'
3
3
import Context from ' ./examples/context.vue'
4
4
import Customized from ' ./examples/customized.vue'
5
5
import DataSlicing from ' ./examples/data-slicing.vue'
6
+ import Link from ' ./examples/link.vue'
6
7
import PageRange from ' ./examples/page-range.vue'
7
8
import PageSizeControl from ' ./examples/page-size-control.vue'
8
9
import RootProvider from ' ./examples/root-provider.vue'
@@ -21,6 +22,9 @@ import RootProvider from './examples/root-provider.vue'
21
22
<Variant title =" DataSlicing" >
22
23
<DataSlicing />
23
24
</Variant >
25
+ <Variant title =" Link" >
26
+ <Link />
27
+ </Variant >
24
28
<Variant title =" PageRange" >
25
29
<PageRange />
26
30
</Variant >
Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ select element to change the page size.
63
63
64
64
<Example id = " page-size-control" />
65
65
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
+
66
73
### Root Provider
67
74
68
75
The ` RootProvider ` component provides a context for the pagination. It accepts the value of the ` usePagination ` hook.
You can’t perform that action at this time.
0 commit comments