|
| 1 | +# Primer Pagination |
| 2 | + |
| 3 | +[](https://www.npmjs.org/package/primer-pagination) |
| 4 | +[](https://travis-ci.org/primer/primer) |
| 5 | + |
| 6 | +> Pagination component for applying button styles to a connected set of links that go to related pages |
| 7 | +
|
| 8 | +This repository is a module of the full [primer][primer] repository. |
| 9 | + |
| 10 | +## Install |
| 11 | + |
| 12 | +This repository is distributed with [npm]. After [installing npm][install-npm], you can install `primer-pagination` with this command. |
| 13 | + |
| 14 | +``` |
| 15 | +$ npm install --save primer-pagination |
| 16 | +``` |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +The source files included are written in [Sass][sass] (SCSS) You can simply point your sass `include-path` at your `node_modules` directory and import it like this. |
| 21 | + |
| 22 | +```scss |
| 23 | +@import "primer-pagination/index.scss"; |
| 24 | +``` |
| 25 | + |
| 26 | +You can also import specific portions of the module by importing those partials from the `/lib/` folder. _Make sure you import any requirements along with the modules._ |
| 27 | + |
| 28 | +## Build |
| 29 | + |
| 30 | +For a compiled **CSS** version of this module, an npm script is included that will output a css version to `build/build.css` The built css file is also included in the npm package: |
| 31 | + |
| 32 | +``` |
| 33 | +$ npm run build |
| 34 | +``` |
| 35 | + |
| 36 | +## Documentation |
| 37 | + |
| 38 | +<!-- %docs |
| 39 | +title: Pagination |
| 40 | +status: New Release |
| 41 | +--> |
| 42 | + |
| 43 | +Use the pagination component to apply button styles to a connected set of links that go to related pages (for example, previous, next, or page numbers). |
| 44 | + |
| 45 | +{:toc} |
| 46 | + |
| 47 | +## Previous/next pagination |
| 48 | + |
| 49 | +You can make a very simple pagination container with just the Previous and Next buttons. Add the class `disabled` to the `Previous` button if there isn't a preceding page, or to the `Next` button if there isn't a succeeding page. |
| 50 | + |
| 51 | +```html |
| 52 | +<nav class="paginate-container" aria-label="Pagination"> |
| 53 | + <div class="pagination"> |
| 54 | + <span class="previous_page disabled">Previous</span> |
| 55 | + <a class="next_page" rel="next" href="#url" aria-label="Next Page">Next</a> |
| 56 | + </div> |
| 57 | +</nav> |
| 58 | +``` |
| 59 | + |
| 60 | +## Numbered pagination |
| 61 | + |
| 62 | +For pagination across multiple pages, make sure it's clear to the user where they are in a set of pages. |
| 63 | + |
| 64 | +To do this, add anchor links to the `pagination` element. Previous and Next buttons should always be present. Add the class `disabled` to the Previous button if you're on the first page. Apply the class `current` to the current numbered page. |
| 65 | + |
| 66 | +As always, make sure to include the appropriate `aria` attributes to make the element accessible. |
| 67 | + |
| 68 | +- Add `aria-label="Pagination"` to the the `paginate-container` element. |
| 69 | +- Add `aria-current="true"` to the current page marker. |
| 70 | +- Add `aria-label="Page X"` to each anchor link. |
| 71 | + |
| 72 | +```html |
| 73 | +<nav class="paginate-container" aria-label="Pagination"> |
| 74 | + <div class="pagination"> |
| 75 | + <span class="previous_page disabled">Previous</span> |
| 76 | + <em class="current selected" aria-current="true">1</em> |
| 77 | + <a href="#url" aria-label="Page 2">2</a> |
| 78 | + <a href="#url" aria-label="Page 3">3</a> |
| 79 | + <span class="gap">…</span> |
| 80 | + <a href="#url" aria-label="Page 8">8</a> |
| 81 | + <a href="#url" aria-label="Page 9">9</a> |
| 82 | + <a href="#url" aria-label="Page 10">10</a> |
| 83 | + <a class="next_page" rel="next" href="#url" aria-label="Next Page">Next</a> |
| 84 | + </div> |
| 85 | +</nav> |
| 86 | +``` |
| 87 | + |
| 88 | +<!-- %enddocs --> |
0 commit comments