@thecb/components 3.6.0-beta.2 → 3.7.0-beta.1

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/dist/index.cjs.js CHANGED
@@ -36452,6 +36452,123 @@ var createPartialAmountFormState = function createPartialAmountFormState(lineIte
36452
36452
  };
36453
36453
  };
36454
36454
 
36455
+ var PAGING_SPACE = 2; // how many pages we want to have before/after delimiter
36456
+
36457
+ var PAGING_INIT_SPACE = 3; // first delimiter should appear after 3 pages
36458
+
36459
+ var PrevNextButton = function PrevNextButton(_ref) {
36460
+ var action = _ref.action,
36461
+ type = _ref.type;
36462
+ return /*#__PURE__*/React__default.createElement(Box, {
36463
+ padding: "0 10px 0",
36464
+ minHeight: "40px",
36465
+ extraStyles: "max-height: 40px;"
36466
+ }, /*#__PURE__*/React__default.createElement(ButtonWithAction, {
36467
+ action: action,
36468
+ contentOverride: true,
36469
+ dataQa: type,
36470
+ extraStyles: "\n min-width: 40px;\n min-height: 100%;\n max-height: 40px;\n padding: 6px;\n border-radius: 3px;\n "
36471
+ }, /*#__PURE__*/React__default.createElement(Box, {
36472
+ padding: "0",
36473
+ extraStyles: type === "prev" && "transform: scaleX(-1)"
36474
+ }, /*#__PURE__*/React__default.createElement(ChevronIcon$1, {
36475
+ variant: "darkMode"
36476
+ }))));
36477
+ };
36478
+
36479
+ var getPagesPanel = function getPagesPanel(page, pagesCount) {
36480
+ if (!pagesCount || pagesCount <= 1) {
36481
+ return [];
36482
+ }
36483
+
36484
+ var lastPageNumber = pagesCount;
36485
+ var space = page === 1 ? PAGING_INIT_SPACE : PAGING_SPACE;
36486
+ var pages = [{
36487
+ index: 1,
36488
+ isButton: true
36489
+ }];
36490
+
36491
+ if (page > space + 1) {
36492
+ pages.push({
36493
+ isDelimiter: true
36494
+ });
36495
+ }
36496
+
36497
+ for (var j = Math.max(1, page - space) + 1; j < Math.min(lastPageNumber, page + space); j++) {
36498
+ pages.push({
36499
+ index: j,
36500
+ isButton: true
36501
+ });
36502
+ }
36503
+
36504
+ if (page < lastPageNumber - space) {
36505
+ pages.push({
36506
+ isDelimiter: true
36507
+ });
36508
+ }
36509
+
36510
+ pages.push({
36511
+ index: lastPageNumber,
36512
+ isButton: true
36513
+ });
36514
+ var activePage = pages.find(function (p) {
36515
+ return p.index === page;
36516
+ });
36517
+
36518
+ if (activePage) {
36519
+ activePage.active = true;
36520
+ }
36521
+
36522
+ return pages;
36523
+ };
36524
+
36525
+ var Pagination = function Pagination(_ref2) {
36526
+ var pagePrevious = _ref2.pagePrevious,
36527
+ pageNext = _ref2.pageNext,
36528
+ setCurrentPage = _ref2.setCurrentPage,
36529
+ currentPage = _ref2.currentPage,
36530
+ pageCount = _ref2.pageCount;
36531
+ return /*#__PURE__*/React__default.createElement(Cluster, {
36532
+ justify: "center",
36533
+ childGap: "10px"
36534
+ }, currentPage > 1 && /*#__PURE__*/React__default.createElement(PrevNextButton, {
36535
+ type: "prev",
36536
+ action: pagePrevious
36537
+ }), getPagesPanel(currentPage, pageCount).map(function (item, index) {
36538
+ return item.isButton ? /*#__PURE__*/React__default.createElement(Box, {
36539
+ padding: "0",
36540
+ border: item.active && "1px solid ".concat(MATISSE_BLUE),
36541
+ borderRadius: item.active && "3px",
36542
+ extraStyles: "max-height: 40px;"
36543
+ }, /*#__PURE__*/React__default.createElement(ButtonWithAction, {
36544
+ variant: "ghost",
36545
+ key: item.index,
36546
+ text: item.index,
36547
+ disabled: item.active,
36548
+ action: !item.active ? function () {
36549
+ return setCurrentPage({
36550
+ pageNumber: item.index
36551
+ });
36552
+ } : noop,
36553
+ textExtraStyles: "font-size: 17px; font-weight: 900;",
36554
+ extraStyles: "\n min-width: 40px; min-height: 100%; padding: 0;\n &:hover, &:focus {\n text-decoration: none;\n > * > span {\n text-decoration: none;\n }\n }\n }\n &:hover { ".concat(item.active ? "cursor: default;" : "background-color: ".concat(ALABASTER_WHITE), " }\n "),
36555
+ dataQa: index
36556
+ }, item.index)) : /*#__PURE__*/React__default.createElement(Box, {
36557
+ padding: "0 10px"
36558
+ }, /*#__PURE__*/React__default.createElement(Cluster, {
36559
+ justify: "flex-end"
36560
+ }, /*#__PURE__*/React__default.createElement(Text$1, {
36561
+ key: index,
36562
+ variant: "pXL",
36563
+ weight: "900",
36564
+ color: MATISSE_BLUE
36565
+ }, "...")));
36566
+ }), currentPage < pageCount && /*#__PURE__*/React__default.createElement(PrevNextButton, {
36567
+ type: "next",
36568
+ action: pageNext
36569
+ }));
36570
+ };
36571
+
36455
36572
  var PaymentButtonBar = function PaymentButtonBar(_ref) {
36456
36573
  var _ref$forwardButtonTex = _ref.forwardButtonText,
36457
36574
  forwardButtonText = _ref$forwardButtonTex === void 0 ? "Next" : _ref$forwardButtonTex,
@@ -38292,6 +38409,7 @@ exports.NavHeader = NavHeader;
38292
38409
  exports.NavMenuDesktop = NavMenuDesktop$1;
38293
38410
  exports.NavMenuMobile = NavMenuMobile$1;
38294
38411
  exports.Obligation = Obligation;
38412
+ exports.Pagination = Pagination;
38295
38413
  exports.Paragraph = Paragraph$1;
38296
38414
  exports.PartialAmountForm = PartialAmountForm;
38297
38415
  exports.PasswordRequirements = PasswordRequirements;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "3.6.0-beta.2",
3
+ "version": "3.7.0-beta.1",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -13,6 +13,7 @@ export { default as Module } from "./module";
13
13
  export * from "./nav-menu";
14
14
  export { default as Obligation } from "./obligation";
15
15
  export * from "./partial-amount-form";
16
+ export { default as Pagination } from "./pagination";
16
17
  export { default as PaymentButtonBar } from "./payment-button-bar";
17
18
  export { default as PaymentDetails } from "./payment-details";
18
19
  export { default as PaymentFormACH } from "./payment-form-ach";
@@ -0,0 +1,125 @@
1
+ import React from "react";
2
+ import { Cluster, Box } from "../../atoms/layouts";
3
+ import Text from "../../atoms/text";
4
+ import ButtonWithAction from "../../atoms/button-with-action";
5
+ import { ChevronIcon } from "../../atoms/icons";
6
+ import { MATISSE_BLUE, ALABASTER_WHITE } from "../../../constants/colors";
7
+ import { noop } from "../../../util/general";
8
+
9
+ const PAGING_SPACE = 2; // how many pages we want to have before/after delimiter
10
+ const PAGING_INIT_SPACE = 3; // first delimiter should appear after 3 pages
11
+
12
+ const PrevNextButton = ({ action, type }) => (
13
+ <Box padding="0 10px 0" minHeight="40px" extraStyles="max-height: 40px;">
14
+ <ButtonWithAction
15
+ action={action}
16
+ contentOverride
17
+ dataQa={type}
18
+ extraStyles={`
19
+ min-width: 40px;
20
+ min-height: 100%;
21
+ max-height: 40px;
22
+ padding: 6px;
23
+ border-radius: 3px;
24
+ `}
25
+ >
26
+ <Box padding="0" extraStyles={type === "prev" && "transform: scaleX(-1)"}>
27
+ <ChevronIcon variant="darkMode" />
28
+ </Box>
29
+ </ButtonWithAction>
30
+ </Box>
31
+ );
32
+
33
+ export const getPagesPanel = (page, pagesCount) => {
34
+ if (!pagesCount || pagesCount <= 1) {
35
+ return [];
36
+ }
37
+ const lastPageNumber = pagesCount;
38
+ const space = page === 1 ? PAGING_INIT_SPACE : PAGING_SPACE;
39
+ const pages = [{ index: 1, isButton: true }];
40
+ if (page > space + 1) {
41
+ pages.push({ isDelimiter: true });
42
+ }
43
+ for (
44
+ let j = Math.max(1, page - space) + 1;
45
+ j < Math.min(lastPageNumber, page + space);
46
+ j++
47
+ ) {
48
+ pages.push({ index: j, isButton: true });
49
+ }
50
+ if (page < lastPageNumber - space) {
51
+ pages.push({ isDelimiter: true });
52
+ }
53
+ pages.push({ index: lastPageNumber, isButton: true });
54
+ const activePage = pages.find(p => p.index === page);
55
+ if (activePage) {
56
+ activePage.active = true;
57
+ }
58
+ return pages;
59
+ };
60
+
61
+ const Pagination = ({
62
+ pagePrevious,
63
+ pageNext,
64
+ setCurrentPage,
65
+ currentPage,
66
+ pageCount
67
+ }) => (
68
+ <Cluster justify="center" childGap="10px">
69
+ {currentPage > 1 && <PrevNextButton type="prev" action={pagePrevious} />}
70
+ {getPagesPanel(currentPage, pageCount).map((item, index) =>
71
+ item.isButton ? (
72
+ <Box
73
+ padding="0"
74
+ border={item.active && `1px solid ${MATISSE_BLUE}`}
75
+ borderRadius={item.active && "3px"}
76
+ extraStyles="max-height: 40px;"
77
+ >
78
+ <ButtonWithAction
79
+ variant="ghost"
80
+ key={item.index}
81
+ text={item.index}
82
+ disabled={item.active}
83
+ action={
84
+ !item.active
85
+ ? () => setCurrentPage({ pageNumber: item.index })
86
+ : noop
87
+ }
88
+ textExtraStyles={`font-size: 17px; font-weight: 900;`}
89
+ extraStyles={`
90
+ min-width: 40px; min-height: 100%; padding: 0;
91
+ &:hover, &:focus {
92
+ text-decoration: none;
93
+ > * > span {
94
+ text-decoration: none;
95
+ }
96
+ }
97
+ }
98
+ &:hover { ${
99
+ item.active
100
+ ? "cursor: default;"
101
+ : `background-color: ${ALABASTER_WHITE}`
102
+ } }
103
+ `}
104
+ dataQa={index}
105
+ >
106
+ {item.index}
107
+ </ButtonWithAction>
108
+ </Box>
109
+ ) : (
110
+ <Box padding="0 10px">
111
+ <Cluster justify="flex-end">
112
+ <Text key={index} variant="pXL" weight="900" color={MATISSE_BLUE}>
113
+ {"..."}
114
+ </Text>
115
+ </Cluster>
116
+ </Box>
117
+ )
118
+ )}
119
+ {currentPage < pageCount && (
120
+ <PrevNextButton type="next" action={pageNext} />
121
+ )}
122
+ </Cluster>
123
+ );
124
+
125
+ export default Pagination;
@@ -0,0 +1,3 @@
1
+ import Pagination from "./Pagination";
2
+
3
+ export default Pagination;