-
Notifications
You must be signed in to change notification settings - Fork 1
/
pagination.svelte
73 lines (72 loc) · 2.35 KB
/
pagination.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script>
export let currentPage, totalPages;
</script>
<ul class="pagination ul">
{#if (currentPage - 1) > 0}
<li class="page-item">
<a href="blog" class="page-link" aria-label="First"><span aria-hidden="true">««</span></a>
</li>
<li class="page-item">
<a href="blog/{currentPage - 1}" class="page-link" aria-label="Previous"><span aria-hidden="true">«</span></a>
</li>
{:else}
<li class="page-item disabled">
<a href="blog" class="page-link" aria-label="First"><span aria-hidden="true">««</span></a>
</li>
<li class="page-item disabled">
<a href="blog/{currentPage - 1}" class="page-link" aria-label="Previous"><span aria-hidden="true">«</span></a>
</li>
{/if}
{#each Array(totalPages) as _, i}
{#if currentPage == i+1}
<li class="page-item active"><a class="page-link" href="blog/{i+1}">{i+1}</a></li>
{:else}
<li class="page-item"><a class="page-link" href="blog/{i+1}">{i+1}</a></li>
{/if}
{/each}
{#if (currentPage + 1) <= totalPages}
<li class="page-item">
<a href="blog/{currentPage + 1}" class="page-link" aria-label="Next"><span aria-hidden="true">»</span></a>
</li>
<li class="page-item">
<a href="blog/{totalPages}" class="page-link" aria-label="Last"><span aria-hidden="true">»»</span></a>
</li>
{:else}
<li class="page-item disabled">
<a href="blog/{currentPage + 1}" class="page-link" aria-label="Next"><span aria-hidden="true">»</span></a>
</li>
<li class="page-item disabled">
<a href="blog/{totalPages}" class="page-link" aria-label="Last"><span aria-hidden="true">»»</span></a>
</li>
{/if}
</ul>
<style>
.pagination {
margin-top: 30px;
justify-content: center;
}
.pagination .page-item:first-child .page-link, .pagination .page-item:last-child .page-link {
border-radius: 5px;
}
.pagination .page-item .page-link {
display: inline-block;
width: 40px;
height: 40px;
line-height: 40px;
border-radius: 5px;
background: #edf6f5;
text-align: center;
padding: 0;
margin-right: 10px;
border: 0;
color: #777;
}
.pagination .page-item.active .page-link {
background: #0aa8a7;
color: #fff;
}
.pagination .page-item .page-link:hover {
background: #0aa8a7;
color: #fff;
}
</style>