Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

micropagination

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micropagination

Pagination component and composable to simplify pagination in vue3

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Micropagination

Pagination component and composable to simplify pagination in vue3

Getting started

You can install using any package manager

npm install --save micropagination

With yarn:

yarn add micropagination

With pnpm:

pnpm add micropagination

Then, you can import the component

import Micropagination from 'micropagination';

And use it in your project:

<template>
   <Micropagination @change="changePage" />
</template>

<script lang="ts" setup>
import Micropagination from 'micropagination';

const changePage = (page: number) => console.log('New page: ', page);
</script>

Props

NameTypeRequiredDefaultDescription
currentPagestringfalse1Current active page
perPagestringfalse10Items count for one page
totalnumberfalse100Total count of items

Events

NameDescription
changeHandle click

Slots:

<template>
  <Micropagination
    @change="handleChange"
    currentPage="2"
    perPage="5"
    :total="200"
  >
    <template v-slot:prev-button>
      <div>prev</div>
    </template>
    <template v-slot:next-button>
      <div>next</div>
    </template>
  </Micropagination>
</template>

css default variables

NameValue
--primary-color#42b984
--pg-item-width40px
--pg-item-height40px
--pg-item-border-radius50%
--pg-item-distance5px

Composables

This package also provides a usePagination composable to handle the pagination, and here show you how to use it:

<template>
  <ul v-if="data && data.length">
    <li v-for="item in data" :key="item.id">
      <p>{{ item.content }}</p>
    </li>
  </ul>
  <hr />
  <Micropagination
    :current-page="page"
    :per-page="perPage"
    :total="total"
    @change="changePage"
    v-if="total"
  />
</template>

<script setup lang="ts">
import Micropagination, { usePagination, type CallbackParams } from "micropagination";
import { unref } from "vue";

type Data = {
  id: string;
  content: string;
};

// Receive a callback and a default params object
const { data, page, total, perPage, changePage } = usePagination<Data>(
  paginationCallback,
  {
    perPage: 5,
  }
);

async function paginationCallback(params: CallbackParams) {
  // unref to avoid the ref wrapper
  const page = unref(params.page);
  const pageSize = unref(params.perPage);

  // get the api result passing the pagination parameters
  const result = await api({ page, pageSize });
   
  // change the reactive variable values
  return {
    total: result.pagination.total,
    pageCount: result.pagination.pageCount,
    data: result.data,
  };
}
</script>

Author

  • David Arenas @dave136

LICENSE

This project is licensed under the MIT License

FAQs

Package last updated on 26 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc