From 52f3c97299bd7341a13f50fe840ee8317413a016 Mon Sep 17 00:00:00 2001 From: gassio Date: Thu, 7 Sep 2023 13:33:25 +0300 Subject: [PATCH] Adds page change event Adds first and last pagination items --- docs/components/pagination.md | 6 ++- .../pagination/examples/PaginationExample.vue | 6 ++- src/components/Pagination/Pagination.vue | 41 +++++++++++++++++-- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/docs/components/pagination.md b/docs/components/pagination.md index 0e4b50b2..425a5f04 100644 --- a/docs/components/pagination.md +++ b/docs/components/pagination.md @@ -16,9 +16,13 @@ import { Pagination } from 'flowbite-vue' import { ref } from 'vue' const currentPage = ref(1) + +const handlePageChange = (page: number) => { + console.log('page changed', page) +} ``` diff --git a/docs/components/pagination/examples/PaginationExample.vue b/docs/components/pagination/examples/PaginationExample.vue index b1322dbb..2aa41667 100644 --- a/docs/components/pagination/examples/PaginationExample.vue +++ b/docs/components/pagination/examples/PaginationExample.vue @@ -1,6 +1,6 @@ diff --git a/src/components/Pagination/Pagination.vue b/src/components/Pagination/Pagination.vue index 3c255265..0f6aa691 100644 --- a/src/components/Pagination/Pagination.vue +++ b/src/components/Pagination/Pagination.vue @@ -9,11 +9,20 @@ {{ computedTotalItems }} @@ -50,7 +68,7 @@ import { computed } from 'vue' import type { PropType } from 'vue' import type { PaginationLayout } from '@/components/Pagination/types' -const emit = defineEmits(['update:modelValue']) +const emit = defineEmits(['update:modelValue', 'page-changed']) const props = defineProps({ modelValue: { @@ -93,12 +111,15 @@ const props = defineProps({ const setPage = (index: number) => { emit('update:modelValue', index) + emit('page-changed', index); } const decreasePage = () => { emit('update:modelValue', props.modelValue - 1) + emit('page-changed', props.modelValue - 1); } const increasePage = () => { emit('update:modelValue', props.modelValue + 1) + emit('page-changed', props.modelValue + 1); } const computedTotalPages = computed(() => { @@ -159,4 +180,18 @@ const computedTotalItems = computed(() => { if (props.totalItems) return props.totalItems return computedTotalPages.value * props.perPage }) + +const isFirstPage = computed(() => props.modelValue === 1); +const isLastPage = computed(() => props.modelValue === computedTotalPages.value); + +const goToFirstPage = () => { + emit('update:modelValue', 1); + emit('page-changed', 1); +} + +const goToLastPage = () => { + const lastPage = computedTotalPages.value; + emit('update:modelValue', lastPage); + emit('page-changed', lastPage); +}