@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Next UI Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @sytechui/pagination
|
|
2
|
+
|
|
3
|
+
The Pagination component allows you to display active page and navigate between multiple pages.
|
|
4
|
+
|
|
5
|
+
Please refer to the [documentation](https://heroui.com/docs/components/pagination) for more information.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add @sytechui/pagination
|
|
11
|
+
# or
|
|
12
|
+
npm i @sytechui/pagination
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Contribution
|
|
16
|
+
|
|
17
|
+
Yes please! See the
|
|
18
|
+
[contributing guidelines](https://github.com/heroui-inc/heroui/blob/master/CONTRIBUTING.md)
|
|
19
|
+
for details.
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
This project is licensed under the terms of the
|
|
24
|
+
[MIT license](https://github.com/heroui-inc/heroui/blob/master/LICENSE).
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/use-pagination-item.ts
|
|
4
|
+
import { useMemo } from "react";
|
|
5
|
+
import { handleLinkClick, useRouter } from "@react-aria/utils";
|
|
6
|
+
import { dataAttr, chain, mergeProps } from "@sytechui/shared-utils";
|
|
7
|
+
import { filterDOMProps, useDOMRef } from "@sytechui/react-utils";
|
|
8
|
+
import { useHover, usePress } from "@react-aria/interactions";
|
|
9
|
+
import { useFocusRing } from "@react-aria/focus";
|
|
10
|
+
import { cn } from "@sytechui/theme";
|
|
11
|
+
function usePaginationItem(props) {
|
|
12
|
+
const {
|
|
13
|
+
as,
|
|
14
|
+
ref,
|
|
15
|
+
value,
|
|
16
|
+
children,
|
|
17
|
+
isActive,
|
|
18
|
+
isDisabled,
|
|
19
|
+
onPress,
|
|
20
|
+
onClick,
|
|
21
|
+
getAriaLabel,
|
|
22
|
+
className,
|
|
23
|
+
...otherProps
|
|
24
|
+
} = props;
|
|
25
|
+
const isLink = !!(props == null ? void 0 : props.href);
|
|
26
|
+
const Component = as || isLink ? "a" : "li";
|
|
27
|
+
const shouldFilterDOMProps = typeof Component === "string";
|
|
28
|
+
const domRef = useDOMRef(ref);
|
|
29
|
+
const router = useRouter();
|
|
30
|
+
const ariaLabel = useMemo(
|
|
31
|
+
() => isActive ? `${getAriaLabel == null ? void 0 : getAriaLabel(value)} active` : getAriaLabel == null ? void 0 : getAriaLabel(value),
|
|
32
|
+
[value, isActive]
|
|
33
|
+
);
|
|
34
|
+
const { isPressed, pressProps } = usePress({
|
|
35
|
+
isDisabled,
|
|
36
|
+
onPress
|
|
37
|
+
});
|
|
38
|
+
const { focusProps, isFocused, isFocusVisible } = useFocusRing({});
|
|
39
|
+
const { isHovered, hoverProps } = useHover({ isDisabled });
|
|
40
|
+
const getItemProps = (props2 = {}) => {
|
|
41
|
+
return {
|
|
42
|
+
ref: domRef,
|
|
43
|
+
role: "button",
|
|
44
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
45
|
+
"aria-label": ariaLabel,
|
|
46
|
+
"aria-current": dataAttr(isActive),
|
|
47
|
+
"aria-disabled": dataAttr(isDisabled),
|
|
48
|
+
"data-disabled": dataAttr(isDisabled),
|
|
49
|
+
"data-active": dataAttr(isActive),
|
|
50
|
+
"data-focus": dataAttr(isFocused),
|
|
51
|
+
"data-hover": dataAttr(isHovered),
|
|
52
|
+
"data-pressed": dataAttr(isPressed),
|
|
53
|
+
"data-focus-visible": dataAttr(isFocusVisible),
|
|
54
|
+
...mergeProps(
|
|
55
|
+
props2,
|
|
56
|
+
pressProps,
|
|
57
|
+
focusProps,
|
|
58
|
+
hoverProps,
|
|
59
|
+
filterDOMProps(otherProps, {
|
|
60
|
+
enabled: shouldFilterDOMProps
|
|
61
|
+
})
|
|
62
|
+
),
|
|
63
|
+
className: cn(className, props2.className),
|
|
64
|
+
onClick: (e) => {
|
|
65
|
+
chain(pressProps == null ? void 0 : pressProps.onClick, onClick)(e);
|
|
66
|
+
handleLinkClick(e, router, props2.href, props2.routerOptions);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
Component,
|
|
72
|
+
children,
|
|
73
|
+
ariaLabel,
|
|
74
|
+
isFocused,
|
|
75
|
+
isFocusVisible,
|
|
76
|
+
getItemProps
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export {
|
|
81
|
+
usePaginationItem
|
|
82
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
pagination_cursor_default
|
|
4
|
+
} from "./chunk-MA7OMMHX.mjs";
|
|
5
|
+
import {
|
|
6
|
+
pagination_item_default
|
|
7
|
+
} from "./chunk-BNRXGTRW.mjs";
|
|
8
|
+
import {
|
|
9
|
+
usePagination
|
|
10
|
+
} from "./chunk-RL6XUYZP.mjs";
|
|
11
|
+
|
|
12
|
+
// src/pagination.tsx
|
|
13
|
+
import { useCallback } from "react";
|
|
14
|
+
import { useLocale } from "@react-aria/i18n";
|
|
15
|
+
import { forwardRef } from "@sytechui/system";
|
|
16
|
+
import { PaginationItemType } from "@sytechui/use-pagination";
|
|
17
|
+
import { ChevronIcon, EllipsisIcon, ForwardIcon } from "@sytechui/shared-icons";
|
|
18
|
+
import { dataAttr } from "@sytechui/shared-utils";
|
|
19
|
+
import { cn } from "@sytechui/theme";
|
|
20
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
21
|
+
import { createElement } from "react";
|
|
22
|
+
var Pagination = forwardRef((props, ref) => {
|
|
23
|
+
const {
|
|
24
|
+
Component,
|
|
25
|
+
dotsJump,
|
|
26
|
+
slots,
|
|
27
|
+
classNames,
|
|
28
|
+
total,
|
|
29
|
+
range,
|
|
30
|
+
loop,
|
|
31
|
+
activePage,
|
|
32
|
+
disableCursorAnimation,
|
|
33
|
+
disableAnimation,
|
|
34
|
+
renderItem: renderItemProp,
|
|
35
|
+
onNext,
|
|
36
|
+
onPrevious,
|
|
37
|
+
setPage,
|
|
38
|
+
getItemAriaLabel,
|
|
39
|
+
getItemRef,
|
|
40
|
+
getBaseProps,
|
|
41
|
+
getWrapperProps,
|
|
42
|
+
getItemProps,
|
|
43
|
+
getCursorProps
|
|
44
|
+
} = usePagination({ ...props, ref });
|
|
45
|
+
const { direction } = useLocale();
|
|
46
|
+
const isRTL = direction === "rtl";
|
|
47
|
+
const renderChevronIcon = useCallback(
|
|
48
|
+
(key) => {
|
|
49
|
+
if (key === PaginationItemType.PREV && !isRTL || key === PaginationItemType.NEXT && isRTL) {
|
|
50
|
+
return /* @__PURE__ */ jsx(ChevronIcon, {});
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ jsx(
|
|
53
|
+
ChevronIcon,
|
|
54
|
+
{
|
|
55
|
+
className: slots.chevronNext({
|
|
56
|
+
class: classNames == null ? void 0 : classNames.chevronNext
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
[slots, isRTL]
|
|
62
|
+
);
|
|
63
|
+
const renderPrevItem = useCallback(
|
|
64
|
+
(value) => {
|
|
65
|
+
return /* @__PURE__ */ jsx(
|
|
66
|
+
pagination_item_default,
|
|
67
|
+
{
|
|
68
|
+
className: slots.prev({
|
|
69
|
+
class: classNames == null ? void 0 : classNames.prev
|
|
70
|
+
}),
|
|
71
|
+
"data-slot": "prev",
|
|
72
|
+
getAriaLabel: getItemAriaLabel,
|
|
73
|
+
isDisabled: !loop && activePage === 1,
|
|
74
|
+
value,
|
|
75
|
+
onPress: onPrevious,
|
|
76
|
+
children: renderChevronIcon(PaginationItemType.PREV)
|
|
77
|
+
},
|
|
78
|
+
PaginationItemType.PREV
|
|
79
|
+
);
|
|
80
|
+
},
|
|
81
|
+
[slots, classNames, loop, activePage, isRTL, total, getItemAriaLabel, onPrevious]
|
|
82
|
+
);
|
|
83
|
+
const renderNextItem = useCallback(
|
|
84
|
+
(value) => {
|
|
85
|
+
return /* @__PURE__ */ jsx(
|
|
86
|
+
pagination_item_default,
|
|
87
|
+
{
|
|
88
|
+
className: slots.next({
|
|
89
|
+
class: cn(classNames == null ? void 0 : classNames.next)
|
|
90
|
+
}),
|
|
91
|
+
"data-slot": "next",
|
|
92
|
+
getAriaLabel: getItemAriaLabel,
|
|
93
|
+
isDisabled: !loop && activePage === total,
|
|
94
|
+
value,
|
|
95
|
+
onPress: onNext,
|
|
96
|
+
children: renderChevronIcon(PaginationItemType.NEXT)
|
|
97
|
+
},
|
|
98
|
+
PaginationItemType.NEXT
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
[slots, classNames, loop, activePage, isRTL, total, getItemAriaLabel, onNext]
|
|
102
|
+
);
|
|
103
|
+
const renderItem = useCallback(
|
|
104
|
+
(value, index) => {
|
|
105
|
+
const isBefore = index < range.indexOf(activePage);
|
|
106
|
+
if (renderItemProp && typeof renderItemProp === "function") {
|
|
107
|
+
let page = typeof value == "number" ? value : index;
|
|
108
|
+
if (value === PaginationItemType.NEXT) {
|
|
109
|
+
page = activePage + 1;
|
|
110
|
+
}
|
|
111
|
+
if (value === PaginationItemType.PREV) {
|
|
112
|
+
page = activePage - 1;
|
|
113
|
+
}
|
|
114
|
+
if (value === PaginationItemType.DOTS) {
|
|
115
|
+
page = isBefore ? activePage - dotsJump >= 1 ? activePage - dotsJump : 1 : activePage + dotsJump <= total ? activePage + dotsJump : total;
|
|
116
|
+
}
|
|
117
|
+
const itemChildren = {
|
|
118
|
+
[PaginationItemType.PREV]: renderChevronIcon(PaginationItemType.PREV),
|
|
119
|
+
[PaginationItemType.NEXT]: renderChevronIcon(PaginationItemType.NEXT),
|
|
120
|
+
[PaginationItemType.DOTS]: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
121
|
+
/* @__PURE__ */ jsx(EllipsisIcon, { className: slots == null ? void 0 : slots.ellipsis({ class: classNames == null ? void 0 : classNames.ellipsis }) }),
|
|
122
|
+
/* @__PURE__ */ jsx(
|
|
123
|
+
ForwardIcon,
|
|
124
|
+
{
|
|
125
|
+
className: slots == null ? void 0 : slots.forwardIcon({ class: classNames == null ? void 0 : classNames.forwardIcon }),
|
|
126
|
+
"data-before": dataAttr(isBefore)
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
] })
|
|
130
|
+
};
|
|
131
|
+
return renderItemProp({
|
|
132
|
+
value,
|
|
133
|
+
index,
|
|
134
|
+
key: `${value}-${index}`,
|
|
135
|
+
page,
|
|
136
|
+
total,
|
|
137
|
+
children: typeof value === "number" ? value : itemChildren[value],
|
|
138
|
+
activePage,
|
|
139
|
+
dotsJump,
|
|
140
|
+
isBefore,
|
|
141
|
+
isActive: value === activePage,
|
|
142
|
+
isPrevious: value === activePage - 1,
|
|
143
|
+
isNext: value === activePage + 1,
|
|
144
|
+
isFirst: value === 1,
|
|
145
|
+
isLast: value === total,
|
|
146
|
+
onNext,
|
|
147
|
+
onPrevious,
|
|
148
|
+
setPage,
|
|
149
|
+
onPress: () => setPage(page),
|
|
150
|
+
ref: typeof value === "number" ? (node) => getItemRef(node, value) : void 0,
|
|
151
|
+
className: slots.item({ class: classNames == null ? void 0 : classNames.item }),
|
|
152
|
+
getAriaLabel: getItemAriaLabel
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (value === PaginationItemType.PREV) {
|
|
156
|
+
return renderPrevItem(value);
|
|
157
|
+
}
|
|
158
|
+
if (value === PaginationItemType.NEXT) {
|
|
159
|
+
return renderNextItem(value);
|
|
160
|
+
}
|
|
161
|
+
if (value === PaginationItemType.DOTS) {
|
|
162
|
+
return /* @__PURE__ */ jsxs(
|
|
163
|
+
pagination_item_default,
|
|
164
|
+
{
|
|
165
|
+
className: slots.item({
|
|
166
|
+
class: cn(classNames == null ? void 0 : classNames.item, "group")
|
|
167
|
+
}),
|
|
168
|
+
"data-slot": "item",
|
|
169
|
+
getAriaLabel: getItemAriaLabel,
|
|
170
|
+
value,
|
|
171
|
+
onPress: () => isBefore ? setPage(activePage - dotsJump >= 1 ? activePage - dotsJump : 1) : setPage(activePage + dotsJump <= total ? activePage + dotsJump : total),
|
|
172
|
+
children: [
|
|
173
|
+
/* @__PURE__ */ jsx(EllipsisIcon, { className: slots == null ? void 0 : slots.ellipsis({ class: classNames == null ? void 0 : classNames.ellipsis }) }),
|
|
174
|
+
/* @__PURE__ */ jsx(
|
|
175
|
+
ForwardIcon,
|
|
176
|
+
{
|
|
177
|
+
className: slots == null ? void 0 : slots.forwardIcon({ class: classNames == null ? void 0 : classNames.forwardIcon }),
|
|
178
|
+
"data-before": dataAttr(isRTL ? !isBefore : isBefore)
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
]
|
|
182
|
+
},
|
|
183
|
+
PaginationItemType.DOTS + isBefore
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return /* @__PURE__ */ createElement(pagination_item_default, { ...getItemProps({ value }), key: value, getAriaLabel: getItemAriaLabel }, value);
|
|
187
|
+
},
|
|
188
|
+
[
|
|
189
|
+
isRTL,
|
|
190
|
+
activePage,
|
|
191
|
+
dotsJump,
|
|
192
|
+
getItemProps,
|
|
193
|
+
loop,
|
|
194
|
+
range,
|
|
195
|
+
renderItemProp,
|
|
196
|
+
slots,
|
|
197
|
+
classNames,
|
|
198
|
+
total,
|
|
199
|
+
getItemAriaLabel,
|
|
200
|
+
onNext,
|
|
201
|
+
onPrevious,
|
|
202
|
+
setPage,
|
|
203
|
+
renderPrevItem,
|
|
204
|
+
renderNextItem
|
|
205
|
+
]
|
|
206
|
+
);
|
|
207
|
+
return /* @__PURE__ */ jsx(Component, { ...getBaseProps(), children: /* @__PURE__ */ jsxs("ul", { ...getWrapperProps(), children: [
|
|
208
|
+
!disableCursorAnimation && !disableAnimation && /* @__PURE__ */ jsx(pagination_cursor_default, { ...getCursorProps() }),
|
|
209
|
+
range.map(renderItem)
|
|
210
|
+
] }) });
|
|
211
|
+
});
|
|
212
|
+
Pagination.displayName = "HeroUI.Pagination";
|
|
213
|
+
var pagination_default = Pagination;
|
|
214
|
+
|
|
215
|
+
export {
|
|
216
|
+
pagination_default
|
|
217
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
usePaginationItem
|
|
4
|
+
} from "./chunk-5S65XA6Q.mjs";
|
|
5
|
+
|
|
6
|
+
// src/pagination-item.tsx
|
|
7
|
+
import { forwardRef } from "@sytechui/system";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var PaginationItem = forwardRef((props, ref) => {
|
|
10
|
+
const { Component, children, getItemProps } = usePaginationItem({ ...props, ref });
|
|
11
|
+
return /* @__PURE__ */ jsx(Component, { ...getItemProps(), children });
|
|
12
|
+
});
|
|
13
|
+
PaginationItem.displayName = "HeroUI.PaginationItem";
|
|
14
|
+
var pagination_item_default = PaginationItem;
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
pagination_item_default
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/pagination-cursor.tsx
|
|
4
|
+
import { forwardRef } from "@sytechui/system";
|
|
5
|
+
import { useDOMRef } from "@sytechui/react-utils";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
var PaginationCursor = forwardRef((props, ref) => {
|
|
8
|
+
const { as, activePage, ...otherProps } = props;
|
|
9
|
+
const Component = as || "span";
|
|
10
|
+
const domRef = useDOMRef(ref);
|
|
11
|
+
return /* @__PURE__ */ jsx(Component, { ref: domRef, "aria-hidden": true, ...otherProps, children: activePage });
|
|
12
|
+
});
|
|
13
|
+
PaginationCursor.displayName = "HeroUI.PaginationCursor";
|
|
14
|
+
var pagination_cursor_default = PaginationCursor;
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
pagination_cursor_default
|
|
18
|
+
};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/use-pagination.ts
|
|
4
|
+
import { objectToDeps } from "@sytechui/shared-utils";
|
|
5
|
+
import { PaginationItemType } from "@sytechui/use-pagination";
|
|
6
|
+
import { useEffect, useRef, useMemo } from "react";
|
|
7
|
+
import { mapPropsVariants, useProviderContext } from "@sytechui/system";
|
|
8
|
+
import { usePagination as useBasePagination } from "@sytechui/use-pagination";
|
|
9
|
+
import scrollIntoView from "scroll-into-view-if-needed";
|
|
10
|
+
import { pagination, cn } from "@sytechui/theme";
|
|
11
|
+
import { useDOMRef } from "@sytechui/react-utils";
|
|
12
|
+
import { dataAttr } from "@sytechui/shared-utils";
|
|
13
|
+
import { useIntersectionObserver } from "@sytechui/use-intersection-observer";
|
|
14
|
+
var CURSOR_TRANSITION_TIMEOUT = 300;
|
|
15
|
+
function usePagination(originalProps) {
|
|
16
|
+
var _a, _b, _c, _d;
|
|
17
|
+
const globalContext = useProviderContext();
|
|
18
|
+
const [props, variantProps] = mapPropsVariants(originalProps, pagination.variantKeys);
|
|
19
|
+
const {
|
|
20
|
+
as,
|
|
21
|
+
ref,
|
|
22
|
+
classNames,
|
|
23
|
+
dotsJump = 5,
|
|
24
|
+
loop = false,
|
|
25
|
+
showControls = false,
|
|
26
|
+
total = 1,
|
|
27
|
+
initialPage = 1,
|
|
28
|
+
page,
|
|
29
|
+
siblings,
|
|
30
|
+
boundaries,
|
|
31
|
+
onChange,
|
|
32
|
+
className,
|
|
33
|
+
renderItem,
|
|
34
|
+
getItemAriaLabel: getItemAriaLabelProp,
|
|
35
|
+
...otherProps
|
|
36
|
+
} = props;
|
|
37
|
+
const Component = as || "nav";
|
|
38
|
+
const domRef = useDOMRef(ref);
|
|
39
|
+
const cursorRef = useRef(null);
|
|
40
|
+
const itemsRef = useRef();
|
|
41
|
+
const cursorTimer = useRef();
|
|
42
|
+
const disableAnimation = (_b = (_a = originalProps == null ? void 0 : originalProps.disableAnimation) != null ? _a : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _b : false;
|
|
43
|
+
const disableCursorAnimation = (_d = (_c = originalProps == null ? void 0 : originalProps.disableCursorAnimation) != null ? _c : disableAnimation) != null ? _d : false;
|
|
44
|
+
function getItemsRefMap() {
|
|
45
|
+
if (!itemsRef.current) {
|
|
46
|
+
itemsRef.current = /* @__PURE__ */ new Map();
|
|
47
|
+
}
|
|
48
|
+
return itemsRef.current;
|
|
49
|
+
}
|
|
50
|
+
function getItemRef(node, value) {
|
|
51
|
+
const map = getItemsRefMap();
|
|
52
|
+
if (node) {
|
|
53
|
+
map.set(value, node);
|
|
54
|
+
} else {
|
|
55
|
+
map.delete(value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function scrollTo(value, skipAnimation) {
|
|
59
|
+
const map = getItemsRefMap();
|
|
60
|
+
const node = map.get(value);
|
|
61
|
+
if (!node || !cursorRef.current) return;
|
|
62
|
+
cursorTimer.current && clearTimeout(cursorTimer.current);
|
|
63
|
+
scrollIntoView(node, {
|
|
64
|
+
scrollMode: "always",
|
|
65
|
+
behavior: "smooth",
|
|
66
|
+
block: "start",
|
|
67
|
+
inline: "start",
|
|
68
|
+
boundary: domRef.current
|
|
69
|
+
});
|
|
70
|
+
const { offsetLeft } = node;
|
|
71
|
+
if (skipAnimation) {
|
|
72
|
+
cursorRef.current.setAttribute("data-moving", "false");
|
|
73
|
+
cursorRef.current.style.transform = `translateX(${offsetLeft}px) scale(1)`;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
cursorRef.current.setAttribute("data-moving", "true");
|
|
77
|
+
cursorRef.current.style.transform = `translateX(${offsetLeft}px) scale(1.1)`;
|
|
78
|
+
cursorTimer.current = setTimeout(() => {
|
|
79
|
+
if (cursorRef.current) {
|
|
80
|
+
cursorRef.current.style.transform = `translateX(${offsetLeft}px) scale(1)`;
|
|
81
|
+
}
|
|
82
|
+
cursorTimer.current = setTimeout(() => {
|
|
83
|
+
var _a2;
|
|
84
|
+
(_a2 = cursorRef.current) == null ? void 0 : _a2.setAttribute("data-moving", "false");
|
|
85
|
+
cursorTimer.current && clearTimeout(cursorTimer.current);
|
|
86
|
+
}, CURSOR_TRANSITION_TIMEOUT);
|
|
87
|
+
}, CURSOR_TRANSITION_TIMEOUT);
|
|
88
|
+
}
|
|
89
|
+
const { range, activePage, setPage, previous, next, first, last } = useBasePagination({
|
|
90
|
+
page,
|
|
91
|
+
total,
|
|
92
|
+
initialPage,
|
|
93
|
+
siblings,
|
|
94
|
+
boundaries,
|
|
95
|
+
showControls,
|
|
96
|
+
onChange
|
|
97
|
+
});
|
|
98
|
+
const [setRef, isVisible] = useIntersectionObserver();
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (domRef.current) {
|
|
101
|
+
setRef(domRef.current);
|
|
102
|
+
}
|
|
103
|
+
}, [domRef.current]);
|
|
104
|
+
const activePageRef = useRef(activePage);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (activePage && !disableAnimation && isVisible) {
|
|
107
|
+
scrollTo(activePage, activePage === activePageRef.current);
|
|
108
|
+
}
|
|
109
|
+
activePageRef.current = activePage;
|
|
110
|
+
}, [
|
|
111
|
+
page,
|
|
112
|
+
activePage,
|
|
113
|
+
disableAnimation,
|
|
114
|
+
disableCursorAnimation,
|
|
115
|
+
isVisible,
|
|
116
|
+
originalProps.dotsJump,
|
|
117
|
+
originalProps.isCompact,
|
|
118
|
+
originalProps.showControls
|
|
119
|
+
]);
|
|
120
|
+
const slots = useMemo(
|
|
121
|
+
() => pagination({
|
|
122
|
+
...variantProps,
|
|
123
|
+
disableAnimation,
|
|
124
|
+
disableCursorAnimation
|
|
125
|
+
}),
|
|
126
|
+
[objectToDeps(variantProps), disableCursorAnimation, disableAnimation]
|
|
127
|
+
);
|
|
128
|
+
const baseStyles = cn(classNames == null ? void 0 : classNames.base, className);
|
|
129
|
+
const onNext = () => {
|
|
130
|
+
if (loop && activePage === total) {
|
|
131
|
+
return first();
|
|
132
|
+
}
|
|
133
|
+
return next();
|
|
134
|
+
};
|
|
135
|
+
const onPrevious = () => {
|
|
136
|
+
if (loop && activePage === 1) {
|
|
137
|
+
return last();
|
|
138
|
+
}
|
|
139
|
+
return previous();
|
|
140
|
+
};
|
|
141
|
+
const getBaseProps = (props2 = {}) => {
|
|
142
|
+
return {
|
|
143
|
+
...props2,
|
|
144
|
+
ref: domRef,
|
|
145
|
+
role: "navigation",
|
|
146
|
+
"aria-label": props2["aria-label"] || "pagination navigation",
|
|
147
|
+
"data-slot": "base",
|
|
148
|
+
"data-controls": dataAttr(showControls),
|
|
149
|
+
"data-loop": dataAttr(loop),
|
|
150
|
+
"data-dots-jump": dotsJump,
|
|
151
|
+
"data-total": total,
|
|
152
|
+
"data-active-page": activePage,
|
|
153
|
+
className: slots.base({ class: cn(baseStyles, props2 == null ? void 0 : props2.className) }),
|
|
154
|
+
...otherProps
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
const getWrapperProps = (props2 = {}) => {
|
|
158
|
+
return {
|
|
159
|
+
...props2,
|
|
160
|
+
"data-slot": "wrapper",
|
|
161
|
+
className: slots.wrapper({ class: cn(classNames == null ? void 0 : classNames.wrapper, props2 == null ? void 0 : props2.className) })
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
const getItemAriaLabel = (page2) => {
|
|
165
|
+
if (!page2) return;
|
|
166
|
+
if (getItemAriaLabelProp) {
|
|
167
|
+
return getItemAriaLabelProp(page2);
|
|
168
|
+
}
|
|
169
|
+
switch (page2) {
|
|
170
|
+
case PaginationItemType.DOTS:
|
|
171
|
+
return "dots element";
|
|
172
|
+
case PaginationItemType.PREV:
|
|
173
|
+
return "previous page button";
|
|
174
|
+
case PaginationItemType.NEXT:
|
|
175
|
+
return "next page button";
|
|
176
|
+
case "first":
|
|
177
|
+
return "first page button";
|
|
178
|
+
case "last":
|
|
179
|
+
return "last page button";
|
|
180
|
+
default:
|
|
181
|
+
return `pagination item ${page2}`;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
const getItemProps = (props2 = {}) => {
|
|
185
|
+
return {
|
|
186
|
+
...props2,
|
|
187
|
+
ref: (node) => getItemRef(node, props2.value),
|
|
188
|
+
"data-slot": "item",
|
|
189
|
+
isActive: props2.value === activePage,
|
|
190
|
+
className: slots.item({ class: cn(classNames == null ? void 0 : classNames.item, props2 == null ? void 0 : props2.className) }),
|
|
191
|
+
onPress: () => {
|
|
192
|
+
if (props2.value !== activePage) {
|
|
193
|
+
setPage(props2.value);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
const getCursorProps = (props2 = {}) => {
|
|
199
|
+
return {
|
|
200
|
+
...props2,
|
|
201
|
+
ref: cursorRef,
|
|
202
|
+
activePage,
|
|
203
|
+
"data-slot": "cursor",
|
|
204
|
+
className: slots.cursor({ class: cn(classNames == null ? void 0 : classNames.cursor, props2 == null ? void 0 : props2.className) })
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
return {
|
|
208
|
+
Component,
|
|
209
|
+
showControls,
|
|
210
|
+
dotsJump,
|
|
211
|
+
slots,
|
|
212
|
+
classNames,
|
|
213
|
+
loop,
|
|
214
|
+
total,
|
|
215
|
+
range,
|
|
216
|
+
activePage,
|
|
217
|
+
getItemRef,
|
|
218
|
+
disableAnimation,
|
|
219
|
+
disableCursorAnimation,
|
|
220
|
+
setPage,
|
|
221
|
+
onPrevious,
|
|
222
|
+
onNext,
|
|
223
|
+
renderItem,
|
|
224
|
+
getBaseProps,
|
|
225
|
+
getWrapperProps,
|
|
226
|
+
getItemProps,
|
|
227
|
+
getCursorProps,
|
|
228
|
+
getItemAriaLabel
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export {
|
|
233
|
+
CURSOR_TRANSITION_TIMEOUT,
|
|
234
|
+
usePagination
|
|
235
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default as Pagination, PaginationProps } from './pagination.mjs';
|
|
2
|
+
export { default as PaginationItem, PaginationItemProps } from './pagination-item.mjs';
|
|
3
|
+
export { default as PaginationCursor, PaginationCursorProps } from './pagination-cursor.mjs';
|
|
4
|
+
export { PaginationItemRenderProps, usePagination } from './use-pagination.mjs';
|
|
5
|
+
export { PaginationItemType, PaginationItemValue } from '@sytechui/use-pagination';
|
|
6
|
+
export { usePaginationItem } from './use-pagination-item.mjs';
|
|
7
|
+
import '@sytechui/system';
|
|
8
|
+
import 'tailwind-variants';
|
|
9
|
+
import '@sytechui/theme';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '@react-types/shared';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default as Pagination, PaginationProps } from './pagination.js';
|
|
2
|
+
export { default as PaginationItem, PaginationItemProps } from './pagination-item.js';
|
|
3
|
+
export { default as PaginationCursor, PaginationCursorProps } from './pagination-cursor.js';
|
|
4
|
+
export { PaginationItemRenderProps, usePagination } from './use-pagination.js';
|
|
5
|
+
export { PaginationItemType, PaginationItemValue } from '@sytechui/use-pagination';
|
|
6
|
+
export { usePaginationItem } from './use-pagination-item.js';
|
|
7
|
+
import '@sytechui/system';
|
|
8
|
+
import 'tailwind-variants';
|
|
9
|
+
import '@sytechui/theme';
|
|
10
|
+
import 'react';
|
|
11
|
+
import '@react-types/shared';
|