This is a pagination component for Vue.js 3+.

Loading component...

Installation

Yarn
yarn add @vlalg-nimbus/nb-pagination
NPM
npm install @vlalg-nimbus/nb-pagination

Usage

Vue 3
import { createApp } from 'vue'
import App from './App.vue'

import NbPaginationComponents from '@vlalg-nimbus/nb-pagination'
import "@vlalg-nimbus/nb-pagination/dist/style.css";

const app = createApp(App)
app.use(NbPaginationComponents)
app.mount('#app')
Nuxt 3
import NbPaginationComponents from '@vlalg-nimbus/nb-pagination'
import "@vlalg-nimbus/nb-pagination/dist/style.css";

export default defineNuxtPlugin(context => {
  context.vueApp.use(NbPaginationComponents)
})

To use, simply call the component, in this case it will be NbPagination or nb-pagination.

Mode 1
<template>
  <NbPagination 
    nb-id="pagination-1"
    v-model="currentPage"
    :total-pages="12"
  />
</template>
Mode 2
<template>
  <nb-pagination 
    nb-id="pagination-1"
    v-model="currentPage"
    :total-pages="12"
  />
</template>
Mode 3
<template>
  <nb-pagination 
    nb-id="pagination-1"
    v-model="currentPage"
    :total-pages="12"
  ></nb-pagination>
</template>

Preview & Playground

Select the component you want to edit/test

Loading Sandbox...

Props

Items with an (*) mean they are required

nameValue typeDefaultDescription
nbId (*)StringSets the id attribute to differentiate from other components
modelValue (*)NumberCurrent page number (v-model)
totalPages (*)NumberTotal number of pages
gapNumber12Gap between pagination and "Go to" section in pixels
gapGoToNumber9Gap between elements in "Go to" section in pixels
fontFamilyString"'Lato', sans-serif"Font family for general buttons and elements
fontSizeString'1.1em'Font size for general buttons and elements
fontWeightNumber400Font weight for general buttons and elements
fontFamilyTextString"'Lato', sans-serif"Font family for text elements (e.g., "Go to" label)
fontSizeTextString'1.2em'Font size for text elements
fontWeightTextNumber400Font weight for text elements
fontFamilyIconString"'Lato', sans-serif"Font family for navigation icons (‹‹, ‹, ›, ››)
fontSizeIconString'1.4em'Font size for navigation icons
fontWeightIconNumber400Font weight for navigation icons
useEllipsisBooleantrueEnables/disables ellipsis ("...") when there are many pages
animatedBooleantrueEnables animation style similar to Instagram/Reels when pages change
maxVisibleNumber5Maximum number of visible page number buttons in the center region
showFirstLastBooleantrueShows first and last page buttons when ellipsis is active
showNumberButtonsBooleantrueShows page number buttons
showSlimTextBooleanfalseShows a slim text display (e.g., "1/12") instead of number buttons
showButtonFirstBooleantrueShows the "first page" button (‹‹)
showButtonPreviewBooleantrueShows the "previous page" button (‹)
showButtonNextBooleantrueShows the "next page" button (›)
showButtonLastBooleantrueShows the "last page" button (››)
gapButtonsNumber4Gap between navigation buttons in pixels
gapNumbersNumber4Gap between page number buttons in pixels
spacingNumbersNumber8Horizontal spacing (left and right) for page number buttons in pixels
buttonBorderRadiusNumber0Border radius for buttons in rem units
showGoToBooleanfalseShows the "Go to" section (input or select)
goToTextString'Go to'Text label for the "Go to" section
goToTypeString'input'Type of "Go to" control. Accepts input and select
goToInputWidthNumber40Width of the "Go to" input in pixels
goToSelectWidthNumber60Width of the "Go to" select in pixels
showGoToButtonBooleanfalseShows the "Go" button next to the input
goToTextMarginString'0 8px 0 0'Margin for the "Go to" text label
disabledBooleanfalseDisables the entire pagination component
themeString'light'Defines the theme. Accepts light and dark
hasBorderBooleanfalseEnables borders on buttons
lightBgColorString'#eeeeee'Background color for buttons in light theme
lightBgColorHoverString'#eaeaea'Background color for buttons on hover in light theme
lightBorderColorString'#d0d0d0'Border color for buttons in light theme
lightTextColorString'#000000'Text color for buttons in light theme
lightTextColorHoverStringnullText color for buttons on hover in light theme. If null, uses lightTextColor
lightActiveBgColorString'#e0e0e0'Background color for active page button in light theme
lightActiveTextColorString'#000000'Text color for active page button in light theme
lightEllipsisColorStringnullColor for ellipsis ("...") in light theme. If null, uses lightActiveBgColor
lightEllipsisOpacityNumber1Opacity for ellipsis in light theme (0-1)
lightDisabledOpacityNumber0.4Opacity for disabled buttons in light theme (0-1)
darkBgColorString'#353734'Background color for buttons in dark theme
darkBgColorHoverString'#272936'Background color for buttons on hover in dark theme
darkBorderColorString'#555555'Border color for buttons in dark theme
darkTextColorString'#ffffff'Text color for buttons in dark theme
darkTextColorHoverStringnullText color for buttons on hover in dark theme. If null, uses darkTextColor
darkActiveBgColorString'#555555'Background color for active page button in dark theme
darkActiveTextColorString'#ffffff'Text color for active page button in dark theme
darkEllipsisColorStringnullColor for ellipsis ("...") in dark theme. If null, uses darkActiveBgColor
darkEllipsisOpacityNumber1Opacity for ellipsis in dark theme (0-1)
darkDisabledOpacityNumber0.4Opacity for disabled buttons in dark theme (0-1)
lightGoToButtonBgColorStringnullBackground color for "Go" button in light theme. If null, uses lightBgColor
lightGoToButtonTextColorStringnullText color for "Go" button in light theme. If null, uses lightTextColor
lightGoToButtonBgColorHoverStringnullBackground color for "Go" button on hover in light theme. If null, uses lightBgColorHover
lightGoToButtonTextColorHoverStringnullText color for "Go" button on hover in light theme. If null, uses lightGoToButtonTextColor
darkGoToButtonBgColorStringnullBackground color for "Go" button in dark theme. If null, uses darkBgColor
darkGoToButtonTextColorStringnullText color for "Go" button in dark theme. If null, uses darkTextColor
darkGoToButtonBgColorHoverStringnullBackground color for "Go" button on hover in dark theme. If null, uses darkBgColorHover
darkGoToButtonTextColorHoverStringnullText color for "Go" button on hover in dark theme. If null, uses darkGoToButtonTextColor
lightGoToTextColorString'#000000'Text color for "Go to" label in light theme
darkGoToTextColorString'#000000'Text color for "Go to" label in dark theme

Events

update:modelValue

Fired when the current page changes (required for v-model binding).

Returns:

  • Number - The new page number

Example:

{
  // Emitted value: 5 (when user navigates to page 5)
}

changed

Fired when the current page changes (alternative to update:modelValue).

Returns:

  • Number - The new page number

Example:

{
  // Emitted value: 5 (when user navigates to page 5)
}

page-changed

Fired when the current page changes, providing detailed information about the change.

Returns:

{
  previousPage: Number,    // Previous page number
  currentPage: Number      // New page number
}

Example:

{
  previousPage: 3,
  currentPage: 5
}

go-to-input

Fired when the user types in the "Go to" input field.

Returns:

{
  value: String,           // Numeric value (cleaned, only digits)
  rawValue: String         // Original value typed by user
}

Example:

{
  value: "12",             // Cleaned numeric value
  rawValue: "12a"          // Original input (non-numeric chars removed)
}

invalid-page

Fired when the user attempts to navigate to an invalid page (outside the valid range).

Returns:

{
  page: Number,            // The invalid page number attempted
  min: Number,             // Minimum valid page (always 1)
  max: Number              // Maximum valid page (totalPages)
}

Example:

{
  page: 15,                // User tried to go to page 15
  min: 1,                  // Minimum valid page
  max: 12                  // Maximum valid page
}

first-page

Fired when the user navigates to the first page.

Returns:

  • Number - The current page number (always 1)

Example:

{
  // Emitted value: 1 (when user navigates to first page)
}

last-page

Fired when the user navigates to the last page.

Returns:

  • Number - The current page number (equals totalPages)

Example:

{
  // Emitted value: 12 (when user navigates to last page, assuming totalPages is 12)
}

Slots

slim-text

Custom slot for displaying custom text when showSlimText is true.

Slot Props:

{
  currentPage: Number,     // Current page number
  totalPages: Number       // Total number of pages
}

Example:

<template #slim-text="{ infos }">
  <span>Página {{ infos.currentPage }}/{{ infos.totalPages }}</span>
</template>

go-to-select

Custom slot for the "Go to" select dropdown when goToType="select".

Slot Props:

{
  currentPage: Number,           // Current page number
  totalPages: Number,            // Total number of pages
  disabled: Boolean,             // Whether the component is disabled
  goToChangedSelect: Function    // Function to call when selection changes
}

Example:

<template #go-to-select="{ infos }">
  <select @change="infos.goToChangedSelect" :disabled="infos.disabled">
    <option
      v-for="i in infos.totalPages"
      :key="i"
      :value="i"
      :selected="i === infos.currentPage"
    >
      {{ i }}
    </option>
  </select>
  <span> de {{ infos.totalPages }}</span>
</template>

Examples

Basic Usage

<template>
  <NbPagination
    nb-id="pagination-1"
    v-model="currentPage"
    :total-pages="12"
  />
</template>

<script setup>
import { ref } from 'vue'

const currentPage = ref(1)
</script>

With Custom Theme

<template>
  <NbPagination
    nb-id="pagination-2"
    v-model="currentPage"
    :total-pages="12"
    theme="dark"
  />
</template>

With "Go to" Input

<template>
  <NbPagination
    nb-id="pagination-3"
    v-model="currentPage"
    :total-pages="12"
    :show-go-to="true"
    :show-go-to-button="true"
  />
</template>

With Custom Colors

<template>
  <NbPagination
    nb-id="pagination-4"
    v-model="currentPage"
    :total-pages="12"
    theme="light"
    light-bg-color="#e3f2fd"
    light-active-bg-color="#1976d2"
    light-active-text-color="#ffffff"
    light-ellipsis-color="#1976d2"
  />
</template>

With Event Handlers

<template>
  <NbPagination
    nb-id="pagination-5"
    v-model="currentPage"
    :total-pages="12"
    @changed="handlePageChange"
    @page-changed="handlePageChanged"
    @go-to-input="handleGoToInput"
    @invalid-page="handleInvalidPage"
    @first-page="handleFirstPage"
    @last-page="handleLastPage"
  />
</template>

<script setup>
import { ref } from 'vue'

const currentPage = ref(1)

const handlePageChange = (page) => {
  console.log('Page changed to:', page)
}

const handlePageChanged = ({ previousPage, currentPage }) => {
  console.log(`Page changed from ${previousPage} to ${currentPage}`)
}

const handleGoToInput = ({ value, rawValue }) => {
  console.log('User typed:', value, 'Original:', rawValue)
}

const handleInvalidPage = ({ page, min, max }) => {
  console.warn(`Invalid page ${page}. Valid range: ${min}-${max}`)
}

const handleFirstPage = (page) => {
  console.log('Reached first page:', page)
}

const handleLastPage = (page) => {
  console.log('Reached last page:', page)
}
</script>

With Custom Slot

<template>
  <NbPagination
    nb-id="pagination-6"
    v-model="currentPage"
    :total-pages="12"
    :show-slim-text="true"
  >
    <template #slim-text="{ infos }">
      <span>Página {{ infos.currentPage }} de {{ infos.totalPages }}</span>
    </template>
  </NbPagination>
</template>

With Custom "Go to" Select

<template>
  <NbPagination
    nb-id="pagination-7"
    v-model="currentPage"
    :total-pages="12"
    :show-go-to="true"
    go-to-type="select"
  >
    <template #go-to-select="{ infos }">
      <select @change="infos.goToChangedSelect" :disabled="infos.disabled">
        <option
          v-for="i in infos.totalPages"
          :key="i"
          :value="i"
          :selected="i === infos.currentPage"
        >
          {{ i }}
        </option>
      </select>
      <span> de {{ infos.totalPages }}</span>
    </template>
  </NbPagination>
</template>