homeflowjs 1.0.38 → 1.0.39
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
package/properties/property-results-pagination/property-results-pagination-item.component.jsx
CHANGED
@@ -13,21 +13,45 @@ export default function PropertyResultsPaginationItem({
|
|
13
13
|
LeftChevron,
|
14
14
|
RightChevron,
|
15
15
|
}) {
|
16
|
-
const activeClassName = (className) =>
|
17
|
-
currentPage === pageNumber ? `${className}--active` : ''
|
18
|
-
|
16
|
+
const activeClassName = (className) =>
|
17
|
+
currentPage === pageNumber ? `${className}--active` : '';
|
18
|
+
|
19
|
+
const pageLink = () => {
|
20
|
+
if (window.location.pathname.includes('page-')) {
|
21
|
+
return window.location.pathname.replace(/page-\d+/, `page-${pageNumber}`);
|
22
|
+
}
|
23
|
+
return `${window.location.pathname}/page-${pageNumber}`;
|
24
|
+
};
|
25
|
+
|
19
26
|
return (
|
20
|
-
<li
|
21
|
-
|
27
|
+
<li
|
28
|
+
className={`property-results-pagination__item ${activeClassName(
|
29
|
+
'property-results-pagination__item'
|
30
|
+
)}`}
|
31
|
+
>
|
32
|
+
<a
|
33
|
+
href={pageLink()}
|
34
|
+
className={`property-results-pagination__link ${activeClassName(
|
35
|
+
'property-results-pagination__link'
|
36
|
+
)}`}
|
37
|
+
>
|
22
38
|
{previous && (
|
23
39
|
<>
|
24
40
|
{!noChevrons && <LeftChevron />}
|
25
|
-
{!noPrevOrNextText &&
|
41
|
+
{!noPrevOrNextText && (
|
42
|
+
<span className="property-results-pagination__link-prev-text">
|
43
|
+
Previous
|
44
|
+
</span>
|
45
|
+
)}
|
26
46
|
</>
|
27
47
|
)}
|
28
48
|
{next && (
|
29
49
|
<>
|
30
|
-
{!noPrevOrNextText &&
|
50
|
+
{!noPrevOrNextText && (
|
51
|
+
<span className="property-results-pagination__link-next-text">
|
52
|
+
Next
|
53
|
+
</span>
|
54
|
+
)}
|
31
55
|
{!noChevrons && <RightChevron />}
|
32
56
|
</>
|
33
57
|
)}
|
@@ -22,78 +22,110 @@ export default function PropertyResultsPagination({
|
|
22
22
|
current_page: currentPage,
|
23
23
|
has_next_page: hasNextPage,
|
24
24
|
has_prev_page: hasPrevPage,
|
25
|
-
total_count: totalCount,
|
26
25
|
page_count: pageCount,
|
27
26
|
} = pagination;
|
28
27
|
|
29
28
|
/**
|
30
|
-
* Generates an array of pagination
|
31
|
-
* based on the current page and total page count.
|
32
|
-
* For example the 2,3,4 and 5 in < 1 ... 2 - 3 - 4 - 5 ... 29 >
|
33
|
-
*
|
29
|
+
* Generates an array of pagination with ellipsis '...' where appropriate
|
34
30
|
* @example
|
35
31
|
* currentPage = 1;
|
36
|
-
* pageCount =
|
37
|
-
*
|
32
|
+
* pageCount = 1;
|
33
|
+
* paginationIncrements = 4;
|
34
|
+
* 'Should output: [1]'
|
38
35
|
*
|
39
36
|
* currentPage = 1;
|
40
37
|
* pageCount = 5;
|
41
|
-
*
|
38
|
+
* paginationIncrements = 4;
|
39
|
+
*'Should output: ['1', '2', '3', '4', '5']'
|
40
|
+
*
|
41
|
+
* currentPage = 1;
|
42
|
+
* pageCount = 3;
|
43
|
+
* paginationIncrements = 4;
|
44
|
+
*'Should output: ['1', '2','3']'
|
45
|
+
*
|
46
|
+
* currentPage = 1;
|
47
|
+
* pageCount = 100;
|
48
|
+
* paginationIncrements = 4;
|
49
|
+
*'Should output: ['1', '2', '3', '4', '5', '...', '100']'
|
42
50
|
*
|
43
51
|
* currentPage = 2;
|
44
52
|
* pageCount = 100;
|
45
|
-
*
|
53
|
+
* paginationIncrements = 4;
|
54
|
+
* 'Should output: ['1', '2', '3', '4', '5', '...', '100']'
|
46
55
|
*
|
47
56
|
* currentPage = 3;
|
48
57
|
* pageCount = 100;
|
49
|
-
*
|
58
|
+
* paginationIncrements = 4;
|
59
|
+
* 'Should output: ['1', '...', '3', '4', '5', '6', '...', '100']'
|
50
60
|
*
|
51
|
-
* currentPage =
|
61
|
+
* currentPage = 99;
|
52
62
|
* pageCount = 100;
|
53
|
-
*
|
63
|
+
* paginationIncrements = 4;
|
64
|
+
* 'Should output: ['1', '...', '96', '97', '98', '99', '100']'
|
54
65
|
*
|
55
|
-
* currentPage =
|
56
|
-
* pageCount =
|
57
|
-
*
|
66
|
+
* currentPage = 96;
|
67
|
+
* pageCount = 100;
|
68
|
+
* paginationIncrements = 4;
|
69
|
+
* 'Should output: ['1', '...', '96', '97', '98', '99', '100']'
|
58
70
|
*
|
59
|
-
* currentPage =
|
60
|
-
* pageCount =
|
61
|
-
*
|
62
|
-
*
|
71
|
+
* currentPage = 100;
|
72
|
+
* pageCount = 100;
|
73
|
+
* paginationIncrements = 4;
|
74
|
+
* 'Should output: ['1', '...','96','97', '98', '99', '100']'
|
75
|
+
*
|
76
|
+
* @returns {string[]} An array of strings for pagination.
|
63
77
|
*/
|
64
|
-
const
|
65
|
-
if (pageCount === 1) return [];
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
78
|
+
const generatePagination = () => {
|
79
|
+
if (pageCount === 1) return ['1'];
|
80
|
+
|
81
|
+
let pages = [];
|
82
|
+
|
83
|
+
if (pageCount <= paginationIncrements + 1) {
|
84
|
+
for (let i = 1; i <= pageCount; i++) {
|
85
|
+
pages.push(i.toString());
|
86
|
+
}
|
87
|
+
return pages;
|
73
88
|
}
|
74
89
|
|
75
|
-
if (
|
76
|
-
|
90
|
+
if (currentPage > 1 && currentPage !== 2) {
|
91
|
+
pages.push('1', '...');
|
77
92
|
}
|
78
93
|
|
79
|
-
|
80
|
-
|
81
|
-
startIncrement = pageCount >= paginationIncrements
|
82
|
-
? currentPage - paginationIncrements : currentPage - (paginationIncrements - currentPage);
|
83
|
-
endIncrement = currentPage;
|
94
|
+
if (currentPage === 2) {
|
95
|
+
pages.push('1');
|
84
96
|
}
|
85
97
|
|
86
|
-
|
87
|
-
|
98
|
+
const getStart = () => {
|
99
|
+
if (currentPage + paginationIncrements >= pageCount)
|
100
|
+
return pageCount - paginationIncrements;
|
101
|
+
return Math.max(currentPage, 1);
|
102
|
+
};
|
103
|
+
|
104
|
+
const getEnd = () => {
|
105
|
+
if (currentPage + paginationIncrements >= pageCount) return pageCount;
|
106
|
+
if (currentPage === 1) return paginationIncrements + 1;
|
107
|
+
return Math.min(currentPage + (paginationIncrements - 1), pageCount);
|
108
|
+
};
|
109
|
+
|
110
|
+
const start = getStart();
|
111
|
+
const end = getEnd();
|
112
|
+
|
113
|
+
for (let i = start; i <= end; i++) {
|
114
|
+
pages.push(i.toString());
|
115
|
+
}
|
116
|
+
|
117
|
+
if (end < pageCount) {
|
118
|
+
pages.push('...', pageCount.toString());
|
88
119
|
}
|
89
|
-
|
120
|
+
|
121
|
+
return pages;
|
90
122
|
};
|
91
123
|
|
92
124
|
return (
|
93
125
|
<div className="property-results-pagination" {...otherProps}>
|
94
126
|
<ul className="property-results-pagination__links">
|
95
127
|
{/* Previous page */}
|
96
|
-
{hasPrevPage &&
|
128
|
+
{hasPrevPage && !noChevrons && !noPrevOrNextText && (
|
97
129
|
<PropertyResultsPaginationItem
|
98
130
|
previous
|
99
131
|
pageNumber={currentPage - 1}
|
@@ -102,45 +134,28 @@ export default function PropertyResultsPagination({
|
|
102
134
|
/>
|
103
135
|
)}
|
104
136
|
|
105
|
-
{
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
{
|
127
|
-
{totalCount > paginationIncrements && (
|
128
|
-
<li className="property-results-pagination__item property-results-pagination__item--ellipsis">
|
129
|
-
<span className="property-results-pagination__ellipsis">…</span>
|
130
|
-
</li>
|
131
|
-
)}
|
132
|
-
|
133
|
-
{/* Total page count */}
|
134
|
-
{showIfPageCountIsOne && pageCount !== 0 ? (
|
135
|
-
<PropertyResultsPaginationItem pageNumber={pageCount} currentPage={currentPage} />
|
136
|
-
) : (
|
137
|
-
pageCount > 1 && (
|
138
|
-
<PropertyResultsPaginationItem pageNumber={pageCount} currentPage={currentPage} />
|
139
|
-
)
|
140
|
-
)}
|
141
|
-
|
142
|
-
{/* Previous page */}
|
143
|
-
{hasNextPage && (!noChevrons && !noPrevOrNextText) && (
|
137
|
+
{generatePagination().map((page) => {
|
138
|
+
if (page === '...') {
|
139
|
+
// Ellipsis
|
140
|
+
return (
|
141
|
+
<li className="property-results-pagination__item property-results-pagination__item--ellipsis">
|
142
|
+
<span className="property-results-pagination__ellipsis">
|
143
|
+
…
|
144
|
+
</span>
|
145
|
+
</li>
|
146
|
+
);
|
147
|
+
}
|
148
|
+
return (
|
149
|
+
<PropertyResultsPaginationItem
|
150
|
+
key={page}
|
151
|
+
pageNumber={parseInt(page, 10)}
|
152
|
+
currentPage={currentPage}
|
153
|
+
/>
|
154
|
+
);
|
155
|
+
})}
|
156
|
+
|
157
|
+
{/* Next page */}
|
158
|
+
{hasNextPage && !noChevrons && !noPrevOrNextText && (
|
144
159
|
<PropertyResultsPaginationItem
|
145
160
|
next
|
146
161
|
pageNumber={currentPage + 1}
|