<script setup>
|
|
import * as itemOffset from '../lib/itemOffset.js'
|
import {onKeyStroke} from "@vueuse/core"
|
|
const props = defineProps({
|
total: Number,
|
offset: Number,
|
limit: Number,
|
})
|
|
const emit = defineEmits(["go"])
|
|
function goStart () {
|
const offset2 = itemOffset.goStart(props.offset, props.limit, props.total)
|
emit("go", offset2)
|
}
|
|
function goEnd () {
|
const offset2 = itemOffset.goEnd(props.offset, props.limit, props.total)
|
emit("go", offset2)
|
}
|
|
function goPrev (multiplier = 1) {
|
const offset2 = itemOffset.goPrev(props.offset, props.limit * multiplier, props.total)
|
emit("go", offset2)
|
}
|
|
function goNext (multiplier = 1) {
|
const offset2 = itemOffset.goNext(props.offset, props.limit * multiplier, props.total)
|
emit("go", offset2)
|
}
|
|
/////// KEYBOARD ////////////////////////////////////////////////////////////////
|
|
onKeyStroke(["ArrowLeft", "ArrowRight"], (e) => {
|
let multiplier = 1
|
switch (e.key) {
|
case "ArrowLeft":
|
console.log("go left")
|
multiplier = e.shiftKey ? 10 : 1
|
goPrev(multiplier)
|
break
|
case "ArrowRight":
|
console.log("go right")
|
multiplier = e.shiftKey ? 10 : 1
|
goNext(multiplier)
|
break
|
}
|
})
|
|
|
</script>
|
|
<template>
|
|
<div class="pagination">
|
<input type="button" @click="goStart()" class="start" value="«">
|
<input type="button" @click="goPrev()" class="prev" value="‹">
|
<span class="current">
|
{{ offset }} - {{ offset + limit }}
|
/ {{ total }}
|
</span>
|
<input type="button" @click="goNext()" class="next" value="›">
|
<input type="button" @click="goEnd()" class="end" value="»">
|
</div>
|
|
</template>
|
|
<style scoped lang="stylus">
|
|
.pagination
|
font-size 1.33rem
|
display flex;
|
gap 1em
|
align-items center;
|
justify-content center;
|
margin -1em 0 1em 0;
|
|
& > div
|
cursor: pointer
|
color #6464b5
|
font-weight bold;
|
|
&:hover
|
color orange
|
|
.start, .end, .prev, .next
|
font-size 130%
|
|
//width 1em
|
.current
|
width 12em;
|
text-align center;
|
|
input
|
//all: unset
|
border none
|
width 1em
|
|
</style>
|