traxxx/assets/components/pagination/pagination.vue

154 lines
2.7 KiB
Vue
Raw Normal View History

2020-05-22 02:32:16 +00:00
<template>
<div class="pagination">
<span
v-show="pageNumber > 1"
class="cursors"
>
2020-05-22 02:32:16 +00:00
<router-link
class="pagination-button cursor"
2020-05-22 02:32:16 +00:00
:to="{ params: { pageNumber: 1 } }"
><Icon icon="first2" /></router-link>
2020-05-22 02:32:16 +00:00
<router-link
class="pagination-button cursor"
2020-05-22 02:32:16 +00:00
:to="{ params: { pageNumber: pageNumber - 1 } }"
><Icon icon="arrow-left" /></router-link>
</span>
<span
v-show="pageNumber === 1"
class="cursors"
>
<span class="pagination-button cursor disabled"><Icon icon="first2" /></span>
<span class="pagination-button cursor disabled"><Icon icon="arrow-left" /></span>
</span>
<span class="pages">
2020-05-22 02:32:16 +00:00
<router-link
v-for="pageX in pageCount"
:key="`page-${pageX}`"
:to="{ params: { pageNumber: pageX } }"
:class="{ active: pageX === pageNumber }"
class="pagination-button page"
> {{ pageX }} </router-link>
</span>
<span
v-show="pageNumber < pageCount"
class="cursors"
>
<router-link
class="pagination-button cursor"
2020-05-22 02:32:16 +00:00
:to="{ params: { pageNumber: pageNumber + 1 } }"
><Icon icon="arrow-right" /></router-link>
2020-05-22 02:32:16 +00:00
<router-link
class="pagination-button cursor"
2020-05-22 02:32:16 +00:00
:to="{ params: { pageNumber: pageCount } }"
><Icon icon="last2" /></router-link>
</span>
<span
v-show="pageNumber === pageCount"
class="cursors"
>
<span class="pagination-button cursor disabled"><Icon icon="arrow-right" /></span>
<span class="pagination-button cursor disabled"><Icon icon="last2" /></span>
</span>
2020-05-22 02:32:16 +00:00
</div>
</template>
<script>
function pageNumber() {
return Number(this.$route.params.pageNumber) || 1;
}
function pageCount() {
const count = Math.max(Math.ceil(this.itemsTotal / this.itemsPerPage), 1);
return count;
2020-05-22 02:32:16 +00:00
}
export default {
props: {
itemsTotal: {
type: Number,
default: 0,
},
itemsPerPage: {
type: Number,
default: 10,
},
},
computed: {
pageNumber,
pageCount,
},
};
</script>
<style lang="scss" scoped>
.pagination {
display: flex;
justify-content: center;
}
.pagination-top {
margin: 0 0 1rem 0;
}
.pagination-bottom {
margin: .5rem 0 1rem 0;
}
.pagination-button {
width: 2.5rem;
2020-05-22 02:32:16 +00:00
height: 2rem;
display: inline-flex;
flex-shrink: 0;
2020-05-22 02:32:16 +00:00
align-items: center;
justify-content: center;
color: var(--shadow);
font-size: 1rem;
2020-05-22 02:32:16 +00:00
font-weight: bold;
text-decoration: none;
.icon {
width: .8rem;
height: .8rem;
margin: 0 0 .125rem 0;
fill: var(--shadow);
}
&:hover:not(.active):not(.disabled) {
2020-05-22 02:32:16 +00:00
color: var(--text);
.icon {
fill: var(--text);
}
2020-05-22 02:32:16 +00:00
}
&.active {
color: var(--primary);
}
&.disabled {
color: var(--shadow-weak);
.icon {
fill: var(--shadow-weak);
}
2020-05-22 02:32:16 +00:00
}
}
.pages,
.cursors {
flex-shrink: 0;
2020-05-22 02:32:16 +00:00
}
.cursors {
margin: 0 .5rem;
font-size: 0;
2020-05-22 02:32:16 +00:00
}
</style>