11<script lang =" ts" >
2- import { Select , Label } from ' $lib' ;
2+ import { Select , Label , Pagination , PaginationItem } from ' $lib' ;
3+ import { ChevronLeftOutline , ChevronRightOutline , ArrowLeftOutline , ArrowRightOutline } from ' flowbite-svelte-icons' ;
4+ import { page } from ' $app/stores' ;
35 import HighlightCompo from ' ../../utils/HighlightCompo.svelte' ;
46 import CodeWrapper from ' ../../utils/CodeWrapper.svelte' ;
57 import H1 from ' ../../utils/H1.svelte' ;
1012 import: ' default' ,
1113 eager: true
1214 });
15+
16+ let activeUrl = $state ($page .url .searchParams .get (' page' ));
17+ let pages = $state ([
18+ { name: " 1" , href: ' /components/pagination?page=1' , active: false },
19+ { name: " 2" , href: ' /components/pagination?page=2' , active: false },
20+ { name: " 3" , href: ' /components/pagination?page=3' , active: false },
21+ { name: " 4" , href: ' /components/pagination?page=4' , active: false },
22+ { name: " 5" , href: ' /components/pagination?page=5' , active: false }
23+ ]);
24+ let helper = { start: 1 , end: 10 , total: 100 };
25+
26+ $effect (()=> {
27+ pages .forEach ((page ) => {
28+ let splitUrl = page .href .split (' ?' );
29+ let queryString = splitUrl .slice (1 ).join (' ?' );
30+ const hrefParams = new URLSearchParams (queryString );
31+ let hrefValue = hrefParams .get (' page' );
32+ if (hrefValue === activeUrl ) {
33+ page .active = true ;
34+ } else {
35+ page .active = false ;
36+ }
37+ });
38+ pages = pages ;
39+ })
40+
41+ const previous = () => {
42+ alert (' Previous btn clicked. Make a call to your server to fetch data.' );
43+ };
44+ const next = () => {
45+ alert (' Next btn clicked. Make a call to your server to fetch data.' );
46+ };
1347 </script >
1448
1549<H1 >Pagination</H1 >
50+
51+ <H2 >Default pagination</H2 >
52+ <CodeWrapper class =" space-y-4 flex flex-col" >
53+ <Pagination {pages } {previous } {next } />
54+ <Pagination {pages } size ="large" {previous } {next } />
55+ </CodeWrapper >
56+
57+ <H2 >Pagination with icons</H2 >
58+ <CodeWrapper >
59+ <Pagination {pages } {previous } {next }>
60+ {#snippet prevContent ()}
61+ <span class =" sr-only" >Previous</span >
62+ <ChevronLeftOutline class =" w-5 h-5" />
63+ {/ snippet }
64+ {#snippet nextContent ()}
65+ <span class =" sr-only" >Next</span >
66+ <ChevronRightOutline class =" w-5 h-5" />
67+ {/ snippet }
68+ </Pagination >
69+ </CodeWrapper >
70+
71+ <H2 >Previous and next</H2 >
72+ <CodeWrapper >
73+ <div class =" flex space-x-3 rtl:space-x-reverse" >
74+ <PaginationItem onclick ={previous }>Previous</PaginationItem >
75+ <PaginationItem onclick ={next }>Next</PaginationItem >
76+ </div >
77+ </CodeWrapper >
78+
79+
80+ <H2 >Previous and next with icons</H2 >
81+ <CodeWrapper >
82+ <div class =" flex space-x-3 rtl:space-x-reverse" >
83+ <PaginationItem class ="flex items-center" onclick ={previous }>
84+ <ArrowLeftOutline class =" me-2 w-5 h-5" />
85+ Previous
86+ </PaginationItem >
87+ <PaginationItem class ="flex items-center" onclick ={next }>
88+ Next
89+ <ArrowRightOutline class =" ms-2 w-5 h-5" />
90+ </PaginationItem >
91+ </div >
92+ </CodeWrapper >
93+
94+ <H2 >Table data pagination</H2 >
95+ <CodeWrapper >
96+ <div class =" flex flex-col items-center justify-center gap-2" >
97+ <div class =" text-sm text-gray-700 dark:text-gray-400" >
98+ Showing <span class ="font-semibold text-gray-900 dark:text-white" >{helper .start }</span >
99+ to
100+ <span class ="font-semibold text-gray-900 dark:text-white" >{helper .end }</span >
101+ of
102+ <span class ="font-semibold text-gray-900 dark:text-white" >{helper .total }</span >
103+ Entries
104+ </div >
105+
106+ <Pagination table >
107+ {#snippet prevContent ()}
108+ Prev
109+ {/ snippet }
110+ </Pagination >
111+ </div >
112+ </CodeWrapper >
0 commit comments