Modrinth/components/ui/Pagination.vue
Emma 0146a077e8
Bundle of small fixes (#355)
* Bundle of small fixes

![bundle of small fixes](https://i.imgur.com/IkPE3uP.png)

- List items in project body may overflow
- Reduce margin between pagination buttons for better mobile support
- Prevent titles from overflowing in search for better mobile support
- Don't show ThisOrThats with only one item
- Fix style inconsistencies on homepage
- Add more links to homepage to docs, GH, and discord, so they can't be missed

* Appease lint

* Dryer lint isn't even the worst type of lint. It's this.
2022-02-19 13:09:58 -07:00

159 lines
2.9 KiB
Vue

<template>
<div v-if="pages.length > 1" class="columns paginates">
<button
:class="{ disabled: currentPage === 1 }"
class="left-arrow paginate has-icon"
aria-label="Previous Page"
@click="currentPage !== 1 ? switchPage(currentPage - 1) : null"
>
<LeftArrowIcon />
</button>
<div
v-for="(item, index) in pages"
:key="'page-' + item + '-' + index"
:class="{
'page-number': currentPage !== item,
shrink: item > 99,
}"
class="page-number-container"
>
<div v-if="item === '-'" class="has-icon">
<GapIcon />
</div>
<button
v-else
:class="{
'page-number current': currentPage === item,
shrink: item > 99,
}"
@click="currentPage !== item ? switchPage(item) : null"
>
{{ item }}
</button>
</div>
<button
:class="{
disabled: currentPage === pages[pages.length - 1],
}"
class="right-arrow paginate has-icon"
aria-label="Next Page"
@click="
currentPage !== pages[pages.length - 1]
? switchPage(currentPage + 1)
: null
"
>
<RightArrowIcon />
</button>
</div>
</template>
<script>
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'
export default {
name: 'Pagination',
components: {
GapIcon,
LeftArrowIcon,
RightArrowIcon,
},
props: {
currentPage: {
type: Number,
default: 1,
},
pages: {
type: Array,
default() {
return []
},
},
},
methods: {
switchPage(newPage) {
this.$emit('switch-page', newPage)
},
},
}
</script>
<style scoped lang="scss">
button {
box-shadow: var(--shadow-card);
padding: 0;
margin: 0;
width: 2rem;
height: 2rem;
border-radius: 2rem;
background: var(--color-raised-bg);
&.page-number.current {
background: var(--color-brand);
color: var(--color-brand-inverted);
cursor: default;
}
&.paginate.disabled {
background-color: var(--color-button-bg);
cursor: default;
color: var(--color-icon);
}
&:hover {
background: var(--color-button-bg-active);
color: var(--color-button-text-active);
}
}
.has-icon {
display: flex;
align-items: center;
height: 2em;
svg {
width: 1em;
}
}
.page-number-container,
button,
.has-icon {
display: flex;
justify-content: center;
align-items: center;
height: 2em;
width: 2em;
}
.paginates {
height: 2em;
margin: 0.5rem 0;
> div,
.has-icon {
margin: 0 0.3em;
}
font-size: 80%;
@media screen and (min-width: 350px) {
font-size: 100%;
}
}
.shrink {
font-size: 0.9rem;
height: 2.225em;
width: 2.225em;
}
.left-arrow {
margin-left: auto !important;
}
.right-arrow {
margin-right: auto !important;
}
</style>