2023-12-30 05:29:53 +00:00
|
|
|
<template>
|
2024-03-17 21:15:11 +00:00
|
|
|
<div class="pagination-container">
|
|
|
|
<div
|
|
|
|
v-if="currentPage === pageTotal && total > env.maxMatches"
|
|
|
|
class="more"
|
2024-03-17 22:55:36 +00:00
|
|
|
>Can't find what you're looking for? Narrow down the results using a filter.</div>
|
2024-03-17 21:15:11 +00:00
|
|
|
|
|
|
|
<nav class="pagination">
|
|
|
|
<ul class="pages nolist">
|
|
|
|
<li>
|
2023-12-30 05:29:53 +00:00
|
|
|
<Link
|
2024-03-17 21:15:11 +00:00
|
|
|
:href="getPath(1)"
|
|
|
|
:class="{ disabled: !hasPrevPage }"
|
|
|
|
class="page first nolink"
|
|
|
|
@click="(event) => go(1, event)"
|
|
|
|
><Icon icon="first2" /></Link>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<li>
|
|
|
|
<Link
|
|
|
|
:href="hasPrevPage ? getPath(currentPage - 1) : null"
|
|
|
|
:class="{ disabled: !hasPrevPage }"
|
|
|
|
class="page prev nolink"
|
|
|
|
@click="(event) => hasPrevPage && go(currentPage - 1, event)"
|
|
|
|
><Icon icon="arrow-left" /></Link>
|
2023-12-30 05:29:53 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
2024-03-17 21:15:11 +00:00
|
|
|
<div class="index">
|
|
|
|
<ul class="pages before wrap nolist">
|
|
|
|
<li
|
|
|
|
v-for="prevPage in prevPages"
|
|
|
|
:key="`page-${prevPage}`"
|
|
|
|
>
|
|
|
|
<Link
|
|
|
|
:href="getPath(prevPage)"
|
|
|
|
:class="{ active: prevPage === currentPage }"
|
|
|
|
class="page nolink"
|
|
|
|
@click="(event) => go(prevPage, event)"
|
|
|
|
>{{ prevPage }}</Link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<ul class="pages nolist">
|
|
|
|
<li>
|
|
|
|
<div class="page active">{{ currentPage }}</div>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<ul class="pages after wrap nolist">
|
|
|
|
<li
|
|
|
|
v-for="nextPage in nextPages"
|
|
|
|
:key="`page-${nextPage}`"
|
|
|
|
>
|
|
|
|
<Link
|
|
|
|
:href="getPath(nextPage)"
|
|
|
|
:class="{ active: nextPage === currentPage }"
|
|
|
|
class="page nolink"
|
|
|
|
@click="(event) => go(nextPage, event)"
|
|
|
|
>{{ nextPage }}</Link>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
<ul class="pages nolist">
|
|
|
|
<li>
|
2024-03-17 21:15:11 +00:00
|
|
|
<Link
|
|
|
|
:href="hasNextPage ? getPath(currentPage + 1) : null"
|
|
|
|
:class="{ disabled: !hasNextPage }"
|
|
|
|
class="page next nolink"
|
|
|
|
@click="(event) => hasNextPage && go(currentPage + 1, event)"
|
|
|
|
><Icon icon="arrow-right" /></Link>
|
2023-12-30 05:29:53 +00:00
|
|
|
</li>
|
|
|
|
|
2024-03-17 21:15:11 +00:00
|
|
|
<li>
|
2023-12-30 05:29:53 +00:00
|
|
|
<Link
|
2024-03-17 21:15:11 +00:00
|
|
|
:href="getPath(pageTotal)"
|
|
|
|
:class="{ disabled: !hasNextPage }"
|
|
|
|
class="page last nolink"
|
|
|
|
@click="(event) => go(pageTotal, event)"
|
|
|
|
><Icon icon="last2" /></Link>
|
2023-12-30 05:29:53 +00:00
|
|
|
</li>
|
|
|
|
</ul>
|
2024-03-17 21:15:11 +00:00
|
|
|
</nav>
|
|
|
|
</div>
|
2023-12-30 05:29:53 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2024-01-04 00:49:16 +00:00
|
|
|
import { computed, inject } from 'vue';
|
|
|
|
import { parse } from 'path-to-regexp';
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
page: {
|
|
|
|
type: Number,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
total: {
|
|
|
|
type: Number,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
redirect: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
2024-02-22 04:08:06 +00:00
|
|
|
query: {
|
|
|
|
type: String,
|
|
|
|
default: null,
|
|
|
|
},
|
2024-01-04 00:49:16 +00:00
|
|
|
includeQuery: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
2024-03-17 21:15:11 +00:00
|
|
|
useMaxMatches: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
2024-01-04 00:49:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const emit = defineEmits(['navigation']);
|
|
|
|
|
|
|
|
const pageContext = inject('pageContext');
|
2024-03-17 21:15:11 +00:00
|
|
|
|
|
|
|
const {
|
|
|
|
routeParams,
|
|
|
|
urlParsed,
|
|
|
|
pageProps,
|
|
|
|
env,
|
|
|
|
} = pageContext;
|
2024-01-04 00:49:16 +00:00
|
|
|
|
|
|
|
const currentPage = computed(() => props.page || Number(routeParams?.page));
|
|
|
|
|
|
|
|
const limit = computed(() => props.limit || Number(pageProps.limit) || 30);
|
|
|
|
const total = computed(() => props.total || Number(pageProps.total));
|
2024-03-17 21:15:11 +00:00
|
|
|
const pageTotal = computed(() => Math.ceil((props.useMaxMatches ? Math.min(total.value, env.maxMatches) : total.value) / limit.value));
|
2024-01-04 00:49:16 +00:00
|
|
|
|
|
|
|
const hasNextPage = computed(() => currentPage.value + 1 <= pageTotal.value);
|
|
|
|
const hasPrevPage = computed(() => currentPage.value - 1 >= 1);
|
|
|
|
|
|
|
|
const prevPages = computed(() => Array.from({ length: 4 }, (value, index) => {
|
|
|
|
const page = currentPage.value - index - 1;
|
2023-12-30 05:29:53 +00:00
|
|
|
|
|
|
|
if (page < 1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return page;
|
2024-01-04 00:49:16 +00:00
|
|
|
}).filter(Boolean));
|
2023-12-30 05:29:53 +00:00
|
|
|
|
2024-01-04 00:49:16 +00:00
|
|
|
const nextPages = computed(() => Array.from({ length: 4 }, (value, index) => {
|
|
|
|
const page = currentPage.value + index + 1;
|
2023-12-30 05:29:53 +00:00
|
|
|
|
2024-01-04 00:49:16 +00:00
|
|
|
if (page > pageTotal.value) {
|
2023-12-30 05:29:53 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return page;
|
2024-01-04 00:49:16 +00:00
|
|
|
}).filter(Boolean));
|
|
|
|
|
|
|
|
function go(page, event) {
|
|
|
|
if (!props.redirect) {
|
|
|
|
event.preventDefault();
|
|
|
|
history.pushState({}, '', event.target.href); // eslint-disable-line no-restricted-globals
|
|
|
|
}
|
2023-12-30 05:29:53 +00:00
|
|
|
|
2024-01-04 00:49:16 +00:00
|
|
|
emit('navigation', {
|
|
|
|
href: event.target.href,
|
|
|
|
page,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPath(page) {
|
2024-03-19 00:40:56 +00:00
|
|
|
const query = typeof window === 'undefined'
|
|
|
|
? urlParsed.searchOriginal
|
|
|
|
: window.location.search;
|
|
|
|
|
|
|
|
if (!routeParams.path && props.includeQuery && query) {
|
|
|
|
return `${pageContext.urlParsed.pathname}${page}${query}`;
|
2024-02-22 04:08:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!routeParams.path) {
|
|
|
|
return `${pageContext.urlParsed.pathname}${page}`;
|
|
|
|
}
|
|
|
|
|
2024-01-04 00:49:16 +00:00
|
|
|
const path = parse(routeParams.path)
|
2024-01-25 02:07:26 +00:00
|
|
|
.map((segment) => {
|
|
|
|
if (segment.name === 'page') {
|
|
|
|
return `/${page}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${segment.prefix || ''}${routeParams[segment.name] || segment}`;
|
|
|
|
})
|
|
|
|
.join('');
|
2024-01-04 00:49:16 +00:00
|
|
|
|
2024-03-19 00:40:56 +00:00
|
|
|
if (props.includeQuery && query) {
|
|
|
|
return `${path}${query}`;
|
2024-01-04 00:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
2023-12-30 05:29:53 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2024-03-17 21:15:11 +00:00
|
|
|
.pagination-container {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
.pagination {
|
|
|
|
height: 5rem;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
2024-01-25 02:07:26 +00:00
|
|
|
flex-shrink: 0;
|
2024-01-04 00:49:16 +00:00
|
|
|
box-sizing: border-box;
|
2023-12-30 05:29:53 +00:00
|
|
|
padding: 1rem;
|
2024-03-21 04:40:02 +00:00
|
|
|
margin-bottom: 1rem;
|
2023-12-30 05:29:53 +00:00
|
|
|
font-size: 0;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
.pages {
|
|
|
|
display: flex;
|
2024-03-21 04:37:50 +00:00
|
|
|
gap: 0 .25rem;
|
2023-12-30 05:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.wrap {
|
|
|
|
flex-wrap: wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
.before {
|
|
|
|
flex-direction: row-reverse;
|
2024-03-21 04:37:50 +00:00
|
|
|
margin-right: .25rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.after {
|
|
|
|
margin-left: .25rem;
|
2023-12-30 05:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.index {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.page {
|
|
|
|
width: 3rem;
|
|
|
|
height: 3rem;
|
|
|
|
display: inline-flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2024-03-21 04:37:50 +00:00
|
|
|
border-radius: .5rem;
|
2023-12-30 05:29:53 +00:00
|
|
|
margin-bottom: 1rem;
|
|
|
|
background: var(--background);
|
|
|
|
box-shadow: 0 0 3px var(--shadow-weak-30);
|
|
|
|
color: var(--shadow);
|
|
|
|
font-weight: bold;
|
|
|
|
font-size: 1rem;
|
|
|
|
|
|
|
|
.icon {
|
|
|
|
width: .9rem;
|
|
|
|
height: .9rem;
|
|
|
|
fill: var(--shadow);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.active {
|
2024-03-21 04:37:50 +00:00
|
|
|
background: var(--primary);
|
|
|
|
color: var(--text-light);
|
2023-12-30 05:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
&.disabled .icon {
|
|
|
|
fill: var(--shadow-weak-20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.prev {
|
|
|
|
margin-right: .5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.next {
|
|
|
|
margin-left: .5rem;
|
|
|
|
}
|
2024-03-17 21:15:11 +00:00
|
|
|
|
|
|
|
.more {
|
|
|
|
padding: 2rem;
|
|
|
|
text-align: center;
|
|
|
|
color: var(--shadow-strong-10);
|
|
|
|
font-size: 1.1rem;
|
|
|
|
}
|
2024-03-19 19:50:50 +00:00
|
|
|
|
|
|
|
@media (--small-30) {
|
|
|
|
.pagination {
|
|
|
|
height: 4.5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.page {
|
2024-03-21 04:37:50 +00:00
|
|
|
width: 2.25rem;
|
2024-03-19 19:50:50 +00:00
|
|
|
height: 2.5rem;
|
|
|
|
}
|
|
|
|
}
|
2023-12-30 05:29:53 +00:00
|
|
|
</style>
|