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

@cagov/ds-pagination

v2.0.4

Published

Pagination provides an easy way to navigate large ordered lists without lots of scrolling. It splits web content into numbered pages.

Downloads

273

Readme

Pagination

Pagination provides an easy way to navigate large ordered lists without lots of scrolling. It splits web content into numbered pages.

People can select a number to see another page. They can also select an arrow to move through pages.

Pagination always shows the first and last page in the series. It automatically shows links to previous and next pages in the series. Selecting a number or arrow shows new content without reloading the webpage.

When and how to use it

Use the component wherever a long list of content could benefit from paged navigation. If you have more than 10 items, use pagination.

Pagination works well with:

  • A list of announcements or press releases
  • Search results
  • A glossary

How not to use it

Do not use pagination:

  • To break up long pages of text
  • For content that is not in an ordered list (for example, by date or relevancy)
  • For a list of steps

Demo and sample markup

First, add the HTML.

<cagov-pagination data-current-page="5" data-total-pages="99"></cagov-pagination>

Next, register an event to respond to clicks.

const paginator = document.querySelector('cagov-pagination');

paginator.addEventListener('paginationClick', function (e) {
  alert(`You requested page ${e.detail}.`);
});

Specs

| Property | Value | | ------------ | --------------------- | | Machine name | ds-pagination | | JavaScript | yes | | SCSS | ./src/scss/index.scss |

Project installation

The instructions assume familiarity with npm package management tool, modern JavaScript techniques, and Sass.

  1. npm i @cagov/ds-pagination
  2. Use import¹ or require to include the component’s JavaScript in your page or compiler.
  3. Add the sample markup to your HTML.
  4. Refer to the Content model section for notes on mapping your data to the sample markup.
  5. If directly importing, be sure to reference the js file at ./dist/index.js
  6. Connect pagination to content block

CDN installation

We recommend using a build system and bundling your JavaScript for faster performance. If you do not use a build system, you can include the code from our CDN with a script tag.

<script type="module" src="https://cdn.designsystem.webstandards.ca.gov/components/ds-pagination/v2.0.4/dist/index.js"></script>

Event registration

The component tracks the current page and triggers custom events on page clicks. You can subscribe to events on this element to watch for clicks. This element does not modify outside content, responding to events and changing body content as desired is left up to your application logic. The following event format is sent on click:

new CustomEvent("paginationClick", { detail: currentPage, })

Here is an example of subscribing to that event, then taking actions to retrieve new page content based on the page number clicked and changing the url to reflect the new state

  • The function writePostsHTML would be your own function that makes whatever call your application needs to retrieve the content for the page in question and write it into the DOM
document.querySelector('cagov-pagination').addEventListener('paginationClick', function (e) { 
  writePostsHTML(e.detail);
  history.replaceState({page: 3}, `${document.title} page ${e.detail}`, `?page=${e.detail}`)
  }, false);

CSS variables

The following CSS variables are used in this component:

  • --s-sm
  • --border-1
  • --radius-2
  • --primary-700
  • --primary-900
  • --accent2-500
  • --white
  • --gray-50
  • --gray-100

All CSS variables define their own fallback value so you do not have to use additional CSS unless you want to change them. You may define your own value for the variable by adding your own style rules. Here is an example defining the global hex value for a CSS variable named “--primary-700”:

:root {
  --primary-700: #165ac2;
}

Accessibility

Component-specific accessibility review

  • Make sure that each pagination link has appropriate aria-label.
  • make sure that pagination component is contained within nav tag and has aria-label="Pagination” added to it.

Standard accessibility review

As a component in Alpha status, this component must pass the following accessibility reviews every time a new version is published:

  • Tested with the axe accessibility tool and passes all automated WCAG Level AA checks
  • Reviewed with the VoiceOver screen reader on desktop
  • Verified keyboard navigation and that all actionable elements of the component are reachable via keyboard commands only
  • Reviewed component layout on a variety of screen sizes

Progressive enhancement

This component uses a custom element defined in JavaScript in addition to HTML and CSS. Edge, Firefox, Safari, and Chrome support custom elements. If the JavaScript for this component is not delivered or supported, the component will not display. This component does not currently perform the desired progressive enhancement because it is critical to site interaction. It uses CSS variables to inherit design token values. Token definitions are not required because these style rules provide fallback values.

Content model

This component accepts data attributes for the number of pages and current page. These changes are monitored and the component re-renders if these attributes change:

| Name | Attribute name | Data type | Field type | | ------------ | ----------------- | --------- | ---------------------- | | Current page | data-current-page | string | Integer (default is 1) | | Total pages | data-total-pages | string | Integer (default is 1) |

It also accepts optional strings for all the text so it can be used in multiple languages:

| Name | Attribute name | Data type | Field type | | -------- | -------------- | --------- | ------------------------------- | | Previous | data-previous | string | Plain text (default is "<") | | Next | data-next | string | Plain text (default is ">") | | Page | data-page | string | Plain text (default is "Page") |

Contributor/developer documentation