@thecb/components 7.7.3 → 7.7.4-beta.2
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 +102 -59
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +102 -59
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/atoms/button-with-action/ButtonWithAction.js +14 -11
- package/src/components/molecules/pagination/Pagination.js +78 -39
- package/src/components/molecules/pagination/Pagination.new.js +187 -0
- package/src/components/molecules/pagination/Pagination.theme.js +15 -0
package/package.json
CHANGED
|
@@ -62,16 +62,19 @@ const Spinner = ({ isMobile }) => (
|
|
|
62
62
|
|
|
63
63
|
const ButtonWithAction = ({
|
|
64
64
|
action = noop,
|
|
65
|
-
|
|
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
|
-
|
|
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:
|
|
107
|
-
border-color:
|
|
108
|
-
color:
|
|
109
|
+
background-color: ${disabledBackgroundColor};
|
|
110
|
+
border-color: ${disabledBorderColor};
|
|
111
|
+
color: ${disabledColor};
|
|
109
112
|
cursor: default;
|
|
110
113
|
&:focus {
|
|
111
|
-
box-shadow: 0 0 10px
|
|
114
|
+
box-shadow: 0 0 10px ${disabledBackgroundColor};
|
|
112
115
|
outline: none;
|
|
113
116
|
}
|
|
114
117
|
`;
|
|
@@ -3,26 +3,42 @@ 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 = ({
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
border-color: ${numberColor ?? MATISSE_BLUE}
|
|
38
|
+
min-width: ${buttonWidth};
|
|
39
|
+
&:focus {
|
|
40
|
+
outline: none
|
|
41
|
+
}
|
|
26
42
|
`}
|
|
27
43
|
>
|
|
28
44
|
<Box padding="0" extraStyles={type === "prev" && "transform: scaleX(-1)"}>
|
|
@@ -61,31 +77,38 @@ export const getPagesPanel = (page, pagesCount) => {
|
|
|
61
77
|
};
|
|
62
78
|
|
|
63
79
|
const Pagination = ({
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
80
|
+
activeBorderWidth = "1px",
|
|
81
|
+
activeBackgroundColor,
|
|
82
|
+
arrowColor,
|
|
83
|
+
borderRadius = "3px",
|
|
84
|
+
buttonHeight = "40px",
|
|
85
|
+
buttonWidth = "40px",
|
|
86
|
+
childGap = "10px",
|
|
67
87
|
currentPage,
|
|
68
|
-
|
|
88
|
+
fontSize = "17px",
|
|
89
|
+
fontWeight = "900",
|
|
69
90
|
numberColor,
|
|
70
|
-
|
|
91
|
+
pageCount,
|
|
92
|
+
pageNext,
|
|
93
|
+
pagePrevious,
|
|
94
|
+
setCurrentPage,
|
|
95
|
+
themeValues
|
|
71
96
|
}) => (
|
|
72
|
-
<Cluster justify="center" childGap=
|
|
97
|
+
<Cluster justify="center" childGap={childGap}>
|
|
73
98
|
{currentPage > 1 && (
|
|
74
99
|
<PrevNextButton
|
|
75
|
-
type="prev"
|
|
76
100
|
action={pagePrevious}
|
|
77
|
-
arrowColor={arrowColor}
|
|
78
|
-
|
|
101
|
+
arrowColor={arrowColor ?? themeValues.arrowColor}
|
|
102
|
+
borderRadius={borderRadius}
|
|
103
|
+
buttonHeight={buttonHeight}
|
|
104
|
+
buttonWidth={buttonWidth}
|
|
105
|
+
numberColor={numberColor ?? themeValues.numberColor}
|
|
106
|
+
type="prev"
|
|
79
107
|
/>
|
|
80
108
|
)}
|
|
81
109
|
{getPagesPanel(currentPage, pageCount).map((item, index) =>
|
|
82
110
|
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
|
-
>
|
|
111
|
+
<Box padding="0" extraStyles={`max-height: ${buttonHeight};`}>
|
|
89
112
|
<ButtonWithAction
|
|
90
113
|
variant="ghost"
|
|
91
114
|
key={item.index}
|
|
@@ -96,9 +119,16 @@ const Pagination = ({
|
|
|
96
119
|
? () => setCurrentPage({ pageNumber: item.index })
|
|
97
120
|
: noop
|
|
98
121
|
}
|
|
99
|
-
textExtraStyles={`font-size:
|
|
122
|
+
textExtraStyles={`font-size: ${fontSize}; font-weight: ${fontWeight};`}
|
|
100
123
|
extraStyles={`
|
|
101
|
-
|
|
124
|
+
${
|
|
125
|
+
item.active
|
|
126
|
+
? `border: ${activeBorderWidth} solid ${numberColor ??
|
|
127
|
+
themeValues.numberColor};`
|
|
128
|
+
: ""
|
|
129
|
+
}
|
|
130
|
+
min-width: ${buttonWidth}; min-height: 100%; padding: 0;
|
|
131
|
+
border-radius: ${borderRadius};
|
|
102
132
|
&:hover, &:focus {
|
|
103
133
|
text-decoration: none;
|
|
104
134
|
> * > span {
|
|
@@ -106,16 +136,22 @@ const Pagination = ({
|
|
|
106
136
|
}
|
|
107
137
|
}
|
|
108
138
|
> * > span {
|
|
109
|
-
color: ${numberColor ??
|
|
139
|
+
color: ${numberColor ?? themeValues.numberColor}
|
|
140
|
+
}
|
|
141
|
+
margin: 0;
|
|
142
|
+
&:hover { ${
|
|
143
|
+
item.active
|
|
144
|
+
? "cursor: default;"
|
|
145
|
+
: `background-color: ${themeValues.hoverBackgroundColor}`
|
|
146
|
+
} }
|
|
147
|
+
&:focus {
|
|
148
|
+
outline: none
|
|
110
149
|
}
|
|
111
|
-
}
|
|
112
|
-
&:hover { ${
|
|
113
|
-
item.active
|
|
114
|
-
? "cursor: default;"
|
|
115
|
-
: `background-color: ${ALABASTER_WHITE}`
|
|
116
|
-
} }
|
|
117
150
|
`}
|
|
118
151
|
dataQa={index}
|
|
152
|
+
disabledBackgroundColor={activeBackgroundColor}
|
|
153
|
+
disabledBorderColor={numberColor ?? themeValues.numberColor}
|
|
154
|
+
disabledColor={numberColor ?? themeValues.numberColor}
|
|
119
155
|
>
|
|
120
156
|
{item.index}
|
|
121
157
|
</ButtonWithAction>
|
|
@@ -126,8 +162,8 @@ const Pagination = ({
|
|
|
126
162
|
<Text
|
|
127
163
|
key={index}
|
|
128
164
|
variant="pXL"
|
|
129
|
-
weight=
|
|
130
|
-
color={numberColor ??
|
|
165
|
+
weight={fontWeight}
|
|
166
|
+
color={numberColor ?? themeValues.numberColor}
|
|
131
167
|
>
|
|
132
168
|
{"..."}
|
|
133
169
|
</Text>
|
|
@@ -137,13 +173,16 @@ const Pagination = ({
|
|
|
137
173
|
)}
|
|
138
174
|
{currentPage < pageCount && (
|
|
139
175
|
<PrevNextButton
|
|
140
|
-
type="next"
|
|
141
176
|
action={pageNext}
|
|
142
|
-
arrowColor={arrowColor}
|
|
143
|
-
|
|
177
|
+
arrowColor={arrowColor ?? themeValues.arrowColor}
|
|
178
|
+
borderRadius={borderRadius}
|
|
179
|
+
buttonHeight={buttonHeight}
|
|
180
|
+
buttonWidth={buttonWidth}
|
|
181
|
+
numberColor={numberColor ?? themeValues.numberColor}
|
|
182
|
+
type="next"
|
|
144
183
|
/>
|
|
145
184
|
)}
|
|
146
185
|
</Cluster>
|
|
147
186
|
);
|
|
148
187
|
|
|
149
|
-
export default Pagination;
|
|
188
|
+
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
|
+
};
|