0.2.2 • Published 4 years ago

default-pagination-vue v0.2.2

Weekly downloads
15
License
-
Repository
github
Last release
4 years ago

default-pagination-vue

Installation

Install the package

$ npm install default-pagination-vue

Register the component globally in the main.js

import DefaultPagination from 'default-pagination-vue';

const app = createApp(App);
app.component('default-pagination', DefaultPagination);

or inside a component

import DefaultPagination from 'default-pagination-vue';
export default {
  components: {
    DefaultPagination
  }
};

Simple example

<default-pagination
  v-model="current"
  :total-pages="20"
  :max-squares="10"
  no-first-last-icon
  not-inherit-font
  @page-click="handleClick"
/>
    handleClick({ newPage, totalPages, blurState, cancelChange, done }){}

Props (every Boolean prop is false by default)

Name                                       TypeDescription
total-pagesNumber1 by default
v-modelNumberWill set/get the current page. 1 by default
max-squaresNumberNumber of squares (all pages including the '...' buttons). 7 by default
no-first-last-iconBooleanRemoves the icon from 'first' and 'last' button
no-first-last-textBooleanRemoves the text from 'first' and 'last' button
no-first-lastBooleanRemoves 'first' and 'last' button
text-firstStringText for the 'first' button 'First' by default
text-lastStringText for the 'last' button 'Last' by default
no-prev-nextBooleanRemoves 'previous' and 'next' button
mode-simpleBooleanpagination without any '...'
mode-defaultBooleanpagination with '...' before and after the pages when it is necessary
mode-fancyBooleanpagination with '...' after at the first square and the first page always visible (same for the last), when it is necessary
primary-colorStringCSS color (text color mainly) #4c4c4c by default
secondary-colorStringCSS color (background page buttons mainly) white by default
shadow-colorStringCSS color #565656 by default
disabled-colorStringCSS color (text color of controller buttons when there is no previous or next page) #808080ad by default
colored-controllersBooleanControllers (first/prev/next/last) with the same color of font (primary-color) when they are enable
not-inherit-fontBooleanWill not inherit the font-family from your project, but the same as the examples 'Commissioner' font-family

'page-click' event

Name                                       TypeDescription
newPageNumberCurrent page
totalPagesNumberTotal pages
cancelChangeFunctionIn case an error happens during the http request for example, it will return to the previous page, recommended use inside '.catch'
blurStateFunctionuse it whenever you use 'cancelChange' in your code, it will blur the component and prevent the user click, the 'cancelChange' or 'done' can deblur the component
doneFunctionwill release the component, you can call inside the '.then' for example

Example

    handleClick({ newPage, totalPages, blurState, cancelChange, done }) {
      console.log(newPage, totalPages, blurState, cancelChange, done);
      blurState();
      setTimeout(() => cancelChange(), 500);
    }
    handleClick({ blurState, cancelChange, done }) {
      blurState();
      yourRequest().then(()=>{
        //your code here
        done();
      })
      .catch(err => {
        cancelChange();
        alert(err);
      });
    }

Slots (replace content)

Name                                       Description
firstContent inside 'first button'
lastContent inside 'last button'
previousContent inside 'previous button'
nextContent inside 'next button'

Example

<default-pagination v-model="current" :total-pages="10">
  <template #first> First one page </template>
  <template #last> Last one page <my-component /> </template>
  <template #previous> <my-own-icon /> </template>
</default-pagination>