react-headless-pagination
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -187,2 +187,8 @@ 'use strict'; | ||
"data-testid": classNames((_classNames = {}, _classNames["" + dataTestIdActive] = dataTestIdActive && pagination.currentPage + 1 === page, _classNames[dataTestIdInactive + "-" + page] = dataTestIdActive && pagination.currentPage + 1 !== page, _classNames)) || undefined, | ||
tabIndex: 0, | ||
onKeyPress: function onKeyPress(event) { | ||
if (event.key === "Enter") { | ||
pagination.setCurrentPage(page - 1); | ||
} | ||
}, | ||
onClick: function onClick() { | ||
@@ -189,0 +195,0 @@ return pagination.setCurrentPage(page - 1); |
@@ -1,2 +0,2 @@ | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),a=e(require("classnames"));function n(e,t){if(null==e)return{};var a,n,r={},s=Object.keys(e);for(n=0;n<s.length;n++)t.indexOf(a=s[n])>=0||(r[a]=e[a]);return r}var r=function(e){var a=e.className,r=e.children,s=e.dataTestId,u=n(e,["className","children","dataTestId"]),c=t.useContext(l);return t.createElement("button",Object.assign({className:a},u,{onClick:function(){c.currentPage+1>1&&c.setCurrentPage(c.currentPage-1)},disabled:0===c.currentPage,"data-testid":s}),r)},s=function(e){var a=e.className,r=e.children,s=e.dataTestId,u=n(e,["className","children","dataTestId"]),c=t.useContext(l);return t.createElement("button",Object.assign({className:a},u,{onClick:function(){c.currentPage+1<c.pages.length&&c.setCurrentPage(c.currentPage+1)},disabled:c.currentPage===c.pages.length-1,"data-testid":s}),r)},u=function(e){var a=e.prev,n=t.useContext(l);return n.isPreviousTruncable&&!0===a||n.isNextTruncable&&!a?t.createElement("li",{className:n.truncableClassName||void 0},n.truncableText):null},c=function(e){var n=e.as,r=void 0===n?t.createElement("a",null):n,s=e.className,c=e.dataTestIdActive,i=e.dataTestIdInactive,o=e.activeClassName,g=e.inactiveClassName,d=t.useContext(l),P=function(e){var n;return t.createElement("li",{key:e},t.createElement(r.type,Object.assign({"data-testid":a((n={},n[""+c]=c&&d.currentPage+1===e,n[i+"-"+e]=c&&d.currentPage+1!==e,n))||void 0,onClick:function(){return d.setCurrentPage(e-1)},className:a(s,d.currentPage+1===e?o:g)},r.props),e))};return t.createElement(t.Fragment,null,d.previousPages.map(P),t.createElement(u,{prev:!0}),d.middlePages.map(P),t.createElement(u,null),d.nextPages.map(P))},l=t.createContext({currentPage:0,setCurrentPage:function(){},truncableText:"...",truncableClassName:"",pages:[],hasPreviousPage:!1,hasNextPage:!1,previousPages:[],isPreviousTruncable:!1,middlePages:[],isNextTruncable:!1,nextPages:[]}),i=function(e){var a,r,s,u,c,i,o,g,d,P,m,v,f,b,x,N,p,C,h,T,E,I=e.dataTestId,M=n(e,["dataTestId"]),j=(r=(a=M).currentPage,s=a.setCurrentPage,c=void 0===(u=a.truncableText)?"...":u,o=void 0===(i=a.truncableClassName)?"":i,g=a.totalPages,d=a.edgePageCount,P=a.middlePagesSiblingCount,m=Array(g).fill(0).map((function(e,t){return t+1})),v=r>1,f=r<g,b=r<=P,x=r+P>=g,N=t.useMemo((function(){var e=2*P+1;return b?m.slice(0,e):x?m.slice(-e):m.slice(r-P,r+P+1)}),[r,m]),p=t.useMemo((function(){return b||m.slice(0,N[0]-1).length<1?[]:m.slice(0,d).filter((function(e){return!N.includes(e)}))}),[r,m]),C=t.useMemo((function(){return m.slice(N[N.length-1],m[m.length])}),[m,N]),h=t.useMemo((function(){return x||C.length<1?[]:m.slice(m.length-d,m.length).filter((function(e){return!N.includes(e)}))}),[N,m]),T=t.useMemo((function(){return N[0]>p[p.length-1]+1}),[p,N]),E=t.useMemo((function(){return N[N.length-1]+1<h[0]}),[h,N]),{currentPage:r,setCurrentPage:s,truncableText:c,truncableClassName:o,pages:m,hasPreviousPage:v,hasNextPage:f,previousPages:p,isPreviousTruncable:T,middlePages:N,isNextTruncable:E,nextPages:h});return t.createElement(l.Provider,{value:j},t.createElement("div",{className:M.className,"data-testid":I},M.children))};i.PrevButton=r,i.NextButton=s,i.PageButton=c,exports.NextButton=s,exports.PageButton=c,exports.Pagination=i,exports.PrevButton=r; | ||
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("react")),n=e(require("classnames"));function a(e,t){if(null==e)return{};var n,a,r={},s=Object.keys(e);for(a=0;a<s.length;a++)t.indexOf(n=s[a])>=0||(r[n]=e[n]);return r}var r=function(e){var n=e.className,r=e.children,s=e.dataTestId,u=a(e,["className","children","dataTestId"]),c=t.useContext(l);return t.createElement("button",Object.assign({className:n},u,{onClick:function(){c.currentPage+1>1&&c.setCurrentPage(c.currentPage-1)},disabled:0===c.currentPage,"data-testid":s}),r)},s=function(e){var n=e.className,r=e.children,s=e.dataTestId,u=a(e,["className","children","dataTestId"]),c=t.useContext(l);return t.createElement("button",Object.assign({className:n},u,{onClick:function(){c.currentPage+1<c.pages.length&&c.setCurrentPage(c.currentPage+1)},disabled:c.currentPage===c.pages.length-1,"data-testid":s}),r)},u=function(e){var n=e.prev,a=t.useContext(l);return a.isPreviousTruncable&&!0===n||a.isNextTruncable&&!n?t.createElement("li",{className:a.truncableClassName||void 0},a.truncableText):null},c=function(e){var a=e.as,r=void 0===a?t.createElement("a",null):a,s=e.className,c=e.dataTestIdActive,i=e.dataTestIdInactive,o=e.activeClassName,g=e.inactiveClassName,d=t.useContext(l),P=function(e){var a;return t.createElement("li",{key:e},t.createElement(r.type,Object.assign({"data-testid":n((a={},a[""+c]=c&&d.currentPage+1===e,a[i+"-"+e]=c&&d.currentPage+1!==e,a))||void 0,tabIndex:0,onKeyPress:function(t){"Enter"===t.key&&d.setCurrentPage(e-1)},onClick:function(){return d.setCurrentPage(e-1)},className:n(s,d.currentPage+1===e?o:g)},r.props),e))};return t.createElement(t.Fragment,null,d.previousPages.map(P),t.createElement(u,{prev:!0}),d.middlePages.map(P),t.createElement(u,null),d.nextPages.map(P))},l=t.createContext({currentPage:0,setCurrentPage:function(){},truncableText:"...",truncableClassName:"",pages:[],hasPreviousPage:!1,hasNextPage:!1,previousPages:[],isPreviousTruncable:!1,middlePages:[],isNextTruncable:!1,nextPages:[]}),i=function(e){var n,r,s,u,c,i,o,g,d,P,m,v,f,b,x,N,p,C,h,T,E,I=e.dataTestId,y=a(e,["dataTestId"]),M=(r=(n=y).currentPage,s=n.setCurrentPage,c=void 0===(u=n.truncableText)?"...":u,o=void 0===(i=n.truncableClassName)?"":i,g=n.totalPages,d=n.edgePageCount,P=n.middlePagesSiblingCount,m=Array(g).fill(0).map((function(e,t){return t+1})),v=r>1,f=r<g,b=r<=P,x=r+P>=g,N=t.useMemo((function(){var e=2*P+1;return b?m.slice(0,e):x?m.slice(-e):m.slice(r-P,r+P+1)}),[r,m]),p=t.useMemo((function(){return b||m.slice(0,N[0]-1).length<1?[]:m.slice(0,d).filter((function(e){return!N.includes(e)}))}),[r,m]),C=t.useMemo((function(){return m.slice(N[N.length-1],m[m.length])}),[m,N]),h=t.useMemo((function(){return x||C.length<1?[]:m.slice(m.length-d,m.length).filter((function(e){return!N.includes(e)}))}),[N,m]),T=t.useMemo((function(){return N[0]>p[p.length-1]+1}),[p,N]),E=t.useMemo((function(){return N[N.length-1]+1<h[0]}),[h,N]),{currentPage:r,setCurrentPage:s,truncableText:c,truncableClassName:o,pages:m,hasPreviousPage:v,hasNextPage:f,previousPages:p,isPreviousTruncable:T,middlePages:N,isNextTruncable:E,nextPages:h});return t.createElement(l.Provider,{value:M},t.createElement("div",{className:y.className,"data-testid":I},y.children))};i.PrevButton=r,i.NextButton=s,i.PageButton=c,exports.NextButton=s,exports.PageButton=c,exports.Pagination=i,exports.PrevButton=r; | ||
//# sourceMappingURL=react-headless-pagination.cjs.production.min.js.map |
@@ -181,2 +181,8 @@ import React from 'react'; | ||
"data-testid": classNames((_classNames = {}, _classNames["" + dataTestIdActive] = dataTestIdActive && pagination.currentPage + 1 === page, _classNames[dataTestIdInactive + "-" + page] = dataTestIdActive && pagination.currentPage + 1 !== page, _classNames)) || undefined, | ||
tabIndex: 0, | ||
onKeyPress: function onKeyPress(event) { | ||
if (event.key === "Enter") { | ||
pagination.setCurrentPage(page - 1); | ||
} | ||
}, | ||
onClick: function onClick() { | ||
@@ -183,0 +189,0 @@ return pagination.setCurrentPage(page - 1); |
{ | ||
"name": "react-headless-pagination", | ||
"author": "Thijs Smudde", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
# React Headless Pagination | ||
Do you want to design your own pagination component, but do not want to worry about the logic of pagination? Then this tiny and performant package is for you. `react-headless-pagination` is ideal if you are working with a utility-based css framework like TailwindCSS. `react-headless-pagination` offers plenty of customization and is also fully typed. | ||
Do you want to design your own pagination component, but do not want to worry about the logic of pagination? Then this tiny, performant and a11y proof package is for you. `react-headless-pagination` is ideal if you are working with a utility-based css framework like TailwindCSS. `react-headless-pagination` offers plenty of customization and is also fully typed. | ||
[![npm](https://img.shields.io/npm/v/react-headless-pagination)](https://www.npmjs.com/package/react-headless-pagination) | ||
![Jest unit tests](https://github.com/fullhdpixel/react-headless-pagination/actions/workflows/main.yml/badge.svg) | ||
[![Line Coverage Status](./coverage-badge-line.svg)](https://github.com/fullhdpixel/react-headless-pagination/) | ||
<!-- ![code coverage](https://img.shields.io/badge/Code%20Coverage-100%25-success?style=flat) --> | ||
[![issues](https://img.shields.io/github/issues/fullhdpixel/react-headless-pagination)](https://github.com/fullhdpixel/react-headless-pagination/issues) | ||
@@ -13,0 +8,0 @@ [![stargazers](https://img.shields.io/github/stars/fullhdpixel/react-headless-pagination)](https://github.com/fullhdpixel/react-headless-pagination) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70629
507
184