@thecb/components 7.7.3-beta.5 → 7.7.4-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "7.7.3-beta.5",
3
+ "version": "7.7.4-beta.1",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
@@ -62,16 +62,19 @@ const Spinner = ({ isMobile }) => (
62
62
 
63
63
  const ButtonWithAction = ({
64
64
  action = noop,
65
- variant = "primary",
66
- text,
67
- textWrap = false,
68
- isLoading = false,
69
- dataQa = null,
70
- textExtraStyles,
65
+ children,
71
66
  contentOverride = false,
67
+ dataQa = null,
68
+ disabledBackgroundColor = "#6D717E",
69
+ disabledBorderColor = "#6D717E",
70
+ disabledColor = "#FFFFFF",
72
71
  extraStyles = "",
72
+ isLoading = false,
73
73
  tabIndex,
74
- children,
74
+ text,
75
+ textExtraStyles,
76
+ textWrap = false,
77
+ variant = "primary",
75
78
  ...rest
76
79
  }) => {
77
80
  const themeContext = useContext(ThemeContext);
@@ -103,12 +106,12 @@ const ButtonWithAction = ({
103
106
  };
104
107
  `;
105
108
  const disabledStyles = `
106
- background-color: #6D717E;
107
- border-color: #6D717E;
108
- color: #FFFFFF;
109
+ background-color: ${disabledBackgroundColor};
110
+ border-color: ${disabledBorderColor};
111
+ color: ${disabledColor};
109
112
  cursor: default;
110
113
  &:focus {
111
- box-shadow: 0 0 10px #6D717E;
114
+ box-shadow: 0 0 10px ${disabledBackgroundColor};
112
115
  outline: none;
113
116
  }
114
117
  `;
@@ -3,26 +3,43 @@ import { Cluster, Box } from "../../atoms/layouts";
3
3
  import Text from "../../atoms/text";
4
4
  import ButtonWithAction from "../../atoms/button-with-action";
5
5
  import { ChevronIcon } from "../../atoms/icons";
6
- import { MATISSE_BLUE, ALABASTER_WHITE } from "../../../constants/colors";
7
6
  import { noop } from "../../../util/general";
7
+ import { themeComponent } from "../../../util/themeUtils";
8
+ import { fallbackValues } from "./Pagination.theme";
8
9
 
9
10
  const PAGING_SPACE = 2; // how many pages we want to have before/after delimiter
10
11
  const PAGING_INIT_SPACE = 3; // first delimiter should appear after 3 pages
11
12
 
12
- const PrevNextButton = ({ action, type, arrowColor, numberColor }) => (
13
- <Box padding="0 10px 0" minHeight="40px" extraStyles="max-height: 40px;">
13
+ const PrevNextButton = ({
14
+ action,
15
+ arrowColor,
16
+ borderRadius,
17
+ buttonHeight,
18
+ buttonWidth,
19
+ numberColor,
20
+ type
21
+ }) => (
22
+ <Box
23
+ padding="0 10px 0"
24
+ minHeight={buttonHeight}
25
+ extraStyles={`max-height: ${buttonHeight};`}
26
+ >
14
27
  <ButtonWithAction
15
28
  action={action}
16
29
  contentOverride
17
30
  dataQa={type}
18
31
  extraStyles={`
19
- min-width: 40px;
32
+ background-color: ${numberColor};
33
+ border-color: ${numberColor}
34
+ border-radius: ${borderRadius};
35
+ margin: 0;
36
+ max-height: ${buttonHeight};
20
37
  min-height: 100%;
21
- max-height: 40px;
38
+ min-width: ${buttonWidth};
22
39
  padding: 6px;
23
- border-radius: 3px;
24
- background-color: ${numberColor ?? MATISSE_BLUE};
25
- border-color: ${numberColor ?? MATISSE_BLUE}
40
+ &:focus {
41
+ outline: none
42
+ }
26
43
  `}
27
44
  >
28
45
  <Box padding="0" extraStyles={type === "prev" && "transform: scaleX(-1)"}>
@@ -61,31 +78,38 @@ export const getPagesPanel = (page, pagesCount) => {
61
78
  };
62
79
 
63
80
  const Pagination = ({
64
- pagePrevious,
65
- pageNext,
66
- setCurrentPage,
81
+ activeBorderWidth = "1px",
82
+ activeBackgroundColor,
83
+ arrowColor,
84
+ borderRadius = "3px",
85
+ buttonHeight = "40px",
86
+ buttonWidth = "40px",
87
+ childGap = "10px",
67
88
  currentPage,
68
- pageCount,
89
+ fontSize = "17px",
90
+ fontWeight = "900",
69
91
  numberColor,
70
- arrowColor
92
+ pageCount,
93
+ pageNext,
94
+ pagePrevious,
95
+ setCurrentPage,
96
+ themeValues
71
97
  }) => (
72
- <Cluster justify="center" childGap="10px">
98
+ <Cluster justify="center" childGap={childGap}>
73
99
  {currentPage > 1 && (
74
100
  <PrevNextButton
75
- type="prev"
76
101
  action={pagePrevious}
77
- arrowColor={arrowColor}
78
- numberColor={numberColor}
102
+ arrowColor={arrowColor ?? themeValues.arrowColor}
103
+ borderRadius={borderRadius}
104
+ buttonHeight={buttonHeight}
105
+ buttonWidth={buttonWidth}
106
+ numberColor={numberColor ?? themeValues.numberColor}
107
+ type="prev"
79
108
  />
80
109
  )}
81
110
  {getPagesPanel(currentPage, pageCount).map((item, index) =>
82
111
  item.isButton ? (
83
- <Box
84
- padding="0"
85
- border={item.active && `1px solid ${numberColor ?? MATISSE_BLUE}`}
86
- borderRadius={item.active && "3px"}
87
- extraStyles="max-height: 40px;"
88
- >
112
+ <Box padding="0" extraStyles={`max-height: ${buttonHeight};`}>
89
113
  <ButtonWithAction
90
114
  variant="ghost"
91
115
  key={item.index}
@@ -96,9 +120,16 @@ const Pagination = ({
96
120
  ? () => setCurrentPage({ pageNumber: item.index })
97
121
  : noop
98
122
  }
99
- textExtraStyles={`font-size: 17px; font-weight: 900;`}
123
+ textExtraStyles={`font-size: ${fontSize}; font-weight: ${fontWeight};`}
100
124
  extraStyles={`
101
- min-width: 40px; min-height: 100%; padding: 0;
125
+ ${
126
+ item.active
127
+ ? `border: ${activeBorderWidth} solid ${numberColor ??
128
+ themeValues.numberColor};`
129
+ : ""
130
+ }
131
+ min-width: ${buttonWidth}; min-height: 100%; padding: 0;
132
+ border-radius: ${borderRadius};
102
133
  &:hover, &:focus {
103
134
  text-decoration: none;
104
135
  > * > span {
@@ -106,16 +137,22 @@ const Pagination = ({
106
137
  }
107
138
  }
108
139
  > * > span {
109
- color: ${numberColor ?? MATISSE_BLUE}
140
+ color: ${numberColor ?? themeValues.numberColor}
141
+ }
142
+ margin: 0;
143
+ &:hover { ${
144
+ item.active
145
+ ? "cursor: default;"
146
+ : `background-color: ${themeValues.hoverBackgroundColor}`
147
+ } }
148
+ &:focus {
149
+ outline: none
110
150
  }
111
- }
112
- &:hover { ${
113
- item.active
114
- ? "cursor: default;"
115
- : `background-color: ${ALABASTER_WHITE}`
116
- } }
117
151
  `}
118
152
  dataQa={index}
153
+ disabledBackgroundColor={activeBackgroundColor}
154
+ disabledBorderColor={numberColor ?? themeValues.numberColor}
155
+ disabledColor={numberColor ?? themeValues.numberColor}
119
156
  >
120
157
  {item.index}
121
158
  </ButtonWithAction>
@@ -126,8 +163,8 @@ const Pagination = ({
126
163
  <Text
127
164
  key={index}
128
165
  variant="pXL"
129
- weight="900"
130
- color={numberColor ?? MATISSE_BLUE}
166
+ weight={fontWeight}
167
+ color={numberColor ?? themeValues.numberColor}
131
168
  >
132
169
  {"..."}
133
170
  </Text>
@@ -137,13 +174,16 @@ const Pagination = ({
137
174
  )}
138
175
  {currentPage < pageCount && (
139
176
  <PrevNextButton
140
- type="next"
141
177
  action={pageNext}
142
- arrowColor={arrowColor}
143
- numberColor={numberColor}
178
+ arrowColor={arrowColor ?? themeValues.arrowColor}
179
+ borderRadius={borderRadius}
180
+ buttonHeight={buttonHeight}
181
+ buttonWidth={buttonWidth}
182
+ numberColor={numberColor ?? themeValues.numberColor}
183
+ type="next"
144
184
  />
145
185
  )}
146
186
  </Cluster>
147
187
  );
148
188
 
149
- export default Pagination;
189
+ export default themeComponent(Pagination, "Pagination", fallbackValues);
@@ -0,0 +1,187 @@
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 { noop } from "../../../util/general";
7
+ import { themeComponent } from "../../../util/themeUtils";
8
+ import { fallbackValues } from "./Pagination.theme";
9
+
10
+ const PAGING_SPACE = 2; // how many pages we want to have before/after delimiter
11
+ const PAGING_INIT_SPACE = 3; // first delimiter should appear after 3 pages
12
+
13
+ const PrevNextButton = ({
14
+ action,
15
+ arrowColor,
16
+ borderRadius,
17
+ numberColor,
18
+ buttonHeight,
19
+ buttonWidth,
20
+ type
21
+ }) => (
22
+ <Box
23
+ padding="0 10px 0"
24
+ minHeight={buttonHeight}
25
+ extraStyles={`max-height: ${buttonHeight};`}
26
+ >
27
+ <ButtonWithAction
28
+ action={action}
29
+ contentOverride
30
+ dataQa={type}
31
+ extraStyles={`
32
+ min-width: ${buttonWidth};
33
+ min-height: 100%;
34
+ max-height: ${buttonHeight};
35
+ padding: 6px;
36
+ border-radius: ${borderRadius};
37
+ background-color: ${numberColor};
38
+ border-color: ${numberColor};
39
+ margin: 0;
40
+ `}
41
+ >
42
+ <Box padding="0" extraStyles={type === "prev" && "transform: scaleX(-1)"}>
43
+ <ChevronIcon variant="darkMode" iconFill={arrowColor} />
44
+ </Box>
45
+ </ButtonWithAction>
46
+ </Box>
47
+ );
48
+
49
+ export const getPagesPanel = (page, pagesCount) => {
50
+ if (!pagesCount || pagesCount <= 1) {
51
+ return [];
52
+ }
53
+ const lastPageNumber = pagesCount;
54
+ const space = page === 1 ? PAGING_INIT_SPACE : PAGING_SPACE;
55
+ const pages = [{ index: 1, isButton: true }];
56
+ if (page > space + 1) {
57
+ pages.push({ isDelimiter: true });
58
+ }
59
+ for (
60
+ let j = Math.max(1, page - space) + 1;
61
+ j < Math.min(lastPageNumber, page + space);
62
+ j++
63
+ ) {
64
+ pages.push({ index: j, isButton: true });
65
+ }
66
+ if (page < lastPageNumber - space) {
67
+ pages.push({ isDelimiter: true });
68
+ }
69
+ pages.push({ index: lastPageNumber, isButton: true });
70
+ const activePage = pages.find(p => p.index === page);
71
+ if (activePage) {
72
+ activePage.active = true;
73
+ }
74
+ return pages;
75
+ };
76
+
77
+ const Pagination = ({
78
+ activeBorderWidth = "1px",
79
+ applyActivePageDisabledStyles = true,
80
+ arrowColor,
81
+ borderRadius = "3px",
82
+ buttonHeight = "40px",
83
+ buttonWidth = "40px",
84
+ childGap = "10px",
85
+ currentPage,
86
+ fontSize = "17px",
87
+ fontWeight = "900",
88
+ numberColor,
89
+ pageCount,
90
+ pageNext,
91
+ pagePrevious,
92
+ setCurrentPage,
93
+ themeValues
94
+ }) => (
95
+ <Cluster justify="center" childGap={childGap}>
96
+ {currentPage > 1 && (
97
+ <PrevNextButton
98
+ action={pagePrevious}
99
+ arrowColor={arrowColor ?? themeValues.arrowColor}
100
+ borderRadius={borderRadius}
101
+ buttonHeight={buttonHeight}
102
+ buttonWidth={buttonWidth}
103
+ numberColor={numberColor ?? themeValues.numberColor}
104
+ type="prev"
105
+ />
106
+ )}
107
+ {getPagesPanel(currentPage, pageCount).map((item, index) =>
108
+ item.isButton ? (
109
+ <Box padding="0" extraStyles={`max-height: ${buttonHeight};`}>
110
+ <ButtonWithAction
111
+ variant="ghost"
112
+ key={item.index}
113
+ text={item.index}
114
+ disabled={item.active}
115
+ applyDisabledStyles={applyActivePageDisabledStyles}
116
+ action={
117
+ !item.active
118
+ ? () => setCurrentPage({ pageNumber: item.index })
119
+ : noop
120
+ }
121
+ textExtraStyles={`font-size: ${fontSize}; font-weight: ${fontWeight};`}
122
+ extraStyles={`
123
+ ${
124
+ item.active
125
+ ? `border: ${activeBorderWidth} solid ${numberColor ??
126
+ themeValues.numberColor};`
127
+ : ""
128
+ }
129
+ min-width: ${buttonWidth}; min-height: 100%; padding: 0;
130
+ border-radius: ${borderRadius};
131
+ &:hover, &:focus {
132
+ text-decoration: none;
133
+ > * > span {
134
+ text-decoration: none;
135
+ }
136
+ }
137
+ > * > span {
138
+ color: ${numberColor ?? themeValues.numberColor}
139
+ }
140
+ margin: 0;
141
+ }
142
+ &:hover { ${
143
+ item.active
144
+ ? `cursor: default;
145
+ border: ${activeBorderWidth} solid ${numberColor ??
146
+ themeValues.numberColor};
147
+ > * > span {
148
+ cursor: default;
149
+ }`
150
+ : `background-color: ${themeValues.hoverBackgroundColor}`
151
+ } }
152
+ `}
153
+ dataQa={index}
154
+ >
155
+ {item.index}
156
+ </ButtonWithAction>
157
+ </Box>
158
+ ) : (
159
+ <Box padding="0 10px">
160
+ <Cluster justify="flex-end">
161
+ <Text
162
+ key={index}
163
+ variant="pXL"
164
+ weight={fontWeight}
165
+ color={numberColor ?? themeValues.numberColor}
166
+ >
167
+ {"..."}
168
+ </Text>
169
+ </Cluster>
170
+ </Box>
171
+ )
172
+ )}
173
+ {currentPage < pageCount && (
174
+ <PrevNextButton
175
+ action={pageNext}
176
+ arrowColor={arrowColor ?? themeValues.arrowColor}
177
+ borderRadius={borderRadius}
178
+ buttonHeight={buttonHeight}
179
+ buttonWidth={buttonWidth}
180
+ numberColor={numberColor ?? themeValues.numberColor}
181
+ type="next"
182
+ />
183
+ )}
184
+ </Cluster>
185
+ );
186
+
187
+ export default themeComponent(Pagination, "Pagination", fallbackValues);
@@ -0,0 +1,15 @@
1
+ import {
2
+ WHITE,
3
+ MATISSE_BLUE,
4
+ ALABASTER_WHITE
5
+ } from "../../../constants/colors";
6
+
7
+ const arrowColor = WHITE;
8
+ const numberColor = MATISSE_BLUE;
9
+ const hoverBackgroundColor = ALABASTER_WHITE;
10
+
11
+ export const fallbackValues = {
12
+ arrowColor,
13
+ hoverBackgroundColor,
14
+ numberColor
15
+ };