@propellerads/pagination 1.1.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/CHANGELOG.md +3 -0
- package/dist/allowJavaScriptModules.d.ts +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -0
- package/dist/pagination.cjs.development.js +118 -0
- package/dist/pagination.cjs.development.js.map +1 -0
- package/dist/pagination.cjs.production.min.js +2 -0
- package/dist/pagination.cjs.production.min.js.map +1 -0
- package/dist/pagination.esm.js +111 -0
- package/dist/pagination.esm.js.map +1 -0
- package/dist/styles.d.ts +7 -0
- package/dist/types.d.ts +26 -0
- package/package.json +43 -0
- package/src/allowJavaScriptModules.ts +1 -0
- package/src/index.tsx +119 -0
- package/src/styles.ts +48 -0
- package/src/types.ts +30 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '*';
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
+
|
|
7
|
+
var React = _interopDefault(require('react'));
|
|
8
|
+
var ArrowButton = require('@propellerads/arrow-button');
|
|
9
|
+
var ArrowButton__default = _interopDefault(ArrowButton);
|
|
10
|
+
var Label = _interopDefault(require('@propellerads/label'));
|
|
11
|
+
var Select = _interopDefault(require('@propellerads/select'));
|
|
12
|
+
var styled = _interopDefault(require('styled-components'));
|
|
13
|
+
var stylevariables = require('@propellerads/stylevariables');
|
|
14
|
+
|
|
15
|
+
function _taggedTemplateLiteralLoose(strings, raw) {
|
|
16
|
+
if (!raw) {
|
|
17
|
+
raw = strings.slice(0);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
strings.raw = raw;
|
|
21
|
+
return strings;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
25
|
+
var StyledPagination = /*#__PURE__*/styled.div(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n"])));
|
|
26
|
+
var StyledPaginationPerPage = /*#__PURE__*/styled.div(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n margin-right: ", "px;\n \n label {\n margin: 0 ", "px 0 0;\n }\n\n select {\n width: 66px;\n }\n"])), stylevariables.spacing * 9, stylevariables.spacing * 3);
|
|
27
|
+
var StyledPaginationSelect = /*#__PURE__*/styled.div(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 70px;\n"])));
|
|
28
|
+
var StyledPaginationAmount = /*#__PURE__*/styled.div(_templateObject4 || (_templateObject4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-right: ", "px;\n"])), stylevariables.spacing * 8);
|
|
29
|
+
var StyledPaginationActions = /*#__PURE__*/styled.div(_templateObject5 || (_templateObject5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n"])));
|
|
30
|
+
var StyledPaginationAction = /*#__PURE__*/styled.div(_templateObject6 || (_templateObject6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n &:not(:last-child) {\n margin-right: ", "px;\n }\n"])), stylevariables.spacing * 2);
|
|
31
|
+
|
|
32
|
+
function getPaginationAmountData(perPage, page, total) {
|
|
33
|
+
var count = perPage * (page - 1);
|
|
34
|
+
return {
|
|
35
|
+
from: count + 1,
|
|
36
|
+
to: Math.min(count + perPage, total),
|
|
37
|
+
total: total
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getPaginationAmountText(_ref) {
|
|
42
|
+
var from = _ref.from,
|
|
43
|
+
to = _ref.to,
|
|
44
|
+
total = _ref.total;
|
|
45
|
+
return from + "-" + to + " of " + total;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var Pagination = function Pagination(_ref2) {
|
|
49
|
+
var pageIndex = _ref2.pageIndex,
|
|
50
|
+
perPage = _ref2.perPage,
|
|
51
|
+
_ref2$pageSizes = _ref2.pageSizes,
|
|
52
|
+
pageSizes = _ref2$pageSizes === void 0 ? [10, 20, 50] : _ref2$pageSizes,
|
|
53
|
+
totalPages = _ref2.totalPages,
|
|
54
|
+
totalItems = _ref2.totalItems,
|
|
55
|
+
setPageSize = _ref2.setPageSize,
|
|
56
|
+
canNextPage = _ref2.canNextPage,
|
|
57
|
+
gotoPage = _ref2.gotoPage,
|
|
58
|
+
canPreviousPage = _ref2.canPreviousPage,
|
|
59
|
+
previousPageHandler = _ref2.previousPageHandler,
|
|
60
|
+
nextPageHandler = _ref2.nextPageHandler,
|
|
61
|
+
parentElementId = _ref2.parentElementId,
|
|
62
|
+
_ref2$paginationAmoun = _ref2.paginationAmount,
|
|
63
|
+
paginationAmount = _ref2$paginationAmoun === void 0 ? '' : _ref2$paginationAmoun,
|
|
64
|
+
_ref2$labelPerPage = _ref2.labelPerPage,
|
|
65
|
+
labelPerPage = _ref2$labelPerPage === void 0 ? '' : _ref2$labelPerPage;
|
|
66
|
+
var selectElementId = parentElementId + "-pagination-select-per-page";
|
|
67
|
+
var selectValues = pageSizes.map(function (size) {
|
|
68
|
+
return {
|
|
69
|
+
id: size,
|
|
70
|
+
label: size,
|
|
71
|
+
value: size
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
var paginationAmountData = getPaginationAmountData(perPage, pageIndex + 1, totalItems);
|
|
75
|
+
var paginationAmountText = paginationAmount || getPaginationAmountText(paginationAmountData);
|
|
76
|
+
return React.createElement(StyledPagination, null, React.createElement(StyledPaginationPerPage, null, labelPerPage && React.createElement(Label, {
|
|
77
|
+
label: labelPerPage,
|
|
78
|
+
"for": selectElementId
|
|
79
|
+
}), React.createElement(StyledPaginationSelect, null, React.createElement(Select, {
|
|
80
|
+
id: selectElementId,
|
|
81
|
+
onChange: function onChange(_ref3) {
|
|
82
|
+
var value = _ref3.value;
|
|
83
|
+
setPageSize(value);
|
|
84
|
+
},
|
|
85
|
+
options: selectValues,
|
|
86
|
+
value: selectValues.find(function (_ref4) {
|
|
87
|
+
var value = _ref4.value;
|
|
88
|
+
return value === perPage;
|
|
89
|
+
})
|
|
90
|
+
}))), React.createElement(StyledPaginationAmount, null, paginationAmountText), React.createElement(StyledPaginationActions, null, React.createElement(StyledPaginationAction, null, React.createElement(ArrowButton__default, {
|
|
91
|
+
type: ArrowButton.ARROW_TYPE.FIRST,
|
|
92
|
+
isDisabled: !canPreviousPage,
|
|
93
|
+
elementId: parentElementId + "-pagination-first-page-button",
|
|
94
|
+
onClick: function onClick() {
|
|
95
|
+
return gotoPage(0);
|
|
96
|
+
}
|
|
97
|
+
})), React.createElement(StyledPaginationAction, null, React.createElement(ArrowButton__default, {
|
|
98
|
+
type: ArrowButton.ARROW_TYPE.PREVIOUS,
|
|
99
|
+
isDisabled: !canPreviousPage,
|
|
100
|
+
elementId: parentElementId + "-pagination-previous-page-button",
|
|
101
|
+
onClick: previousPageHandler
|
|
102
|
+
})), React.createElement(StyledPaginationAction, null, React.createElement(ArrowButton__default, {
|
|
103
|
+
type: ArrowButton.ARROW_TYPE.NEXT,
|
|
104
|
+
isDisabled: !canNextPage,
|
|
105
|
+
elementId: parentElementId + "-pagination-next-page-button",
|
|
106
|
+
onClick: nextPageHandler
|
|
107
|
+
})), React.createElement(StyledPaginationAction, null, React.createElement(ArrowButton__default, {
|
|
108
|
+
type: ArrowButton.ARROW_TYPE.LAST,
|
|
109
|
+
isDisabled: !canNextPage,
|
|
110
|
+
elementId: parentElementId + "-pagination-last-page-button",
|
|
111
|
+
onClick: function onClick() {
|
|
112
|
+
return gotoPage(totalPages - 1);
|
|
113
|
+
}
|
|
114
|
+
}))));
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
exports.default = Pagination;
|
|
118
|
+
//# sourceMappingURL=pagination.cjs.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.cjs.development.js","sources":["../src/styles.ts","../src/index.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport {spacing} from '@propellerads/stylevariables';\n\nconst StyledPagination = styled.div`\n display: flex;\n align-items: center;\n`;\n\nconst StyledPaginationPerPage = styled.div`\n display: flex;\n align-items: center;\n margin-right: ${spacing * 9}px;\n \n label {\n margin: 0 ${spacing * 3}px 0 0;\n }\n\n select {\n width: 66px;\n }\n`;\n\nconst StyledPaginationSelect = styled.div`\n width: 70px;\n`;\n\nconst StyledPaginationAmount = styled.div`\n margin-right: ${spacing * 8}px;\n`;\n\nconst StyledPaginationActions = styled.div`\n display: flex;\n`;\n\nconst StyledPaginationAction = styled.div`\n &:not(:last-child) {\n margin-right: ${spacing * 2}px;\n }\n`;\n\nexport {\n StyledPagination,\n StyledPaginationPerPage,\n StyledPaginationSelect,\n StyledPaginationAmount,\n StyledPaginationActions,\n StyledPaginationAction,\n};\n","import React, {FunctionComponent} from 'react';\n\nimport ArrowButton, {ARROW_TYPE} from '@propellerads/arrow-button';\nimport Label from '@propellerads/label';\nimport Select from '@propellerads/select';\n\nimport {PaginationAmountText, PaginationProps, SelectValue} from 'types';\nimport {\n StyledPagination,\n StyledPaginationPerPage,\n StyledPaginationSelect,\n StyledPaginationAmount,\n StyledPaginationActions,\n StyledPaginationAction,\n} from './styles';\n\nfunction getPaginationAmountData(perPage: number, page: number, total: number): PaginationAmountText {\n const count = perPage * (page - 1);\n\n return {\n from: count + 1,\n to: Math.min(count + perPage, total),\n total,\n };\n}\n\nfunction getPaginationAmountText({from, to, total}: PaginationAmountText): string {\n return `${from}-${to} of ${total}`;\n}\n\nconst Pagination: FunctionComponent<PaginationProps> = ({\n pageIndex,\n perPage,\n pageSizes = [10, 20, 50],\n totalPages,\n totalItems,\n setPageSize,\n canNextPage,\n gotoPage,\n canPreviousPage,\n previousPageHandler,\n nextPageHandler,\n parentElementId,\n paginationAmount = '',\n labelPerPage = '',\n}: PaginationProps) => {\n const selectElementId = `${parentElementId}-pagination-select-per-page`;\n\n const selectValues = pageSizes.map((size) => ({\n id: size,\n label: size,\n value: size,\n }));\n\n const paginationAmountData = getPaginationAmountData(perPage, pageIndex + 1, totalItems);\n const paginationAmountText = paginationAmount || getPaginationAmountText(paginationAmountData);\n\n return (\n <StyledPagination>\n <StyledPaginationPerPage>\n {labelPerPage && (\n <Label\n label={labelPerPage}\n for={selectElementId}\n />\n )}\n <StyledPaginationSelect>\n <Select\n id={selectElementId}\n onChange={({value}: SelectValue) => {\n setPageSize(value);\n }}\n options={selectValues}\n value={selectValues.find(({value}) => value === perPage)}\n />\n </StyledPaginationSelect>\n </StyledPaginationPerPage>\n <StyledPaginationAmount>\n {paginationAmountText}\n </StyledPaginationAmount>\n <StyledPaginationActions>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.FIRST}\n isDisabled={!canPreviousPage}\n elementId={`${parentElementId}-pagination-first-page-button`}\n onClick={() => gotoPage(0)}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.PREVIOUS}\n isDisabled={!canPreviousPage}\n elementId={`${parentElementId}-pagination-previous-page-button`}\n onClick={previousPageHandler}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.NEXT}\n isDisabled={!canNextPage}\n elementId={`${parentElementId}-pagination-next-page-button`}\n onClick={nextPageHandler}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.LAST}\n isDisabled={!canNextPage}\n elementId={`${parentElementId}-pagination-last-page-button`}\n onClick={() => gotoPage(totalPages - 1)}\n />\n </StyledPaginationAction>\n </StyledPaginationActions>\n </StyledPagination>\n );\n};\n\nexport default Pagination;\n"],"names":["StyledPagination","styled","div","StyledPaginationPerPage","spacing","StyledPaginationSelect","StyledPaginationAmount","StyledPaginationActions","StyledPaginationAction","getPaginationAmountData","perPage","page","total","count","from","to","Math","min","getPaginationAmountText","Pagination","pageIndex","pageSizes","totalPages","totalItems","setPageSize","canNextPage","gotoPage","canPreviousPage","previousPageHandler","nextPageHandler","parentElementId","paginationAmount","labelPerPage","selectElementId","selectValues","map","size","id","label","value","paginationAmountData","paginationAmountText","React","Label","Select","onChange","options","find","ArrowButton","type","ARROW_TYPE","FIRST","isDisabled","elementId","onClick","PREVIOUS","NEXT","LAST"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAMA,gBAAgB,gBAAGC,MAAM,CAACC,GAAV,mIAAtB;AAKA,IAAMC,uBAAuB,gBAAGF,MAAM,CAACC,GAAV,mPAGXE,sBAAO,GAAG,CAHC,EAMbA,sBAAO,GAAG,CANG,CAA7B;AAcA,IAAMC,sBAAsB,gBAAGJ,MAAM,CAACC,GAAV,2GAA5B;AAIA,IAAMI,sBAAsB,gBAAGL,MAAM,CAACC,GAAV,qHACVE,sBAAO,GAAG,CADA,CAA5B;AAIA,IAAMG,uBAAuB,gBAAGN,MAAM,CAACC,GAAV,6GAA7B;AAIA,IAAMM,sBAAsB,gBAAGP,MAAM,CAACC,GAAV,oJAERE,sBAAO,GAAG,CAFF,CAA5B;;AClBA,SAASK,uBAAT,CAAiCC,OAAjC,EAAkDC,IAAlD,EAAgEC,KAAhE;EACE,IAAMC,KAAK,GAAGH,OAAO,IAAIC,IAAI,GAAG,CAAX,CAArB;EAEA,OAAO;IACLG,IAAI,EAAED,KAAK,GAAG,CADT;IAELE,EAAE,EAAEC,IAAI,CAACC,GAAL,CAASJ,KAAK,GAAGH,OAAjB,EAA0BE,KAA1B,CAFC;IAGLA,KAAK,EAALA;GAHF;AAKD;;AAED,SAASM,uBAAT;MAAkCJ,YAAAA;MAAMC,UAAAA;MAAIH,aAAAA;EAC1C,OAAUE,IAAV,SAAkBC,EAAlB,YAA2BH,KAA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AA,CAACnC,uBAAD,MAAA,EACEmC,mBAAA,CAAClC,sBAAD,MAAA,EACEkC,mBAAA,CAACM,oBAAD;IACEC,IAAI,EAAEC,sBAAU,CAACC;IACjBC,UAAU,EAAE,CAACzB;IACb0B,SAAS,EAAKvB,eAAL;IACTwB,OAAO,EAAE;MAAA,OAAM5B,QAAQ,CAAC,CAAD,CAAd;;GAJX,CADF,CADF,EASEgB,mBAAA,CAAClC,sBAAD,MAAA,EACEkC,mBAAA,CAACM,oBAAD;IACEC,IAAI,EAAEC,sBAAU,CAACK;IACjBH,UAAU,EAAE,CAACzB;IACb0B,SAAS,EAAKvB,eAAL;IACTwB,OAAO,EAAE1B;GAJX,CADF,CATF,EAiBEc,mBAAA,CAAClC,sBAAD,MAAA,EACEkC,mBAAA,CAACM,oBAAD;IACEC,IAAI,EAAEC,sBAAU,CAACM;IACjBJ,UAAU,EAAE,CAAC3B;IACb4B,SAAS,EAAKvB,eAAL;IACTwB,OAAO,EAAEzB;GAJX,CADF,CAjBF,EAyBEa,mBAAA,CAAClC,sBAAD,MAAA,EACEkC,mBAAA,CAACM,oBAAD;IACEC,IAAI,EAAEC,sBAAU,CAACO;IACjBL,UAAU,EAAE,CAAC3B;IACb4B,SAAS,EAAKvB,eAAL;IACTwB,OAAO,EAAE;MAAA,OAAM5B,QAAQ,CAACJ,UAAU,GAAG,CAAd,CAAd;;GAJX,CADF,CAzBF,CAtBF,CADF;AA2DD,CAtFD;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var n,t,a,l,r,i,o=e(require("react")),u=require("@propellerads/arrow-button"),p=e(u),c=e(require("@propellerads/label")),s=e(require("@propellerads/select")),d=e(require("styled-components")),g=require("@propellerads/stylevariables");function m(e,n){return n||(n=e.slice(0)),e.raw=n,e}var f=d.div(n||(n=m(["\n display: flex;\n align-items: center;\n"]))),v=d.div(t||(t=m(["\n display: flex;\n align-items: center;\n margin-right: ","px;\n \n label {\n margin: 0 ","px 0 0;\n }\n\n select {\n width: 66px;\n }\n"])),9*g.spacing,3*g.spacing),E=d.div(a||(a=m(["\n width: 70px;\n"]))),b=d.div(l||(l=m(["\n margin-right: ","px;\n"])),8*g.spacing),P=d.div(r||(r=m(["\n display: flex;\n"]))),x=d.div(i||(i=m(["\n &:not(:last-child) {\n margin-right: ","px;\n }\n"])),2*g.spacing);exports.default=function(e){var n,t=e.pageIndex,a=e.perPage,l=e.pageSizes,r=e.totalPages,i=e.totalItems,d=e.setPageSize,g=e.canNextPage,m=e.gotoPage,y=e.canPreviousPage,R=e.previousPageHandler,I=e.nextPageHandler,h=e.parentElementId,T=e.paginationAmount,q=void 0===T?"":T,A=e.labelPerPage,O=void 0===A?"":A,_=h+"-pagination-select-per-page",C=(void 0===l?[10,20,50]:l).map((function(e){return{id:e,label:e,value:e}})),S=function(e,n,t){var a=e*(n-1);return{from:a+1,to:Math.min(a+e,t),total:t}}(a,t+1,i),k=q||(n=S).from+"-"+n.to+" of "+n.total;return o.createElement(f,null,o.createElement(v,null,O&&o.createElement(c,{label:O,for:_}),o.createElement(E,null,o.createElement(s,{id:_,onChange:function(e){d(e.value)},options:C,value:C.find((function(e){return e.value===a}))}))),o.createElement(b,null,k),o.createElement(P,null,o.createElement(x,null,o.createElement(p,{type:u.ARROW_TYPE.FIRST,isDisabled:!y,elementId:h+"-pagination-first-page-button",onClick:function(){return m(0)}})),o.createElement(x,null,o.createElement(p,{type:u.ARROW_TYPE.PREVIOUS,isDisabled:!y,elementId:h+"-pagination-previous-page-button",onClick:R})),o.createElement(x,null,o.createElement(p,{type:u.ARROW_TYPE.NEXT,isDisabled:!g,elementId:h+"-pagination-next-page-button",onClick:I})),o.createElement(x,null,o.createElement(p,{type:u.ARROW_TYPE.LAST,isDisabled:!g,elementId:h+"-pagination-last-page-button",onClick:function(){return m(r-1)}}))))};
|
|
2
|
+
//# sourceMappingURL=pagination.cjs.production.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.cjs.production.min.js","sources":["../src/styles.ts","../src/index.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport {spacing} from '@propellerads/stylevariables';\n\nconst StyledPagination = styled.div`\n display: flex;\n align-items: center;\n`;\n\nconst StyledPaginationPerPage = styled.div`\n display: flex;\n align-items: center;\n margin-right: ${spacing * 9}px;\n \n label {\n margin: 0 ${spacing * 3}px 0 0;\n }\n\n select {\n width: 66px;\n }\n`;\n\nconst StyledPaginationSelect = styled.div`\n width: 70px;\n`;\n\nconst StyledPaginationAmount = styled.div`\n margin-right: ${spacing * 8}px;\n`;\n\nconst StyledPaginationActions = styled.div`\n display: flex;\n`;\n\nconst StyledPaginationAction = styled.div`\n &:not(:last-child) {\n margin-right: ${spacing * 2}px;\n }\n`;\n\nexport {\n StyledPagination,\n StyledPaginationPerPage,\n StyledPaginationSelect,\n StyledPaginationAmount,\n StyledPaginationActions,\n StyledPaginationAction,\n};\n","import React, {FunctionComponent} from 'react';\n\nimport ArrowButton, {ARROW_TYPE} from '@propellerads/arrow-button';\nimport Label from '@propellerads/label';\nimport Select from '@propellerads/select';\n\nimport {PaginationAmountText, PaginationProps, SelectValue} from 'types';\nimport {\n StyledPagination,\n StyledPaginationPerPage,\n StyledPaginationSelect,\n StyledPaginationAmount,\n StyledPaginationActions,\n StyledPaginationAction,\n} from './styles';\n\nfunction getPaginationAmountData(perPage: number, page: number, total: number): PaginationAmountText {\n const count = perPage * (page - 1);\n\n return {\n from: count + 1,\n to: Math.min(count + perPage, total),\n total,\n };\n}\n\nfunction getPaginationAmountText({from, to, total}: PaginationAmountText): string {\n return `${from}-${to} of ${total}`;\n}\n\nconst Pagination: FunctionComponent<PaginationProps> = ({\n pageIndex,\n perPage,\n pageSizes = [10, 20, 50],\n totalPages,\n totalItems,\n setPageSize,\n canNextPage,\n gotoPage,\n canPreviousPage,\n previousPageHandler,\n nextPageHandler,\n parentElementId,\n paginationAmount = '',\n labelPerPage = '',\n}: PaginationProps) => {\n const selectElementId = `${parentElementId}-pagination-select-per-page`;\n\n const selectValues = pageSizes.map((size) => ({\n id: size,\n label: size,\n value: size,\n }));\n\n const paginationAmountData = getPaginationAmountData(perPage, pageIndex + 1, totalItems);\n const paginationAmountText = paginationAmount || getPaginationAmountText(paginationAmountData);\n\n return (\n <StyledPagination>\n <StyledPaginationPerPage>\n {labelPerPage && (\n <Label\n label={labelPerPage}\n for={selectElementId}\n />\n )}\n <StyledPaginationSelect>\n <Select\n id={selectElementId}\n onChange={({value}: SelectValue) => {\n setPageSize(value);\n }}\n options={selectValues}\n value={selectValues.find(({value}) => value === perPage)}\n />\n </StyledPaginationSelect>\n </StyledPaginationPerPage>\n <StyledPaginationAmount>\n {paginationAmountText}\n </StyledPaginationAmount>\n <StyledPaginationActions>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.FIRST}\n isDisabled={!canPreviousPage}\n elementId={`${parentElementId}-pagination-first-page-button`}\n onClick={() => gotoPage(0)}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.PREVIOUS}\n isDisabled={!canPreviousPage}\n elementId={`${parentElementId}-pagination-previous-page-button`}\n onClick={previousPageHandler}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.NEXT}\n isDisabled={!canNextPage}\n elementId={`${parentElementId}-pagination-next-page-button`}\n onClick={nextPageHandler}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.LAST}\n isDisabled={!canNextPage}\n elementId={`${parentElementId}-pagination-last-page-button`}\n onClick={() => gotoPage(totalPages - 1)}\n />\n </StyledPaginationAction>\n </StyledPaginationActions>\n </StyledPagination>\n );\n};\n\nexport default Pagination;\n"],"names":["StyledPagination","styled","div","StyledPaginationPerPage","spacing","StyledPaginationSelect","StyledPaginationAmount","StyledPaginationActions","StyledPaginationAction","pageIndex","perPage","pageSizes","totalPages","totalItems","setPageSize","canNextPage","gotoPage","canPreviousPage","previousPageHandler","nextPageHandler","parentElementId","paginationAmount","labelPerPage","selectElementId","selectValues","map","size","id","label","value","paginationAmountData","page","total","count","from","to","Math","min","getPaginationAmountData","paginationAmountText","React","Label","for","Select","onChange","options","find","ArrowButton","type","ARROW_TYPE","FIRST","isDisabled","elementId","onClick","PREVIOUS","NEXT","LAST"],"mappings":"uaAGA,IAAMA,EAAmBC,EAAOC,gEAK1BC,EAA0BF,EAAOC,0KAGX,EAAVE,UAGQ,EAAVA,WAQVC,EAAyBJ,EAAOC,sCAIhCI,EAAyBL,EAAOC,6CACV,EAAVE,WAGZG,EAA0BN,EAAOC,wCAIjCM,EAAyBP,EAAOC,4EAER,EAAVE,2BCNmC,kBACrDK,IAAAA,UACAC,IAAAA,YACAC,UACAC,IAAAA,WACAC,IAAAA,WACAC,IAAAA,YACAC,IAAAA,YACAC,IAAAA,SACAC,IAAAA,gBACAC,IAAAA,oBACAC,IAAAA,gBACAC,IAAAA,oBACAC,iBAAAA,aAAmB,SACnBC,aAAAA,aAAe,KAETC,EAAqBH,gCAErBI,cAfM,CAAC,GAAI,GAAI,OAeUC,KAAI,SAACC,GAAD,MAAW,CAC5CC,GAAID,EACJE,MAAOF,EACPG,MAAOH,MAGHI,EAtCR,SAAiCpB,EAAiBqB,EAAcC,GAC9D,IAAMC,EAAQvB,GAAWqB,EAAO,GAEhC,MAAO,CACLG,KAAMD,EAAQ,EACdE,GAAIC,KAAKC,IAAIJ,EAAQvB,EAASsB,GAC9BA,MAAAA,GAgC2BM,CAAwB5B,EAASD,EAAY,EAAGI,GACvE0B,EAAuBlB,MAA4CS,GA7BzCI,WAAMC,YAAIH,MA+B1C,OACEQ,gBAACxC,OACCwC,gBAACrC,OACEmB,GACCkB,gBAACC,GACCb,MAAON,EACPoB,IAAKnB,IAGTiB,gBAACnC,OACCmC,gBAACG,GACChB,GAAIJ,EACJqB,SAAU,YACR9B,IADUe,QAGZgB,QAASrB,EACTK,MAAOL,EAAasB,MAAK,YAAA,SAAEjB,QAAqBnB,SAItD8B,gBAAClC,OACEiC,GAEHC,gBAACjC,OACCiC,gBAAChC,OACCgC,gBAACO,GACCC,KAAMC,aAAWC,MACjBC,YAAalC,EACbmC,UAAchC,kCACdiC,QAAS,WAAA,OAAMrC,EAAS,OAG5BwB,gBAAChC,OACCgC,gBAACO,GACCC,KAAMC,aAAWK,SACjBH,YAAalC,EACbmC,UAAchC,qCACdiC,QAASnC,KAGbsB,gBAAChC,OACCgC,gBAACO,GACCC,KAAMC,aAAWM,KACjBJ,YAAapC,EACbqC,UAAchC,iCACdiC,QAASlC,KAGbqB,gBAAChC,OACCgC,gBAACO,GACCC,KAAMC,aAAWO,KACjBL,YAAapC,EACbqC,UAAchC,iCACdiC,QAAS,WAAA,OAAMrC,EAASJ,EAAa"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ArrowButton, { ARROW_TYPE } from '@propellerads/arrow-button';
|
|
3
|
+
import Label from '@propellerads/label';
|
|
4
|
+
import Select from '@propellerads/select';
|
|
5
|
+
import styled from 'styled-components';
|
|
6
|
+
import { spacing } from '@propellerads/stylevariables';
|
|
7
|
+
|
|
8
|
+
function _taggedTemplateLiteralLoose(strings, raw) {
|
|
9
|
+
if (!raw) {
|
|
10
|
+
raw = strings.slice(0);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
strings.raw = raw;
|
|
14
|
+
return strings;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
|
|
18
|
+
var StyledPagination = /*#__PURE__*/styled.div(_templateObject || (_templateObject = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n"])));
|
|
19
|
+
var StyledPaginationPerPage = /*#__PURE__*/styled.div(_templateObject2 || (_templateObject2 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n margin-right: ", "px;\n \n label {\n margin: 0 ", "px 0 0;\n }\n\n select {\n width: 66px;\n }\n"])), spacing * 9, spacing * 3);
|
|
20
|
+
var StyledPaginationSelect = /*#__PURE__*/styled.div(_templateObject3 || (_templateObject3 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n width: 70px;\n"])));
|
|
21
|
+
var StyledPaginationAmount = /*#__PURE__*/styled.div(_templateObject4 || (_templateObject4 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n margin-right: ", "px;\n"])), spacing * 8);
|
|
22
|
+
var StyledPaginationActions = /*#__PURE__*/styled.div(_templateObject5 || (_templateObject5 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n display: flex;\n"])));
|
|
23
|
+
var StyledPaginationAction = /*#__PURE__*/styled.div(_templateObject6 || (_templateObject6 = /*#__PURE__*/_taggedTemplateLiteralLoose(["\n &:not(:last-child) {\n margin-right: ", "px;\n }\n"])), spacing * 2);
|
|
24
|
+
|
|
25
|
+
function getPaginationAmountData(perPage, page, total) {
|
|
26
|
+
var count = perPage * (page - 1);
|
|
27
|
+
return {
|
|
28
|
+
from: count + 1,
|
|
29
|
+
to: Math.min(count + perPage, total),
|
|
30
|
+
total: total
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getPaginationAmountText(_ref) {
|
|
35
|
+
var from = _ref.from,
|
|
36
|
+
to = _ref.to,
|
|
37
|
+
total = _ref.total;
|
|
38
|
+
return from + "-" + to + " of " + total;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var Pagination = function Pagination(_ref2) {
|
|
42
|
+
var pageIndex = _ref2.pageIndex,
|
|
43
|
+
perPage = _ref2.perPage,
|
|
44
|
+
_ref2$pageSizes = _ref2.pageSizes,
|
|
45
|
+
pageSizes = _ref2$pageSizes === void 0 ? [10, 20, 50] : _ref2$pageSizes,
|
|
46
|
+
totalPages = _ref2.totalPages,
|
|
47
|
+
totalItems = _ref2.totalItems,
|
|
48
|
+
setPageSize = _ref2.setPageSize,
|
|
49
|
+
canNextPage = _ref2.canNextPage,
|
|
50
|
+
gotoPage = _ref2.gotoPage,
|
|
51
|
+
canPreviousPage = _ref2.canPreviousPage,
|
|
52
|
+
previousPageHandler = _ref2.previousPageHandler,
|
|
53
|
+
nextPageHandler = _ref2.nextPageHandler,
|
|
54
|
+
parentElementId = _ref2.parentElementId,
|
|
55
|
+
_ref2$paginationAmoun = _ref2.paginationAmount,
|
|
56
|
+
paginationAmount = _ref2$paginationAmoun === void 0 ? '' : _ref2$paginationAmoun,
|
|
57
|
+
_ref2$labelPerPage = _ref2.labelPerPage,
|
|
58
|
+
labelPerPage = _ref2$labelPerPage === void 0 ? '' : _ref2$labelPerPage;
|
|
59
|
+
var selectElementId = parentElementId + "-pagination-select-per-page";
|
|
60
|
+
var selectValues = pageSizes.map(function (size) {
|
|
61
|
+
return {
|
|
62
|
+
id: size,
|
|
63
|
+
label: size,
|
|
64
|
+
value: size
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
var paginationAmountData = getPaginationAmountData(perPage, pageIndex + 1, totalItems);
|
|
68
|
+
var paginationAmountText = paginationAmount || getPaginationAmountText(paginationAmountData);
|
|
69
|
+
return React.createElement(StyledPagination, null, React.createElement(StyledPaginationPerPage, null, labelPerPage && React.createElement(Label, {
|
|
70
|
+
label: labelPerPage,
|
|
71
|
+
"for": selectElementId
|
|
72
|
+
}), React.createElement(StyledPaginationSelect, null, React.createElement(Select, {
|
|
73
|
+
id: selectElementId,
|
|
74
|
+
onChange: function onChange(_ref3) {
|
|
75
|
+
var value = _ref3.value;
|
|
76
|
+
setPageSize(value);
|
|
77
|
+
},
|
|
78
|
+
options: selectValues,
|
|
79
|
+
value: selectValues.find(function (_ref4) {
|
|
80
|
+
var value = _ref4.value;
|
|
81
|
+
return value === perPage;
|
|
82
|
+
})
|
|
83
|
+
}))), React.createElement(StyledPaginationAmount, null, paginationAmountText), React.createElement(StyledPaginationActions, null, React.createElement(StyledPaginationAction, null, React.createElement(ArrowButton, {
|
|
84
|
+
type: ARROW_TYPE.FIRST,
|
|
85
|
+
isDisabled: !canPreviousPage,
|
|
86
|
+
elementId: parentElementId + "-pagination-first-page-button",
|
|
87
|
+
onClick: function onClick() {
|
|
88
|
+
return gotoPage(0);
|
|
89
|
+
}
|
|
90
|
+
})), React.createElement(StyledPaginationAction, null, React.createElement(ArrowButton, {
|
|
91
|
+
type: ARROW_TYPE.PREVIOUS,
|
|
92
|
+
isDisabled: !canPreviousPage,
|
|
93
|
+
elementId: parentElementId + "-pagination-previous-page-button",
|
|
94
|
+
onClick: previousPageHandler
|
|
95
|
+
})), React.createElement(StyledPaginationAction, null, React.createElement(ArrowButton, {
|
|
96
|
+
type: ARROW_TYPE.NEXT,
|
|
97
|
+
isDisabled: !canNextPage,
|
|
98
|
+
elementId: parentElementId + "-pagination-next-page-button",
|
|
99
|
+
onClick: nextPageHandler
|
|
100
|
+
})), React.createElement(StyledPaginationAction, null, React.createElement(ArrowButton, {
|
|
101
|
+
type: ARROW_TYPE.LAST,
|
|
102
|
+
isDisabled: !canNextPage,
|
|
103
|
+
elementId: parentElementId + "-pagination-last-page-button",
|
|
104
|
+
onClick: function onClick() {
|
|
105
|
+
return gotoPage(totalPages - 1);
|
|
106
|
+
}
|
|
107
|
+
}))));
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default Pagination;
|
|
111
|
+
//# sourceMappingURL=pagination.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.esm.js","sources":["../src/styles.ts","../src/index.tsx"],"sourcesContent":["import styled from 'styled-components';\nimport {spacing} from '@propellerads/stylevariables';\n\nconst StyledPagination = styled.div`\n display: flex;\n align-items: center;\n`;\n\nconst StyledPaginationPerPage = styled.div`\n display: flex;\n align-items: center;\n margin-right: ${spacing * 9}px;\n \n label {\n margin: 0 ${spacing * 3}px 0 0;\n }\n\n select {\n width: 66px;\n }\n`;\n\nconst StyledPaginationSelect = styled.div`\n width: 70px;\n`;\n\nconst StyledPaginationAmount = styled.div`\n margin-right: ${spacing * 8}px;\n`;\n\nconst StyledPaginationActions = styled.div`\n display: flex;\n`;\n\nconst StyledPaginationAction = styled.div`\n &:not(:last-child) {\n margin-right: ${spacing * 2}px;\n }\n`;\n\nexport {\n StyledPagination,\n StyledPaginationPerPage,\n StyledPaginationSelect,\n StyledPaginationAmount,\n StyledPaginationActions,\n StyledPaginationAction,\n};\n","import React, {FunctionComponent} from 'react';\n\nimport ArrowButton, {ARROW_TYPE} from '@propellerads/arrow-button';\nimport Label from '@propellerads/label';\nimport Select from '@propellerads/select';\n\nimport {PaginationAmountText, PaginationProps, SelectValue} from 'types';\nimport {\n StyledPagination,\n StyledPaginationPerPage,\n StyledPaginationSelect,\n StyledPaginationAmount,\n StyledPaginationActions,\n StyledPaginationAction,\n} from './styles';\n\nfunction getPaginationAmountData(perPage: number, page: number, total: number): PaginationAmountText {\n const count = perPage * (page - 1);\n\n return {\n from: count + 1,\n to: Math.min(count + perPage, total),\n total,\n };\n}\n\nfunction getPaginationAmountText({from, to, total}: PaginationAmountText): string {\n return `${from}-${to} of ${total}`;\n}\n\nconst Pagination: FunctionComponent<PaginationProps> = ({\n pageIndex,\n perPage,\n pageSizes = [10, 20, 50],\n totalPages,\n totalItems,\n setPageSize,\n canNextPage,\n gotoPage,\n canPreviousPage,\n previousPageHandler,\n nextPageHandler,\n parentElementId,\n paginationAmount = '',\n labelPerPage = '',\n}: PaginationProps) => {\n const selectElementId = `${parentElementId}-pagination-select-per-page`;\n\n const selectValues = pageSizes.map((size) => ({\n id: size,\n label: size,\n value: size,\n }));\n\n const paginationAmountData = getPaginationAmountData(perPage, pageIndex + 1, totalItems);\n const paginationAmountText = paginationAmount || getPaginationAmountText(paginationAmountData);\n\n return (\n <StyledPagination>\n <StyledPaginationPerPage>\n {labelPerPage && (\n <Label\n label={labelPerPage}\n for={selectElementId}\n />\n )}\n <StyledPaginationSelect>\n <Select\n id={selectElementId}\n onChange={({value}: SelectValue) => {\n setPageSize(value);\n }}\n options={selectValues}\n value={selectValues.find(({value}) => value === perPage)}\n />\n </StyledPaginationSelect>\n </StyledPaginationPerPage>\n <StyledPaginationAmount>\n {paginationAmountText}\n </StyledPaginationAmount>\n <StyledPaginationActions>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.FIRST}\n isDisabled={!canPreviousPage}\n elementId={`${parentElementId}-pagination-first-page-button`}\n onClick={() => gotoPage(0)}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.PREVIOUS}\n isDisabled={!canPreviousPage}\n elementId={`${parentElementId}-pagination-previous-page-button`}\n onClick={previousPageHandler}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.NEXT}\n isDisabled={!canNextPage}\n elementId={`${parentElementId}-pagination-next-page-button`}\n onClick={nextPageHandler}\n />\n </StyledPaginationAction>\n <StyledPaginationAction>\n <ArrowButton\n type={ARROW_TYPE.LAST}\n isDisabled={!canNextPage}\n elementId={`${parentElementId}-pagination-last-page-button`}\n onClick={() => gotoPage(totalPages - 1)}\n />\n </StyledPaginationAction>\n </StyledPaginationActions>\n </StyledPagination>\n );\n};\n\nexport default Pagination;\n"],"names":["StyledPagination","styled","div","StyledPaginationPerPage","spacing","StyledPaginationSelect","StyledPaginationAmount","StyledPaginationActions","StyledPaginationAction","getPaginationAmountData","perPage","page","total","count","from","to","Math","min","getPaginationAmountText","Pagination","pageIndex","pageSizes","totalPages","totalItems","setPageSize","canNextPage","gotoPage","canPreviousPage","previousPageHandler","nextPageHandler","parentElementId","paginationAmount","labelPerPage","selectElementId","selectValues","map","size","id","label","value","paginationAmountData","paginationAmountText","React","Label","Select","onChange","options","find","ArrowButton","type","ARROW_TYPE","FIRST","isDisabled","elementId","onClick","PREVIOUS","NEXT","LAST"],"mappings":";;;;;;;;;;;;;;;;;AAGA,IAAMA,gB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AO,EAAE1B;GAJX,CADF,CATF,EAiBEc,mBAAA,CAAClC,sBAAD,MAAA,EACEkC,mBAAA,CAACM,WAAD;IACEC,IAAI,EAAEC,UAAU,CAACM;IACjBJ,UAAU,EAAE,CAAC3B;IACb4B,SAAS,EAAKvB,eAAL;IACTwB,OAAO,EAAEzB;GAJX,CADF,CAjBF,EAyBEa,mBAAA,CAAClC,sBAAD,MAAA,EACEkC,mBAAA,CAACM,WAAD;IACEC,IAAI,EAAEC,UAAU,CAACO;IACjBL,UAAU,EAAE,CAAC3B;IACb4B,SAAS,EAAKvB,eAAL;IACTwB,OAAO,EAAE;MAAA,OAAM5B,QAAQ,CAACJ,UAAU,GAAG,CAAd,CAAd;;GAJX,CADF,CAzBF,CAtBF,CADF;AA2DD,CAtFD;;;;"}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const StyledPagination: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
2
|
+
declare const StyledPaginationPerPage: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
|
+
declare const StyledPaginationSelect: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
|
+
declare const StyledPaginationAmount: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
+
declare const StyledPaginationActions: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
|
+
declare const StyledPaginationAction: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
7
|
+
export { StyledPagination, StyledPaginationPerPage, StyledPaginationSelect, StyledPaginationAmount, StyledPaginationActions, StyledPaginationAction, };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
declare type PaginationProps = {
|
|
3
|
+
paginationAmount?: string | ReactNode | ReactElement;
|
|
4
|
+
parentElementId: string;
|
|
5
|
+
labelPerPage?: string;
|
|
6
|
+
pageSizes?: Array<string | number>;
|
|
7
|
+
pageIndex: number;
|
|
8
|
+
perPage: number;
|
|
9
|
+
totalPages: number;
|
|
10
|
+
totalItems: number;
|
|
11
|
+
canNextPage: boolean;
|
|
12
|
+
canPreviousPage: boolean;
|
|
13
|
+
nextPageHandler: () => void;
|
|
14
|
+
previousPageHandler: () => void;
|
|
15
|
+
setPageSize: (size: number) => void;
|
|
16
|
+
gotoPage: (page: number) => void;
|
|
17
|
+
};
|
|
18
|
+
declare type PaginationAmountText = {
|
|
19
|
+
from: number;
|
|
20
|
+
to: number;
|
|
21
|
+
total: number;
|
|
22
|
+
};
|
|
23
|
+
declare type SelectValue = {
|
|
24
|
+
value: number;
|
|
25
|
+
};
|
|
26
|
+
export { PaginationProps, PaginationAmountText, SelectValue };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@propellerads/pagination",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"repository": "https://github.com/propellerads/ui-components",
|
|
5
|
+
"author": "n.milantyeva@propellerads.net",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"private": false,
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"typings": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=10"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"prepublishOnly": "tsdx build",
|
|
19
|
+
"start": "tsdx watch",
|
|
20
|
+
"build": "tsdx build"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": ">=16"
|
|
24
|
+
},
|
|
25
|
+
"module": "dist/pagination.esm.js",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/react": "^16.9.49",
|
|
28
|
+
"@types/react-dom": "^16.9.8",
|
|
29
|
+
"@types/styled-components": "^5.1.3",
|
|
30
|
+
"react": "^16.13.1",
|
|
31
|
+
"react-dom": "^16.13.1",
|
|
32
|
+
"tsdx": "^0.13.3",
|
|
33
|
+
"tslib": "^2.0.1",
|
|
34
|
+
"typescript": "^4.0.2"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@propellerads/stylevariables": "^1.3.0",
|
|
38
|
+
"@propellerads/arrow-button": "^1.2.0",
|
|
39
|
+
"@propellerads/label": "^2.1.0",
|
|
40
|
+
"@propellerads/select": "^2.1.2",
|
|
41
|
+
"styled-components": "^5.2.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '*';
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import React, {FunctionComponent} from 'react';
|
|
2
|
+
|
|
3
|
+
import ArrowButton, {ARROW_TYPE} from '@propellerads/arrow-button';
|
|
4
|
+
import Label from '@propellerads/label';
|
|
5
|
+
import Select from '@propellerads/select';
|
|
6
|
+
|
|
7
|
+
import {PaginationAmountText, PaginationProps, SelectValue} from 'types';
|
|
8
|
+
import {
|
|
9
|
+
StyledPagination,
|
|
10
|
+
StyledPaginationPerPage,
|
|
11
|
+
StyledPaginationSelect,
|
|
12
|
+
StyledPaginationAmount,
|
|
13
|
+
StyledPaginationActions,
|
|
14
|
+
StyledPaginationAction,
|
|
15
|
+
} from './styles';
|
|
16
|
+
|
|
17
|
+
function getPaginationAmountData(perPage: number, page: number, total: number): PaginationAmountText {
|
|
18
|
+
const count = perPage * (page - 1);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
from: count + 1,
|
|
22
|
+
to: Math.min(count + perPage, total),
|
|
23
|
+
total,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getPaginationAmountText({from, to, total}: PaginationAmountText): string {
|
|
28
|
+
return `${from}-${to} of ${total}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const Pagination: FunctionComponent<PaginationProps> = ({
|
|
32
|
+
pageIndex,
|
|
33
|
+
perPage,
|
|
34
|
+
pageSizes = [10, 20, 50],
|
|
35
|
+
totalPages,
|
|
36
|
+
totalItems,
|
|
37
|
+
setPageSize,
|
|
38
|
+
canNextPage,
|
|
39
|
+
gotoPage,
|
|
40
|
+
canPreviousPage,
|
|
41
|
+
previousPageHandler,
|
|
42
|
+
nextPageHandler,
|
|
43
|
+
parentElementId,
|
|
44
|
+
paginationAmount = '',
|
|
45
|
+
labelPerPage = '',
|
|
46
|
+
}: PaginationProps) => {
|
|
47
|
+
const selectElementId = `${parentElementId}-pagination-select-per-page`;
|
|
48
|
+
|
|
49
|
+
const selectValues = pageSizes.map((size) => ({
|
|
50
|
+
id: size,
|
|
51
|
+
label: size,
|
|
52
|
+
value: size,
|
|
53
|
+
}));
|
|
54
|
+
|
|
55
|
+
const paginationAmountData = getPaginationAmountData(perPage, pageIndex + 1, totalItems);
|
|
56
|
+
const paginationAmountText = paginationAmount || getPaginationAmountText(paginationAmountData);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<StyledPagination>
|
|
60
|
+
<StyledPaginationPerPage>
|
|
61
|
+
{labelPerPage && (
|
|
62
|
+
<Label
|
|
63
|
+
label={labelPerPage}
|
|
64
|
+
for={selectElementId}
|
|
65
|
+
/>
|
|
66
|
+
)}
|
|
67
|
+
<StyledPaginationSelect>
|
|
68
|
+
<Select
|
|
69
|
+
id={selectElementId}
|
|
70
|
+
onChange={({value}: SelectValue) => {
|
|
71
|
+
setPageSize(value);
|
|
72
|
+
}}
|
|
73
|
+
options={selectValues}
|
|
74
|
+
value={selectValues.find(({value}) => value === perPage)}
|
|
75
|
+
/>
|
|
76
|
+
</StyledPaginationSelect>
|
|
77
|
+
</StyledPaginationPerPage>
|
|
78
|
+
<StyledPaginationAmount>
|
|
79
|
+
{paginationAmountText}
|
|
80
|
+
</StyledPaginationAmount>
|
|
81
|
+
<StyledPaginationActions>
|
|
82
|
+
<StyledPaginationAction>
|
|
83
|
+
<ArrowButton
|
|
84
|
+
type={ARROW_TYPE.FIRST}
|
|
85
|
+
isDisabled={!canPreviousPage}
|
|
86
|
+
elementId={`${parentElementId}-pagination-first-page-button`}
|
|
87
|
+
onClick={() => gotoPage(0)}
|
|
88
|
+
/>
|
|
89
|
+
</StyledPaginationAction>
|
|
90
|
+
<StyledPaginationAction>
|
|
91
|
+
<ArrowButton
|
|
92
|
+
type={ARROW_TYPE.PREVIOUS}
|
|
93
|
+
isDisabled={!canPreviousPage}
|
|
94
|
+
elementId={`${parentElementId}-pagination-previous-page-button`}
|
|
95
|
+
onClick={previousPageHandler}
|
|
96
|
+
/>
|
|
97
|
+
</StyledPaginationAction>
|
|
98
|
+
<StyledPaginationAction>
|
|
99
|
+
<ArrowButton
|
|
100
|
+
type={ARROW_TYPE.NEXT}
|
|
101
|
+
isDisabled={!canNextPage}
|
|
102
|
+
elementId={`${parentElementId}-pagination-next-page-button`}
|
|
103
|
+
onClick={nextPageHandler}
|
|
104
|
+
/>
|
|
105
|
+
</StyledPaginationAction>
|
|
106
|
+
<StyledPaginationAction>
|
|
107
|
+
<ArrowButton
|
|
108
|
+
type={ARROW_TYPE.LAST}
|
|
109
|
+
isDisabled={!canNextPage}
|
|
110
|
+
elementId={`${parentElementId}-pagination-last-page-button`}
|
|
111
|
+
onClick={() => gotoPage(totalPages - 1)}
|
|
112
|
+
/>
|
|
113
|
+
</StyledPaginationAction>
|
|
114
|
+
</StyledPaginationActions>
|
|
115
|
+
</StyledPagination>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export default Pagination;
|
package/src/styles.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import {spacing} from '@propellerads/stylevariables';
|
|
3
|
+
|
|
4
|
+
const StyledPagination = styled.div`
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
`;
|
|
8
|
+
|
|
9
|
+
const StyledPaginationPerPage = styled.div`
|
|
10
|
+
display: flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
margin-right: ${spacing * 9}px;
|
|
13
|
+
|
|
14
|
+
label {
|
|
15
|
+
margin: 0 ${spacing * 3}px 0 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
select {
|
|
19
|
+
width: 66px;
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
const StyledPaginationSelect = styled.div`
|
|
24
|
+
width: 70px;
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const StyledPaginationAmount = styled.div`
|
|
28
|
+
margin-right: ${spacing * 8}px;
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
const StyledPaginationActions = styled.div`
|
|
32
|
+
display: flex;
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
const StyledPaginationAction = styled.div`
|
|
36
|
+
&:not(:last-child) {
|
|
37
|
+
margin-right: ${spacing * 2}px;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
StyledPagination,
|
|
43
|
+
StyledPaginationPerPage,
|
|
44
|
+
StyledPaginationSelect,
|
|
45
|
+
StyledPaginationAmount,
|
|
46
|
+
StyledPaginationActions,
|
|
47
|
+
StyledPaginationAction,
|
|
48
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {ReactElement, ReactNode} from 'react';
|
|
2
|
+
|
|
3
|
+
type PaginationProps = {
|
|
4
|
+
paginationAmount?: string | ReactNode | ReactElement,
|
|
5
|
+
parentElementId: string,
|
|
6
|
+
labelPerPage?: string,
|
|
7
|
+
pageSizes?: Array<string | number>,
|
|
8
|
+
pageIndex: number,
|
|
9
|
+
perPage: number,
|
|
10
|
+
totalPages: number,
|
|
11
|
+
totalItems: number,
|
|
12
|
+
canNextPage: boolean,
|
|
13
|
+
canPreviousPage: boolean,
|
|
14
|
+
nextPageHandler: () => void,
|
|
15
|
+
previousPageHandler: () => void,
|
|
16
|
+
setPageSize: (size: number) => void,
|
|
17
|
+
gotoPage: (page: number) => void,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type PaginationAmountText = {
|
|
21
|
+
from: number,
|
|
22
|
+
to: number,
|
|
23
|
+
total: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type SelectValue = {
|
|
27
|
+
value: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {PaginationProps, PaginationAmountText, SelectValue};
|