Skip to content

Commit d6b7c09

Browse files
feat: slot for pagination and usage example
1 parent 06a15bb commit d6b7c09

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

examples/App.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
:show-customize-editor-add-draw="true"
1212
:show-line-size-select = 'true'
1313
:show-font-size-select= 'true'
14+
:show-pagination="true"
1415
:show-font-select="true"
1516
:show-rename="true"
1617
:show-save-btn="true"
@@ -24,6 +25,13 @@
2425
:seal-image-hidden-on-save="false"
2526
@onSave2Upload="save2Upload"
2627
>
28+
<template #pagination="{ pages, currentPage, onPageChange }">
29+
<ul class="inline-flex">
30+
<li @click="onPageChange(currentPage-1)">previous</li>
31+
<p>{{ currentPage }}/{{ pages }}</p>
32+
<li @click="onPageChange(currentPage+1)">next</li>
33+
</ul>
34+
</template>
2735
</VuePdfEditor>
2836

2937
</div>
@@ -42,6 +50,9 @@ export default {
4250
}
4351
},
4452
methods:{
53+
pageChange(e){
54+
console.log(e)
55+
},
4556
save2Upload(payload){
4657
console.log(payload.pdfBytes);
4758
console.log(payload.fileName);

src/Components/Pagination.vue

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
<template>
22
<div class="inline-flex -space-x-px text-sm">
3-
<button :disabled="!canPreviousPage" class="flex items-center px-3 h-8 ms-0 leading-tight bg-blue-500 border border-e-0 rounded-s-lg hover:bg-blue-700 text-white font-bold disabled:dark:bg-blue-300" @click="onPreviousPage" :class="{'cursor-not-allowed': !canPreviousPage}">Previous</button>
4-
<p class="flex items-center px-3 h-8 leading-tight text-white bg-blue-500 border border-gray-300 font-bold">{{ page }} Of {{ pages }}</p>
5-
<button :disabled="!canNextPage" class="flex items-center px-3 h-8 ms-0 leading-tight bg-blue-500 border border-e-0 rounded-r-lg hover:bg-blue-700 text-white font-bold disabled:dark:bg-blue-300" @click="onNextPage" :class="{'cursor-not-allowed': !canNextPage}">Next</button>
3+
<button :disabled="!canPreviousPage" class="flex items-center px-3 h-8 ms-0 leading-tight bg-blue-500 border border-e-0 rounded-s-lg hover:bg-blue-700 text-white font-bold disabled:dark:bg-blue-300" @click="onPreviousPage" :class="{'cursor-not-allowed': !canPreviousPage}">Previous</button>
4+
<p class="flex items-center px-3 h-8 leading-tight text-white bg-blue-500 border border-gray-300 font-bold">{{ page }} Of {{ pages }}</p>
5+
<button :disabled="!canNextPage" class="flex items-center px-3 h-8 ms-0 leading-tight bg-blue-500 border border-e-0 rounded-r-lg hover:bg-blue-700 text-white font-bold disabled:dark:bg-blue-300" @click="onNextPage" :class="{'cursor-not-allowed': !canNextPage}">Next</button>
66
</div>
77
</template>
88

99
<script>
1010
export default {
1111
name: 'PaginationComponent',
12-
data(){
13-
return {
14-
currentPage: 0,
15-
}
16-
},
1712
computed: {
1813
page(){
1914
return this.currentPage + 1
@@ -26,23 +21,26 @@
2621
}
2722
},
2823
updated(){
29-
this.$emit('onPageChange',{
30-
page: this.currentPage
31-
})
24+
this.$emit('onPageChange',this.currentPage)
3225
},
3326
props:{
3427
pages: {
3528
type: Number,
3629
default: 0,
3730
required: true,
3831
},
32+
currentPage: {
33+
type: Number,
34+
default: 0,
35+
required: true
36+
}
3937
},
4038
methods: {
4139
onPreviousPage(){
42-
this.currentPage--
40+
this.$emit('update:current-page', this.currentPage-1)
4341
},
4442
onNextPage(){
45-
this.currentPage++
43+
this.$emit('update:current-page', this.currentPage+1)
4644
},
4745
}
4846
}

src/VuePdfEditor.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@
7878
{{ saving ? 'saving' : 'keep' }}
7979
</button>
8080

81-
<div v-if="pages.length" class="flex items-center gap-4">
82-
<Pagination :pages="pages.length" @onPageChange="onPageChange" />
83-
</div>
81+
<slot name="pagination" v-if="pages.length && showPagination" class="flex items-center gap-4" :pages="pages.length" :current-page="currentPage" :onPageChange="onPageChange">
82+
<Pagination :pages="pages.length" :current-page.sync="currentPage" @onPageChange="onPageChange" />
83+
</slot>
8484

8585
</div>
8686
<div v-if="addingDrawing">
@@ -232,6 +232,10 @@ export default {
232232
type: String,
233233
default: '100%',
234234
},
235+
showPagination:{
236+
type: Boolean,
237+
default: false
238+
},
235239
showChooseFileBtn: {
236240
type: Boolean,
237241
default: false,
@@ -682,7 +686,7 @@ export default {
682686
this.saving = false
683687
}
684688
},
685-
onPageChange({ page }){
689+
onPageChange(page){
686690
this.currentPage = page
687691
}
688692
}

0 commit comments

Comments
 (0)