npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vueginate

v1.1.2

Published

A simple pagination component for Vue 3

Downloads

341

Readme

GitHub release (latest SemVer) npm tests GitHub

Vueginate

Pagination component for Vue 3

Vueginate is a simple pagination component for Vue 3 applications. It includes out-of-the-box component variants for some of the most popular CSS Frameworks, such as Tailwind CSS, Bootstrap (4 and 5) and Bulma.

Demo

Try it on StackBlitz

Installation

# or `yarn add vueginate` | `npm install vueginate`
pnpm add vueginate

Basic usage

Import the component

Import the component and use it in your template.

<script setup>
  import { reactive } from 'vue'
  import { Vueginate } from 'vueginate'

  const data = reactive({
    totalItems: 86,
    currentPage: 9,
    itemsPerPage: 5,
  })
</script>

<template>
  <Vueginate
    :total-items="data.totalItems"
    :current-page="data.currentPage"
    :items-per-page="data.itemsPerPage"
  />
</template>
<nav aria-label="Page navigation">
  <ul class="vueginate-container">
    <li>
      <a class="vg-item vg-arrow" href="#">
        <span class="sr-only">Prev Page</span>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
          <path
            fill-rule="evenodd"
            d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"
            clip-rule="evenodd"
          />
        </svg>
      </a>
    </li>
    <li>
      <a class="vg-item vg-page" href="#">1</a>
    </li>
    <li>
      <span class="vg-item vg-disabled">…</span>
    </li>
    <li>
      <a class="vg-item vg-page" href="#">7</a>
    </li>
    <li>
      <a class="vg-item vg-page" href="#">8</a>
    </li>
    <li>
      <span class="vg-item vg-active" aria-current="page">9</span>
    </li>
    <li>
      <a class="vg-item vg-page" href="#">10</a>
    </li>
    <li>
      <a class="vg-item vg-page" href="#">11</a>
    </li>
    <li>
      <span class="vg-item vg-disabled">…</span>
    </li>
    <li>
      <a class="vg-item vg-page" href="#">18</a>
    </li>
    <li>
      <a class="vg-item vg-arrow" href="#">
        <span class="sr-only">Next Page</span>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
          <path
            fill-rule="evenodd"
            d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z"
            clip-rule="evenodd"
          />
        </svg>
      </a>
    </li>
  </ul>
</nav>

Events

Vueginate triggers a pageChange event, passing a number parameter with the new page, every time the page changes.

<script setup>
  // ...
  function updateData(page: number) {
    data.currentPage = page
  }
</script>

<template>
  <Vueginate
    :total-items="data.totalItems"
    :current-page="data.currentPage"
    :items-per-page="data.itemsPerPage"
    @page-change="updateData"
  />
</template>

Styling your component

Using default styles

Vueginate includes a default styles you can import inside your script:

<script setup>
  import 'vueginate/css/vueginate.css'
</script>

or from your style:

<style>
  /* or `@import 'vueginate/css/vueginate.css';` */
  @import 'vueginate';
</style>

Custom styles

Or you can style your component based in the classes it provides:

  • vueginate-container: pagination container ul
  • vg-item: every item in the list
  • vg-page: any item that is not ..., previous/next buttons, or the current page
  • vg-active: current page
  • vg-arrow: previous/next button
  • vg-disabled: used for ... items and for previous button (when currentPage === 1) and next button (when currentPage === totalPages)

All classes are applied to the a (or span if disabled or active) element inside the li

Using with CSS Frameworks

Vueginate includes component variants for Tailwind, Bootstrap and Bulma. You can use them importing their respective component:

<script setup>
  import { VueginateTailwind } from 'vueginate'
  import { VueginateBootstrap } from 'vueginate'
  import { VueginateBulma } from 'vueginate'

  // ...
</script>

<template>
  <VueginateTailwind
    :total-items="data.totalItems"
    :current-page="data.currentPage"
    :items-per-page="data.itemsPerPage"
  />

  <VueginateBootstrap
    :total-items="data.totalItems"
    :current-page="data.currentPage"
    :items-per-page="data.itemsPerPage"
  />

  <VueginateBulma
    :total-items="data.totalItems"
    :current-page="data.currentPage"
    :items-per-page="data.itemsPerPage"
  />
</template>

Roadmap

  • [ ] Documentation
  • [x] Support to be able to change the default ul container to div
  • [x] Support to have a fixed size for the component

License

MIT