best-react-pagination 0.1.3 → 0.2.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 CHANGED
@@ -1,50 +1,144 @@
1
1
  # best-react-pagination
2
2
 
3
- [![NPM](https://nodei.co/npm/best-react-pagination.png?downloads=true)](https://nodei.co/npm/best-react-pagination/)
4
-
5
- **Simple and stylized react component to render a pagination.**
6
-
7
- ## Installation
3
+ A controlled React pagination component with keyboard navigation, two built-in styles, and an unstyled mode.
8
4
 
5
+ ```sh
6
+ npm install best-react-pagination
9
7
  ```
10
- npm install best-react-pagination --save
11
- ```
12
8
 
13
- ```javascript
9
+ ## Built-in styles
10
+
11
+ ```tsx
12
+ import { useState } from "react";
14
13
  import Pagination from "best-react-pagination";
14
+ import "best-react-pagination/styles.css";
15
15
 
16
- const YourComponent: FC = () => {
17
- const [index, setIndex] = useState(0);
16
+ export function ResultsPagination() {
17
+ const [page, setPage] = useState(1);
18
18
 
19
19
  return (
20
- // Your code
21
20
  <Pagination
22
- paginationStart={0}
23
- currentIndex={index}
24
- setIndex={setIndex}
25
- totalPages={10}
21
+ aria-label="Search results"
22
+ paginationStart={1}
23
+ currentIndex={page}
24
+ setIndex={setPage}
25
+ totalPages={24}
26
+ isDefaultStyles
26
27
  />
27
28
  );
28
- };
29
+ }
30
+ ```
31
+
32
+ Use `variant="compact"` for smaller controls. The stylesheet is shared by both variants and applies only to instances with `isDefaultStyles` enabled.
33
+
34
+ You can override the CSS variables on the root element using `className`. The themes expose `--brp-control-size`, `--brp-gap`, `--brp-radius`, `--brp-text`, `--brp-muted`, `--brp-border`, `--brp-background`, `--brp-hover`, `--brp-accent`, `--brp-on-accent`, and `--brp-focus`.
35
+
36
+ ## Unstyled mode
37
+
38
+ Use `isDefaultStyles={false}` or omit the flag. Apply your own CSS through `className` and the documented selectors. The component provides the navigation landmark, list, buttons and keyboard behavior.
39
+
40
+ ```tsx
41
+ <Pagination
42
+ aria-label="Search results"
43
+ paginationStart={1}
44
+ currentIndex={page}
45
+ setIndex={setPage}
46
+ totalPages={24}
47
+ className="results-pagination"
48
+ isDefaultStyles={false}
49
+ />
50
+ ```
51
+
52
+ ```css
53
+ .results-pagination [data-pagination-list] {
54
+ display: flex;
55
+ flex-wrap: wrap;
56
+ gap: 0.25rem;
57
+ margin: 0;
58
+ padding: 0;
59
+ list-style: none;
60
+ }
61
+
62
+ .results-pagination button[aria-current="page"] {
63
+ font-weight: bold;
64
+ background: #5f3977;
65
+ color: white;
66
+ }
67
+
68
+ .results-pagination button:focus-visible {
69
+ outline: 2px solid #5f3977;
70
+ outline-offset: 2px;
71
+ }
29
72
  ```
30
73
 
31
- #### Example https://codesandbox.io/s/lingering-breeze-gh2dk
74
+ | Selector | Element or state |
75
+ | --- | --- |
76
+ | `[data-pagination]` | Navigation root |
77
+ | `[data-pagination-list]` | Page list |
78
+ | `[data-pagination-item="page"]` | List item around a page button |
79
+ | `[data-pagination-item="previous"]`, `[data-pagination-item="next"]` | List items around navigation buttons |
80
+ | `[data-pagination-item="ellipsis"]` | Gap between visible page numbers |
81
+ | `button[aria-current="page"]` | Current page button |
82
+ | `button[aria-disabled="true"]` | Navigation button at a boundary |
32
83
 
33
84
  ## Props
34
85
 
35
- | Name | Type | Description |
36
- | ------------------- |----------------------------------| ---------------------------------------------------------------------- |
37
- | `paginationStart` | `Number` | **Required.** The number of start pages on your logic (0 or 1). |
38
- | `currentIndex` | `Number` | **Required.** The current index from hook useState of pages displayed. |
39
- | `totalPages` | `Number` | **Required.** The range of pages displayed. |
40
- | `setIndex` | `React.SetStateAction<number>` | **Required.** The dispatch from hook useState |
41
- | `isDefaultStyles` | `Boolean` | **Default true** |
42
- | `wrapperClass` | `String` | Css class |
43
- | `itemListClass` | `String` | Css class |
44
- | `itemClass` | `String` | Css class |
45
- | `selectedItemClass` | `String` | Css class |
46
- | `disableItemClass` | `String` | Css class |
47
- | `className` | `String` | **Field for styled-component** |
48
-
49
- ### Remark
50
- For rewrite default styles - use !important in your css
86
+ | Prop | Type | Behavior |
87
+ | --- | --- | --- |
88
+ | `paginationStart` | `0 \| 1` | Base for `currentIndex` and values passed to `setIndex`. Displayed page numbers start at 1. |
89
+ | `currentIndex` | `number` | Controlled page index. An out-of-range index is clamped for rendering without calling `setIndex`. |
90
+ | `totalPages` | `number` | Page count. The component renders nothing for zero or an invalid count. |
91
+ | `setIndex` | `React.Dispatch<React.SetStateAction<number>>` | Receives the new index when the user changes pages. |
92
+ | `isDefaultStyles` | `boolean` | Enables the built-in styles when the stylesheet is imported. Defaults to `false`. |
93
+ | `variant` | `"default" \| "compact"` | Built-in style variant. Defaults to `"default"`. |
94
+ | `aria-label` | `string` | Accessible label for the navigation landmark. Defaults to `"Pagination"`. Give each landmark a distinct label when it controls a different list. |
95
+ | `aria-labelledby` | `string` | ID of a visible heading or label for the pagination. Takes precedence over `aria-label`. |
96
+ | `labels` | `{ previous?: string, next?: string, page?: (page: number) => string }` | Localized accessible names for buttons. The formatter receives the displayed, one-based page number. Include the visible number in the name. |
97
+ | `dir` | `"ltr" \| "rtl"` | Text direction. Inherits from the surrounding page when omitted. |
98
+ | `className`, `wrapperClass` | `string` | Root class. When both are supplied, `className` takes precedence. |
99
+ | `itemListClass` | `string` | Page list class. |
100
+ | `itemClass`, `selectedItemClass`, `disableItemClass` | `string` | Classes on list items in their ordinary, current, and disabled or ellipsis states. |
101
+
102
+ React 16.8 and later are supported. The component has ESM and CommonJS entry points and is safe to render on the server. In CommonJS use `require("best-react-pagination").default`. TypeScript consumers can import `PaginationProps` from the package.
103
+
104
+ ### Accessibility in your application
105
+
106
+ Tab and Shift+Tab move between controls. Enter and Space select a page. The current page is exposed through `aria-current="page"`. Unavailable arrows keep focus when a keyboard action reaches a boundary and are skipped on subsequent Tab navigation.
107
+
108
+ When changing pages replaces results in place, announce the update from the results view. For example, render a persistent `<p role="status">Page {page} of {totalPages}</p>` and update its text when the new results are ready. If a results update removes the focused page button or the entire pagination, move focus to a persistent control or a results heading with `tabIndex={-1}`.
109
+
110
+ Custom styles should keep a visible keyboard focus ring, distinguish the current page by more than color, and leave enough room for the controls to wrap with increased text size.
111
+
112
+ ### Upgrading from 0.1.x
113
+
114
+ Import `best-react-pagination/styles.css` in your application if you use `isDefaultStyles`. Update any element-specific selectors to match the new `<nav>` root and the buttons nested inside list items.
115
+
116
+ ## Development
117
+
118
+ Use the Node.js version in `.nvmrc`.
119
+
120
+ ```sh
121
+ npm ci
122
+ npm run dev
123
+ npm run lint
124
+ npm run typecheck
125
+ npm test
126
+ npm run build:demo
127
+ npm run test:pack
128
+ npx playwright install chromium
129
+ npm run test:a11y
130
+ ```
131
+
132
+ The library and demo share the component in `lib/`. `npm pack` builds the distributable files. The package check installs the resulting archive in clean consumers and checks server rendering, TypeScript declarations, and the CSS export on React 16.8, 17, 18, and 19.
133
+
134
+ The browser suite combines axe-core scans with keyboard, forced-color, and reflow checks. Set `PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH` to run it with an existing local Chromium installation.
135
+
136
+ ## Publishing
137
+
138
+ Merging into `main` runs CI and submits the same tarball that passed the package tests to npm for review. The workflow skips versions already published and runs for older commits. After approval, stable versions use `latest` and prereleases use `next`.
139
+
140
+ In the npm package settings, configure a GitHub Actions trusted publisher with owner `97Dmitry`, repository `best-react-pagination`, and workflow filename `publish.yml`. Leave the environment empty and keep **Allow npm publish** unchecked to require manual approval. An optional label is `GitHub Actions - main release`. [npm Trusted Publishing](https://docs.npmjs.com/trusted-publishers/)
141
+
142
+ After the staging job succeeds, open **Staged Packages** on npmjs.com, review the version and archive checksum, and approve it with 2FA. The CI log shows the stage ID and archive checksum. [npm staged publishing](https://docs.npmjs.com/staged-publishing/)
143
+
144
+ If staging fails, rerun the failed job on the latest `main` run to reuse its verified tarball. Rerun the entire workflow if the artifact has expired. If npm reports that the version is already staged, inspect the existing entry before approving it. To replace it, reject the existing stage in npm and rerun the staging job.
@@ -0,0 +1 @@
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("react");c=s(c,1);function l(e,t){if(t<=7)return Array.from({length:t},(e,t)=>t+1);let n=Math.min(Math.max(e-1,2),t-3),r=Math.max(Math.min(e+1,t-1),4),i=[1];n>2&&i.push(n===3?2:`start-gap`);for(let e=n;e<=r;e++)i.push(e);return r<t-1&&i.push(r===t-2?t-1:`end-gap`),i.push(t),i}function u({paginationStart:e,currentIndex:t,totalPages:n,setIndex:r,isDefaultStyles:i=!1,variant:a=`default`,wrapperClass:o,itemListClass:s,itemClass:u,selectedItemClass:d,disableItemClass:f,className:p,"aria-label":m,"aria-labelledby":h,dir:g,labels:_}){var v,y;if(!Number.isSafeInteger(n)||n<1)return null;let b=Math.min(Math.max((Number.isSafeInteger(t)?t:e)-e+1,1),n),x=b===1,S=b===n,C=(h==null?void 0:h.trim())||void 0,w=i=>{let a=i-1+e;i>=1&&i<=n&&a!==t&&r(a)};return c.default.createElement(`nav`,{"aria-label":(m==null?void 0:m.trim())||`Pagination`,"aria-labelledby":C,dir:g,className:p||o,"data-pagination":``,"data-pagination-variant":i?a:void 0},c.default.createElement(`ul`,{className:s,role:`list`,"data-pagination-list":``},c.default.createElement(`li`,{className:x?f:u,"data-pagination-item":`previous`},c.default.createElement(`button`,{type:`button`,"aria-label":(_==null||(v=_.previous)==null?void 0:v.trim())||`Previous page`,"aria-disabled":x||void 0,tabIndex:x?-1:void 0,onClick:()=>w(b-1)},c.default.createElement(`span`,{"aria-hidden":`true`},`‹`))),l(b,n).map(e=>{var t;if(typeof e!=`number`)return c.default.createElement(`li`,{key:e,className:f,"data-pagination-item":`ellipsis`,"aria-hidden":`true`},`…`);let n=e===b;return c.default.createElement(`li`,{key:e,className:n?d:u,"data-pagination-item":`page`},c.default.createElement(`button`,{type:`button`,"aria-label":(_==null||(t=_.page)==null||(t=t.call(_,e))==null?void 0:t.trim())||`Page ${e}`,"aria-current":n?`page`:void 0,onClick:()=>w(e)},e))}),c.default.createElement(`li`,{className:S?f:u,"data-pagination-item":`next`},c.default.createElement(`button`,{type:`button`,"aria-label":(_==null||(y=_.next)==null?void 0:y.trim())||`Next page`,"aria-disabled":S||void 0,tabIndex:S?-1:void 0,onClick:()=>w(b+1)},c.default.createElement(`span`,{"aria-hidden":`true`},`›`)))))}exports.default=u;
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ export interface PaginationProps {
3
+ paginationStart: 0 | 1;
4
+ currentIndex: number;
5
+ totalPages: number;
6
+ setIndex: React.Dispatch<React.SetStateAction<number>>;
7
+ isDefaultStyles?: boolean;
8
+ variant?: "default" | "compact";
9
+ wrapperClass?: string;
10
+ itemListClass?: string;
11
+ itemClass?: string;
12
+ selectedItemClass?: string;
13
+ disableItemClass?: string;
14
+ className?: string;
15
+ "aria-label"?: string;
16
+ "aria-labelledby"?: string;
17
+ dir?: "ltr" | "rtl";
18
+ labels?: {
19
+ previous?: string;
20
+ next?: string;
21
+ page?: (page: number) => string;
22
+ };
23
+ }
24
+ export default function Pagination({ paginationStart, currentIndex, totalPages, setIndex, isDefaultStyles, variant, wrapperClass, itemListClass, itemClass, selectedItemClass, disableItemClass, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, dir, labels, }: PaginationProps): React.ReactElement<unknown> | null;
@@ -0,0 +1,24 @@
1
+ import React from "react";
2
+ export interface PaginationProps {
3
+ paginationStart: 0 | 1;
4
+ currentIndex: number;
5
+ totalPages: number;
6
+ setIndex: React.Dispatch<React.SetStateAction<number>>;
7
+ isDefaultStyles?: boolean;
8
+ variant?: "default" | "compact";
9
+ wrapperClass?: string;
10
+ itemListClass?: string;
11
+ itemClass?: string;
12
+ selectedItemClass?: string;
13
+ disableItemClass?: string;
14
+ className?: string;
15
+ "aria-label"?: string;
16
+ "aria-labelledby"?: string;
17
+ dir?: "ltr" | "rtl";
18
+ labels?: {
19
+ previous?: string;
20
+ next?: string;
21
+ page?: (page: number) => string;
22
+ };
23
+ }
24
+ export default function Pagination({ paginationStart, currentIndex, totalPages, setIndex, isDefaultStyles, variant, wrapperClass, itemListClass, itemClass, selectedItemClass, disableItemClass, className, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, dir, labels, }: PaginationProps): React.ReactElement<unknown> | null;
@@ -0,0 +1,67 @@
1
+ import e from "react";
2
+ // lib/pagination.tsx
3
+ function t(e, t) {
4
+ if (t <= 7) return Array.from({ length: t }, (e, t) => t + 1);
5
+ let n = Math.min(Math.max(e - 1, 2), t - 3), r = Math.max(Math.min(e + 1, t - 1), 4), i = [1];
6
+ n > 2 && i.push(n === 3 ? 2 : "start-gap");
7
+ for (let e = n; e <= r; e++) i.push(e);
8
+ return r < t - 1 && i.push(r === t - 2 ? t - 1 : "end-gap"), i.push(t), i;
9
+ }
10
+ function n({ paginationStart: n, currentIndex: r, totalPages: i, setIndex: a, isDefaultStyles: o = !1, variant: s = "default", wrapperClass: c, itemListClass: l, itemClass: u, selectedItemClass: d, disableItemClass: f, className: p, "aria-label": m, "aria-labelledby": h, dir: g, labels: _ }) {
11
+ var v, y;
12
+ if (!Number.isSafeInteger(i) || i < 1) return null;
13
+ let b = Math.min(Math.max((Number.isSafeInteger(r) ? r : n) - n + 1, 1), i), x = b === 1, S = b === i, C = (h == null ? void 0 : h.trim()) || void 0, w = (e) => {
14
+ let t = e - 1 + n;
15
+ e >= 1 && e <= i && t !== r && a(t);
16
+ };
17
+ return /* @__PURE__ */ e.createElement("nav", {
18
+ "aria-label": (m == null ? void 0 : m.trim()) || "Pagination",
19
+ "aria-labelledby": C,
20
+ dir: g,
21
+ className: p || c,
22
+ "data-pagination": "",
23
+ "data-pagination-variant": o ? s : void 0
24
+ }, /* @__PURE__ */ e.createElement("ul", {
25
+ className: l,
26
+ role: "list",
27
+ "data-pagination-list": ""
28
+ }, /* @__PURE__ */ e.createElement("li", {
29
+ className: x ? f : u,
30
+ "data-pagination-item": "previous"
31
+ }, /* @__PURE__ */ e.createElement("button", {
32
+ type: "button",
33
+ "aria-label": (_ == null || (v = _.previous) == null ? void 0 : v.trim()) || "Previous page",
34
+ "aria-disabled": x || void 0,
35
+ tabIndex: x ? -1 : void 0,
36
+ onClick: () => w(b - 1)
37
+ }, /* @__PURE__ */ e.createElement("span", { "aria-hidden": "true" }, "‹"))), t(b, i).map((t) => {
38
+ var n;
39
+ if (typeof t != "number") return /* @__PURE__ */ e.createElement("li", {
40
+ key: t,
41
+ className: f,
42
+ "data-pagination-item": "ellipsis",
43
+ "aria-hidden": "true"
44
+ }, "…");
45
+ let r = t === b;
46
+ return /* @__PURE__ */ e.createElement("li", {
47
+ key: t,
48
+ className: r ? d : u,
49
+ "data-pagination-item": "page"
50
+ }, /* @__PURE__ */ e.createElement("button", {
51
+ type: "button",
52
+ "aria-label": (_ == null || (n = _.page) == null || (n = n.call(_, t)) == null ? void 0 : n.trim()) || `Page ${t}`,
53
+ "aria-current": r ? "page" : void 0,
54
+ onClick: () => w(t)
55
+ }, t));
56
+ }), /* @__PURE__ */ e.createElement("li", {
57
+ className: S ? f : u,
58
+ "data-pagination-item": "next"
59
+ }, /* @__PURE__ */ e.createElement("button", {
60
+ type: "button",
61
+ "aria-label": (_ == null || (y = _.next) == null ? void 0 : y.trim()) || "Next page",
62
+ "aria-disabled": S || void 0,
63
+ tabIndex: S ? -1 : void 0,
64
+ onClick: () => w(b + 1)
65
+ }, /* @__PURE__ */ e.createElement("span", { "aria-hidden": "true" }, "›")))));
66
+ }
67
+ export { n as default };
@@ -0,0 +1,90 @@
1
+ :where([data-pagination-variant="default"], [data-pagination-variant="compact"]) {
2
+ --_brp-control-size: 2.75rem;
3
+ --_brp-gap: 0.375rem;
4
+ color: var(--brp-text, #153e37);
5
+ }
6
+
7
+ :where([data-pagination-variant="compact"]) {
8
+ --_brp-control-size: 2rem;
9
+ --_brp-gap: 0.25rem;
10
+ }
11
+
12
+ :where([data-pagination-variant]) > [data-pagination-list] {
13
+ display: flex;
14
+ flex-wrap: wrap;
15
+ gap: var(--brp-gap, var(--_brp-gap));
16
+ margin: 0;
17
+ padding: 0;
18
+ list-style: none;
19
+ }
20
+
21
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item] {
22
+ display: grid;
23
+ place-items: center;
24
+ min-block-size: var(--brp-control-size, var(--_brp-control-size));
25
+ min-inline-size: 0;
26
+ max-inline-size: 100%;
27
+ }
28
+
29
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item="ellipsis"] {
30
+ min-inline-size: 1.25rem;
31
+ color: var(--brp-muted, #526860);
32
+ }
33
+
34
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item] > button {
35
+ box-sizing: border-box;
36
+ appearance: none;
37
+ min-block-size: var(--brp-control-size, var(--_brp-control-size));
38
+ min-inline-size: var(--brp-control-size, var(--_brp-control-size));
39
+ max-inline-size: 100%;
40
+ overflow-wrap: anywhere;
41
+ padding: 0 0.5em;
42
+ border: 1px solid var(--brp-border, #748980);
43
+ border-radius: var(--brp-radius, 0.5rem);
44
+ background: var(--brp-background, #ffffff);
45
+ color: inherit;
46
+ cursor: pointer;
47
+ font: inherit;
48
+ font-variant-numeric: tabular-nums;
49
+ }
50
+
51
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item] > button:where(:hover:not([aria-disabled], [aria-current])) {
52
+ background: var(--brp-hover, #e9f5ec);
53
+ }
54
+
55
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item] > button:where([aria-current="page"]) {
56
+ border-color: var(--brp-accent, #165347);
57
+ background: var(--brp-accent, #165347);
58
+ color: var(--brp-on-accent, #ffffff);
59
+ font-weight: 700;
60
+ text-decoration: underline;
61
+ text-underline-offset: 0.18em;
62
+ }
63
+
64
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item] > button:where([aria-disabled="true"]) {
65
+ color: var(--brp-muted, #526860);
66
+ cursor: default;
67
+ opacity: 0.65;
68
+ }
69
+
70
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item] > button:where(:focus-visible) {
71
+ outline: 2px solid var(--brp-focus, #176c58);
72
+ outline-offset: 2px;
73
+ opacity: 1;
74
+ }
75
+
76
+ @media (forced-colors: active) {
77
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item] > button:where([aria-current="page"]) {
78
+ border-color: Highlight;
79
+ }
80
+
81
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item] > button:where([aria-disabled="true"]) {
82
+ border-color: GrayText;
83
+ color: GrayText;
84
+ opacity: 1;
85
+ }
86
+
87
+ :where([data-pagination-variant]) > [data-pagination-list] > [data-pagination-item] > button:where(:focus-visible) {
88
+ outline-color: Highlight;
89
+ }
90
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,23 +1,50 @@
1
1
  {
2
2
  "name": "best-react-pagination",
3
- "version": "0.1.3",
4
- "description": "Pagination for work with React",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "module": "dist/index.js",
8
- "prepublish": "npm run build && npm run test",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/97Dmitry/best-react-pagination.git"
3
+ "version": "0.2.0",
4
+ "description": "Accessible pagination for React",
5
+ "type": "module",
6
+ "main": "./dist/pagination.cjs",
7
+ "module": "./dist/pagination.js",
8
+ "types": "./dist/pagination.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/pagination.d.ts",
13
+ "default": "./dist/pagination.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/pagination.d.cts",
17
+ "default": "./dist/pagination.cjs"
18
+ }
19
+ },
20
+ "./styles.css": {
21
+ "types": "./dist/styles.css.d.ts",
22
+ "default": "./dist/styles.css"
23
+ }
12
24
  },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "sideEffects": [
29
+ "**/*.css"
30
+ ],
13
31
  "scripts": {
14
- "build": "webpack --mode production",
15
- "dev": "webpack serve --config demo/webpack.config.js --hot --mode development",
32
+ "build": "vite build --config vite.lib.config.ts && tsc -p tsconfig.build.json && node scripts/finalize-build.mjs",
33
+ "build:demo": "vite build demo",
34
+ "dev": "vite demo",
16
35
  "start": "npm run dev",
17
- "prettier": "prettier --write --no-error-on-unmatched-pattern demo/src/**/*.{ts,tsx}",
18
- "lint": "eslint --debug demo/src/",
19
- "lint:write": "eslint --debug demo/src/ --fix",
20
- "prepare": "npx husky install"
36
+ "lint": "eslint lib demo/src e2e vite.lib.config.ts playwright.config.ts",
37
+ "lint:write": "npm run lint -- --fix",
38
+ "prettier": "prettier --write lib demo/src",
39
+ "typecheck": "tsc",
40
+ "test": "npm run build && node --test \"test/*.test.mjs\"",
41
+ "test:a11y": "playwright test",
42
+ "test:pack": "node scripts/verify-package.mjs",
43
+ "prepack": "npm run build"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/97Dmitry/best-react-pagination.git"
21
48
  },
22
49
  "author": "Dmitry Tsybizov",
23
50
  "license": "ISC",
@@ -29,41 +56,18 @@
29
56
  "react": ">=16.8"
30
57
  },
31
58
  "devDependencies": {
32
- "@babel/core": "^7.15.8",
33
- "@babel/preset-env": "^7.15.8",
34
- "@babel/preset-react": "^7.14.5",
35
- "@babel/preset-typescript": "^7.15.0",
36
- "@commitlint/cli": "^15.0.0",
37
- "@commitlint/config-conventional": "^15.0.0",
38
- "@types/jest": "^27.0.2",
39
- "@types/node": "^16.11.0",
40
- "@types/react": "^17.0.30",
41
- "@types/react-dom": "^17.0.9",
42
- "@types/webpack": "^5.28.0",
43
- "@types/webpack-dev-server": "^4.3.1",
44
- "@typescript-eslint/eslint-plugin": "^4.33.0",
45
- "@typescript-eslint/parser": "^4.33.0",
46
- "babel-loader": "^8.2.2",
47
- "clean-webpack-plugin": "^4.0.0",
48
- "copy-webpack-plugin": "^9.0.1",
49
- "eslint": "^7.32.0",
50
- "eslint-plugin-react": "^7.26.1",
51
- "eslint-plugin-react-hooks": "^4.2.0",
52
- "fs-extra": "^10.0.0",
53
- "husky": "^7.0.4",
54
- "jest": "^27.2.5",
55
- "lint-staged": "^12.1.2",
56
- "ncp": "^2.0.0",
57
- "prettier": "^2.5.1",
58
- "react": "17.0.2",
59
- "react-dom": "^17.0.2",
60
- "react-hot-loader": "^4.13.0",
61
- "ts-loader": "^9.2.6",
62
- "ts-node": "^10.3.0",
63
- "typescript": "^4.4.4",
64
- "webpack": "^5.58.2",
65
- "webpack-cli": "^4.9.0",
66
- "webpack-dev-server": "^4.3.1",
67
- "webpack-node-externals": "^3.0.0"
59
+ "@axe-core/playwright": "^4.14.0",
60
+ "@eslint/js": "^10.0.1",
61
+ "@playwright/test": "^1.65.1",
62
+ "@types/node": "^26.0.0",
63
+ "@types/react": "^19.3.0",
64
+ "@types/react-dom": "^19.3.0",
65
+ "eslint": "^10.15.0",
66
+ "prettier": "^3.6.2",
67
+ "react": "^19.3.1",
68
+ "react-dom": "^19.3.1",
69
+ "typescript": "^6.0.3",
70
+ "typescript-eslint": "^8.73.0",
71
+ "vite": "^8.3.8"
68
72
  }
69
73
  }
package/.husky/commit-msg DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- npx --no-install commitlint --edit "$1"
package/.husky/pre-commit DELETED
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- npm run build
5
- git add dist
6
- git add lib
7
- npx lint-staged
package/dist/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import React, { FC } from "react";
2
- interface PaginationProps {
3
- paginationStart: 0 | 1;
4
- currentIndex: number;
5
- totalPages: number;
6
- setIndex: React.Dispatch<React.SetStateAction<number>>;
7
- isDefaultStyles?: boolean;
8
- wrapperClass?: string;
9
- itemListClass?: string;
10
- itemClass?: string;
11
- selectedItemClass?: string;
12
- disableItemClass?: string;
13
- className?: string;
14
- }
15
- declare const Pagination: FC<PaginationProps>;
16
- export default Pagination;
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["best-react-pagination"]=t():e["best-react-pagination"]=t()}(self,(function(){return(()=>{"use strict";var e={743:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=a(l(689)),n=l(40);t.default=function(e){var t=e.isDefaultStyles,l=e.itemListClass,a=e.children;return s.default.createElement("ul",{className:l,style:t?n.defaultStyles.itemListClass:void 0},a)}},175:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=l(743);Object.defineProperty(t,"default",{enumerable:!0,get:function(){return a(s).default}})},775:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=a(l(689)),n=l(40);t.default=function(e){var t=e.isDefaultStyles,l=e.itemClass,a=e.itemStyle,u=e.onClick,i=e.children;return s.default.createElement("li",{className:l,style:t?n.defaultStyles[a]:void 0,onClick:u},i)}},541:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=l(775);Object.defineProperty(t,"default",{enumerable:!0,get:function(){return a(s).default}})},989:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=a(l(689)),n=l(40);t.default=function(e){var t=e.isDefaultStyles,l=e.wrapperClass,a=e.children;return s.default.createElement("div",{className:l,style:t?n.defaultStyles.wrapperClass:void 0},a)}},704:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=l(989);Object.defineProperty(t,"default",{enumerable:!0,get:function(){return a(s).default}})},40:(e,t)=>{var l;Object.defineProperty(t,"__esModule",{value:!0}),t.defaultStyles=t.defaultStylesEnum=void 0,(l=t.defaultStylesEnum||(t.defaultStylesEnum={})).wrapperClass="wrapperClass",l.itemListClass="itemListClass",l.itemClass="itemClass",l.selectedItemClass="selectedItemClass",l.disableItemClass="disableItemClass",t.defaultStyles={wrapperClass:{position:"sticky",display:"flex",justifyContent:"center",alignItems:"center",width:"100%",bottom:0},itemListClass:{padding:"10px 0"},itemClass:{display:"inline",cursor:"pointer",padding:"6px 12px",borderRadius:"4px",margin:"0 2px",backgroundColor:"#45c954",userSelect:"none"},selectedItemClass:{display:"inline",cursor:"pointer",padding:"6px 12px",borderRadius:"4px",margin:"0 2px",backgroundColor:"#48bbff",userSelect:"none"},disableItemClass:{display:"inline",cursor:"not-allowed",padding:"6px 12px",borderRadius:"4px",margin:"0 2px",userSelect:"none"}}},741:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.Item=t.ItemList=t.Wrapper=void 0;var s=l(704);Object.defineProperty(t,"Wrapper",{enumerable:!0,get:function(){return a(s).default}});var n=l(175);Object.defineProperty(t,"ItemList",{enumerable:!0,get:function(){return a(n).default}});var u=l(541);Object.defineProperty(t,"Item",{enumerable:!0,get:function(){return a(u).default}})},876:(e,t)=>{function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var l=0,a=new Array(t);l<t;l++)a[l]=e[l];return a}Object.defineProperty(t,"__esModule",{value:!0}),t.range=void 0,t.range=function(e){return(t=Array(e).keys(),function(e){if(Array.isArray(e))return l(e)}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,t){if(e){if("string"==typeof e)return l(e,t);var a=Object.prototype.toString.call(e).slice(8,-1);return"Object"===a&&e.constructor&&(a=e.constructor.name),"Map"===a||"Set"===a?Array.from(e):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?l(e,t):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map((function(e){return e}));var t}},708:function(e,t,l){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var s=a(l(689)),n=l(40),u=l(741),i=l(876);t.default=function(e){var t=e.paginationStart,l=e.currentIndex,a=e.totalPages,r=e.setIndex,m=e.isDefaultStyles,f=e.wrapperClass,d=void 0===f?"":f,o=e.itemListClass,c=void 0===o?"":o,y=e.itemClass,S=void 0===y?"":y,p=e.selectedItemClass,C=void 0===p?"":p,E=e.disableItemClass,I=void 0===E?"":E,v=e.className;return a<=1?s.default.createElement(u.Wrapper,{wrapperClass:v||d,isDefaultStyles:m},s.default.createElement(u.ItemList,{itemListClass:c,isDefaultStyles:m},s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"<<"),s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"1"),s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},">>"))):a>1&&a<4?s.default.createElement(u.Wrapper,{wrapperClass:v||d,isDefaultStyles:m},s.default.createElement(u.ItemList,{itemListClass:c,isDefaultStyles:m},(0,i.range)(a).map((function(e){var a=0===t?e:e+1;return l===a?s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.selectedItemClass,isDefaultStyles:m,key:e},e+1):s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(a)},key:e},e+1)})))):4===a?s.default.createElement(u.Wrapper,{wrapperClass:v||d,isDefaultStyles:m},s.default.createElement(u.ItemList,{itemListClass:c,isDefaultStyles:m},l>(0===t?0:1)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l-1)}},"<<"):s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"<<"),(0,i.range)(a).map((function(e){var a=0===t?e:e+1;return l===a?s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.selectedItemClass,isDefaultStyles:m,key:e},e+1):s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,key:e,onClick:function(){return r(a)}},e+1)})),l<(0===t?3:4)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l+1)}},">>"):s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},">>"))):s.default.createElement(u.Wrapper,{wrapperClass:v||d,isDefaultStyles:m},s.default.createElement(u.ItemList,{itemListClass:c,isDefaultStyles:m},l>(0===t?0:1)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l-1)}},"<<"):s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"<<"),l>(0==t?2:3)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?0:1)}},"1"):null,l<(0===t?3:4)?(0,i.range)(4).map((function(e){var a=0===t?e:e+1;return l===a?s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.selectedItemClass,isDefaultStyles:m,key:e},e+1):s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(a)},key:e},e+1)})):null,l>(0===t?2:3)?s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"..."):null,l>(0===t?2:3)&&(0===t?l:l-1)<a?s.default.createElement(s.default.Fragment,null,l===(0===t?a-2:a-1)&&s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?a-4:a-3)}},a-3),l===(0===t?a-1:a)&&s.default.createElement(s.default.Fragment,null,s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?a-4:a-3)}},a-3),s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?a-3:a-2)}},a-2)),s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l-1)}},0===t?l:l-1),s.default.createElement(u.Item,{itemClass:C,itemStyle:n.defaultStylesEnum.selectedItemClass,isDefaultStyles:m},0===t?l+1:l),l<(0===t?a-1:a)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l+1)}},0===t?l+2:l+1):null):null,l<(0===t?a-3:a-2)?s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},"..."):null,l<(0===t?a-2:a-1)?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(0===t?a-1:a)}},a):null,(0===t?l+1:l)<a?s.default.createElement(u.Item,{itemClass:S,itemStyle:n.defaultStylesEnum.itemClass,isDefaultStyles:m,onClick:function(){return r(l+1)}},">>"):s.default.createElement(u.Item,{itemClass:I,itemStyle:n.defaultStylesEnum.disableItemClass,isDefaultStyles:m},">>")))}},689:e=>{e.exports=require("react")}},t={};return function l(a){var s=t[a];if(void 0!==s)return s.exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,l),n.exports}(708)})()}));
package/husky.config.js DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- "hooks": {
3
- "pre-commit": "npm run build && npm run test"
4
- }
5
- };