@sytechui/pagination 2.2.27
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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/chunk-5S65XA6Q.mjs +82 -0
- package/dist/chunk-BIG4ST5P.mjs +217 -0
- package/dist/chunk-BNRXGTRW.mjs +18 -0
- package/dist/chunk-MA7OMMHX.mjs +18 -0
- package/dist/chunk-RL6XUYZP.mjs +235 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +589 -0
- package/dist/index.mjs +27 -0
- package/dist/pagination-cursor.d.mts +12 -0
- package/dist/pagination-cursor.d.ts +12 -0
- package/dist/pagination-cursor.js +37 -0
- package/dist/pagination-cursor.mjs +7 -0
- package/dist/pagination-item.d.mts +11 -0
- package/dist/pagination-item.d.ts +11 -0
- package/dist/pagination-item.js +113 -0
- package/dist/pagination-item.mjs +8 -0
- package/dist/pagination.d.mts +13 -0
- package/dist/pagination.d.ts +13 -0
- package/dist/pagination.js +570 -0
- package/dist/pagination.mjs +11 -0
- package/dist/use-pagination-item.d.mts +53 -0
- package/dist/use-pagination-item.d.ts +53 -0
- package/dist/use-pagination-item.js +105 -0
- package/dist/use-pagination-item.mjs +7 -0
- package/dist/use-pagination.d.mts +374 -0
- package/dist/use-pagination.d.ts +374 -0
- package/dist/use-pagination.js +269 -0
- package/dist/use-pagination.mjs +9 -0
- package/package.json +63 -0
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/pagination.tsx
|
|
32
|
+
var pagination_exports = {};
|
|
33
|
+
__export(pagination_exports, {
|
|
34
|
+
default: () => pagination_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(pagination_exports);
|
|
37
|
+
var import_react3 = require("react");
|
|
38
|
+
var import_i18n = require("@react-aria/i18n");
|
|
39
|
+
var import_system4 = require("@sytechui/system");
|
|
40
|
+
var import_use_pagination3 = require("@sytechui/use-pagination");
|
|
41
|
+
var import_shared_icons = require("@sytechui/shared-icons");
|
|
42
|
+
var import_shared_utils4 = require("@sytechui/shared-utils");
|
|
43
|
+
var import_theme3 = require("@sytechui/theme");
|
|
44
|
+
|
|
45
|
+
// src/use-pagination.ts
|
|
46
|
+
var import_shared_utils = require("@sytechui/shared-utils");
|
|
47
|
+
var import_use_pagination = require("@sytechui/use-pagination");
|
|
48
|
+
var import_react = require("react");
|
|
49
|
+
var import_system = require("@sytechui/system");
|
|
50
|
+
var import_use_pagination2 = require("@sytechui/use-pagination");
|
|
51
|
+
var import_scroll_into_view_if_needed = __toESM(require("scroll-into-view-if-needed"));
|
|
52
|
+
var import_theme = require("@sytechui/theme");
|
|
53
|
+
var import_react_utils = require("@sytechui/react-utils");
|
|
54
|
+
var import_shared_utils2 = require("@sytechui/shared-utils");
|
|
55
|
+
var import_use_intersection_observer = require("@sytechui/use-intersection-observer");
|
|
56
|
+
var CURSOR_TRANSITION_TIMEOUT = 300;
|
|
57
|
+
function usePagination(originalProps) {
|
|
58
|
+
var _a, _b, _c, _d;
|
|
59
|
+
const globalContext = (0, import_system.useProviderContext)();
|
|
60
|
+
const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.pagination.variantKeys);
|
|
61
|
+
const {
|
|
62
|
+
as,
|
|
63
|
+
ref,
|
|
64
|
+
classNames,
|
|
65
|
+
dotsJump = 5,
|
|
66
|
+
loop = false,
|
|
67
|
+
showControls = false,
|
|
68
|
+
total = 1,
|
|
69
|
+
initialPage = 1,
|
|
70
|
+
page,
|
|
71
|
+
siblings,
|
|
72
|
+
boundaries,
|
|
73
|
+
onChange,
|
|
74
|
+
className,
|
|
75
|
+
renderItem,
|
|
76
|
+
getItemAriaLabel: getItemAriaLabelProp,
|
|
77
|
+
...otherProps
|
|
78
|
+
} = props;
|
|
79
|
+
const Component = as || "nav";
|
|
80
|
+
const domRef = (0, import_react_utils.useDOMRef)(ref);
|
|
81
|
+
const cursorRef = (0, import_react.useRef)(null);
|
|
82
|
+
const itemsRef = (0, import_react.useRef)();
|
|
83
|
+
const cursorTimer = (0, import_react.useRef)();
|
|
84
|
+
const disableAnimation = (_b = (_a = originalProps == null ? void 0 : originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
|
|
85
|
+
const disableCursorAnimation = (_d = (_c = originalProps == null ? void 0 : originalProps.disableCursorAnimation) != null ? _c : disableAnimation) != null ? _d : false;
|
|
86
|
+
function getItemsRefMap() {
|
|
87
|
+
if (!itemsRef.current) {
|
|
88
|
+
itemsRef.current = /* @__PURE__ */ new Map();
|
|
89
|
+
}
|
|
90
|
+
return itemsRef.current;
|
|
91
|
+
}
|
|
92
|
+
function getItemRef(node, value) {
|
|
93
|
+
const map = getItemsRefMap();
|
|
94
|
+
if (node) {
|
|
95
|
+
map.set(value, node);
|
|
96
|
+
} else {
|
|
97
|
+
map.delete(value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function scrollTo(value, skipAnimation) {
|
|
101
|
+
const map = getItemsRefMap();
|
|
102
|
+
const node = map.get(value);
|
|
103
|
+
if (!node || !cursorRef.current) return;
|
|
104
|
+
cursorTimer.current && clearTimeout(cursorTimer.current);
|
|
105
|
+
(0, import_scroll_into_view_if_needed.default)(node, {
|
|
106
|
+
scrollMode: "always",
|
|
107
|
+
behavior: "smooth",
|
|
108
|
+
block: "start",
|
|
109
|
+
inline: "start",
|
|
110
|
+
boundary: domRef.current
|
|
111
|
+
});
|
|
112
|
+
const { offsetLeft } = node;
|
|
113
|
+
if (skipAnimation) {
|
|
114
|
+
cursorRef.current.setAttribute("data-moving", "false");
|
|
115
|
+
cursorRef.current.style.transform = `translateX(${offsetLeft}px) scale(1)`;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
cursorRef.current.setAttribute("data-moving", "true");
|
|
119
|
+
cursorRef.current.style.transform = `translateX(${offsetLeft}px) scale(1.1)`;
|
|
120
|
+
cursorTimer.current = setTimeout(() => {
|
|
121
|
+
if (cursorRef.current) {
|
|
122
|
+
cursorRef.current.style.transform = `translateX(${offsetLeft}px) scale(1)`;
|
|
123
|
+
}
|
|
124
|
+
cursorTimer.current = setTimeout(() => {
|
|
125
|
+
var _a2;
|
|
126
|
+
(_a2 = cursorRef.current) == null ? void 0 : _a2.setAttribute("data-moving", "false");
|
|
127
|
+
cursorTimer.current && clearTimeout(cursorTimer.current);
|
|
128
|
+
}, CURSOR_TRANSITION_TIMEOUT);
|
|
129
|
+
}, CURSOR_TRANSITION_TIMEOUT);
|
|
130
|
+
}
|
|
131
|
+
const { range, activePage, setPage, previous, next, first, last } = (0, import_use_pagination2.usePagination)({
|
|
132
|
+
page,
|
|
133
|
+
total,
|
|
134
|
+
initialPage,
|
|
135
|
+
siblings,
|
|
136
|
+
boundaries,
|
|
137
|
+
showControls,
|
|
138
|
+
onChange
|
|
139
|
+
});
|
|
140
|
+
const [setRef, isVisible] = (0, import_use_intersection_observer.useIntersectionObserver)();
|
|
141
|
+
(0, import_react.useEffect)(() => {
|
|
142
|
+
if (domRef.current) {
|
|
143
|
+
setRef(domRef.current);
|
|
144
|
+
}
|
|
145
|
+
}, [domRef.current]);
|
|
146
|
+
const activePageRef = (0, import_react.useRef)(activePage);
|
|
147
|
+
(0, import_react.useEffect)(() => {
|
|
148
|
+
if (activePage && !disableAnimation && isVisible) {
|
|
149
|
+
scrollTo(activePage, activePage === activePageRef.current);
|
|
150
|
+
}
|
|
151
|
+
activePageRef.current = activePage;
|
|
152
|
+
}, [
|
|
153
|
+
page,
|
|
154
|
+
activePage,
|
|
155
|
+
disableAnimation,
|
|
156
|
+
disableCursorAnimation,
|
|
157
|
+
isVisible,
|
|
158
|
+
originalProps.dotsJump,
|
|
159
|
+
originalProps.isCompact,
|
|
160
|
+
originalProps.showControls
|
|
161
|
+
]);
|
|
162
|
+
const slots = (0, import_react.useMemo)(
|
|
163
|
+
() => (0, import_theme.pagination)({
|
|
164
|
+
...variantProps,
|
|
165
|
+
disableAnimation,
|
|
166
|
+
disableCursorAnimation
|
|
167
|
+
}),
|
|
168
|
+
[(0, import_shared_utils.objectToDeps)(variantProps), disableCursorAnimation, disableAnimation]
|
|
169
|
+
);
|
|
170
|
+
const baseStyles = (0, import_theme.cn)(classNames == null ? void 0 : classNames.base, className);
|
|
171
|
+
const onNext = () => {
|
|
172
|
+
if (loop && activePage === total) {
|
|
173
|
+
return first();
|
|
174
|
+
}
|
|
175
|
+
return next();
|
|
176
|
+
};
|
|
177
|
+
const onPrevious = () => {
|
|
178
|
+
if (loop && activePage === 1) {
|
|
179
|
+
return last();
|
|
180
|
+
}
|
|
181
|
+
return previous();
|
|
182
|
+
};
|
|
183
|
+
const getBaseProps = (props2 = {}) => {
|
|
184
|
+
return {
|
|
185
|
+
...props2,
|
|
186
|
+
ref: domRef,
|
|
187
|
+
role: "navigation",
|
|
188
|
+
"aria-label": props2["aria-label"] || "pagination navigation",
|
|
189
|
+
"data-slot": "base",
|
|
190
|
+
"data-controls": (0, import_shared_utils2.dataAttr)(showControls),
|
|
191
|
+
"data-loop": (0, import_shared_utils2.dataAttr)(loop),
|
|
192
|
+
"data-dots-jump": dotsJump,
|
|
193
|
+
"data-total": total,
|
|
194
|
+
"data-active-page": activePage,
|
|
195
|
+
className: slots.base({ class: (0, import_theme.cn)(baseStyles, props2 == null ? void 0 : props2.className) }),
|
|
196
|
+
...otherProps
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
const getWrapperProps = (props2 = {}) => {
|
|
200
|
+
return {
|
|
201
|
+
...props2,
|
|
202
|
+
"data-slot": "wrapper",
|
|
203
|
+
className: slots.wrapper({ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.wrapper, props2 == null ? void 0 : props2.className) })
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
const getItemAriaLabel = (page2) => {
|
|
207
|
+
if (!page2) return;
|
|
208
|
+
if (getItemAriaLabelProp) {
|
|
209
|
+
return getItemAriaLabelProp(page2);
|
|
210
|
+
}
|
|
211
|
+
switch (page2) {
|
|
212
|
+
case import_use_pagination.PaginationItemType.DOTS:
|
|
213
|
+
return "dots element";
|
|
214
|
+
case import_use_pagination.PaginationItemType.PREV:
|
|
215
|
+
return "previous page button";
|
|
216
|
+
case import_use_pagination.PaginationItemType.NEXT:
|
|
217
|
+
return "next page button";
|
|
218
|
+
case "first":
|
|
219
|
+
return "first page button";
|
|
220
|
+
case "last":
|
|
221
|
+
return "last page button";
|
|
222
|
+
default:
|
|
223
|
+
return `pagination item ${page2}`;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const getItemProps = (props2 = {}) => {
|
|
227
|
+
return {
|
|
228
|
+
...props2,
|
|
229
|
+
ref: (node) => getItemRef(node, props2.value),
|
|
230
|
+
"data-slot": "item",
|
|
231
|
+
isActive: props2.value === activePage,
|
|
232
|
+
className: slots.item({ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.item, props2 == null ? void 0 : props2.className) }),
|
|
233
|
+
onPress: () => {
|
|
234
|
+
if (props2.value !== activePage) {
|
|
235
|
+
setPage(props2.value);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
const getCursorProps = (props2 = {}) => {
|
|
241
|
+
return {
|
|
242
|
+
...props2,
|
|
243
|
+
ref: cursorRef,
|
|
244
|
+
activePage,
|
|
245
|
+
"data-slot": "cursor",
|
|
246
|
+
className: slots.cursor({ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.cursor, props2 == null ? void 0 : props2.className) })
|
|
247
|
+
};
|
|
248
|
+
};
|
|
249
|
+
return {
|
|
250
|
+
Component,
|
|
251
|
+
showControls,
|
|
252
|
+
dotsJump,
|
|
253
|
+
slots,
|
|
254
|
+
classNames,
|
|
255
|
+
loop,
|
|
256
|
+
total,
|
|
257
|
+
range,
|
|
258
|
+
activePage,
|
|
259
|
+
getItemRef,
|
|
260
|
+
disableAnimation,
|
|
261
|
+
disableCursorAnimation,
|
|
262
|
+
setPage,
|
|
263
|
+
onPrevious,
|
|
264
|
+
onNext,
|
|
265
|
+
renderItem,
|
|
266
|
+
getBaseProps,
|
|
267
|
+
getWrapperProps,
|
|
268
|
+
getItemProps,
|
|
269
|
+
getCursorProps,
|
|
270
|
+
getItemAriaLabel
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// src/pagination-item.tsx
|
|
275
|
+
var import_system2 = require("@sytechui/system");
|
|
276
|
+
|
|
277
|
+
// src/use-pagination-item.ts
|
|
278
|
+
var import_react2 = require("react");
|
|
279
|
+
var import_utils = require("@react-aria/utils");
|
|
280
|
+
var import_shared_utils3 = require("@sytechui/shared-utils");
|
|
281
|
+
var import_react_utils2 = require("@sytechui/react-utils");
|
|
282
|
+
var import_interactions = require("@react-aria/interactions");
|
|
283
|
+
var import_focus = require("@react-aria/focus");
|
|
284
|
+
var import_theme2 = require("@sytechui/theme");
|
|
285
|
+
function usePaginationItem(props) {
|
|
286
|
+
const {
|
|
287
|
+
as,
|
|
288
|
+
ref,
|
|
289
|
+
value,
|
|
290
|
+
children,
|
|
291
|
+
isActive,
|
|
292
|
+
isDisabled,
|
|
293
|
+
onPress,
|
|
294
|
+
onClick,
|
|
295
|
+
getAriaLabel,
|
|
296
|
+
className,
|
|
297
|
+
...otherProps
|
|
298
|
+
} = props;
|
|
299
|
+
const isLink = !!(props == null ? void 0 : props.href);
|
|
300
|
+
const Component = as || isLink ? "a" : "li";
|
|
301
|
+
const shouldFilterDOMProps = typeof Component === "string";
|
|
302
|
+
const domRef = (0, import_react_utils2.useDOMRef)(ref);
|
|
303
|
+
const router = (0, import_utils.useRouter)();
|
|
304
|
+
const ariaLabel = (0, import_react2.useMemo)(
|
|
305
|
+
() => isActive ? `${getAriaLabel == null ? void 0 : getAriaLabel(value)} active` : getAriaLabel == null ? void 0 : getAriaLabel(value),
|
|
306
|
+
[value, isActive]
|
|
307
|
+
);
|
|
308
|
+
const { isPressed, pressProps } = (0, import_interactions.usePress)({
|
|
309
|
+
isDisabled,
|
|
310
|
+
onPress
|
|
311
|
+
});
|
|
312
|
+
const { focusProps, isFocused, isFocusVisible } = (0, import_focus.useFocusRing)({});
|
|
313
|
+
const { isHovered, hoverProps } = (0, import_interactions.useHover)({ isDisabled });
|
|
314
|
+
const getItemProps = (props2 = {}) => {
|
|
315
|
+
return {
|
|
316
|
+
ref: domRef,
|
|
317
|
+
role: "button",
|
|
318
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
319
|
+
"aria-label": ariaLabel,
|
|
320
|
+
"aria-current": (0, import_shared_utils3.dataAttr)(isActive),
|
|
321
|
+
"aria-disabled": (0, import_shared_utils3.dataAttr)(isDisabled),
|
|
322
|
+
"data-disabled": (0, import_shared_utils3.dataAttr)(isDisabled),
|
|
323
|
+
"data-active": (0, import_shared_utils3.dataAttr)(isActive),
|
|
324
|
+
"data-focus": (0, import_shared_utils3.dataAttr)(isFocused),
|
|
325
|
+
"data-hover": (0, import_shared_utils3.dataAttr)(isHovered),
|
|
326
|
+
"data-pressed": (0, import_shared_utils3.dataAttr)(isPressed),
|
|
327
|
+
"data-focus-visible": (0, import_shared_utils3.dataAttr)(isFocusVisible),
|
|
328
|
+
...(0, import_shared_utils3.mergeProps)(
|
|
329
|
+
props2,
|
|
330
|
+
pressProps,
|
|
331
|
+
focusProps,
|
|
332
|
+
hoverProps,
|
|
333
|
+
(0, import_react_utils2.filterDOMProps)(otherProps, {
|
|
334
|
+
enabled: shouldFilterDOMProps
|
|
335
|
+
})
|
|
336
|
+
),
|
|
337
|
+
className: (0, import_theme2.cn)(className, props2.className),
|
|
338
|
+
onClick: (e) => {
|
|
339
|
+
(0, import_shared_utils3.chain)(pressProps == null ? void 0 : pressProps.onClick, onClick)(e);
|
|
340
|
+
(0, import_utils.handleLinkClick)(e, router, props2.href, props2.routerOptions);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
return {
|
|
345
|
+
Component,
|
|
346
|
+
children,
|
|
347
|
+
ariaLabel,
|
|
348
|
+
isFocused,
|
|
349
|
+
isFocusVisible,
|
|
350
|
+
getItemProps
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// src/pagination-item.tsx
|
|
355
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
356
|
+
var PaginationItem = (0, import_system2.forwardRef)((props, ref) => {
|
|
357
|
+
const { Component, children, getItemProps } = usePaginationItem({ ...props, ref });
|
|
358
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...getItemProps(), children });
|
|
359
|
+
});
|
|
360
|
+
PaginationItem.displayName = "HeroUI.PaginationItem";
|
|
361
|
+
var pagination_item_default = PaginationItem;
|
|
362
|
+
|
|
363
|
+
// src/pagination-cursor.tsx
|
|
364
|
+
var import_system3 = require("@sytechui/system");
|
|
365
|
+
var import_react_utils3 = require("@sytechui/react-utils");
|
|
366
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
367
|
+
var PaginationCursor = (0, import_system3.forwardRef)((props, ref) => {
|
|
368
|
+
const { as, activePage, ...otherProps } = props;
|
|
369
|
+
const Component = as || "span";
|
|
370
|
+
const domRef = (0, import_react_utils3.useDOMRef)(ref);
|
|
371
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component, { ref: domRef, "aria-hidden": true, ...otherProps, children: activePage });
|
|
372
|
+
});
|
|
373
|
+
PaginationCursor.displayName = "HeroUI.PaginationCursor";
|
|
374
|
+
var pagination_cursor_default = PaginationCursor;
|
|
375
|
+
|
|
376
|
+
// src/pagination.tsx
|
|
377
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
378
|
+
var import_react4 = require("react");
|
|
379
|
+
var Pagination = (0, import_system4.forwardRef)((props, ref) => {
|
|
380
|
+
const {
|
|
381
|
+
Component,
|
|
382
|
+
dotsJump,
|
|
383
|
+
slots,
|
|
384
|
+
classNames,
|
|
385
|
+
total,
|
|
386
|
+
range,
|
|
387
|
+
loop,
|
|
388
|
+
activePage,
|
|
389
|
+
disableCursorAnimation,
|
|
390
|
+
disableAnimation,
|
|
391
|
+
renderItem: renderItemProp,
|
|
392
|
+
onNext,
|
|
393
|
+
onPrevious,
|
|
394
|
+
setPage,
|
|
395
|
+
getItemAriaLabel,
|
|
396
|
+
getItemRef,
|
|
397
|
+
getBaseProps,
|
|
398
|
+
getWrapperProps,
|
|
399
|
+
getItemProps,
|
|
400
|
+
getCursorProps
|
|
401
|
+
} = usePagination({ ...props, ref });
|
|
402
|
+
const { direction } = (0, import_i18n.useLocale)();
|
|
403
|
+
const isRTL = direction === "rtl";
|
|
404
|
+
const renderChevronIcon = (0, import_react3.useCallback)(
|
|
405
|
+
(key) => {
|
|
406
|
+
if (key === import_use_pagination3.PaginationItemType.PREV && !isRTL || key === import_use_pagination3.PaginationItemType.NEXT && isRTL) {
|
|
407
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_shared_icons.ChevronIcon, {});
|
|
408
|
+
}
|
|
409
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
410
|
+
import_shared_icons.ChevronIcon,
|
|
411
|
+
{
|
|
412
|
+
className: slots.chevronNext({
|
|
413
|
+
class: classNames == null ? void 0 : classNames.chevronNext
|
|
414
|
+
})
|
|
415
|
+
}
|
|
416
|
+
);
|
|
417
|
+
},
|
|
418
|
+
[slots, isRTL]
|
|
419
|
+
);
|
|
420
|
+
const renderPrevItem = (0, import_react3.useCallback)(
|
|
421
|
+
(value) => {
|
|
422
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
423
|
+
pagination_item_default,
|
|
424
|
+
{
|
|
425
|
+
className: slots.prev({
|
|
426
|
+
class: classNames == null ? void 0 : classNames.prev
|
|
427
|
+
}),
|
|
428
|
+
"data-slot": "prev",
|
|
429
|
+
getAriaLabel: getItemAriaLabel,
|
|
430
|
+
isDisabled: !loop && activePage === 1,
|
|
431
|
+
value,
|
|
432
|
+
onPress: onPrevious,
|
|
433
|
+
children: renderChevronIcon(import_use_pagination3.PaginationItemType.PREV)
|
|
434
|
+
},
|
|
435
|
+
import_use_pagination3.PaginationItemType.PREV
|
|
436
|
+
);
|
|
437
|
+
},
|
|
438
|
+
[slots, classNames, loop, activePage, isRTL, total, getItemAriaLabel, onPrevious]
|
|
439
|
+
);
|
|
440
|
+
const renderNextItem = (0, import_react3.useCallback)(
|
|
441
|
+
(value) => {
|
|
442
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
443
|
+
pagination_item_default,
|
|
444
|
+
{
|
|
445
|
+
className: slots.next({
|
|
446
|
+
class: (0, import_theme3.cn)(classNames == null ? void 0 : classNames.next)
|
|
447
|
+
}),
|
|
448
|
+
"data-slot": "next",
|
|
449
|
+
getAriaLabel: getItemAriaLabel,
|
|
450
|
+
isDisabled: !loop && activePage === total,
|
|
451
|
+
value,
|
|
452
|
+
onPress: onNext,
|
|
453
|
+
children: renderChevronIcon(import_use_pagination3.PaginationItemType.NEXT)
|
|
454
|
+
},
|
|
455
|
+
import_use_pagination3.PaginationItemType.NEXT
|
|
456
|
+
);
|
|
457
|
+
},
|
|
458
|
+
[slots, classNames, loop, activePage, isRTL, total, getItemAriaLabel, onNext]
|
|
459
|
+
);
|
|
460
|
+
const renderItem = (0, import_react3.useCallback)(
|
|
461
|
+
(value, index) => {
|
|
462
|
+
const isBefore = index < range.indexOf(activePage);
|
|
463
|
+
if (renderItemProp && typeof renderItemProp === "function") {
|
|
464
|
+
let page = typeof value == "number" ? value : index;
|
|
465
|
+
if (value === import_use_pagination3.PaginationItemType.NEXT) {
|
|
466
|
+
page = activePage + 1;
|
|
467
|
+
}
|
|
468
|
+
if (value === import_use_pagination3.PaginationItemType.PREV) {
|
|
469
|
+
page = activePage - 1;
|
|
470
|
+
}
|
|
471
|
+
if (value === import_use_pagination3.PaginationItemType.DOTS) {
|
|
472
|
+
page = isBefore ? activePage - dotsJump >= 1 ? activePage - dotsJump : 1 : activePage + dotsJump <= total ? activePage + dotsJump : total;
|
|
473
|
+
}
|
|
474
|
+
const itemChildren = {
|
|
475
|
+
[import_use_pagination3.PaginationItemType.PREV]: renderChevronIcon(import_use_pagination3.PaginationItemType.PREV),
|
|
476
|
+
[import_use_pagination3.PaginationItemType.NEXT]: renderChevronIcon(import_use_pagination3.PaginationItemType.NEXT),
|
|
477
|
+
[import_use_pagination3.PaginationItemType.DOTS]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
478
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_shared_icons.EllipsisIcon, { className: slots == null ? void 0 : slots.ellipsis({ class: classNames == null ? void 0 : classNames.ellipsis }) }),
|
|
479
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
480
|
+
import_shared_icons.ForwardIcon,
|
|
481
|
+
{
|
|
482
|
+
className: slots == null ? void 0 : slots.forwardIcon({ class: classNames == null ? void 0 : classNames.forwardIcon }),
|
|
483
|
+
"data-before": (0, import_shared_utils4.dataAttr)(isBefore)
|
|
484
|
+
}
|
|
485
|
+
)
|
|
486
|
+
] })
|
|
487
|
+
};
|
|
488
|
+
return renderItemProp({
|
|
489
|
+
value,
|
|
490
|
+
index,
|
|
491
|
+
key: `${value}-${index}`,
|
|
492
|
+
page,
|
|
493
|
+
total,
|
|
494
|
+
children: typeof value === "number" ? value : itemChildren[value],
|
|
495
|
+
activePage,
|
|
496
|
+
dotsJump,
|
|
497
|
+
isBefore,
|
|
498
|
+
isActive: value === activePage,
|
|
499
|
+
isPrevious: value === activePage - 1,
|
|
500
|
+
isNext: value === activePage + 1,
|
|
501
|
+
isFirst: value === 1,
|
|
502
|
+
isLast: value === total,
|
|
503
|
+
onNext,
|
|
504
|
+
onPrevious,
|
|
505
|
+
setPage,
|
|
506
|
+
onPress: () => setPage(page),
|
|
507
|
+
ref: typeof value === "number" ? (node) => getItemRef(node, value) : void 0,
|
|
508
|
+
className: slots.item({ class: classNames == null ? void 0 : classNames.item }),
|
|
509
|
+
getAriaLabel: getItemAriaLabel
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
if (value === import_use_pagination3.PaginationItemType.PREV) {
|
|
513
|
+
return renderPrevItem(value);
|
|
514
|
+
}
|
|
515
|
+
if (value === import_use_pagination3.PaginationItemType.NEXT) {
|
|
516
|
+
return renderNextItem(value);
|
|
517
|
+
}
|
|
518
|
+
if (value === import_use_pagination3.PaginationItemType.DOTS) {
|
|
519
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
520
|
+
pagination_item_default,
|
|
521
|
+
{
|
|
522
|
+
className: slots.item({
|
|
523
|
+
class: (0, import_theme3.cn)(classNames == null ? void 0 : classNames.item, "group")
|
|
524
|
+
}),
|
|
525
|
+
"data-slot": "item",
|
|
526
|
+
getAriaLabel: getItemAriaLabel,
|
|
527
|
+
value,
|
|
528
|
+
onPress: () => isBefore ? setPage(activePage - dotsJump >= 1 ? activePage - dotsJump : 1) : setPage(activePage + dotsJump <= total ? activePage + dotsJump : total),
|
|
529
|
+
children: [
|
|
530
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_shared_icons.EllipsisIcon, { className: slots == null ? void 0 : slots.ellipsis({ class: classNames == null ? void 0 : classNames.ellipsis }) }),
|
|
531
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
532
|
+
import_shared_icons.ForwardIcon,
|
|
533
|
+
{
|
|
534
|
+
className: slots == null ? void 0 : slots.forwardIcon({ class: classNames == null ? void 0 : classNames.forwardIcon }),
|
|
535
|
+
"data-before": (0, import_shared_utils4.dataAttr)(isRTL ? !isBefore : isBefore)
|
|
536
|
+
}
|
|
537
|
+
)
|
|
538
|
+
]
|
|
539
|
+
},
|
|
540
|
+
import_use_pagination3.PaginationItemType.DOTS + isBefore
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
return /* @__PURE__ */ (0, import_react4.createElement)(pagination_item_default, { ...getItemProps({ value }), key: value, getAriaLabel: getItemAriaLabel }, value);
|
|
544
|
+
},
|
|
545
|
+
[
|
|
546
|
+
isRTL,
|
|
547
|
+
activePage,
|
|
548
|
+
dotsJump,
|
|
549
|
+
getItemProps,
|
|
550
|
+
loop,
|
|
551
|
+
range,
|
|
552
|
+
renderItemProp,
|
|
553
|
+
slots,
|
|
554
|
+
classNames,
|
|
555
|
+
total,
|
|
556
|
+
getItemAriaLabel,
|
|
557
|
+
onNext,
|
|
558
|
+
onPrevious,
|
|
559
|
+
setPage,
|
|
560
|
+
renderPrevItem,
|
|
561
|
+
renderNextItem
|
|
562
|
+
]
|
|
563
|
+
);
|
|
564
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Component, { ...getBaseProps(), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("ul", { ...getWrapperProps(), children: [
|
|
565
|
+
!disableCursorAnimation && !disableAnimation && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(pagination_cursor_default, { ...getCursorProps() }),
|
|
566
|
+
range.map(renderItem)
|
|
567
|
+
] }) });
|
|
568
|
+
});
|
|
569
|
+
Pagination.displayName = "HeroUI.Pagination";
|
|
570
|
+
var pagination_default = Pagination;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
pagination_default
|
|
4
|
+
} from "./chunk-BIG4ST5P.mjs";
|
|
5
|
+
import "./chunk-MA7OMMHX.mjs";
|
|
6
|
+
import "./chunk-BNRXGTRW.mjs";
|
|
7
|
+
import "./chunk-5S65XA6Q.mjs";
|
|
8
|
+
import "./chunk-RL6XUYZP.mjs";
|
|
9
|
+
export {
|
|
10
|
+
pagination_default as default
|
|
11
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { Ref } from 'react';
|
|
3
|
+
import { HTMLHeroUIProps, PropGetter } from '@sytechui/system';
|
|
4
|
+
import { PressEvent, LinkDOMProps } from '@react-types/shared';
|
|
5
|
+
import { PaginationItemValue } from '@sytechui/use-pagination';
|
|
6
|
+
|
|
7
|
+
interface Props extends Omit<HTMLHeroUIProps<"li">, "onClick"> {
|
|
8
|
+
/**
|
|
9
|
+
* Ref to the DOM node.
|
|
10
|
+
*/
|
|
11
|
+
ref?: Ref<HTMLElement>;
|
|
12
|
+
/**
|
|
13
|
+
* Value of the item.
|
|
14
|
+
*/
|
|
15
|
+
value?: PaginationItemValue;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the item is active.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
isActive?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the item is disabled.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
isDisabled?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Callback fired when the item is clicked.
|
|
28
|
+
* @param e MouseEvent
|
|
29
|
+
* @deprecated Use `onPress` instead.
|
|
30
|
+
*/
|
|
31
|
+
onClick?: HTMLHeroUIProps<"li">["onClick"];
|
|
32
|
+
/**
|
|
33
|
+
* Callback fired when the item is clicked.
|
|
34
|
+
* @param e PressEvent
|
|
35
|
+
*/
|
|
36
|
+
onPress?: (e: PressEvent) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Function to get the aria-label of the item.
|
|
39
|
+
*/
|
|
40
|
+
getAriaLabel?: (page?: PaginationItemValue) => string | undefined;
|
|
41
|
+
}
|
|
42
|
+
type UsePaginationItemProps = Props & LinkDOMProps;
|
|
43
|
+
declare function usePaginationItem(props: UsePaginationItemProps): {
|
|
44
|
+
Component: string;
|
|
45
|
+
children: react.ReactNode;
|
|
46
|
+
ariaLabel: string | undefined;
|
|
47
|
+
isFocused: boolean;
|
|
48
|
+
isFocusVisible: boolean;
|
|
49
|
+
getItemProps: PropGetter;
|
|
50
|
+
};
|
|
51
|
+
type UsePaginationItemReturn = ReturnType<typeof usePaginationItem>;
|
|
52
|
+
|
|
53
|
+
export { type UsePaginationItemProps, type UsePaginationItemReturn, usePaginationItem };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { Ref } from 'react';
|
|
3
|
+
import { HTMLHeroUIProps, PropGetter } from '@sytechui/system';
|
|
4
|
+
import { PressEvent, LinkDOMProps } from '@react-types/shared';
|
|
5
|
+
import { PaginationItemValue } from '@sytechui/use-pagination';
|
|
6
|
+
|
|
7
|
+
interface Props extends Omit<HTMLHeroUIProps<"li">, "onClick"> {
|
|
8
|
+
/**
|
|
9
|
+
* Ref to the DOM node.
|
|
10
|
+
*/
|
|
11
|
+
ref?: Ref<HTMLElement>;
|
|
12
|
+
/**
|
|
13
|
+
* Value of the item.
|
|
14
|
+
*/
|
|
15
|
+
value?: PaginationItemValue;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the item is active.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
isActive?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the item is disabled.
|
|
23
|
+
* @default false
|
|
24
|
+
*/
|
|
25
|
+
isDisabled?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Callback fired when the item is clicked.
|
|
28
|
+
* @param e MouseEvent
|
|
29
|
+
* @deprecated Use `onPress` instead.
|
|
30
|
+
*/
|
|
31
|
+
onClick?: HTMLHeroUIProps<"li">["onClick"];
|
|
32
|
+
/**
|
|
33
|
+
* Callback fired when the item is clicked.
|
|
34
|
+
* @param e PressEvent
|
|
35
|
+
*/
|
|
36
|
+
onPress?: (e: PressEvent) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Function to get the aria-label of the item.
|
|
39
|
+
*/
|
|
40
|
+
getAriaLabel?: (page?: PaginationItemValue) => string | undefined;
|
|
41
|
+
}
|
|
42
|
+
type UsePaginationItemProps = Props & LinkDOMProps;
|
|
43
|
+
declare function usePaginationItem(props: UsePaginationItemProps): {
|
|
44
|
+
Component: string;
|
|
45
|
+
children: react.ReactNode;
|
|
46
|
+
ariaLabel: string | undefined;
|
|
47
|
+
isFocused: boolean;
|
|
48
|
+
isFocusVisible: boolean;
|
|
49
|
+
getItemProps: PropGetter;
|
|
50
|
+
};
|
|
51
|
+
type UsePaginationItemReturn = ReturnType<typeof usePaginationItem>;
|
|
52
|
+
|
|
53
|
+
export { type UsePaginationItemProps, type UsePaginationItemReturn, usePaginationItem };
|