widenarrow-ui 1.0.48 → 1.0.49

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": "widenarrow-ui",
3
- "version": "1.0.48",
3
+ "version": "1.0.49",
4
4
  "description": "A storybook 6 typeScript component library used for Wide Narrow by infodesk",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
@@ -21,15 +21,19 @@ const s = classNames.bind(styles);
21
21
  const Pagination: FC<PaginationProps> = ({
22
22
  className,
23
23
  pagination,
24
- onPaginate,
25
24
  slim,
26
- onPageSizeChange,
25
+ onChange,
27
26
  buttonType = HierarchyTypes.SECONDARY,
28
- tablePagination,
27
+ pageSizeOptions = [10, 20, 30, 40, 50, 80, 100],
28
+ firstPageTitle,
29
29
  previousPageTitle,
30
30
  nextPageTitle,
31
+ lastPageTitle,
31
32
  pageSizeTitleCallback,
32
- tableIntervalTitleCallback
33
+ tableIntervalTitleCallback,
34
+ withTablePagination,
35
+ withFastForwardButtons,
36
+ withPageSizeChange
33
37
  }) => {
34
38
  if (!pagination) {
35
39
  return null;
@@ -41,6 +45,7 @@ const Pagination: FC<PaginationProps> = ({
41
45
  : is(Number, pagination.numberOfPages)
42
46
  ? pagination.numberOfPages
43
47
  : 0;
48
+
44
49
  const isLastPage = pagination.currentPage >= numberOfPages;
45
50
 
46
51
  const itemClassName = s('item', { item_slim: slim });
@@ -48,10 +53,6 @@ const Pagination: FC<PaginationProps> = ({
48
53
  const buttonClassName = (additionalClassName?: string) =>
49
54
  s('button', { button_slim: slim, [additionalClassName as string]: additionalClassName });
50
55
 
51
- if (numberOfPages < 2) {
52
- return null;
53
- }
54
-
55
56
  if (pagination.fetching && !numberOfPages) {
56
57
  return (
57
58
  <ul className={s('container', { [className as string]: className })}>
@@ -82,40 +83,79 @@ const Pagination: FC<PaginationProps> = ({
82
83
  );
83
84
  };
84
85
 
86
+ const firstPageButton = withFastForwardButtons ? (
87
+ <li>
88
+ <button
89
+ title={firstPageTitle || 'First page'}
90
+ className={buttonClassName(isFirstPage ? 'button_disabled' : undefined)}
91
+ onClick={() => {
92
+ onChange({ ...pagination, currentPage: 1 });
93
+ }}
94
+ disabled={isFirstPage}
95
+ >
96
+ <Icon icon={IconTypes.ARROW_FIRST_PAGE} />
97
+ </button>
98
+ </li>
99
+ ) : null;
100
+
101
+ const previousPageButton = (
102
+ <li className={itemClassName}>
103
+ <button
104
+ title={previousPageTitle || 'Previous page'}
105
+ className={buttonClassName(isFirstPage ? 'button_disabled' : undefined)}
106
+ onClick={() => {
107
+ !isFirstPage && onChange({ ...pagination, currentPage: pagination.currentPage - 1 });
108
+ }}
109
+ disabled={isFirstPage}
110
+ >
111
+ <Icon icon={IconTypes.CHEVRON_LEFT} />
112
+ </button>
113
+ </li>
114
+ );
115
+
116
+ const nextPageButton = (
117
+ <li className={itemClassName}>
118
+ <button
119
+ title={nextPageTitle || 'Next page'}
120
+ className={buttonClassName(isLastPage ? 'button_disabled' : undefined)}
121
+ onClick={() => {
122
+ onChange({ ...pagination, currentPage: pagination.currentPage + 1 });
123
+ }}
124
+ disabled={isLastPage}
125
+ >
126
+ <Icon icon={IconTypes.CHEVRON_RIGHT} />
127
+ </button>
128
+ </li>
129
+ );
130
+
131
+ const lastPageButton = withFastForwardButtons ? (
132
+ <li>
133
+ <button
134
+ title={lastPageTitle || 'Last page'}
135
+ className={buttonClassName(isLastPage ? 'button_disabled' : undefined)}
136
+ onClick={() => {
137
+ onChange({ ...pagination, currentPage: pagination.numberOfPages });
138
+ }}
139
+ disabled={isLastPage}
140
+ >
141
+ <Icon icon={IconTypes.ARROW_LAST_PAGE} />
142
+ </button>
143
+ </li>
144
+ ) : null;
145
+
85
146
  /*
86
147
  paginationMarkup
87
148
  */
88
149
  const paginationMarkup = () => {
89
- if (tablePagination) {
150
+ if (withTablePagination) {
90
151
  return (
91
152
  <Box alignItems={'center'}>
92
153
  <ul className={s('container', { [className as string]: className })}>
93
- <li className={itemClassName}>
94
- <button
95
- title={previousPageTitle || 'Previous page'}
96
- className={buttonClassName(isFirstPage ? 'button_disabled' : undefined)}
97
- onClick={() => {
98
- !isFirstPage && onPaginate(pagination.currentPage - 1);
99
- }}
100
- disabled={isFirstPage}
101
- >
102
- <Icon icon={IconTypes.CHEVRON_LEFT} />
103
- </button>
104
- </li>
105
- <li className={itemClassName}>
106
- <button
107
- title={nextPageTitle || 'Next page'}
108
- className={buttonClassName(isLastPage ? 'button_disabled' : undefined)}
109
- onClick={() => {
110
- onPaginate(pagination.currentPage + 1);
111
- }}
112
- disabled={isLastPage}
113
- >
114
- <Icon icon={IconTypes.CHEVRON_RIGHT} />
115
- </button>
116
- </li>
154
+ {firstPageButton}
155
+ {previousPageButton}
156
+ {nextPageButton}
157
+ {lastPageButton}
117
158
  </ul>
118
-
119
159
  {getPageInfoText()}
120
160
  </Box>
121
161
  );
@@ -123,18 +163,8 @@ const Pagination: FC<PaginationProps> = ({
123
163
 
124
164
  return (
125
165
  <ul className={s('container', { [className as string]: className })}>
126
- <li className={itemClassName}>
127
- <button
128
- title={previousPageTitle || 'Previous page'}
129
- className={buttonClassName(isFirstPage ? 'button_disabled' : undefined)}
130
- onClick={() => {
131
- !isFirstPage && onPaginate(pagination.currentPage - 1);
132
- }}
133
- disabled={isFirstPage}
134
- >
135
- <Icon icon={IconTypes.CHEVRON_LEFT} />
136
- </button>
137
- </li>
166
+ {firstPageButton}
167
+ {previousPageButton}
138
168
  {getPaginationArray(pagination).map((pageObject, index) => {
139
169
  if (pageObject.type === 'dots') {
140
170
  return (
@@ -149,7 +179,7 @@ const Pagination: FC<PaginationProps> = ({
149
179
  title={`Go to page ${pageObject.page}`}
150
180
  className={buttonClassName(pageObject.page === pagination.currentPage ? 'button_isActive' : undefined)}
151
181
  onClick={() => {
152
- onPaginate(pageObject.page);
182
+ onChange({ ...pagination, currentPage: pageObject.page });
153
183
  }}
154
184
  >
155
185
  {pageObject.page}
@@ -157,38 +187,25 @@ const Pagination: FC<PaginationProps> = ({
157
187
  </li>
158
188
  );
159
189
  })}
160
- <li className={itemClassName}>
161
- <button
162
- title={nextPageTitle || 'Next page'}
163
- className={buttonClassName(isLastPage ? 'button_disabled' : undefined)}
164
- onClick={() => {
165
- onPaginate(pagination.currentPage + 1);
166
- }}
167
- disabled={isLastPage}
168
- >
169
- <Icon icon={IconTypes.CHEVRON_RIGHT} />
170
- </button>
171
- </li>
190
+ {nextPageButton}
191
+ {lastPageButton}
172
192
  </ul>
173
193
  );
174
194
  };
175
195
 
176
- /*
177
- pageSizeMarkup
178
- */
179
196
  const sizeTitle = pageSizeTitleCallback ? pageSizeTitleCallback({ pageSize: pagination.pageSize }) : `Page size: ${pagination.pageSize}`;
180
197
 
181
198
  const pageSizeMarkup = () =>
182
- onPageSizeChange ? (
199
+ withPageSizeChange ? (
183
200
  <Fragment>
184
201
  <Separator marginX={'15'} />
185
202
  <DropDown buttonComponent={<InlineButton type={buttonType} text={sizeTitle} />} title={sizeTitle}>
186
- {[10, 20, 30, 40, 50, 80, 100]
203
+ {pageSizeOptions
187
204
  .filter((pageSize) => pageSize < pagination.numberOfHits)
188
205
  .map((pageSize) => (
189
206
  <DropDownItem
190
207
  text={pageSize.toString()}
191
- onClickCallback={() => onPageSizeChange(pageSize)}
208
+ onClickCallback={() => onChange({ ...pagination, pageSize })}
192
209
  active={pagination.pageSize === pageSize}
193
210
  closeDropDownOnClick
194
211
  withEllipsis
@@ -3,14 +3,18 @@ import { SearchResultInterface } from '../../types/common.types';
3
3
 
4
4
  export interface PaginationProps {
5
5
  pagination: SearchResultInterface;
6
- onPaginate: (page: number) => void;
7
- onPageSizeChange?: (pageSize: number) => void;
6
+ onChange: (searchResult: SearchResultInterface) => void;
8
7
  slim?: boolean;
9
- tablePagination?: boolean;
8
+ withPageSizeChange?: boolean;
9
+ withTablePagination?: boolean;
10
+ withFastForwardButtons: boolean;
11
+ pageSizeOptions?: Array<number>;
10
12
  buttonType?: HierarchyTypes.PRIMARY | HierarchyTypes.SECONDARY;
11
13
  className?: string;
12
14
  nextPageTitle?: string;
13
15
  previousPageTitle?: string;
16
+ firstPageTitle?: string;
17
+ lastPageTitle?: string;
14
18
  pageSizeTitleCallback?: (args: { pageSize: number }) => string;
15
19
  tableIntervalTitleCallback?: (args: { start: number; end: number; total: number }) => string;
16
20
  }