1.0.16 • Published 2 years ago

@snappywc/pagination v1.0.16

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

<snappy-pagination>

An easy-to use pagination element. (1 kb)

Demo

npm.io

Installation

Option 1: As a package.

npm i @snappywc/pagination
import '@snappywc/pagination'

Option 2: In your markup.

<script type="module">
  import '//unpkg.com/@snappywc/pagination'
</script>

Usage

HTML

<snappy-pagination></snappy-pagination>

JavaScript

// 1: Create a function that will run when the page changes.
const fetchPhotos = (page) => {
  fetch(`https://picsum.photos/v2/list?page=${page}&limit=20`)
    .then((res) => res.json())
    .then((photos) => renderPhotos(photos));
};

// 2: Query your <snappy-pagination> element.
const pagination = document.querySelector("snappy-pagination");

// 3: Run the setup function with the desired options
pagination.setup({
  total: 50, // Number of pages available
  spread: 2, // Number of pages to show left/right of current page
})

// 4: Listen for the component's `page-changed` event
pagination.addEventListener("page-changed", (e) => {
  // 4.1 pass e.detail.page to your function
  fetchPhotos(e.detail.page);
});

fetchPhotos(1);

Customization

The default styles and part selectors for this element were carefully considered to be as minimal and un-opinionated as possible.

Parts

The following parts are available for styling.

namedescription
pageeach numbered page button
current-pagethe current page's button
prevthe previous page button
nextthe next page button

Example CSS

snappy-pagination::part(page) {
  color: red;
  font-weight: bold;
}

Slots

The following slots are available to customize the element's markup.

namedescriptiondefault
prevthe previous button's content
nextthe next button's content
ellipsisshown between pages...

Example HTML

<snappy-pagination total="50" range="2">
  <svg slot="prev" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
    <path d="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z" />
  </svg>
  <svg slot="next" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
    <path d="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z" />
  </svg>
</snappy-pagination>
1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.8

2 years ago