@propellerads/pagination 3.1.5 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +89 -709
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/index.css +0 -2
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Pagination
|
|
2
|
+
|
|
3
|
+
The row under a table: how many rows a page shows, which rows are on screen
|
|
4
|
+
("101-200 of 569"), and the arrows to the first, the previous, the next and the
|
|
5
|
+
last page. The rows-per-page select is [Select](../Select/README.md), the
|
|
6
|
+
arrows are quiet ghost [Buttons](../Button/README.md) — grey, as the frame
|
|
7
|
+
around a table is, and the whole button answers the pointer.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
[NPM](https://www.npmjs.com/package/@propellerads/pagination) |
|
|
12
|
+
[Github](https://github.com/propellerads/ui-components/tree/master/Components/Pagination)
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
bun add @propellerads/pagination
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The select and the buttons draw with [@propellerads/tokens](../Tokens/README.md);
|
|
21
|
+
the tokens are the app's:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import '@propellerads/tokens/common.css';
|
|
25
|
+
import '@propellerads/tokens/propellerads.css'; // or monetag / propush / zeydoo
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Use
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import Pagination from '@propellerads/pagination';
|
|
32
|
+
|
|
33
|
+
<Pagination
|
|
34
|
+
parentElementId="campaigns"
|
|
35
|
+
labelPerPage="Rows per page"
|
|
36
|
+
pageSizes={[25, 50, 100, 500]}
|
|
37
|
+
perPage={perPage}
|
|
38
|
+
pageIndex={pageIndex}
|
|
39
|
+
totalPages={totalPages}
|
|
40
|
+
totalItems={totalItems}
|
|
41
|
+
canPreviousPage={pageIndex > 0}
|
|
42
|
+
canNextPage={pageIndex < totalPages - 1}
|
|
43
|
+
gotoPage={setPageIndex}
|
|
44
|
+
previousPageHandler={previousPage}
|
|
45
|
+
nextPageHandler={nextPage}
|
|
46
|
+
setPageSize={setPerPage}
|
|
47
|
+
/>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## The label
|
|
51
|
+
|
|
52
|
+
`labelPerPage` is the label of the rows-per-page select, drawn by the select's
|
|
53
|
+
own field ([Field from `@propellerads/label`](../Label/README.md)): a click on
|
|
54
|
+
it focuses the select, and a screen reader reads it as the select's name. The
|
|
55
|
+
counter is not a label.
|
|
56
|
+
|
|
57
|
+
- **`labelPosition`** puts it on the left — the default, the way Pagination has
|
|
58
|
+
always looked — on top of the select, or hides it for a screen reader alone.
|
|
59
|
+
On the left the label takes its own width, not the label column of a form.
|
|
60
|
+
- **No colon.** A colon at the end is dropped: "Rows per page:" shows as
|
|
61
|
+
"Rows per page", as no label of the library has one. Pass it without one.
|
|
62
|
+
- **Without `labelPerPage`** nothing is shown beside the select, and a screen
|
|
63
|
+
reader names it "Rows per page".
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
<Pagination labelPerPage="Rows per page" labelPosition="top" {...paging} />
|
|
67
|
+
<Pagination labelPerPage="Rows per page" labelPosition="hidden" {...paging} />
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Width and wrapping
|
|
71
|
+
|
|
72
|
+
The select is as wide as the longest of `pageSizes`, so "100" or "500" is never
|
|
73
|
+
cut to "1…", and it keeps its width when another size is chosen.
|
|
74
|
+
|
|
75
|
+
The three parts — the select with its label, the counter, the arrows — stand
|
|
76
|
+
in a row. Where the row has no room, a whole part goes to the next line: the
|
|
77
|
+
select does not shrink, the counter does not break, the four arrows stay
|
|
78
|
+
together. The parts stand on the line of the select, so a label on top rises
|
|
79
|
+
above the row.
|
|
80
|
+
|
|
81
|
+
## Props
|
|
82
|
+
|
|
83
|
+
| Prop | Default | What it does |
|
|
84
|
+
|-----------------------|----------------|----------------------------------------------------------------------|
|
|
85
|
+
| `parentElementId` | — | Starts the ids: `${parentElementId}-pagination-select-per-page` names the select's input, `-first-page-button` and the rest name the arrows |
|
|
86
|
+
| `labelPerPage` | `''` | The label of the rows-per-page select; a colon at its end is dropped |
|
|
87
|
+
| `labelPosition` | `'left'` | `'left'`, `'top'` or `'hidden'` |
|
|
88
|
+
| `pageSizes` | `[10, 20, 50]` | The sizes the select offers |
|
|
89
|
+
| `perPage` | — | The chosen size |
|
|
90
|
+
| `pageIndex` | — | The page on screen, from 0 |
|
|
91
|
+
| `totalPages` | — | The last arrow goes to `totalPages - 1` |
|
|
92
|
+
| `totalItems` | — | The total of the counter |
|
|
93
|
+
| `paginationAmount` | — | The counter's text instead of "101-200 of 569" |
|
|
94
|
+
| `canPreviousPage`, `canNextPage` | — | Switch the arrows on and off |
|
|
95
|
+
| `gotoPage` | — | Called with 0 or `totalPages - 1` by the first and the last arrow |
|
|
96
|
+
| `previousPageHandler`, `nextPageHandler` | — | Called by the middle arrows |
|
|
97
|
+
| `setPageSize` | — | Called with the size chosen in the select |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { LabelPosition } from '@propellerads/label';
|
|
2
3
|
import { ReactNode } from 'react';
|
|
3
4
|
|
|
4
5
|
type PaginationProps = {
|
|
5
6
|
paginationAmount?: ReactNode;
|
|
6
7
|
parentElementId: string;
|
|
8
|
+
/**
|
|
9
|
+
* The label of the rows-per-page select. A click on it focuses the select.
|
|
10
|
+
* A colon at its end is dropped: no label of the library has one. Without
|
|
11
|
+
* it the select is named "Rows per page" for a screen reader alone.
|
|
12
|
+
*/
|
|
7
13
|
labelPerPage?: string;
|
|
14
|
+
/** Where `labelPerPage` stands: beside the select, on top of it, or only for a screen reader. @default 'left' */
|
|
15
|
+
labelPosition?: LabelPosition;
|
|
8
16
|
pageSizes?: Array<string | number>;
|
|
9
17
|
pageIndex: number;
|
|
10
18
|
perPage: number;
|
|
@@ -23,7 +31,7 @@ type PaginationAmountText = {
|
|
|
23
31
|
total: number;
|
|
24
32
|
};
|
|
25
33
|
|
|
26
|
-
declare const Pagination: ({ pageIndex, perPage, pageSizes, totalPages, totalItems, setPageSize, canNextPage, gotoPage, canPreviousPage, previousPageHandler, nextPageHandler, parentElementId, paginationAmount, labelPerPage, }: PaginationProps) => react_jsx_runtime.JSX.Element;
|
|
34
|
+
declare const Pagination: ({ pageIndex, perPage, pageSizes, totalPages, totalItems, setPageSize, canNextPage, gotoPage, canPreviousPage, previousPageHandler, nextPageHandler, parentElementId, paginationAmount, labelPerPage, labelPosition, }: PaginationProps) => react_jsx_runtime.JSX.Element;
|
|
27
35
|
|
|
28
36
|
export { Pagination as default };
|
|
29
37
|
export type { PaginationAmountText, PaginationProps };
|