@semcore/pagination 2.5.1 → 3.0.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.
@@ -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
- defaultCurrentPage: 1,
53
- defaultTotalPages: 1,
54
- i18n,
55
- children: (
56
- <>
57
- <Pagination.FirstPage />
58
- <Pagination.PrevPage />
59
- <Pagination.NextPage />
60
- <Pagination.PageInput />
61
- <Pagination.TotalPages />
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, totalPagesFormatter, getI18nText } = this.asProps;
190
+ const { currentPage, totalPages, getI18nText } = this.asProps;
205
191
  return {
206
- // deprecated
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, label, getI18nText } = this.asProps;
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 size={100}>{label || getI18nText('totalPagesLabel')}</STotalPagesLabel>
272
- <STotalPages render={Link} tag="button" type="button" size={100} />
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
- class PageInput extends Component {
284
- static defaultProps = () => ({
285
- children: (
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 { label, getI18nText, styles } = this.asProps;
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 size={100}>{label || getI18nText('pageInputLabel')}</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: Input.Addon,
302
+ Addon: PageInputAddon,
323
303
  },
324
304
  ],
325
305
  });
package/src/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React, { ComponentProps } from 'react';
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: 64px;
30
+ max-width: 68px;
29
31
  margin-left: 4px;
30
32
  }
31
33
 
32
- SPageInputValue {
33
- & + * {
34
- visibility: hidden;
35
- clip: rect(1px, 1px, 1px, 1px);
36
- position: absolute;
37
- }
38
- &:focus {
39
- padding-right: 0;
40
- }
41
- &:focus + * {
42
- padding-left: 2px;
43
- visibility: visible;
44
- clip: initial;
45
- position: static;
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
  }