@semcore/pagination 2.5.0 → 3.0.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 +19 -0
- package/lib/cjs/Pagination.js +52 -67
- package/lib/cjs/Pagination.js.map +1 -1
- package/lib/cjs/index.d.ts +3 -25
- package/lib/cjs/style/pagination.shadow.css +21 -17
- package/lib/es6/Pagination.js +52 -59
- package/lib/es6/Pagination.js.map +1 -1
- package/lib/es6/index.d.ts +3 -25
- package/lib/es6/style/pagination.shadow.css +21 -17
- package/lib/types/index.d.ts +3 -25
- package/package.json +5 -5
- package/src/Pagination.jsx +48 -68
- package/src/index.d.ts +3 -25
- package/src/style/pagination.shadow.css +21 -17
package/src/Pagination.jsx
CHANGED
|
@@ -7,9 +7,7 @@ import { Text } from '@semcore/typography';
|
|
|
7
7
|
import Button from '@semcore/button';
|
|
8
8
|
import Return from '@semcore/icon/Return/m';
|
|
9
9
|
import ChevronDoubleLeft from '@semcore/icon/ChevronDoubleLeft/m';
|
|
10
|
-
import fire from '@semcore/utils/lib/fire';
|
|
11
10
|
import i18nEnhance from '@semcore/utils/lib/enhances/i18nEnhance';
|
|
12
|
-
import logger from '@semcore/utils/lib/logger';
|
|
13
11
|
import de from './translations/de.json';
|
|
14
12
|
import en from './translations/en.json';
|
|
15
13
|
import es from './translations/es.json';
|
|
@@ -48,20 +46,27 @@ function formatThousands(value) {
|
|
|
48
46
|
class PaginationRoot extends Component {
|
|
49
47
|
static displayName = 'Pagination';
|
|
50
48
|
|
|
51
|
-
static defaultProps = () =>
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
49
|
+
static defaultProps = (props) => {
|
|
50
|
+
const totalPages = props.totalPages || props.defaultTotalPages || 1;
|
|
51
|
+
return {
|
|
52
|
+
defaultCurrentPage: 1,
|
|
53
|
+
defaultTotalPages: 1,
|
|
54
|
+
i18n,
|
|
55
|
+
children: (
|
|
56
|
+
<>
|
|
57
|
+
{totalPages === 1 ? null : (
|
|
58
|
+
<>
|
|
59
|
+
<Pagination.FirstPage />
|
|
60
|
+
<Pagination.PrevPage />
|
|
61
|
+
<Pagination.NextPage />
|
|
62
|
+
</>
|
|
63
|
+
)}
|
|
64
|
+
<Pagination.PageInput />
|
|
65
|
+
<Pagination.TotalPages />
|
|
66
|
+
</>
|
|
67
|
+
),
|
|
68
|
+
};
|
|
69
|
+
};
|
|
65
70
|
static style = style;
|
|
66
71
|
static enhance = [i18nEnhance()];
|
|
67
72
|
|
|
@@ -70,20 +75,6 @@ class PaginationRoot extends Component {
|
|
|
70
75
|
dirtyCurrentPage: undefined,
|
|
71
76
|
};
|
|
72
77
|
|
|
73
|
-
constructor(props) {
|
|
74
|
-
super(props);
|
|
75
|
-
logger.warn(
|
|
76
|
-
!!props.onPageChange,
|
|
77
|
-
'The property "onPageChange" is deprecated, use "onCurrentPageChange"',
|
|
78
|
-
props['data-ui-name'],
|
|
79
|
-
);
|
|
80
|
-
logger.warn(
|
|
81
|
-
!!props.totalPagesFormatter,
|
|
82
|
-
'The "totalPagesFormatter" property is deprecated, use the "<Pagination.TotalPages/>" component',
|
|
83
|
-
props['data-ui-name'],
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
78
|
uncontrolledProps() {
|
|
88
79
|
return {
|
|
89
80
|
totalPages: null,
|
|
@@ -92,7 +83,7 @@ class PaginationRoot extends Component {
|
|
|
92
83
|
}
|
|
93
84
|
|
|
94
85
|
componentDidUpdate(prevProps) {
|
|
95
|
-
if (prevProps.currentPage !== this.asProps.currentPage) {
|
|
86
|
+
if (prevProps.currentPage !== undefined && prevProps.currentPage !== this.asProps.currentPage) {
|
|
96
87
|
this.setState({ dirtyCurrentPage: undefined });
|
|
97
88
|
}
|
|
98
89
|
}
|
|
@@ -102,12 +93,8 @@ class PaginationRoot extends Component {
|
|
|
102
93
|
if (Number.isNaN(currentPage)) {
|
|
103
94
|
return;
|
|
104
95
|
}
|
|
105
|
-
|
|
106
96
|
this.handlers.currentPage(currentPage);
|
|
107
|
-
this.setState({ dirtyCurrentPage: undefined }
|
|
108
|
-
// deprecated
|
|
109
|
-
fire(this, 'onPageChange', currentPage);
|
|
110
|
-
});
|
|
97
|
+
this.setState({ dirtyCurrentPage: undefined });
|
|
111
98
|
};
|
|
112
99
|
|
|
113
100
|
handlePageValueChange = (value) => {
|
|
@@ -188,7 +175,6 @@ class PaginationRoot extends Component {
|
|
|
188
175
|
getPageInputValueProps = () => {
|
|
189
176
|
const { dirtyCurrentPage } = this.state;
|
|
190
177
|
const { currentPage, totalPages, getI18nText } = this.asProps;
|
|
191
|
-
|
|
192
178
|
return {
|
|
193
179
|
min: 1,
|
|
194
180
|
max: totalPages,
|
|
@@ -201,10 +187,9 @@ class PaginationRoot extends Component {
|
|
|
201
187
|
};
|
|
202
188
|
|
|
203
189
|
getTotalPagesProps = () => {
|
|
204
|
-
const { currentPage, totalPages,
|
|
190
|
+
const { currentPage, totalPages, getI18nText } = this.asProps;
|
|
205
191
|
return {
|
|
206
|
-
|
|
207
|
-
children: totalPagesFormatter ? totalPagesFormatter(totalPages) : formatThousands(totalPages),
|
|
192
|
+
children: formatThousands(totalPages),
|
|
208
193
|
disabled: currentPage === totalPages,
|
|
209
194
|
onClick: () => this.handlePageChange(totalPages),
|
|
210
195
|
getI18nText,
|
|
@@ -258,18 +243,12 @@ class TotalPages extends Component {
|
|
|
258
243
|
render() {
|
|
259
244
|
const STotalPages = Root;
|
|
260
245
|
const STotalPagesLabel = Text;
|
|
261
|
-
const { styles,
|
|
262
|
-
|
|
263
|
-
logger.warn(
|
|
264
|
-
!!label,
|
|
265
|
-
'"Label" property is deprecated, use i118n to override text',
|
|
266
|
-
this.asProps['data-ui-name'],
|
|
267
|
-
);
|
|
246
|
+
const { styles, getI18nText } = this.asProps;
|
|
268
247
|
|
|
269
248
|
return sstyled(styles)(
|
|
270
249
|
<>
|
|
271
|
-
<STotalPagesLabel
|
|
272
|
-
<STotalPages render={Link} tag="button" type="button"
|
|
250
|
+
<STotalPagesLabel>{getI18nText('totalPagesLabel')}</STotalPagesLabel>
|
|
251
|
+
<STotalPages render={Link} tag="button" type="button" />
|
|
273
252
|
</>,
|
|
274
253
|
);
|
|
275
254
|
}
|
|
@@ -280,31 +259,32 @@ const PageInputValue = (props) => {
|
|
|
280
259
|
return sstyled(props.styles)(<SPageInputValue render={Input.Value} aria-label="Current page" />);
|
|
281
260
|
};
|
|
282
261
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
<Pagination.PageInput.Value />
|
|
288
|
-
<Pagination.PageInput.Addon tag={Return} interactive />
|
|
289
|
-
</>
|
|
290
|
-
),
|
|
291
|
-
});
|
|
262
|
+
const PageInputAddon = (props) => {
|
|
263
|
+
const SPageInputAddon = Root;
|
|
264
|
+
return sstyled(props.styles)(<SPageInputAddon render={Input.Addon} />);
|
|
265
|
+
};
|
|
292
266
|
|
|
267
|
+
class PageInput extends Component {
|
|
293
268
|
render() {
|
|
294
269
|
const SPageInput = Root;
|
|
295
270
|
const SLabel = Text;
|
|
296
|
-
const {
|
|
297
|
-
|
|
298
|
-
logger.warn(
|
|
299
|
-
!!label,
|
|
300
|
-
'"Label" property is deprecated, use i118n to override text',
|
|
301
|
-
this.asProps['data-ui-name'],
|
|
302
|
-
);
|
|
271
|
+
const { Children, getI18nText, styles } = this.asProps;
|
|
303
272
|
|
|
304
273
|
return sstyled(styles)(
|
|
305
274
|
<>
|
|
306
|
-
<SLabel
|
|
307
|
-
<SPageInput render={Input}
|
|
275
|
+
<SLabel>{getI18nText('pageInputLabel')}</SLabel>
|
|
276
|
+
<SPageInput render={Input} controlsLength={Children.origin ? undefined : 2}>
|
|
277
|
+
{Children.origin ? (
|
|
278
|
+
<Children />
|
|
279
|
+
) : (
|
|
280
|
+
<>
|
|
281
|
+
<Pagination.PageInput.Value />
|
|
282
|
+
<Pagination.PageInput.Addon interactive>
|
|
283
|
+
<Return />
|
|
284
|
+
</Pagination.PageInput.Addon>
|
|
285
|
+
</>
|
|
286
|
+
)}
|
|
287
|
+
</SPageInput>
|
|
308
288
|
</>,
|
|
309
289
|
);
|
|
310
290
|
}
|
|
@@ -319,7 +299,7 @@ const Pagination = createComponent(PaginationRoot, {
|
|
|
319
299
|
PageInput,
|
|
320
300
|
{
|
|
321
301
|
Value: PageInputValue,
|
|
322
|
-
Addon:
|
|
302
|
+
Addon: PageInputAddon,
|
|
323
303
|
},
|
|
324
304
|
],
|
|
325
305
|
});
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
2
2
|
import { CProps, PropGetterFn, ReturnEl } from '@semcore/core';
|
|
3
3
|
import { IBoxProps } from '@semcore/flex-box';
|
|
4
4
|
import Input, { IInputProps } from '@semcore/input';
|
|
@@ -12,23 +12,11 @@ export interface IPaginationProps extends IBoxProps, IWithI18nEnhanceProps {
|
|
|
12
12
|
* @default 1
|
|
13
13
|
*/
|
|
14
14
|
totalPages?: number;
|
|
15
|
-
/**
|
|
16
|
-
* Function of formatting the value totalPages
|
|
17
|
-
* @default formatThousands - inserts a comma every 3 characters
|
|
18
|
-
* @deprecated v2.0.0 The property "totalPagesFormatter" is outdated, use the component "<Pagination.TotalPages/>"
|
|
19
|
-
*/
|
|
20
|
-
totalPagesFormatter?: (totalPages: number) => string | number;
|
|
21
15
|
/**
|
|
22
16
|
* Active page number
|
|
23
17
|
* @default 1
|
|
24
18
|
*/
|
|
25
19
|
currentPage?: number;
|
|
26
|
-
/**
|
|
27
|
-
* Callback for changing the active page
|
|
28
|
-
* @param pageNumber
|
|
29
|
-
* @deprecated v2.0.0 {@link IPaginationProps.onCurrentPageChange}
|
|
30
|
-
*/
|
|
31
|
-
onPageChange?: (pageNumber: number) => void;
|
|
32
20
|
/**
|
|
33
21
|
* Callback for changing the active page
|
|
34
22
|
* @param pageNumber
|
|
@@ -36,19 +24,9 @@ export interface IPaginationProps extends IBoxProps, IWithI18nEnhanceProps {
|
|
|
36
24
|
onCurrentPageChange?: (pageNumber: number) => void;
|
|
37
25
|
}
|
|
38
26
|
|
|
39
|
-
export interface ITotalPagesProps extends ITextProps, IWithI18nEnhanceProps {
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated v2.0.0 Use i118n, in order to redefine the text
|
|
42
|
-
* */
|
|
43
|
-
label?: React.ReactNode;
|
|
44
|
-
}
|
|
27
|
+
export interface ITotalPagesProps extends ITextProps, IWithI18nEnhanceProps {}
|
|
45
28
|
|
|
46
|
-
export interface IPageInputProps extends IInputProps, IWithI18nEnhanceProps {
|
|
47
|
-
/**
|
|
48
|
-
* @deprecated v2.0.0 Use i118n, in order to redefine the text
|
|
49
|
-
* */
|
|
50
|
-
label?: React.ReactNode;
|
|
51
|
-
}
|
|
29
|
+
export interface IPageInputProps extends IInputProps, IWithI18nEnhanceProps {}
|
|
52
30
|
|
|
53
31
|
export interface IPaginationContext {
|
|
54
32
|
getFirstPageProps: PropGetterFn;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
@import '@semcore/utils/style/var.css';
|
|
2
|
+
|
|
1
3
|
SPagination {
|
|
2
4
|
display: flex;
|
|
3
5
|
justify-content: flex-start;
|
|
@@ -10,7 +12,7 @@ SPrevPage {
|
|
|
10
12
|
margin-left: 8px;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
SLabel {
|
|
15
|
+
SLabel:not(:first-child) {
|
|
14
16
|
margin-left: 16px;
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -25,23 +27,25 @@ STotalPagesLabel {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
SPageInput {
|
|
28
|
-
max-width:
|
|
30
|
+
max-width: 68px;
|
|
29
31
|
margin-left: 4px;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
SPageInputValue {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
SPageInputValue:focus ~ SPageInputAddon {
|
|
35
|
+
visibility: visible;
|
|
36
|
+
clip: initial;
|
|
37
|
+
position: static;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
SPageInputAddon {
|
|
41
|
+
visibility: hidden;
|
|
42
|
+
clip: rect(1px, 1px, 1px, 1px);
|
|
43
|
+
position: absolute;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
SLabel,
|
|
47
|
+
STotalPages,
|
|
48
|
+
STotalPagesLabel {
|
|
49
|
+
font-size: var(--fs-200);
|
|
50
|
+
line-height: var(--lh-200);
|
|
47
51
|
}
|