@automattic/vip-design-system 2.18.0 → 2.18.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.
- package/build/system/Pagination/Pagination.d.ts +10 -20
- package/build/system/Pagination/Pagination.js +50 -68
- package/build/system/Pagination/Pagination.stories.js +13 -11
- package/build/system/Pagination/Pagination.test.js +4 -4
- package/build/system/Pagination/PaginationLayout.d.ts +27 -0
- package/build/system/Pagination/PaginationLayout.js +63 -0
- package/build/system/Pagination/SimplePagination.d.ts +26 -0
- package/build/system/Pagination/SimplePagination.js +76 -0
- package/build/system/Pagination/SimplePagination.stories.d.ts +13 -0
- package/build/system/Pagination/SimplePagination.stories.js +130 -0
- package/build/system/Pagination/SimplePagination.test.d.ts +2 -0
- package/build/system/Pagination/SimplePagination.test.js +171 -0
- package/build/system/Pagination/index.d.ts +3 -1
- package/build/system/Pagination/index.js +2 -1
- package/build/system/index.d.ts +2 -2
- package/build/system/index.js +2 -2
- package/package.json +1 -1
- package/src/system/Pagination/Pagination.stories.tsx +13 -10
- package/src/system/Pagination/Pagination.test.tsx +4 -6
- package/src/system/Pagination/Pagination.tsx +36 -71
- package/src/system/Pagination/PaginationLayout.tsx +93 -0
- package/src/system/Pagination/SimplePagination.stories.tsx +127 -0
- package/src/system/Pagination/SimplePagination.test.tsx +120 -0
- package/src/system/Pagination/SimplePagination.tsx +97 -0
- package/src/system/Pagination/index.ts +3 -1
- package/src/system/index.ts +2 -1
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/** @jsxImportSource theme-ui */
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
export interface PaginationProps {
|
|
5
|
-
/** Whether to show the items-per-page dropdown selector.
|
|
6
|
-
* @default false
|
|
7
|
-
*/
|
|
8
|
-
displayItemsPerPageSelector?: boolean;
|
|
2
|
+
import { PaginationLayoutProps } from './PaginationLayout';
|
|
3
|
+
export interface PaginationProps extends PaginationLayoutProps {
|
|
9
4
|
/** The currently active page number (1-based). */
|
|
10
5
|
currentPage: number;
|
|
11
6
|
/** Total number of items across all pages. Used to compute totalPages if not provided. */
|
|
@@ -22,25 +17,20 @@ export interface PaginationProps {
|
|
|
22
17
|
hasNextPage?: boolean;
|
|
23
18
|
/** The maximum page number that can be reached. Used for open-ended pagination without totalPages. */
|
|
24
19
|
maxReachablePage?: number;
|
|
25
|
-
/**
|
|
26
|
-
* @default
|
|
20
|
+
/** When true, shows a compact dropdown page selector instead of individual page buttons.
|
|
21
|
+
* @default false
|
|
27
22
|
*/
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @default
|
|
23
|
+
compact?: boolean;
|
|
24
|
+
/** Display variant. Use 'compact' for dropdown page selector. Equivalent to the `compact` prop.
|
|
25
|
+
* @default 'full'
|
|
26
|
+
* @deprecated Use the `compact` prop instead, or `SimplePagination` for cursor-based navigation.
|
|
31
27
|
*/
|
|
32
|
-
|
|
33
|
-
/** Additional CSS class name for the pagination container. */
|
|
34
|
-
className?: string;
|
|
35
|
-
/** Theme UI style overrides. */
|
|
36
|
-
sx?: ThemeUIStyleObject;
|
|
37
|
-
/** Optional content rendered between the items-per-page selector and page navigation. */
|
|
38
|
-
children?: React.ReactNode;
|
|
28
|
+
variant?: 'full' | 'compact';
|
|
39
29
|
}
|
|
40
30
|
export type PageNumberItem = number | 'ellipsis';
|
|
41
31
|
export declare function getPageNumbers(currentPage: number, totalPages?: number, hasNextPage?: boolean, maxReachablePage?: number): PageNumberItem[];
|
|
42
32
|
/**
|
|
43
33
|
* A pagination control for navigating through paged content.
|
|
44
|
-
*
|
|
34
|
+
* Shows page-number buttons by default, or a compact dropdown when `compact` is true.
|
|
45
35
|
*/
|
|
46
36
|
export declare const Pagination: import("react").ForwardRefExoticComponent<PaginationProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var _excluded = ["
|
|
1
|
+
var _excluded = ["currentPage", "totalItems", "totalPages", "itemsPerPage", "onPageChange", "onItemsPerPageChange", "hasNextPage", "maxReachablePage", "compact", "variant", "displayItemsPerPageSelector", "pageSizeOptions", "className", "sx", "children"];
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
4
|
/** @jsxImportSource theme-ui */
|
|
5
5
|
|
|
6
|
-
import classNames from 'classnames';
|
|
7
6
|
import { forwardRef } from 'react';
|
|
8
7
|
import { BiDotsHorizontalRounded } from 'react-icons/bi';
|
|
9
8
|
import { MdChevronLeft, MdChevronRight } from 'react-icons/md';
|
|
10
9
|
import { Flex } from 'theme-ui';
|
|
11
|
-
import {
|
|
10
|
+
import { PaginationLayout } from './PaginationLayout';
|
|
11
|
+
import { navigationStyles, pageButtonStyles, activePageButtonStyles, arrowButtonStyles, compactTextStyles } from './styles';
|
|
12
12
|
import { Box } from '../Box';
|
|
13
13
|
import { Button } from '../Button';
|
|
14
14
|
import { Select } from '../NewForm';
|
|
@@ -75,32 +75,12 @@ export function getPageNumbers(currentPage, totalPages, hasNextPage, maxReachabl
|
|
|
75
75
|
// Fully open-ended middle
|
|
76
76
|
return [1, 'ellipsis'].concat(range(currentPage - PAGES_BEFORE_CURRENT, currentPage + PAGES_AFTER_CURRENT + 1), ['ellipsis']);
|
|
77
77
|
}
|
|
78
|
-
var
|
|
79
|
-
var
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"aria-label": "Items per page",
|
|
85
|
-
separator: false,
|
|
86
|
-
value: itemsPerPage,
|
|
87
|
-
options: pageSizeOptions.map(function (size) {
|
|
88
|
-
return {
|
|
89
|
-
value: size,
|
|
90
|
-
label: size.toString() + " / page"
|
|
91
|
-
};
|
|
92
|
-
}),
|
|
93
|
-
onChange: function onChange(option) {
|
|
94
|
-
return onItemsPerPageChange(Number(option == null ? void 0 : option.value));
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
var PageNumbers = function PageNumbers(_ref2) {
|
|
99
|
-
var currentPage = _ref2.currentPage,
|
|
100
|
-
totalPages = _ref2.totalPages,
|
|
101
|
-
hasNextPage = _ref2.hasNextPage,
|
|
102
|
-
maxReachablePage = _ref2.maxReachablePage,
|
|
103
|
-
onPageChange = _ref2.onPageChange;
|
|
78
|
+
var PageNumbers = function PageNumbers(_ref) {
|
|
79
|
+
var currentPage = _ref.currentPage,
|
|
80
|
+
totalPages = _ref.totalPages,
|
|
81
|
+
hasNextPage = _ref.hasNextPage,
|
|
82
|
+
maxReachablePage = _ref.maxReachablePage,
|
|
83
|
+
onPageChange = _ref.onPageChange;
|
|
104
84
|
var pages = getPageNumbers(currentPage, totalPages, hasNextPage, maxReachablePage);
|
|
105
85
|
return _jsx(_Fragment, {
|
|
106
86
|
children: pages.map(function (page, index) {
|
|
@@ -121,11 +101,11 @@ var PageNumbers = function PageNumbers(_ref2) {
|
|
|
121
101
|
})
|
|
122
102
|
});
|
|
123
103
|
};
|
|
124
|
-
var CompactPageSelector = function CompactPageSelector(
|
|
125
|
-
var currentPage =
|
|
126
|
-
totalPages =
|
|
127
|
-
maxReachablePage =
|
|
128
|
-
onPageChange =
|
|
104
|
+
var CompactPageSelector = function CompactPageSelector(_ref2) {
|
|
105
|
+
var currentPage = _ref2.currentPage,
|
|
106
|
+
totalPages = _ref2.totalPages,
|
|
107
|
+
maxReachablePage = _ref2.maxReachablePage,
|
|
108
|
+
onPageChange = _ref2.onPageChange;
|
|
129
109
|
var isOpenEnded = totalPages === undefined;
|
|
130
110
|
var upperBound = isOpenEnded ? maxReachablePage != null ? maxReachablePage : currentPage + 1 : totalPages;
|
|
131
111
|
var pageOptions = Array.from({
|
|
@@ -175,58 +155,60 @@ var CompactPageSelector = function CompactPageSelector(_ref3) {
|
|
|
175
155
|
|
|
176
156
|
/**
|
|
177
157
|
* A pagination control for navigating through paged content.
|
|
178
|
-
*
|
|
158
|
+
* Shows page-number buttons by default, or a compact dropdown when `compact` is true.
|
|
179
159
|
*/
|
|
180
|
-
export var Pagination = /*#__PURE__*/forwardRef(function (
|
|
181
|
-
var
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
160
|
+
export var Pagination = /*#__PURE__*/forwardRef(function (_ref3, ref) {
|
|
161
|
+
var currentPage = _ref3.currentPage,
|
|
162
|
+
totalItems = _ref3.totalItems,
|
|
163
|
+
totalPages = _ref3.totalPages,
|
|
164
|
+
itemsPerPage = _ref3.itemsPerPage,
|
|
165
|
+
onPageChange = _ref3.onPageChange,
|
|
166
|
+
onItemsPerPageChange = _ref3.onItemsPerPageChange,
|
|
167
|
+
hasNextPage = _ref3.hasNextPage,
|
|
168
|
+
maxReachablePage = _ref3.maxReachablePage,
|
|
169
|
+
_ref3$compact = _ref3.compact,
|
|
170
|
+
compact = _ref3$compact === void 0 ? false : _ref3$compact,
|
|
171
|
+
variant = _ref3.variant,
|
|
172
|
+
displayItemsPerPageSelector = _ref3.displayItemsPerPageSelector,
|
|
173
|
+
pageSizeOptions = _ref3.pageSizeOptions,
|
|
174
|
+
className = _ref3.className,
|
|
175
|
+
sx = _ref3.sx,
|
|
176
|
+
children = _ref3.children,
|
|
177
|
+
rest = _objectWithoutPropertiesLoose(_ref3, _excluded);
|
|
178
|
+
var isCompact = compact || variant === 'compact';
|
|
199
179
|
var resolvedTotalPages = totalPages != null ? totalPages : totalItems !== undefined ? Math.ceil(totalItems / itemsPerPage) : undefined;
|
|
200
180
|
var isFirstPage = currentPage <= 1;
|
|
201
|
-
var isLastPage
|
|
202
|
-
|
|
181
|
+
var isLastPage;
|
|
182
|
+
if (resolvedTotalPages !== undefined) {
|
|
183
|
+
isLastPage = currentPage >= resolvedTotalPages;
|
|
184
|
+
} else {
|
|
185
|
+
isLastPage = hasNextPage === false;
|
|
186
|
+
}
|
|
187
|
+
return _jsxs(PaginationLayout, _extends({
|
|
203
188
|
ref: ref,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
189
|
+
displayItemsPerPageSelector: displayItemsPerPageSelector,
|
|
190
|
+
itemsPerPage: itemsPerPage,
|
|
191
|
+
pageSizeOptions: pageSizeOptions,
|
|
192
|
+
onItemsPerPageChange: onItemsPerPageChange,
|
|
193
|
+
className: className,
|
|
194
|
+
sx: sx
|
|
207
195
|
}, rest, {
|
|
208
196
|
children: [_jsx(Box, {
|
|
209
|
-
children: displayItemsPerPageSelector && _jsx(ItemsPerPageSelect, {
|
|
210
|
-
itemsPerPage: itemsPerPage,
|
|
211
|
-
pageSizeOptions: pageSizeOptions,
|
|
212
|
-
onItemsPerPageChange: onItemsPerPageChange
|
|
213
|
-
})
|
|
214
|
-
}), _jsx(Box, {
|
|
215
197
|
sx: {
|
|
216
198
|
flex: 1
|
|
217
199
|
},
|
|
218
200
|
children: children
|
|
219
201
|
}), _jsxs(Flex, {
|
|
220
202
|
sx: navigationStyles,
|
|
221
|
-
children: [
|
|
203
|
+
children: [isCompact ? _jsx(CompactPageSelector, {
|
|
222
204
|
currentPage: currentPage,
|
|
223
205
|
totalPages: resolvedTotalPages,
|
|
224
|
-
hasNextPage: hasNextPage,
|
|
225
206
|
maxReachablePage: maxReachablePage,
|
|
226
207
|
onPageChange: onPageChange
|
|
227
|
-
})
|
|
208
|
+
}) : _jsx(PageNumbers, {
|
|
228
209
|
currentPage: currentPage,
|
|
229
210
|
totalPages: resolvedTotalPages,
|
|
211
|
+
hasNextPage: hasNextPage,
|
|
230
212
|
maxReachablePage: maxReachablePage,
|
|
231
213
|
onPageChange: onPageChange
|
|
232
214
|
}), _jsx(Button, {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var _excluded = ["initialPage", "totalItems", "initialItemsPerPage", "displayItemsPerPageSelector"]
|
|
2
|
-
_excluded2 = ["initialPage", "initialItemsPerPage", "hasNextPage"];
|
|
1
|
+
var _excluded = ["initialPage", "totalItems", "initialItemsPerPage", "displayItemsPerPageSelector", "compact"];
|
|
3
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
4
3
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
5
4
|
/** @jsxImportSource theme-ui */
|
|
@@ -20,7 +19,7 @@ var meta = {
|
|
|
20
19
|
parameters: {
|
|
21
20
|
docs: {
|
|
22
21
|
description: {
|
|
23
|
-
component: "\nA Pagination component for navigating paged data.\n\n##
|
|
22
|
+
component: "\nA Pagination component for navigating paged data.\n\n## Modes\n\n- **Default**: Shows individual page number buttons with ellipsis for large page counts.\n- **Compact** (`compact` prop): Shows a dropdown page selector instead of individual page numbers.\n\nFor cursor-based pagination with only prev/next arrows, see `SimplePagination`.\n\n## Component Properties\n"
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
}
|
|
@@ -35,6 +34,8 @@ var PaginationWithState = function PaginationWithState(_ref) {
|
|
|
35
34
|
initialItemsPerPage = _ref$initialItemsPerP === void 0 ? 20 : _ref$initialItemsPerP,
|
|
36
35
|
_ref$displayItemsPerP = _ref.displayItemsPerPageSelector,
|
|
37
36
|
displayItemsPerPageSelector = _ref$displayItemsPerP === void 0 ? false : _ref$displayItemsPerP,
|
|
37
|
+
_ref$compact = _ref.compact,
|
|
38
|
+
compact = _ref$compact === void 0 ? false : _ref$compact,
|
|
38
39
|
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
39
40
|
var _useState = useState(initialPage),
|
|
40
41
|
currentPage = _useState[0],
|
|
@@ -49,6 +50,7 @@ var PaginationWithState = function PaginationWithState(_ref) {
|
|
|
49
50
|
itemsPerPage: itemsPerPage,
|
|
50
51
|
onPageChange: setCurrentPage,
|
|
51
52
|
displayItemsPerPageSelector: displayItemsPerPageSelector,
|
|
53
|
+
compact: compact,
|
|
52
54
|
onItemsPerPageChange: function onItemsPerPageChange(size) {
|
|
53
55
|
setItemsPerPage(size);
|
|
54
56
|
setCurrentPage(1);
|
|
@@ -78,14 +80,15 @@ var OpenEndedPaginationWithState = function OpenEndedPaginationWithState(_ref2)
|
|
|
78
80
|
_ref2$initialItemsPer = _ref2.initialItemsPerPage,
|
|
79
81
|
initialItemsPerPage = _ref2$initialItemsPer === void 0 ? 20 : _ref2$initialItemsPer,
|
|
80
82
|
hasNextPage = _ref2.hasNextPage,
|
|
81
|
-
|
|
83
|
+
_ref2$compact = _ref2.compact,
|
|
84
|
+
compact = _ref2$compact === void 0 ? false : _ref2$compact;
|
|
82
85
|
var _useState3 = useState(initialPage),
|
|
83
86
|
currentPage = _useState3[0],
|
|
84
87
|
setCurrentPage = _useState3[1];
|
|
85
88
|
var _useState4 = useState(initialItemsPerPage),
|
|
86
89
|
itemsPerPage = _useState4[0],
|
|
87
90
|
setItemsPerPage = _useState4[1];
|
|
88
|
-
return _jsx(Pagination,
|
|
91
|
+
return _jsx(Pagination, {
|
|
89
92
|
currentPage: currentPage,
|
|
90
93
|
itemsPerPage: itemsPerPage,
|
|
91
94
|
onPageChange: setCurrentPage,
|
|
@@ -93,8 +96,8 @@ var OpenEndedPaginationWithState = function OpenEndedPaginationWithState(_ref2)
|
|
|
93
96
|
setItemsPerPage(size);
|
|
94
97
|
setCurrentPage(1);
|
|
95
98
|
},
|
|
96
|
-
hasNextPage: hasNextPage
|
|
97
|
-
|
|
99
|
+
hasNextPage: hasNextPage,
|
|
100
|
+
compact: compact,
|
|
98
101
|
children: _jsxs(Flex, {
|
|
99
102
|
sx: {
|
|
100
103
|
justifyContent: 'center',
|
|
@@ -111,14 +114,13 @@ var OpenEndedPaginationWithState = function OpenEndedPaginationWithState(_ref2)
|
|
|
111
114
|
children: ["Page ", currentPage, " (open-ended)"]
|
|
112
115
|
})]
|
|
113
116
|
})
|
|
114
|
-
})
|
|
117
|
+
});
|
|
115
118
|
};
|
|
116
119
|
export var Primary = {
|
|
117
120
|
args: {
|
|
118
121
|
currentPage: 1,
|
|
119
122
|
totalItems: 200,
|
|
120
123
|
itemsPerPage: 20,
|
|
121
|
-
variant: 'full',
|
|
122
124
|
displayItemsPerPageSelector: false
|
|
123
125
|
}
|
|
124
126
|
};
|
|
@@ -130,7 +132,7 @@ export var Default = {
|
|
|
130
132
|
export var Compact = {
|
|
131
133
|
render: function render() {
|
|
132
134
|
return _jsx(PaginationWithState, {
|
|
133
|
-
|
|
135
|
+
compact: true
|
|
134
136
|
});
|
|
135
137
|
}
|
|
136
138
|
};
|
|
@@ -230,7 +232,7 @@ export var OpenEnded = {
|
|
|
230
232
|
export var OpenEndedCompact = {
|
|
231
233
|
render: function render() {
|
|
232
234
|
return _jsx(OpenEndedPaginationWithState, {
|
|
233
|
-
|
|
235
|
+
compact: true
|
|
234
236
|
});
|
|
235
237
|
}
|
|
236
238
|
};
|
|
@@ -166,7 +166,7 @@ describe('<Pagination />', function () {
|
|
|
166
166
|
});
|
|
167
167
|
it('renders compact variant with Page text', function () {
|
|
168
168
|
render(_jsx(Pagination, _extends({}, defaultProps, {
|
|
169
|
-
|
|
169
|
+
compact: true,
|
|
170
170
|
currentPage: 3
|
|
171
171
|
})));
|
|
172
172
|
expect(screen.getByText('Page')).toBeInTheDocument();
|
|
@@ -205,7 +205,7 @@ describe('<Pagination />', function () {
|
|
|
205
205
|
while (1) switch (_context5.n) {
|
|
206
206
|
case 0:
|
|
207
207
|
_render2 = render(_jsx(Pagination, _extends({}, defaultProps, {
|
|
208
|
-
|
|
208
|
+
compact: true,
|
|
209
209
|
currentPage: 5
|
|
210
210
|
}))), container = _render2.container;
|
|
211
211
|
_t2 = expect;
|
|
@@ -370,7 +370,7 @@ describe('<Pagination /> open-ended mode', function () {
|
|
|
370
370
|
})));
|
|
371
371
|
it('renders compact variant with "Page" but without "of Y"', function () {
|
|
372
372
|
render(_jsx(Pagination, _extends({}, openEndedProps, {
|
|
373
|
-
|
|
373
|
+
compact: true
|
|
374
374
|
})));
|
|
375
375
|
expect(screen.getByText('Page')).toBeInTheDocument();
|
|
376
376
|
expect(screen.queryByText(/of \d+/)).not.toBeInTheDocument();
|
|
@@ -397,7 +397,7 @@ describe('<Pagination /> open-ended mode', function () {
|
|
|
397
397
|
while (1) switch (_context9.n) {
|
|
398
398
|
case 0:
|
|
399
399
|
_render5 = render(_jsx(Pagination, _extends({}, openEndedProps, {
|
|
400
|
-
|
|
400
|
+
compact: true
|
|
401
401
|
}))), container = _render5.container;
|
|
402
402
|
_t5 = expect;
|
|
403
403
|
_context9.n = 1;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
import { ThemeUIStyleObject } from 'theme-ui';
|
|
3
|
+
export interface PaginationLayoutProps {
|
|
4
|
+
/** Whether to show the items-per-page dropdown selector.
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
displayItemsPerPageSelector?: boolean;
|
|
8
|
+
/** Number of items displayed per page. */
|
|
9
|
+
itemsPerPage?: number;
|
|
10
|
+
/** Available page size options for the items-per-page selector.
|
|
11
|
+
* @default [20, 50, 100]
|
|
12
|
+
*/
|
|
13
|
+
pageSizeOptions?: number[];
|
|
14
|
+
/** Callback fired when the user changes the items-per-page value. */
|
|
15
|
+
onItemsPerPageChange?: (itemsPerPage: number) => void;
|
|
16
|
+
/** Additional CSS class name for the pagination container. */
|
|
17
|
+
className?: string;
|
|
18
|
+
/** Theme UI style overrides. */
|
|
19
|
+
sx?: ThemeUIStyleObject;
|
|
20
|
+
/** Slot for variant-specific content (page numbers, arrows, etc.). */
|
|
21
|
+
children?: React.ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Shared layout wrapper for pagination components.
|
|
25
|
+
* Renders the nav landmark, optional items-per-page selector, and variant content.
|
|
26
|
+
*/
|
|
27
|
+
export declare const PaginationLayout: import("react").ForwardRefExoticComponent<PaginationLayoutProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var _excluded = ["displayItemsPerPageSelector", "itemsPerPage", "pageSizeOptions", "onItemsPerPageChange", "className", "sx", "children"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
/** @jsxImportSource theme-ui */
|
|
5
|
+
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { forwardRef } from 'react';
|
|
8
|
+
import { containerStyles } from './styles';
|
|
9
|
+
import { Box } from '../Box';
|
|
10
|
+
import { Select } from '../NewForm';
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
12
|
+
var ItemsPerPageSelect = function ItemsPerPageSelect(_ref) {
|
|
13
|
+
var itemsPerPage = _ref.itemsPerPage,
|
|
14
|
+
pageSizeOptions = _ref.pageSizeOptions,
|
|
15
|
+
onItemsPerPageChange = _ref.onItemsPerPageChange;
|
|
16
|
+
return _jsx(Select, {
|
|
17
|
+
id: "items-per-page",
|
|
18
|
+
"aria-label": "Items per page",
|
|
19
|
+
separator: false,
|
|
20
|
+
value: itemsPerPage,
|
|
21
|
+
options: pageSizeOptions.map(function (size) {
|
|
22
|
+
return {
|
|
23
|
+
value: size,
|
|
24
|
+
label: size.toString() + " / page"
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
onChange: function onChange(option) {
|
|
28
|
+
return onItemsPerPageChange(Number(option == null ? void 0 : option.value));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Shared layout wrapper for pagination components.
|
|
35
|
+
* Renders the nav landmark, optional items-per-page selector, and variant content.
|
|
36
|
+
*/
|
|
37
|
+
export var PaginationLayout = /*#__PURE__*/forwardRef(function (_ref2, ref) {
|
|
38
|
+
var _ref2$displayItemsPer = _ref2.displayItemsPerPageSelector,
|
|
39
|
+
displayItemsPerPageSelector = _ref2$displayItemsPer === void 0 ? false : _ref2$displayItemsPer,
|
|
40
|
+
itemsPerPage = _ref2.itemsPerPage,
|
|
41
|
+
_ref2$pageSizeOptions = _ref2.pageSizeOptions,
|
|
42
|
+
pageSizeOptions = _ref2$pageSizeOptions === void 0 ? [20, 50, 100] : _ref2$pageSizeOptions,
|
|
43
|
+
onItemsPerPageChange = _ref2.onItemsPerPageChange,
|
|
44
|
+
className = _ref2.className,
|
|
45
|
+
sx = _ref2.sx,
|
|
46
|
+
children = _ref2.children,
|
|
47
|
+
rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
48
|
+
return _jsxs("nav", _extends({
|
|
49
|
+
ref: ref,
|
|
50
|
+
"aria-label": "Pagination",
|
|
51
|
+
className: classNames('vip-pagination-component', className),
|
|
52
|
+
sx: _extends({}, containerStyles, sx)
|
|
53
|
+
}, rest, {
|
|
54
|
+
children: [_jsx(Box, {
|
|
55
|
+
children: displayItemsPerPageSelector && itemsPerPage && onItemsPerPageChange && _jsx(ItemsPerPageSelect, {
|
|
56
|
+
itemsPerPage: itemsPerPage,
|
|
57
|
+
pageSizeOptions: pageSizeOptions,
|
|
58
|
+
onItemsPerPageChange: onItemsPerPageChange
|
|
59
|
+
})
|
|
60
|
+
}), children]
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
PaginationLayout.displayName = 'PaginationLayout';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
import { PaginationLayoutProps } from './PaginationLayout';
|
|
3
|
+
/** A navigation parameter for SimplePagination. */
|
|
4
|
+
export interface SimpleNavigationParam {
|
|
5
|
+
/** The query parameter name (e.g., 'after', 'before'). */
|
|
6
|
+
param: string;
|
|
7
|
+
/** The parameter token value. */
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SimplePaginationProps extends PaginationLayoutProps {
|
|
11
|
+
/** Whether there is a next page available. */
|
|
12
|
+
hasNextPage?: boolean;
|
|
13
|
+
/** Whether there is a previous page available. */
|
|
14
|
+
hasPreviousPage?: boolean;
|
|
15
|
+
/** Navigation parameter for the next page. */
|
|
16
|
+
nextParam?: SimpleNavigationParam;
|
|
17
|
+
/** Navigation parameter for the previous page. */
|
|
18
|
+
previousParam?: SimpleNavigationParam;
|
|
19
|
+
/** Callback fired when the user navigates. Receives the param name and value. */
|
|
20
|
+
onNavigate: (param: string, value: string) => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A pagination control with only previous/next arrow buttons.
|
|
24
|
+
* Designed for cursor-based pagination APIs with custom param names (e.g., `after`/`before`).
|
|
25
|
+
*/
|
|
26
|
+
export declare const SimplePagination: import("react").ForwardRefExoticComponent<SimplePaginationProps & import("react").RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var _excluded = ["hasNextPage", "hasPreviousPage", "nextParam", "previousParam", "onNavigate", "displayItemsPerPageSelector", "itemsPerPage", "pageSizeOptions", "onItemsPerPageChange", "className", "sx", "children"];
|
|
2
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
4
|
+
/** @jsxImportSource theme-ui */
|
|
5
|
+
|
|
6
|
+
import { forwardRef } from 'react';
|
|
7
|
+
import { MdChevronLeft, MdChevronRight } from 'react-icons/md';
|
|
8
|
+
import { Flex } from 'theme-ui';
|
|
9
|
+
import { PaginationLayout } from './PaginationLayout';
|
|
10
|
+
import { navigationStyles, arrowButtonStyles } from './styles';
|
|
11
|
+
import { Box } from '../Box';
|
|
12
|
+
import { Button } from '../Button';
|
|
13
|
+
|
|
14
|
+
/** A navigation parameter for SimplePagination. */
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
|
|
16
|
+
/**
|
|
17
|
+
* A pagination control with only previous/next arrow buttons.
|
|
18
|
+
* Designed for cursor-based pagination APIs with custom param names (e.g., `after`/`before`).
|
|
19
|
+
*/
|
|
20
|
+
export var SimplePagination = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
21
|
+
var hasNextPage = _ref.hasNextPage,
|
|
22
|
+
hasPreviousPage = _ref.hasPreviousPage,
|
|
23
|
+
nextParam = _ref.nextParam,
|
|
24
|
+
previousParam = _ref.previousParam,
|
|
25
|
+
onNavigate = _ref.onNavigate,
|
|
26
|
+
displayItemsPerPageSelector = _ref.displayItemsPerPageSelector,
|
|
27
|
+
itemsPerPage = _ref.itemsPerPage,
|
|
28
|
+
pageSizeOptions = _ref.pageSizeOptions,
|
|
29
|
+
onItemsPerPageChange = _ref.onItemsPerPageChange,
|
|
30
|
+
className = _ref.className,
|
|
31
|
+
sx = _ref.sx,
|
|
32
|
+
children = _ref.children,
|
|
33
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
34
|
+
var isPrevDisabled = !hasPreviousPage || !(previousParam != null && previousParam.value);
|
|
35
|
+
var isNextDisabled = !hasNextPage || !(nextParam != null && nextParam.value);
|
|
36
|
+
return _jsxs(PaginationLayout, _extends({
|
|
37
|
+
ref: ref,
|
|
38
|
+
displayItemsPerPageSelector: displayItemsPerPageSelector,
|
|
39
|
+
itemsPerPage: itemsPerPage,
|
|
40
|
+
pageSizeOptions: pageSizeOptions,
|
|
41
|
+
onItemsPerPageChange: onItemsPerPageChange,
|
|
42
|
+
className: className,
|
|
43
|
+
sx: sx
|
|
44
|
+
}, rest, {
|
|
45
|
+
children: [_jsx(Box, {
|
|
46
|
+
sx: {
|
|
47
|
+
flex: 1
|
|
48
|
+
},
|
|
49
|
+
children: children
|
|
50
|
+
}), _jsxs(Flex, {
|
|
51
|
+
sx: navigationStyles,
|
|
52
|
+
children: [_jsx(Button, {
|
|
53
|
+
"aria-label": "Previous page",
|
|
54
|
+
disabled: isPrevDisabled,
|
|
55
|
+
onClick: function onClick() {
|
|
56
|
+
return previousParam && onNavigate(previousParam.param, previousParam.value);
|
|
57
|
+
},
|
|
58
|
+
sx: arrowButtonStyles,
|
|
59
|
+
children: _jsx(MdChevronLeft, {
|
|
60
|
+
size: 20
|
|
61
|
+
})
|
|
62
|
+
}), _jsx(Button, {
|
|
63
|
+
"aria-label": "Next page",
|
|
64
|
+
disabled: isNextDisabled,
|
|
65
|
+
onClick: function onClick() {
|
|
66
|
+
return nextParam && onNavigate(nextParam.param, nextParam.value);
|
|
67
|
+
},
|
|
68
|
+
sx: arrowButtonStyles,
|
|
69
|
+
children: _jsx(MdChevronRight, {
|
|
70
|
+
size: 20
|
|
71
|
+
})
|
|
72
|
+
})]
|
|
73
|
+
})]
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
SimplePagination.displayName = 'SimplePagination';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** @jsxImportSource theme-ui */
|
|
2
|
+
/**
|
|
3
|
+
* Internal dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { SimplePagination } from './SimplePagination';
|
|
6
|
+
import type { StoryObj, Meta } from '@storybook/react-vite';
|
|
7
|
+
declare const meta: Meta<typeof SimplePagination>;
|
|
8
|
+
export default meta;
|
|
9
|
+
type Story = StoryObj<typeof SimplePagination>;
|
|
10
|
+
export declare const Default: Story;
|
|
11
|
+
export declare const FirstPage: Story;
|
|
12
|
+
export declare const LastPage: Story;
|
|
13
|
+
export declare const WithPageSize: Story;
|