adrema/resources/js/components/ui/Pagination.vue

91 lines
3.9 KiB
Vue
Raw Normal View History

2021-04-11 02:55:26 +02:00
<template>
2023-07-27 14:00:27 +02:00
<div class="flex flex-col md:flex-row justify-between items-center space-y-3 md:space-y-0">
<div class="text-sm text-gray-500" v-text="desc"></div>
<div v-if="value.last_page > 1" class="items-center flex space-x-2">
<div class="hidden sm:flex text-gray-500 text-sm" v-text="pages"></div>
<button v-if="value.current_page !== 1" href="#"
class="rounded hidden sm:flex w-8 h-8 text-primary-100 items-center justify-center leading-none shadow bg-primary-900 hover:bg-primary-800 items-center justify-center"
@click.prevent="goto(1)">
<ui-sprite class="w-3 h-3 fill-current rotate-90" src="chevron-double"></ui-sprite>
</button>
<button v-if="value.current_page !== 1" href="#"
class="rounded !ml-0 sm:!ml-2 flex w-8 h-8 text-primary-100 items-center justify-center leading-none shadow bg-primary-900 hover:bg-primary-800 items-center justify-center"
@click.prevent="goto(value.current_page - 1)">
<ui-sprite class="w-3 h-3 fill-current rotate-90" src="chevron"></ui-sprite>
</button>
<button v-for="(button, index) in pageButtons" :key="index" href="#"
class="rounded text-sm w-8 h-8 text-primary-100 flex items-center justify-center leading-none shadow"
:class="{ 'bg-primary-700': button.current, 'bg-primary-900 hover:bg-primary-800': !button.current }"
@click.prevent="goto(button.page)" v-text="button.page"></button>
<button v-if="value.current_page !== value.last_page" href="#"
class="flex rounded text-sm w-8 h-8 text-primary-100 items-center justify-center leading-none shadow bg-primary-900 hover:bg-primary-800 items-center justify-center"
@click.prevent="goto(value.current_page + 1)">
<ui-sprite class="w-3 h-3 fill-current -rotate-90" src="chevron"></ui-sprite>
</button>
<button v-if="value.current_page !== value.last_page" href="#"
class="hidden sm:flex rounded text-sm w-8 h-8 text-primary-100 items-center justify-center leading-none shadow bg-primary-900 hover:bg-primary-800 items-center justify-center"
@click.prevent="goto(value.last_page)">
<ui-sprite class="w-3 h-3 fill-current -rotate-90" src="chevron-double"></ui-sprite>
</button>
2021-04-11 02:55:26 +02:00
</div>
</div>
</template>
<script>
export default {
props: {
only: {
2023-05-08 15:11:16 +02:00
default: null,
required: false,
2021-04-11 02:55:26 +02:00
},
value: {
required: true,
2021-04-11 02:55:26 +02:00
},
preserve: {
default: false,
type: Boolean,
},
2021-04-11 02:55:26 +02:00
},
computed: {
2023-07-27 14:00:27 +02:00
pageButtons() {
var buttons = [];
2021-04-11 02:55:26 +02:00
2023-07-27 14:00:27 +02:00
var from = Math.max(1, this.value.current_page - 2);
var to = Math.min(this.value.last_page, this.value.current_page + 2);
2021-04-11 02:55:26 +02:00
for (var i = from; i <= to; i++) {
2023-07-27 14:00:27 +02:00
buttons.push({
2021-04-11 02:55:26 +02:00
page: i,
current: i === this.value.current_page,
2021-04-11 02:55:26 +02:00
});
}
2023-07-27 14:00:27 +02:00
return buttons;
},
pages() {
return `Seite ${this.value.current_page} von ${this.value.last_page}`;
2021-04-11 02:55:26 +02:00
},
desc() {
return `${this.value.from} - ${this.value.to} von ${this.value.total} Einträgen`;
},
},
2023-08-25 00:23:38 +02:00
methods: {
goto(page) {
if (this.$attrs.onReload) {
2023-07-27 14:00:27 +02:00
this.$emit('reload', page);
2023-08-25 00:23:38 +02:00
return;
}
var params = new URLSearchParams(window.location.search);
2023-07-27 14:00:27 +02:00
params.set('page', page);
2023-08-25 00:23:38 +02:00
this.$inertia.visit(window.location.pathname + '?' + params.toString(), {
only: this.only,
preserveState: this.preserve,
});
},
},
2021-04-11 02:55:26 +02:00
};
</script>