-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pagination.vue
85 lines (76 loc) · 2.99 KB
/
Pagination.vue
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
74
75
76
77
78
79
80
81
82
83
84
85
<template>
<nav :aria-label="$t('component.pagination.ariaLabel')" class="align-items-center d-flex text-nowrap">
<div class="mr-3 pagination-records" v-if="!hideRecords">
{{ $t('component.pagination.records', { from: from ? from : 0 , to: to, total: total }) }}
</div>
<ul class="pagination">
<template v-if="syncCurrent === 1">
<li class="page-item disabled">
<a aria-disabled="true" class="page-link" tabindex="-1">«</a>
</li>
<li class="page-item disabled">
<a aria-disabled="true" class="page-link" tabindex="-1">‹</a>
</li>
</template>
<template v-else>
<li class="page-item">
<a class="page-link pointer text-primary" @click="changePage(1)">«</a>
</li>
<li class="page-item">
<a class="page-link pointer text-primary" @click="changePage(syncCurrent - 1)">‹</a>
</li>
</template>
<li class="page-item mx-3">
<label class="sr-only" :for="'pagination_pageSelector-' + uuid">{{ $t('component.pagination.select') }}</label>
<select class="selection" v-model="syncCurrent" :id="'pagination_pageSelector-' + uuid">
<option v-for="i in last" :key="i" :selected="i === syncCurrent" :value="i">{{ i }}</option>
</select>
<span class="ml-2">{{ $t('component.pagination.of', { last: last }) }}</span>
</li>
<template v-if="syncCurrent === last || last < 1">
<li class="page-item disabled">
<a aria-disabled="true" class="page-link" tabindex="-1">›</a>
</li>
<li class="page-item disabled">
<a aria-disabled="true" class="page-link" tabindex="-1">»</a>
</li>
</template>
<template v-else>
<li class="page-item">
<a class="page-link pointer text-primary" @click="changePage(syncCurrent + 1)">›</a>
</li>
<li class="page-item">
<a class="page-link pointer text-primary" @click="changePage(last)">»</a>
</li>
</template>
</ul>
</nav>
</template>
<script lang="ts">
import Vue from 'vue';
import { Component, Prop, PropSync, Watch } from 'vue-property-decorator';
import { uuidv4 } from '@/helpers';
@Component
export default class Pagination extends Vue {
@Prop({ required: true }) readonly from!: null|number;
@Prop([Boolean]) readonly hideRecords!: boolean;
@Prop({ required: true, type: Number }) readonly last!: number;
@Prop({ required: true }) readonly to!: null|number;
@Prop({ required: true, type: Number }) readonly total!: number;
@PropSync('current', { required: true, type: Number }) syncCurrent!: number;
uuid!: string;
created (): void {
this.uuid = uuidv4();
this.$on('update:current', this.changePage);
}
changePage (page: number): void {
this.$emit('pagination:changed', page);
}
@Watch('last')
onLastUpdate (last: number): void {
if (this.syncCurrent > last) {
this.syncCurrent = last;
}
}
}
</script>