1.0.1 • Published 2 years ago

atomic-pagination v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Atomic Pagination

This package generates JavaScript objects for building pagination. Using the generated values, you can create your own pagination with modern web front-end frameworks such as React and Vue.

usage

install package

npm install atomic-pagination

example

Vue(3.x)

<script setup>
import { pagination } from 'atomic-pagination'
import { defineProps, defineEmits, computed } from 'vue'
const props = defineProps({
  current: Number,
  last: Number,
})
const paginationData = computed(() => pagination({
  current: props.current,
  last: props.last,
}))
</script>

<template>
  <ul>
    <li v-if="paginationData.previous">
      <router-link :to="`/?page=${paginationData.previous}`">previous</router-link>
    </li>
    <li v-for="button in paginationData.buttons">
      <router-link :to="`/?page=${button.page}`">{{ button.page }}</router-link>
    </li>
    <li v-if="paginationData.next">
      <router-link :to="`/?page=${paginationData.next}`">next</router-link>
    </li>
  </ul>
</template>

API

pagination()

settingrequiredtypedescription
currentonumbernumber of current page
lastonumbernumber of last page
first-numbernumber of first page
rangeDisplayed-numbernumber of buttons displayed
hasFirstAndLast-booleanalways display the first and last number of buttons or not (must be an odd number)
hasEllipsis-booleandisplay ellipsis(...) when numbers are not next to each other or not

Contributing

Contributions are welcome. Feel free to send a PR.

# development
pnpm i
pnpm dev
1.0.1

2 years ago

1.0.0

2 years ago