@rypen-dev/shared-components 5.2.7 → 5.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rypen-dev/shared-components",
3
3
  "description": "Shared styles and Vuejs ui components for Rypen projects.",
4
- "version": "5.2.7",
4
+ "version": "5.2.8",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
7
7
  "build": "webpack --config ./webpack.config.js",
@@ -0,0 +1,133 @@
1
+ <template>
2
+ <nav>
3
+ <ul class="pagination">
4
+ <li class="pagination-previous" :class="{ disabled: !hasPreviousPage }">
5
+ <a v-if="hasPreviousPage" @click="navigateToPrev"><span>Previous</span></a>
6
+ <span v-else><span>Previous</span></span>
7
+ </li>
8
+ <template v-if="totalPages > 0">
9
+ <li v-for="page in initialPageset" :class="{ current: page === pageIndex }">
10
+ <span v-if="page === pageIndex">{{ page + 1 }}</span>
11
+ <a v-else @click="navigateToPage(page)">{{ page + 1 }}</a>
12
+ </li>
13
+ <li v-if="showInitialEllipse" class="ellipsis"></li>
14
+ <li v-for="page in mainPageset" :class="{ current: page === pageIndex }">
15
+ <span v-if="page === pageIndex">{{ page + 1 }}</span>
16
+ <a v-else @click="navigateToPage(page)">{{ page + 1 }}</a>
17
+ </li>
18
+ <li v-if="showSubsequentEllipse" class="ellipsis"></li>
19
+ <li v-for="page in subsequentPageset" :class="{ current: page === pageIndex }">
20
+ <span v-if="page === pageIndex">{{ page + 1 }}</span>
21
+ <a v-else @click="navigateToPage(page)">{{ page + 1 }}</a>
22
+ </li>
23
+ </template>
24
+ <li v-else><span class="disabled">1</span></li>
25
+ <li class="pagination-next" :class="{ disabled: !hasNextPage }">
26
+ <a v-if="hasNextPage" @click="navigateToNext"><span>Next</span></a>
27
+ <span v-else><span>Next</span></span>
28
+ </li>
29
+ </ul>
30
+ </nav>
31
+ </template>
32
+
33
+ <script>
34
+ export default {
35
+ name: 'Pagination',
36
+ props: {
37
+ pageIndex: Number,
38
+ totalPages: Number,
39
+ maxVisiblePages: {
40
+ type: Number,
41
+ default: 7,
42
+ },
43
+ hasPreviousPage: {
44
+ type: Boolean,
45
+ default: false,
46
+ },
47
+ hasNextPage: {
48
+ type: Boolean,
49
+ default: false,
50
+ },
51
+ loading: {
52
+ type: Boolean,
53
+ default: false,
54
+ },
55
+ },
56
+ data: () => {
57
+ return {
58
+ initialPageset: [],
59
+ showInitialEllipse: false,
60
+ mainPageset: [],
61
+ subsequentPageset: [],
62
+ showSubsequentEllipse: false,
63
+ };
64
+ },
65
+ created: function () {
66
+
67
+ },
68
+ methods: {
69
+ navigateToNext() {
70
+ if (this.hasNextPage) {
71
+ this.navigateToPage(this.pageIndex + 1);
72
+ }
73
+ },
74
+ navigationToPrev() {
75
+ if (this.hasPreviousPage) {
76
+ this.navigateToPage(this.pageIndex - 1);
77
+ }
78
+ },
79
+ navigateToPage() {
80
+ if (idx !== this.pageIndex) {
81
+ this.$emit('navigate', idx);
82
+ this.$emit('top');
83
+ }
84
+ },
85
+
86
+ recalculateVisiblePages() {
87
+ this.initialPageset.splice(0);
88
+ this.showInitialEllipse = false;
89
+ this.mainPageset.splice(0);
90
+ this.showSubsequentEllipse = false;
91
+ this.subsequentPageset.splice(0);
92
+
93
+ if (this.totalPages > 0) {
94
+ if (this.totalPages > this.maxVisiblePages) {
95
+ let start = 0;
96
+ const middle = Math.floor(this.maxVisiblePages / 2);
97
+
98
+ if (this.pageIndex > (this.totalPages - middle - 1)) {
99
+ start = this.totalPages - this.maxVisiblePages;
100
+ } else if (this.pageIndex > middle) {
101
+ start = this.pageIndex - middle;
102
+ }
103
+
104
+ if (start > 0) {
105
+ this.initialPageset.push(0);
106
+ this.showInitialEllipse = true;
107
+ }
108
+
109
+ for (let i = start; i < (start + this.maxVisiblePages); i++) {
110
+ this.mainPageset.push(i);
111
+ }
112
+
113
+ if (start < this.totalPages - this.maxVisiblePages) {
114
+ this.showSubsequentEllipse = true;
115
+ this.subsequentPageset.push(this.totalPages - 1);
116
+ }
117
+ } else {
118
+ for (let i = 0; i < this.totalPages; i++) {
119
+ this.mainPageset.push(i);
120
+ }
121
+ }
122
+ }
123
+ },
124
+ },
125
+ watch: {
126
+ loading(value, prev) {
127
+ if (!value && prev) {
128
+ this.recalculateVisiblePages();
129
+ }
130
+ },
131
+ },
132
+ };
133
+ </script>