@yamada-ui/pagination 0.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Hirotomo Yamada
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,28 @@
1
+ # @yamada-ui/pagination
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ $ pnpm add @yamada-ui/pagination
7
+ ```
8
+
9
+ or
10
+
11
+ ```sh
12
+ $ yarn add @yamada-ui/pagination
13
+ ```
14
+
15
+ or
16
+
17
+ ```sh
18
+ $ npm install @yamada-ui/pagination
19
+ ```
20
+
21
+ ## Contribution
22
+
23
+ Wouldn't you like to contribute? That's amazing! We have prepared a [contribution guide](https://github.com/hirotomoyamada/yamada-ui/blob/main/CONTRIBUTING.md) to assist you.
24
+
25
+ ## Licence
26
+
27
+ This package is licensed under the terms of the
28
+ [MIT license](https://github.com/hirotomoyamada/yamada-ui/blob/main/LICENSE).
@@ -0,0 +1,59 @@
1
+ import {
2
+ DotsIcon,
3
+ FirstIcon,
4
+ LastIcon,
5
+ NextIcon,
6
+ PrevIcon
7
+ } from "./chunk-IXTXZCRI.mjs";
8
+ import {
9
+ usePaginationContext
10
+ } from "./chunk-3KNXDAHV.mjs";
11
+
12
+ // src/pagination-item.tsx
13
+ import { ui } from "@yamada-ui/core";
14
+ import { cx, dataAttr } from "@yamada-ui/utils";
15
+ import { jsx } from "react/jsx-runtime";
16
+ var iconMap = {
17
+ dots: /* @__PURE__ */ jsx(DotsIcon, {}),
18
+ next: /* @__PURE__ */ jsx(NextIcon, {}),
19
+ prev: /* @__PURE__ */ jsx(PrevIcon, {}),
20
+ first: /* @__PURE__ */ jsx(FirstIcon, {}),
21
+ last: /* @__PURE__ */ jsx(LastIcon, {})
22
+ };
23
+ var PaginationItem = ({
24
+ className,
25
+ isActive,
26
+ page,
27
+ isDisabled,
28
+ children,
29
+ ...rest
30
+ }) => {
31
+ var _a;
32
+ const styles = usePaginationContext();
33
+ children != null ? children : children = (_a = iconMap[page]) != null ? _a : page;
34
+ const css = {
35
+ display: "flex",
36
+ justifyContent: "center",
37
+ alignItems: "center",
38
+ ...styles.item,
39
+ ...styles[page]
40
+ };
41
+ return /* @__PURE__ */ jsx(
42
+ ui.button,
43
+ {
44
+ className: cx("ui-pagination-item", className),
45
+ type: "button",
46
+ tabIndex: page !== "dots" ? 0 : -1,
47
+ disabled: isDisabled,
48
+ "data-selected": dataAttr(isActive),
49
+ "data-disabled": dataAttr(isDisabled),
50
+ __css: css,
51
+ ...rest,
52
+ children
53
+ }
54
+ );
55
+ };
56
+
57
+ export {
58
+ PaginationItem
59
+ };
@@ -0,0 +1,88 @@
1
+ // src/use-pagination.ts
2
+ import { useControllableState } from "@yamada-ui/use-controllable-state";
3
+ import { useValue } from "@yamada-ui/use-value";
4
+ import { createContext } from "@yamada-ui/utils";
5
+ import { useCallback, useMemo } from "react";
6
+ var [PaginationProvider, usePaginationContext] = createContext({
7
+ strict: false,
8
+ name: "PaginationContext"
9
+ });
10
+ var computedRange = (start, end) => Array.from({ length: end - start + 1 }, (_, index) => index + start);
11
+ var usePagination = ({
12
+ page,
13
+ defaultPage = 1,
14
+ total,
15
+ siblings = 1,
16
+ boundaries = 1,
17
+ isDisabled = false,
18
+ ...rest
19
+ }) => {
20
+ const computedSiblings = useValue(siblings);
21
+ const computedBoundaries = useValue(boundaries);
22
+ const [currentPage, setCurrentPage] = useControllableState({
23
+ value: page,
24
+ defaultValue: defaultPage,
25
+ onChange: rest.onChange
26
+ });
27
+ const onFirst = useCallback(() => setCurrentPage(1), [setCurrentPage]);
28
+ const onLast = useCallback(() => setCurrentPage(total), [setCurrentPage, total]);
29
+ const onPrev = useCallback(
30
+ () => setCurrentPage((prev) => prev === 1 ? prev : prev - 1),
31
+ [setCurrentPage]
32
+ );
33
+ const onNext = useCallback(
34
+ () => setCurrentPage((prev) => prev === total ? prev : prev + 1),
35
+ [setCurrentPage, total]
36
+ );
37
+ const onChange = useCallback((page2) => setCurrentPage(page2), [setCurrentPage]);
38
+ const range = useMemo(() => {
39
+ const minimumTotal = computedSiblings * 2 + 3 + computedBoundaries * 2;
40
+ if (minimumTotal >= total)
41
+ return computedRange(1, total);
42
+ const prevSiblings = Math.max(currentPage - computedSiblings, computedBoundaries);
43
+ const nextSiblings = Math.min(currentPage + computedSiblings, total - computedBoundaries);
44
+ const prevDots = prevSiblings > computedBoundaries + 2;
45
+ const nextDots = nextSiblings < total - (computedBoundaries + 1);
46
+ if (!prevDots && nextDots) {
47
+ const prevPages = computedSiblings * 2 + computedBoundaries + 2;
48
+ return [
49
+ ...computedRange(1, prevPages),
50
+ "dots",
51
+ ...computedRange(total - (computedBoundaries - 1), total)
52
+ ];
53
+ }
54
+ if (prevDots && !nextDots) {
55
+ const nextPages = computedBoundaries + 1 + 2 * computedSiblings;
56
+ return [
57
+ ...computedRange(1, computedBoundaries),
58
+ "dots",
59
+ ...computedRange(total - nextPages, total)
60
+ ];
61
+ }
62
+ return [
63
+ ...computedRange(1, computedBoundaries),
64
+ "dots",
65
+ ...computedRange(prevSiblings, nextSiblings),
66
+ "dots",
67
+ ...computedRange(total - computedBoundaries + 1, total)
68
+ ];
69
+ }, [computedBoundaries, computedSiblings, currentPage, total]);
70
+ return {
71
+ currentPage,
72
+ total,
73
+ isDisabled,
74
+ onFirst,
75
+ onLast,
76
+ onPrev,
77
+ onNext,
78
+ onChange,
79
+ range
80
+ };
81
+ };
82
+
83
+ export {
84
+ PaginationProvider,
85
+ usePaginationContext,
86
+ computedRange,
87
+ usePagination
88
+ };
@@ -0,0 +1,56 @@
1
+ // src/pagination-icon.tsx
2
+ import { Icon } from "@yamada-ui/icon";
3
+ import { jsx } from "react/jsx-runtime";
4
+ var DotsIcon = (props) => {
5
+ return /* @__PURE__ */ jsx(Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ jsx(
6
+ "path",
7
+ {
8
+ fill: "currentColor",
9
+ d: "M2 8c0-.733.6-1.333 1.333-1.333.734 0 1.334.6 1.334 1.333s-.6 1.333-1.334 1.333C2.6 9.333 2 8.733 2 8zm9.333 0c0-.733.6-1.333 1.334-1.333C13.4 6.667 14 7.267 14 8s-.6 1.333-1.333 1.333c-.734 0-1.334-.6-1.334-1.333zM6.667 8c0-.733.6-1.333 1.333-1.333s1.333.6 1.333 1.333S8.733 9.333 8 9.333 6.667 8.733 6.667 8z"
10
+ }
11
+ ) });
12
+ };
13
+ var FirstIcon = (props) => {
14
+ return /* @__PURE__ */ jsx(Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ jsx(
15
+ "path",
16
+ {
17
+ fill: "currentColor",
18
+ d: "M6.85355 3.85355C7.04882 3.65829 7.04882 3.34171 6.85355 3.14645C6.65829 2.95118 6.34171 2.95118 6.14645 3.14645L2.14645 7.14645C1.95118 7.34171 1.95118 7.65829 2.14645 7.85355L6.14645 11.8536C6.34171 12.0488 6.65829 12.0488 6.85355 11.8536C7.04882 11.6583 7.04882 11.3417 6.85355 11.1464L3.20711 7.5L6.85355 3.85355ZM12.8536 3.85355C13.0488 3.65829 13.0488 3.34171 12.8536 3.14645C12.6583 2.95118 12.3417 2.95118 12.1464 3.14645L8.14645 7.14645C7.95118 7.34171 7.95118 7.65829 8.14645 7.85355L12.1464 11.8536C12.3417 12.0488 12.6583 12.0488 12.8536 11.8536C13.0488 11.6583 13.0488 11.3417 12.8536 11.1464L9.20711 7.5L12.8536 3.85355Z"
19
+ }
20
+ ) });
21
+ };
22
+ var LastIcon = (props) => {
23
+ return /* @__PURE__ */ jsx(Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ jsx(
24
+ "path",
25
+ {
26
+ fill: "currentColor",
27
+ d: "M2.14645 11.1464C1.95118 11.3417 1.95118 11.6583 2.14645 11.8536C2.34171 12.0488 2.65829 12.0488 2.85355 11.8536L6.85355 7.85355C7.04882 7.65829 7.04882 7.34171 6.85355 7.14645L2.85355 3.14645C2.65829 2.95118 2.34171 2.95118 2.14645 3.14645C1.95118 3.34171 1.95118 3.65829 2.14645 3.85355L5.79289 7.5L2.14645 11.1464ZM8.14645 11.1464C7.95118 11.3417 7.95118 11.6583 8.14645 11.8536C8.34171 12.0488 8.65829 12.0488 8.85355 11.8536L12.8536 7.85355C13.0488 7.65829 13.0488 7.34171 12.8536 7.14645L8.85355 3.14645C8.65829 2.95118 8.34171 2.95118 8.14645 3.14645C7.95118 3.34171 7.95118 3.65829 8.14645 3.85355L11.7929 7.5L8.14645 11.1464Z"
28
+ }
29
+ ) });
30
+ };
31
+ var PrevIcon = (props) => {
32
+ return /* @__PURE__ */ jsx(Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ jsx(
33
+ "path",
34
+ {
35
+ fill: "currentColor",
36
+ d: "M7.219 8l3.3 3.3-.943.943L5.333 8l4.243-4.243.943.943-3.3 3.3z"
37
+ }
38
+ ) });
39
+ };
40
+ var NextIcon = (props) => {
41
+ return /* @__PURE__ */ jsx(Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ jsx(
42
+ "path",
43
+ {
44
+ fill: "currentColor",
45
+ d: "M8.781 8l-3.3-3.3.943-.943L10.667 8l-4.243 4.243-.943-.943 3.3-3.3z"
46
+ }
47
+ ) });
48
+ };
49
+
50
+ export {
51
+ DotsIcon,
52
+ FirstIcon,
53
+ LastIcon,
54
+ PrevIcon,
55
+ NextIcon
56
+ };
@@ -0,0 +1,119 @@
1
+ import {
2
+ PaginationItem
3
+ } from "./chunk-3JXQPHJH.mjs";
4
+ import {
5
+ PaginationProvider,
6
+ usePagination
7
+ } from "./chunk-3KNXDAHV.mjs";
8
+
9
+ // src/pagination.tsx
10
+ import {
11
+ ui,
12
+ forwardRef,
13
+ useMultiComponentStyle,
14
+ omitThemeProps
15
+ } from "@yamada-ui/core";
16
+ import { useValue } from "@yamada-ui/use-value";
17
+ import { cx, omitObject, dataAttr, handlerAll } from "@yamada-ui/utils";
18
+ import { useMemo } from "react";
19
+ import { jsx, jsxs } from "react/jsx-runtime";
20
+ var Pagination = forwardRef((props, ref) => {
21
+ const [styles, mergedProps] = useMultiComponentStyle("Pagination", props);
22
+ const {
23
+ className,
24
+ component: Component = PaginationItem,
25
+ itemProps,
26
+ withControls = true,
27
+ withEdges = false,
28
+ controlProps,
29
+ controlPrevProps,
30
+ controlNextProps,
31
+ edgeProps,
32
+ edgeFirstProps,
33
+ edgeLastProps,
34
+ ...rest
35
+ } = omitThemeProps(mergedProps);
36
+ const computedWithControls = useValue(withControls);
37
+ const computedWithEdges = useValue(withEdges);
38
+ const { currentPage, total, isDisabled, onFirst, onLast, onPrev, onNext, onChange, range } = usePagination(rest);
39
+ const children = useMemo(
40
+ () => range.map((page, key) => /* @__PURE__ */ jsx(
41
+ Component,
42
+ {
43
+ page,
44
+ isActive: currentPage === page,
45
+ isDisabled,
46
+ ...itemProps,
47
+ onClick: handlerAll(
48
+ itemProps == null ? void 0 : itemProps.onClick,
49
+ page !== "dots" ? () => onChange(page) : void 0
50
+ )
51
+ },
52
+ key
53
+ )),
54
+ [Component, currentPage, isDisabled, onChange, range, itemProps]
55
+ );
56
+ const css = { display: "flex", alignItems: "center", ...styles.container };
57
+ return /* @__PURE__ */ jsx(PaginationProvider, { value: styles, children: /* @__PURE__ */ jsxs(
58
+ ui.div,
59
+ {
60
+ ref,
61
+ className: cx("ui-pagination", className),
62
+ role: "navigation",
63
+ __css: css,
64
+ ...omitObject(rest, ["onChange"]),
65
+ "data-disabled": dataAttr(isDisabled),
66
+ children: [
67
+ computedWithEdges ? /* @__PURE__ */ jsx(
68
+ Component,
69
+ {
70
+ page: "first",
71
+ className: "ui-pagination-item-first",
72
+ isDisabled: isDisabled || currentPage === 1,
73
+ ...edgeProps,
74
+ ...edgeFirstProps,
75
+ onClick: handlerAll(edgeProps == null ? void 0 : edgeProps.onClick, edgeFirstProps == null ? void 0 : edgeFirstProps.onClick, onFirst)
76
+ }
77
+ ) : null,
78
+ computedWithControls ? /* @__PURE__ */ jsx(
79
+ Component,
80
+ {
81
+ page: "prev",
82
+ className: "ui-pagination-item-prev",
83
+ isDisabled: isDisabled || currentPage === 1,
84
+ ...controlProps,
85
+ ...controlPrevProps,
86
+ onClick: handlerAll(controlProps == null ? void 0 : controlProps.onClick, controlPrevProps == null ? void 0 : controlPrevProps.onClick, onPrev)
87
+ }
88
+ ) : null,
89
+ children,
90
+ computedWithControls ? /* @__PURE__ */ jsx(
91
+ Component,
92
+ {
93
+ page: "next",
94
+ className: "ui-pagination-item-next",
95
+ isDisabled: isDisabled || currentPage === total,
96
+ ...controlProps,
97
+ ...controlNextProps,
98
+ onClick: handlerAll(controlProps == null ? void 0 : controlProps.onClick, controlNextProps == null ? void 0 : controlNextProps.onClick, onNext)
99
+ }
100
+ ) : null,
101
+ computedWithEdges ? /* @__PURE__ */ jsx(
102
+ Component,
103
+ {
104
+ page: "last",
105
+ className: "ui-pagination-item-last",
106
+ isDisabled: isDisabled || currentPage === total,
107
+ ...edgeProps,
108
+ ...edgeLastProps,
109
+ onClick: handlerAll(edgeProps == null ? void 0 : edgeProps.onClick, edgeLastProps == null ? void 0 : edgeLastProps.onClick, onLast)
110
+ }
111
+ ) : null
112
+ ]
113
+ }
114
+ ) });
115
+ });
116
+
117
+ export {
118
+ Pagination
119
+ };
@@ -0,0 +1,5 @@
1
+ export { Pagination, PaginationProps } from './pagination.js';
2
+ import '@yamada-ui/core';
3
+ import 'react';
4
+ import './pagination-item.js';
5
+ import './use-pagination.js';
package/dist/index.js ADDED
@@ -0,0 +1,312 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Pagination: () => Pagination
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/pagination.tsx
28
+ var import_core2 = require("@yamada-ui/core");
29
+ var import_use_value2 = require("@yamada-ui/use-value");
30
+ var import_utils3 = require("@yamada-ui/utils");
31
+ var import_react2 = require("react");
32
+
33
+ // src/pagination-item.tsx
34
+ var import_core = require("@yamada-ui/core");
35
+ var import_utils2 = require("@yamada-ui/utils");
36
+
37
+ // src/pagination-icon.tsx
38
+ var import_icon = require("@yamada-ui/icon");
39
+ var import_jsx_runtime = require("react/jsx-runtime");
40
+ var DotsIcon = (props) => {
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
42
+ "path",
43
+ {
44
+ fill: "currentColor",
45
+ d: "M2 8c0-.733.6-1.333 1.333-1.333.734 0 1.334.6 1.334 1.333s-.6 1.333-1.334 1.333C2.6 9.333 2 8.733 2 8zm9.333 0c0-.733.6-1.333 1.334-1.333C13.4 6.667 14 7.267 14 8s-.6 1.333-1.333 1.333c-.734 0-1.334-.6-1.334-1.333zM6.667 8c0-.733.6-1.333 1.333-1.333s1.333.6 1.333 1.333S8.733 9.333 8 9.333 6.667 8.733 6.667 8z"
46
+ }
47
+ ) });
48
+ };
49
+ var FirstIcon = (props) => {
50
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
51
+ "path",
52
+ {
53
+ fill: "currentColor",
54
+ d: "M6.85355 3.85355C7.04882 3.65829 7.04882 3.34171 6.85355 3.14645C6.65829 2.95118 6.34171 2.95118 6.14645 3.14645L2.14645 7.14645C1.95118 7.34171 1.95118 7.65829 2.14645 7.85355L6.14645 11.8536C6.34171 12.0488 6.65829 12.0488 6.85355 11.8536C7.04882 11.6583 7.04882 11.3417 6.85355 11.1464L3.20711 7.5L6.85355 3.85355ZM12.8536 3.85355C13.0488 3.65829 13.0488 3.34171 12.8536 3.14645C12.6583 2.95118 12.3417 2.95118 12.1464 3.14645L8.14645 7.14645C7.95118 7.34171 7.95118 7.65829 8.14645 7.85355L12.1464 11.8536C12.3417 12.0488 12.6583 12.0488 12.8536 11.8536C13.0488 11.6583 13.0488 11.3417 12.8536 11.1464L9.20711 7.5L12.8536 3.85355Z"
55
+ }
56
+ ) });
57
+ };
58
+ var LastIcon = (props) => {
59
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
60
+ "path",
61
+ {
62
+ fill: "currentColor",
63
+ d: "M2.14645 11.1464C1.95118 11.3417 1.95118 11.6583 2.14645 11.8536C2.34171 12.0488 2.65829 12.0488 2.85355 11.8536L6.85355 7.85355C7.04882 7.65829 7.04882 7.34171 6.85355 7.14645L2.85355 3.14645C2.65829 2.95118 2.34171 2.95118 2.14645 3.14645C1.95118 3.34171 1.95118 3.65829 2.14645 3.85355L5.79289 7.5L2.14645 11.1464ZM8.14645 11.1464C7.95118 11.3417 7.95118 11.6583 8.14645 11.8536C8.34171 12.0488 8.65829 12.0488 8.85355 11.8536L12.8536 7.85355C13.0488 7.65829 13.0488 7.34171 12.8536 7.14645L8.85355 3.14645C8.65829 2.95118 8.34171 2.95118 8.14645 3.14645C7.95118 3.34171 7.95118 3.65829 8.14645 3.85355L11.7929 7.5L8.14645 11.1464Z"
64
+ }
65
+ ) });
66
+ };
67
+ var PrevIcon = (props) => {
68
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
69
+ "path",
70
+ {
71
+ fill: "currentColor",
72
+ d: "M7.219 8l3.3 3.3-.943.943L5.333 8l4.243-4.243.943.943-3.3 3.3z"
73
+ }
74
+ ) });
75
+ };
76
+ var NextIcon = (props) => {
77
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.Icon, { viewBox: "0 0 16 16", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
78
+ "path",
79
+ {
80
+ fill: "currentColor",
81
+ d: "M8.781 8l-3.3-3.3.943-.943L10.667 8l-4.243 4.243-.943-.943 3.3-3.3z"
82
+ }
83
+ ) });
84
+ };
85
+
86
+ // src/use-pagination.ts
87
+ var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
88
+ var import_use_value = require("@yamada-ui/use-value");
89
+ var import_utils = require("@yamada-ui/utils");
90
+ var import_react = require("react");
91
+ var [PaginationProvider, usePaginationContext] = (0, import_utils.createContext)({
92
+ strict: false,
93
+ name: "PaginationContext"
94
+ });
95
+ var computedRange = (start, end) => Array.from({ length: end - start + 1 }, (_, index) => index + start);
96
+ var usePagination = ({
97
+ page,
98
+ defaultPage = 1,
99
+ total,
100
+ siblings = 1,
101
+ boundaries = 1,
102
+ isDisabled = false,
103
+ ...rest
104
+ }) => {
105
+ const computedSiblings = (0, import_use_value.useValue)(siblings);
106
+ const computedBoundaries = (0, import_use_value.useValue)(boundaries);
107
+ const [currentPage, setCurrentPage] = (0, import_use_controllable_state.useControllableState)({
108
+ value: page,
109
+ defaultValue: defaultPage,
110
+ onChange: rest.onChange
111
+ });
112
+ const onFirst = (0, import_react.useCallback)(() => setCurrentPage(1), [setCurrentPage]);
113
+ const onLast = (0, import_react.useCallback)(() => setCurrentPage(total), [setCurrentPage, total]);
114
+ const onPrev = (0, import_react.useCallback)(
115
+ () => setCurrentPage((prev) => prev === 1 ? prev : prev - 1),
116
+ [setCurrentPage]
117
+ );
118
+ const onNext = (0, import_react.useCallback)(
119
+ () => setCurrentPage((prev) => prev === total ? prev : prev + 1),
120
+ [setCurrentPage, total]
121
+ );
122
+ const onChange = (0, import_react.useCallback)((page2) => setCurrentPage(page2), [setCurrentPage]);
123
+ const range = (0, import_react.useMemo)(() => {
124
+ const minimumTotal = computedSiblings * 2 + 3 + computedBoundaries * 2;
125
+ if (minimumTotal >= total)
126
+ return computedRange(1, total);
127
+ const prevSiblings = Math.max(currentPage - computedSiblings, computedBoundaries);
128
+ const nextSiblings = Math.min(currentPage + computedSiblings, total - computedBoundaries);
129
+ const prevDots = prevSiblings > computedBoundaries + 2;
130
+ const nextDots = nextSiblings < total - (computedBoundaries + 1);
131
+ if (!prevDots && nextDots) {
132
+ const prevPages = computedSiblings * 2 + computedBoundaries + 2;
133
+ return [
134
+ ...computedRange(1, prevPages),
135
+ "dots",
136
+ ...computedRange(total - (computedBoundaries - 1), total)
137
+ ];
138
+ }
139
+ if (prevDots && !nextDots) {
140
+ const nextPages = computedBoundaries + 1 + 2 * computedSiblings;
141
+ return [
142
+ ...computedRange(1, computedBoundaries),
143
+ "dots",
144
+ ...computedRange(total - nextPages, total)
145
+ ];
146
+ }
147
+ return [
148
+ ...computedRange(1, computedBoundaries),
149
+ "dots",
150
+ ...computedRange(prevSiblings, nextSiblings),
151
+ "dots",
152
+ ...computedRange(total - computedBoundaries + 1, total)
153
+ ];
154
+ }, [computedBoundaries, computedSiblings, currentPage, total]);
155
+ return {
156
+ currentPage,
157
+ total,
158
+ isDisabled,
159
+ onFirst,
160
+ onLast,
161
+ onPrev,
162
+ onNext,
163
+ onChange,
164
+ range
165
+ };
166
+ };
167
+
168
+ // src/pagination-item.tsx
169
+ var import_jsx_runtime2 = require("react/jsx-runtime");
170
+ var iconMap = {
171
+ dots: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DotsIcon, {}),
172
+ next: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NextIcon, {}),
173
+ prev: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PrevIcon, {}),
174
+ first: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(FirstIcon, {}),
175
+ last: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LastIcon, {})
176
+ };
177
+ var PaginationItem = ({
178
+ className,
179
+ isActive,
180
+ page,
181
+ isDisabled,
182
+ children,
183
+ ...rest
184
+ }) => {
185
+ var _a;
186
+ const styles = usePaginationContext();
187
+ children != null ? children : children = (_a = iconMap[page]) != null ? _a : page;
188
+ const css = {
189
+ display: "flex",
190
+ justifyContent: "center",
191
+ alignItems: "center",
192
+ ...styles.item,
193
+ ...styles[page]
194
+ };
195
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
196
+ import_core.ui.button,
197
+ {
198
+ className: (0, import_utils2.cx)("ui-pagination-item", className),
199
+ type: "button",
200
+ tabIndex: page !== "dots" ? 0 : -1,
201
+ disabled: isDisabled,
202
+ "data-selected": (0, import_utils2.dataAttr)(isActive),
203
+ "data-disabled": (0, import_utils2.dataAttr)(isDisabled),
204
+ __css: css,
205
+ ...rest,
206
+ children
207
+ }
208
+ );
209
+ };
210
+
211
+ // src/pagination.tsx
212
+ var import_jsx_runtime3 = require("react/jsx-runtime");
213
+ var Pagination = (0, import_core2.forwardRef)((props, ref) => {
214
+ const [styles, mergedProps] = (0, import_core2.useMultiComponentStyle)("Pagination", props);
215
+ const {
216
+ className,
217
+ component: Component = PaginationItem,
218
+ itemProps,
219
+ withControls = true,
220
+ withEdges = false,
221
+ controlProps,
222
+ controlPrevProps,
223
+ controlNextProps,
224
+ edgeProps,
225
+ edgeFirstProps,
226
+ edgeLastProps,
227
+ ...rest
228
+ } = (0, import_core2.omitThemeProps)(mergedProps);
229
+ const computedWithControls = (0, import_use_value2.useValue)(withControls);
230
+ const computedWithEdges = (0, import_use_value2.useValue)(withEdges);
231
+ const { currentPage, total, isDisabled, onFirst, onLast, onPrev, onNext, onChange, range } = usePagination(rest);
232
+ const children = (0, import_react2.useMemo)(
233
+ () => range.map((page, key) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
234
+ Component,
235
+ {
236
+ page,
237
+ isActive: currentPage === page,
238
+ isDisabled,
239
+ ...itemProps,
240
+ onClick: (0, import_utils3.handlerAll)(
241
+ itemProps == null ? void 0 : itemProps.onClick,
242
+ page !== "dots" ? () => onChange(page) : void 0
243
+ )
244
+ },
245
+ key
246
+ )),
247
+ [Component, currentPage, isDisabled, onChange, range, itemProps]
248
+ );
249
+ const css = { display: "flex", alignItems: "center", ...styles.container };
250
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PaginationProvider, { value: styles, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
251
+ import_core2.ui.div,
252
+ {
253
+ ref,
254
+ className: (0, import_utils3.cx)("ui-pagination", className),
255
+ role: "navigation",
256
+ __css: css,
257
+ ...(0, import_utils3.omitObject)(rest, ["onChange"]),
258
+ "data-disabled": (0, import_utils3.dataAttr)(isDisabled),
259
+ children: [
260
+ computedWithEdges ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
261
+ Component,
262
+ {
263
+ page: "first",
264
+ className: "ui-pagination-item-first",
265
+ isDisabled: isDisabled || currentPage === 1,
266
+ ...edgeProps,
267
+ ...edgeFirstProps,
268
+ onClick: (0, import_utils3.handlerAll)(edgeProps == null ? void 0 : edgeProps.onClick, edgeFirstProps == null ? void 0 : edgeFirstProps.onClick, onFirst)
269
+ }
270
+ ) : null,
271
+ computedWithControls ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
272
+ Component,
273
+ {
274
+ page: "prev",
275
+ className: "ui-pagination-item-prev",
276
+ isDisabled: isDisabled || currentPage === 1,
277
+ ...controlProps,
278
+ ...controlPrevProps,
279
+ onClick: (0, import_utils3.handlerAll)(controlProps == null ? void 0 : controlProps.onClick, controlPrevProps == null ? void 0 : controlPrevProps.onClick, onPrev)
280
+ }
281
+ ) : null,
282
+ children,
283
+ computedWithControls ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
284
+ Component,
285
+ {
286
+ page: "next",
287
+ className: "ui-pagination-item-next",
288
+ isDisabled: isDisabled || currentPage === total,
289
+ ...controlProps,
290
+ ...controlNextProps,
291
+ onClick: (0, import_utils3.handlerAll)(controlProps == null ? void 0 : controlProps.onClick, controlNextProps == null ? void 0 : controlNextProps.onClick, onNext)
292
+ }
293
+ ) : null,
294
+ computedWithEdges ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
295
+ Component,
296
+ {
297
+ page: "last",
298
+ className: "ui-pagination-item-last",
299
+ isDisabled: isDisabled || currentPage === total,
300
+ ...edgeProps,
301
+ ...edgeLastProps,
302
+ onClick: (0, import_utils3.handlerAll)(edgeProps == null ? void 0 : edgeProps.onClick, edgeLastProps == null ? void 0 : edgeLastProps.onClick, onLast)
303
+ }
304
+ ) : null
305
+ ]
306
+ }
307
+ ) });
308
+ });
309
+ // Annotate the CommonJS export names for ESM import in node:
310
+ 0 && (module.exports = {
311
+ Pagination
312
+ });