Pagination github location npm version

Variants


Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (exampe), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);",
  "pagination__list": [
    {
      "page_number": "Previous",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--previous-page"
    },
    {
      "page_number": -10,
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-back"
    },
    {
      "page_number": 1,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 2,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": "..."
    },
    {
      "page_number": 17,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 18,
      "item_modifier": "vf-pagination__item--is-active"
    },
    {
      "page_number": 19,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": "..."
    },
    {
      "page_number": 91,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 92,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 10,
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-forward"
    },
    {
      "page_number": "Next",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--next-page"
    }
  ]
}
 %}
{% include "../path_to/vf-pagination/vf-pagination.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-pagination', {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);",
  "pagination__list": [
    {
      "page_number": "Previous",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--previous-page"
    },
    {
      "page_number": -10,
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-back"
    },
    {
      "page_number": 1,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 2,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": "..."
    },
    {
      "page_number": 17,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 18,
      "item_modifier": "vf-pagination__item--is-active"
    },
    {
      "page_number": 19,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": "..."
    },
    {
      "page_number": 91,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 92,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 10,
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-forward"
    },
    {
      "page_number": "Next",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--next-page"
    }
  ]
} %}
                
HTML
<nav class="vf-pagination" aria-label="Pagination">
  <ul class="vf-pagination__list">
    <li class="vf-pagination__item vf-pagination__item--previous-page">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        Previous<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--jump-back">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        -10<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        1<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        2<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <span class="vf-pagination__label">...</span>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        17<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--is-active">
      <span class="vf-pagination__label" aria-current="page">
        <span class="vf-u-sr-only">Page </span>18
      </span>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        19<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <span class="vf-pagination__label">...</span>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        91<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        92<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--jump-forward">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        10<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--next-page">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        Next<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
  </ul>
</nav>
              
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (exampe), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);",
  "pagination__list": [
    {
      "page_number": "Previous",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--previous-page"
    },
    {
      "page_number": "Next",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--next-page"
    }
  ]
}
 %}
{% include "../path_to/vf-pagination/vf-pagination.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-pagination', {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);",
  "pagination__list": [
    {
      "page_number": "Previous",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--previous-page"
    },
    {
      "page_number": "Next",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--next-page"
    }
  ]
} %}
                
HTML
<nav class="vf-pagination" aria-label="Pagination">
  <ul class="vf-pagination__list">
    <li class="vf-pagination__item vf-pagination__item--previous-page">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        Previous<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--next-page">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        Next<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
  </ul>
</nav>
              
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (exampe), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);",
  "pagination__list": [
    {
      "page_number": "First",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-back"
    },
    {
      "page_number": "..."
    },
    {
      "page_number": 6,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 7,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 8,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 9,
      "item_modifier": "vf-pagination__item--is-active"
    },
    {
      "page_number": 10,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": "..."
    },
    {
      "page_number": "Last",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-forward"
    }
  ]
}
 %}
{% include "../path_to/vf-pagination/vf-pagination.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-pagination', {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);",
  "pagination__list": [
    {
      "page_number": "First",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-back"
    },
    {
      "page_number": "..."
    },
    {
      "page_number": 6,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 7,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 8,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 9,
      "item_modifier": "vf-pagination__item--is-active"
    },
    {
      "page_number": 10,
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": "..."
    },
    {
      "page_number": "Last",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-forward"
    }
  ]
} %}
                
HTML
<nav class="vf-pagination" aria-label="Pagination">
  <ul class="vf-pagination__list">
    <li class="vf-pagination__item vf-pagination__item--jump-back">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        First<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <span class="vf-pagination__label">...</span>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        6<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        7<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        8<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--is-active">
      <span class="vf-pagination__label" aria-current="page">
        <span class="vf-u-sr-only">Page </span>9
      </span>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        10<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <span class="vf-pagination__label">...</span>
    </li>
    <li class="vf-pagination__item vf-pagination__item--jump-forward">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        Last<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
  </ul>
</nav>
              
Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (exampe), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);",
  "pagination__list": [
    {
      "page_number": "First (1)",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-back"
    },
    {
      "page_number": "Previous (5)",
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 6,
      "item_modifier": "vf-pagination__item--is-active"
    },
    {
      "page_number": "Next (7)",
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": "Last (88)",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-forward"
    }
  ]
}
 %}
{% include "../path_to/vf-pagination/vf-pagination.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-pagination', {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);",
  "pagination__list": [
    {
      "page_number": "First (1)",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-back"
    },
    {
      "page_number": "Previous (5)",
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": 6,
      "item_modifier": "vf-pagination__item--is-active"
    },
    {
      "page_number": "Next (7)",
      "page_href": "JavaScript:Void(0);"
    },
    {
      "page_number": "Last (88)",
      "page_href": "JavaScript:Void(0);",
      "item_modifier": "vf-pagination__item--jump-forward"
    }
  ]
} %}
                
HTML
<nav class="vf-pagination" aria-label="Pagination">
  <ul class="vf-pagination__list">
    <li class="vf-pagination__item vf-pagination__item--jump-back">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        First (1)<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        Previous (5)<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--is-active">
      <span class="vf-pagination__label" aria-current="page">
        <span class="vf-u-sr-only">Page </span>6
      </span>
    </li>
    <li class="vf-pagination__item">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        Next (7)<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--jump-forward">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        Last (88)<span class="vf-u-sr-only"> page</span>
      </a>
    </li>
  </ul>
</nav>
              

Generally reserved for deep and enganging databses of infromation, ulitmately you should try to avoid needing such a complex pager and mitigate through search and faceting filters.

Nunjucks syntax

Depending on your environment you'll want to use render or include. As a rule of thumb: server-side use include, precompiled browser use render. If you're using vf-eleventy you should use include.

Using include

You'll need to pass a context object from your code or Yaml file (exampe), as well as the path to the Nunjucks template. Nunjucks' include is an abstraction of render and provides some additional portability.


{% set context fromYourYamlFile %}
- or -
{% set context = {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);"
}
 %}
{% include "../path_to/vf-pagination/vf-pagination.njk" %}
                

Using render

This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include is not be available.

{% render '@vf-pagination', {
  "component-type": "block",
  "previous_text": "Previous",
  "previous_url": "JavaScript:Void(0);",
  "next_text": "Next",
  "next_url": "JavaScript:Void(0);",
  "jumpBack_text": -10,
  "jumpBack_url": "JavaScript:Void(0);",
  "jumpForward_text": 10,
  "jumpForward_url": "JavaScript:Void(0);"
} %}
                
HTML
<p class="vf-text--body vf-text-body--3">
  Generally reserved for deep and enganging databses of infromation,
  ulitmately you should try to avoid needing such a complex pager and
  mitigate through search and faceting filters.
</p>

<nav class="vf-pagination" aria-label="Pagination">
  <ul class="vf-pagination__list">
    <li class="vf-pagination__item vf-pagination__item--previous-page">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        Previous<span class="vf-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--jump-back">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        -10<span class="vf-sr-only"> page</span>
      </a>
    </li>
    <li class="vf-pagination__item">
      <a href="#" class="vf-pagination__link">
        <span class="vf-sr-only">Page </span>1
      </a>
    </li>
    <li class="vf-pagination__item">
      <a href="#" class="vf-pagination__link">
        <span class="vf-sr-only">Page </span>2
      </a>
    </li>
    <li class="vf-pagination__item">
      <span class="vf-pagination__label">
        ...
      </span>
    </li>
    <li class="vf-pagination__item">
      <a href="#" class="vf-pagination__link">
        <span class="vf-sr-only">Page </span>17
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--is-active">
      <span class="vf-pagination__label" aria-current="page">
        <span class="vf-sr-only">Page </span>18
      </span>
    </li>
    <li class="vf-pagination__item">
      <a href="#" class="vf-pagination__link">
        <span class="vf-sr-only">Page </span>19
      </a>
    </li>
    <li class="vf-pagination__item">
      <span class="vf-pagination__label">
        ...
      </span>
    </li>
    <li class="vf-pagination__item">
      <a href="#" class="vf-pagination__link">
        <span class="vf-sr-only">Page </span>91
      </a>
    </li>
    <li class="vf-pagination__item">
      <a href="#" class="vf-pagination__link">
        <span class="vf-sr-only">Page </span>92
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--jump-forward">
      <a href="JavaScript:Void(0);" class="vf-pagination__link">
        10<span class="vf-sr-only"> pages</span>
      </a>
    </li>
    <li class="vf-pagination__item vf-pagination__item--next-page">
      <a href="#" class="vf-pagination__link">
        Next<span class="vf-sr-only"> page</span>
      </a>
    </li>

    <li class="vf-pagination__item vf-pagination__item--pages-per">

      <div class="vf-form__item--inline">
        <label class="vf-form__label" for="vf-form__select">Results per page</label>

        <select class="vf-form__select" id="vf-form__select">
          <option value="10" selected>10</option>
          <option value="20">20</option>
          <option value="30">30</option>
          <option value="40">40</option>
          <option value="50">50</option>
        </select>
      </div>
    </li>
  </ul>
</nav>
              
Installation info

This repository is distributed with npm. After installing npm and yarn, you can install with this command.

$ yarn add --dev @visual-framework/vf-pagination

Sass/CSS

The style files included are written in Sass. If you're using a VF-core project, you can import it like this:

@import "@visual-framework/vf-pagination/index.scss";

Make sure you import Sass requirements along with the modules. You can use a project boilerplate or the vf-sass-starter

Changelog

Changelog

1.0.23

  • small change to cards on homepage

1.0.18

  • dependency bump

1.0.17

  • dependency bump

1.0.16

  • dependency bump

1.0.13

  • dependency bump
  • adds roamap and consultation docs

1.0.12

  • design token documenation now lives in the component libary

1.0.7

  • adds updates blog

1.0.6

  • begin to make more pattern/boilerplate guidance
  • minor templating updates

1.0.5

  • dependency bump

1.0.4

  • uses vf-favicon
  • adds meta attributes

1.0.3

  • run vf-component-assets:everything on local dev
  • remove reference to removed /css/app.css

1.0.2

  • Add 404
  • Fix component CSS generation

1.0.1

  • Also generate per-component CSS with vf-css:generate-component-css

1.0.0

  • Initial release to be used with vf-core 2.2.0

Assets



File system location: components/vf-pagination

Find an issue on this page? Propose a change or discuss it.