1.0.2 • Published 6 years ago

vue-smatr-pagination v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

Vue-smart-pagination

A data pagination component that splits any data into pages and has many settings.

All data is stored in an array and can have any values.

Demo

img

Demo page

Installation

Install NPM package.

$ npm install vue-smart-pagination --save

Register the component globally in your main.js file.

import { PaginationControl, PaginationPage } from 'vue-smart-pagination'
Vue.component('PaginationControl', PaginationControl)
Vue.component('PaginationPage', PaginationPage)

Or register the component locally in your vue file.

import { PaginationControl, PaginationPage } from 'vue-smart-pagination'
components: {
    PaginationPage,
    PaginationControl
},

Usage

Vue-smart-pagination contains two main components:

PaginationPage - has content of the pages.

PaginationControl - has content controls.

Both components are registered globally after installing package.

Also we have props - :settings="settings” which has two main objects - PaginationControlSettings и PaginationPageSettings, also we have property - pageToChange.

PaginationControlSettings contains settings related to buttons, arrows, dots and the start page.

PaginationPageSettings contains settings related to the page, the spinner and animation of the content change.

pageToChange contains actual page, update after change page value.

Array arrayData serves to output data to the page and is required to fill.

Example:

<template>
  <div id="app">
    <pagination-page :settings="settings">
      <div slot="page" slot-scope="item">
        <div>{{item.originalEvent.data}}</div>
      </div>
    </pagination-page>
    <pagination-control :settings="settings" />
  </div>
</template>

<script>
import { PaginationControl, PaginationPage } from 'vue-smart-pagination'

export default {
  name: 'App',
  components: {
    PaginationPage,
    PaginationControl
  },
  data: function () {
    return {
      arrayData: [
        {
          data: 'Page № 1'
        },
        {
          data: 'Page № 2'
        },
        {
          data: 'Page № 3'
        },
      ]
    }
  },
  computed: {
    settings: function () {
      return {
        arrayData: this.arrayData
      }
    }
  }
}
</script>

Adding Data to a Component:

In the array arrayData we add data and output them to the <pagination-page>. When referring to an array of elements, specify the originalEvent property to display the current data. To display simple data, use <div>, and for components use <component>.

<div slot =" page "slot-scope =" item "> </ div> is required.

Example:

import testComponent from 'testComponent'

export default {
  components: {
    testComponent
  }
}
arrayData: [
  {
    data: 'apple',
    component: 'testComponent'
  }
]
<pagination-page :settings="settings">
  <div slot="page" slot-scope="item">
    <div>{{item.originalEvent.data}}</div>
    <components :is="item.originalEvent.component"></components>
  </div>
</pagination-page>

To display the pagination buttons, insert the pagination-control component into the template.

Example:

<pagination-control :settings="settings" />

Props

NameTypeAll valuesDefault valueDescription
PaginationControlSettings:
Buttons settings:
controlClassString--Common class to the parent block with pagination buttons.
controlStyleStringsquare, circle, defaultdefaultStyle of pagination buttons.
maxButtonsNumber-5The maximum number of pagination buttons on the page.
allpageButtonsStyle
backgroundString-#ffffffBackground color of buttons
borderColorString-#02C8F3Border color of buttons
colorString-#02C8F3Color of buttons
backgroundHoverString-#02C8F3Background color of buttons when hovering
borderColorHoverString-#02C8F3Border color of buttons when hovering
colorHoverString-#ffffffColor of buttons when hovering
fontFamilyString-AvenirFont family of buttons
currentPageButtonStyle
backgroundActiveString-#02C8F3Background color of active button
borderColorActiveString-#02C8F3Border color of active button
colorActiveString-#ffffffColor of active button
Arrows settings:
hideArrowsBooleantrue, falsefalseShow or hide the arrows of pagination.
arrowSwitchHideBooleantrue, falsefalseSwitches the mode of the arrows from disabled to full hiding.
arrowStyleStringstyleArrow-1, styleArrow-2, styleArrow-3styleArrow-2Styles icons of arrow.
arrowStyleColorString-#02C8F3Color of arrow.
arrowStyleColorHoverString-#ffffffColor of arrow when hovering.
Dots settings:
controlDotsStyleStringstyleDots-1, styleDots-2, styleDots-3styleDots-1Styles of dots.
controlDotsColorString-#02C8F3Color of dots.
pageStarted:Number-1Number of start page.
PaginationPageSettings:
Page settings:
pageClassString--Common class for all pages.
Spinner settings:
spinnerBooleantrue, falsefalseShow or hide loading spinner.
spinnerStyleStringspinnerStyle-1, spinnerStyle-2, spinnerStyle-3spinnerStyle-3Styles for loading spinner.
spinnerColorString-#ffffffColor of loading spinner.
Animations settings:
animationPageStringfade, slide, bounce, defaultdefaultAnimation when switching pages.

Methods

To call a custom method, when switching pages, in the <pagination-control /> component in the action callMethod, you must pass a user-defined function that is declared in the methods object.

Example:

<pagination-control @callMethod =" showText "/>
methods: {
  showText: function (e) {
    console.log (e)
  }
}

Browsers

Vue-smart-pagination has been successfully tested in browsers such as:

  • Chrome (66.0)
  • Safari (11.1)
  • Opera (52.0)
  • Firefox (59.0.2)
  • Edge (16)

License

MIT

Copyright (c) 2018 Private Enterprise "WebFriends"