2020-09-17 22:14:57 -07:00
|
|
|
<template>
|
|
|
|
|
<div v-if="pages.length > 1" class="columns paginates">
|
2020-11-30 13:55:01 -08:00
|
|
|
<button
|
|
|
|
|
:class="{ disabled: currentPage === 1 }"
|
|
|
|
|
class="paginate has-icon"
|
2020-12-11 20:11:31 +00:00
|
|
|
aria-label="Previous Page"
|
2020-12-16 16:19:49 -07:00
|
|
|
@click="currentPage !== 1 ? switchPage(currentPage - 1) : null"
|
2020-09-17 22:14:57 -07:00
|
|
|
>
|
2020-11-30 13:55:01 -08:00
|
|
|
<LeftArrowIcon />
|
|
|
|
|
</button>
|
|
|
|
|
<div
|
2020-09-17 22:14:57 -07:00
|
|
|
v-for="(item, index) in pages"
|
2021-05-27 09:27:13 -07:00
|
|
|
:key="'page-' + item + '-' + index"
|
2020-09-17 22:14:57 -07:00
|
|
|
:class="{
|
2020-11-30 13:55:01 -08:00
|
|
|
'page-number': currentPage !== item,
|
2021-05-27 09:27:13 -07:00
|
|
|
shrink: item > 99,
|
2020-09-17 22:14:57 -07:00
|
|
|
}"
|
2020-11-30 13:55:01 -08:00
|
|
|
class="page-number-container"
|
2020-09-17 22:14:57 -07:00
|
|
|
>
|
2021-05-27 09:27:13 -07:00
|
|
|
<div v-if="item == '-'" class="has-icon">
|
2020-11-30 13:55:01 -08:00
|
|
|
<GapIcon />
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
2021-05-27 09:27:13 -07:00
|
|
|
v-else
|
|
|
|
|
:class="{
|
|
|
|
|
'page-number current': currentPage === item,
|
|
|
|
|
shrink: item > 99,
|
|
|
|
|
}"
|
2020-11-30 13:55:01 -08:00
|
|
|
@click="currentPage !== item ? switchPage(item) : null"
|
|
|
|
|
>
|
|
|
|
|
{{ item }}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2020-09-17 22:14:57 -07:00
|
|
|
|
2020-11-30 13:55:01 -08:00
|
|
|
<button
|
2021-05-27 09:27:13 -07:00
|
|
|
:class="{
|
|
|
|
|
disabled: currentPage === pages[pages.length - 1],
|
|
|
|
|
}"
|
2020-11-30 13:55:01 -08:00
|
|
|
class="paginate has-icon"
|
2020-12-16 16:19:49 -07:00
|
|
|
aria-label="Next Page"
|
2020-09-17 22:14:57 -07:00
|
|
|
@click="
|
|
|
|
|
currentPage !== pages[pages.length - 1]
|
|
|
|
|
? switchPage(currentPage + 1)
|
|
|
|
|
: null
|
|
|
|
|
"
|
|
|
|
|
>
|
2020-11-30 13:55:01 -08:00
|
|
|
<RightArrowIcon />
|
|
|
|
|
</button>
|
2020-09-17 22:14:57 -07:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-03-31 19:09:18 +02:00
|
|
|
import GapIcon from '~/assets/images/utils/gap.svg?inline'
|
|
|
|
|
import LeftArrowIcon from '~/assets/images/utils/left-arrow.svg?inline'
|
|
|
|
|
import RightArrowIcon from '~/assets/images/utils/right-arrow.svg?inline'
|
2020-11-30 13:55:01 -08:00
|
|
|
|
2020-09-17 22:14:57 -07:00
|
|
|
export default {
|
|
|
|
|
name: 'Pagination',
|
2020-11-30 13:55:01 -08:00
|
|
|
components: {
|
|
|
|
|
GapIcon,
|
|
|
|
|
LeftArrowIcon,
|
|
|
|
|
RightArrowIcon,
|
|
|
|
|
},
|
2020-09-17 22:14:57 -07:00
|
|
|
props: {
|
|
|
|
|
currentPage: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 1,
|
|
|
|
|
},
|
|
|
|
|
pages: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default() {
|
|
|
|
|
return []
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
switchPage(newPage) {
|
|
|
|
|
this.$emit('switch-page', newPage)
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2020-11-30 13:55:01 -08:00
|
|
|
<style scoped lang="scss">
|
|
|
|
|
button {
|
2021-05-27 09:27:13 -07:00
|
|
|
padding: 0;
|
|
|
|
|
margin: 0;
|
|
|
|
|
width: 2em;
|
|
|
|
|
height: 2em;
|
|
|
|
|
border-radius: 2em;
|
2020-11-30 13:55:01 -08:00
|
|
|
background: transparent;
|
|
|
|
|
&.page-number.current {
|
|
|
|
|
background: var(--color-button-bg-hover);
|
|
|
|
|
color: var(--color-button-text-hover);
|
|
|
|
|
cursor: default;
|
|
|
|
|
}
|
|
|
|
|
&.paginate.disabled {
|
|
|
|
|
background: none;
|
|
|
|
|
color: var(--color-button-text-disabled);
|
|
|
|
|
cursor: default;
|
|
|
|
|
}
|
|
|
|
|
&:hover {
|
|
|
|
|
background: var(--color-button-bg-active);
|
|
|
|
|
color: var(--color-button-text-active);
|
|
|
|
|
}
|
2020-09-17 22:14:57 -07:00
|
|
|
}
|
|
|
|
|
|
2020-11-30 13:55:01 -08:00
|
|
|
.has-icon {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
2021-05-27 09:27:13 -07:00
|
|
|
height: 2em;
|
2020-11-30 13:55:01 -08:00
|
|
|
svg {
|
2021-05-27 09:27:13 -07:00
|
|
|
width: 1em;
|
2020-11-30 13:55:01 -08:00
|
|
|
}
|
2020-09-17 22:14:57 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-27 09:27:13 -07:00
|
|
|
.page-number-container,
|
|
|
|
|
button,
|
|
|
|
|
.has-icon {
|
2020-11-30 13:55:01 -08:00
|
|
|
display: flex;
|
2021-05-27 09:27:13 -07:00
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
height: 2em;
|
|
|
|
|
width: 2em;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.paginates {
|
|
|
|
|
height: 2em;
|
|
|
|
|
margin: 0.5rem 0;
|
|
|
|
|
> div {
|
|
|
|
|
margin: 0 0.1em;
|
|
|
|
|
}
|
|
|
|
|
font-size: 80%;
|
|
|
|
|
@media screen and (min-width: 350px) {
|
|
|
|
|
font-size: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.shrink {
|
|
|
|
|
font-size: 0.9rem;
|
|
|
|
|
height: 2.225em;
|
|
|
|
|
width: 2.225em;
|
2020-09-17 22:14:57 -07:00
|
|
|
}
|
|
|
|
|
</style>
|